当前位置: 首页>>代码示例>>Python>>正文


Python message.OBCIMessageTool类代码示例

本文整理汇总了Python中obci.control.common.message.OBCIMessageTool的典型用法代码示例。如果您正苦于以下问题:Python OBCIMessageTool类的具体用法?Python OBCIMessageTool怎么用?Python OBCIMessageTool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OBCIMessageTool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_new_experiments_and_push_results

def find_new_experiments_and_push_results(ctx, rq_message):
    LOGGER = logger.get_logger("eeg_AMPLIFIER_finder", "info")

    if not rq_message.amplifier_types:
        LOGGER.info("AMPLIFIER TYPES NOT SET, FINDING ALL...")
        driv = find_drivers()
    else:
        driv = []
        for amptype in rq_message.amplifier_types:

            if amptype == 'bt' or amptype == 'bluetooth':
                driv += find_bluetooth_amps()
            elif amptype == 'usb':
                driv += find_usb_amps()
            elif amptype == 'virtual':
                driv += find_virtual_amps()

    LOGGER.info("amplifiers! return to:  " + rq_message.client_push_address)
    mtool = OBCIMessageTool(message_templates)
    to_client = ctx.socket(zmq.PUSH)
    to_client.connect(rq_message.client_push_address)

    send_msg(to_client, mtool.fill_msg('eeg_amplifiers', sender_ip=socket.gethostname(),
                                       amplifier_list=driv))
    LOGGER.info("sent amplifier data... " + str(driv)[:500] + ' [...]')
    time.sleep(0.1)
开发者ID:mroja,项目名称:openbci,代码行数:26,代码来源:eeg_experiment_finder.py

示例2: broadcast_server

def broadcast_server(server_uuid, rep_port, pub_port, bcast_port):
    mtool = OBCIMessageTool(message_templates)

    str_msg = mtool.fill_msg("server_broadcast", sender_ip=socket.gethostname(), sender=server_uuid,
                             rep_port=rep_port, pub_port=pub_port)
    str_msg += b'\n'

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    # introduction
    for i in range(10):
        try:
            s.sendto(str_msg, ('<broadcast>', bcast_port))
        except socket.error as e:
            pass
        time.sleep(0.3)

    # updates
    while True:
        try:
            s.sendto(str_msg, ('<broadcast>', bcast_port))
        except socket.error as e:
            print("[obci_server] Cannot broadcast obci_server, will try again in 1min:", str(e))
            time.sleep(53)
        time.sleep(7)

    s.close()
开发者ID:mroja,项目名称:openbci,代码行数:29,代码来源:server_scanner.py

示例3: start_eeg_signal_experiment

def start_eeg_signal_experiment(ctx, srv_addrs, rq_message):
    client = OBCIClient(srv_addrs, ctx)
    # server_req_socket = ctx.socket(zmq.REQ)
    #     for addr in srv_addrs:
    #         server_req_socket.connect(addr)

    amp_params = {}
    amp_params.update(rq_message.amplifier_params['additional_params'])
    del rq_message.amplifier_params['additional_params']
    amp_params.update(rq_message.amplifier_params)

    par_list = ['--peer', 'amplifier']
    for par, val in amp_params.iteritems():
        par_list += ['-p', par, unicode(val)]

    overwrites = peer_cmd.peer_overwrites_pack(par_list)
    result = client.launch(rq_message.launch_file, None, rq_message.name, overwrites)


    LOGGER.info("START EEG signal! return to:  " + rq_message.client_push_address)
    mtool = OBCIMessageTool(message_templates)
    to_client = ctx.socket(zmq.PUSH)
    to_client.connect(rq_message.client_push_address)
    if result is None:
        send_msg(to_client, mtool.fill_msg("rq_error", err_code="launch_failed",
                    details="No response from server or experiment"))
    else:
        send_msg(to_client, result.raw())
    LOGGER.info("sent eeg launch result"  + str(result)[:500] )
    time.sleep(0.1)
开发者ID:niklasrogers,项目名称:openbci,代码行数:30,代码来源:start_eeg_signal.py

示例4: _gather_other_server_results

def _gather_other_server_results(ctx, this_addr, ip_list):
    exps = []
    if not ip_list:
        return exps
    mtool = OBCIMessageTool(message_templates)
    other_exps_pull = ctx.socket(zmq.PULL)
    port = other_exps_pull.bind_to_random_port('tcp://*',
                                               min_port=PORT_RANGE[0],
                                               max_port=PORT_RANGE[1], max_tries=500)

    my_push_addr = this_addr + ':' + str(port)
    LOGGER.info("my exp_data pull: " + my_push_addr)

    harvester = zmq.Poller()
    harvester.register(other_exps_pull)

    reqs = {}
    for srv_ip in ip_list:

        addr = 'tcp://' + srv_ip + ':' + net.server_rep_port()
        req = ctx.socket(zmq.REQ)
        req.connect(addr)
        send_msg(req, mtool.fill_msg('find_eeg_experiments',
                                     client_push_address='tcp://' + my_push_addr,
                                     checked_srvs=[this_addr]))
        harvester.register(req, zmq.POLLIN)
        reqs[req] = addr

    srv_responses = 0

    for i in range(len(reqs) * 50):
        socks = dict(harvester.poll(timeout=300))

        for req in socks:
            msg = recv_msg(req)
            msg = mtool.unpack_msg(msg)

            if msg.type == 'rq_ok':
                LOGGER.info("waiting for experiments from server: " + str(reqs[req]))
                harvester.unregister(req)
                req.close()

            elif msg.type == 'eeg_experiments':
                LOGGER.info("GOT EXPERIMENTS from: " + msg.sender_ip)
                exps += msg.experiment_list
                srv_responses += 1
            else:
                LOGGER.warning('strange msg:  ' + str(msg))
        if srv_responses == len(ip_list):
            print("GOT ALL eeg_experiment RESPONSES :-) [addr list:  ", ip_list, "]")
            break

    other_exps_pull.close()
    return exps
开发者ID:mroja,项目名称:openbci,代码行数:54,代码来源:eeg_experiment_finder.py

示例5: ObciBaseClient

class ObciBaseClient(object):
    """
    Base class for communicating with OBCI peers.
    """
    def __init__(self, address):
        self.context = zmq.Context.instance()
        templates = launcher_messages.message_templates
        self.msg_factory = OBCIMessageTool(msg_templates=templates)
        self.socket = self.context.socket(zmq.REQ)
        self.socket.connect(address)
        
        # disabled bc Ubuntu LTS uses archaic zmq version
        # self.socket.RCVTIMEO = 7000
        self.poller = zmq.Poller()
        self.poller.register(self.socket, zmq.POLLIN)
        
        self.open = True

    def close(self):
        if self.open:
            self.socket.close()
            self.open = False

    def send_recv(self, message_name, **kwargs):
        data = self.msg_factory.fill_msg(message_name, **kwargs)
        self.socket.send(data)
        poll_results = self.poller.poll(7000)
        response = self.socket.recv(zmq.NOBLOCK) if poll_results else None
        return json.loads(response)
开发者ID:BrainTech,项目名称:psychopy,代码行数:29,代码来源:obci_connection.py

示例6: __init__

    def __init__(self, proc_description,
                                reg_timeout_desc=None,
                                monitoring_optflags=PING,
                                logger=None):

        self.desc = proc_description

        self.must_register = reg_timeout_desc is not None
        self._status_lock = threading.RLock()
        self._status = UNKNOWN if self.must_register else RUNNING
        self._status_details = None

        self.ping_it = monitoring_optflags & PING
        self.check_returncode = monitoring_optflags & RETURNCODE if \
                                        self.desc.pid is not None else False

        self.logger = logger or get_logger(
                                'subprocess_monitor'+'-'+self.desc.name+'-'+str(self.desc.pid),
                                stream_level='info')
        self.set_registration_timeout_handler(reg_timeout_desc)
        self.registration_data = None

        self._stop_monitoring = False
        self._ping_thread = None
        self._ping_retries = 8
        self._returncode_thread = None
        self._mtool = OBCIMessageTool(message_templates)
        self._ctx = None
        self.rq_sock = None
        self._poller = PollingObject()

        self.delete = False
开发者ID:niklasrogers,项目名称:openbci,代码行数:32,代码来源:process.py

示例7: update_nearby_servers

def update_nearby_servers(srv_data, bcast_port, ctx=None, update_push_addr=None):
    mtool = OBCIMessageTool(message_templates)

    loops_to_update = _LOOPS

    s = socket(AF_INET, SOCK_DGRAM)
    s.bind(('', bcast_port))

    notify_sock = None
    if update_push_addr is not None:
        ctx = ctx if ctx else zmq.Context()
        notify_sock = ctx.socket(zmq.PUSH)
        notify_sock.connect(update_push_addr)

    while 1:
        changed = False
        try:
            inp, out, exc = select.select([s], [], [], UPDATE_INTERVAL / _LOOPS)
        except Exception, e:
            srv_data.logger.critical("nearby_servers_update - exception: %s", str(e))
            srv_data.logger.critical("nearby_servers - aborting")
            return

        if s in inp:
            data, wherefrom = s.recvfrom(1500, 0)
            # sys.stderr.write(repr(wherefrom) + '\n')
            # sys.stdout.write(data)
            msg = unicode(data, encoding='utf-8')
            msg = msg[:-1]
            message = mtool.unpack_msg(msg)
            changed = srv_data.update(ip=wherefrom[0], hostname=message.sender_ip,
                                      uuid=message.sender, rep_port=message.rep_port,
                                      pub_port=message.pub_port)

        else:
            # print "no data"
            pass

        loops_to_update -= 1

        if loops_to_update == 0:
            loops_to_update = _LOOPS
            changed = srv_data.clean_silent()

        if changed:
            send_msg(notify_sock, mtool.fill_msg('nearby_machines',
                                                 nearby_machines=srv_data.dict_snapshot()))
开发者ID:BrainTech,项目名称:openbci,代码行数:47,代码来源:server_scanner.py

示例8: __init__

 def __init__(self, zmq_ctx, uuid, logger=None, obci_dns=None):
     self._processes = {}
     self._ctx = zmq_ctx
     self.uuid = uuid
     self.logger = logger or get_logger('subprocess_monitor',
                             stream_level='warning')
     self.obci_dns = obci_dns
     self._mtool = OBCIMessageTool(message_templates)
     self.poller = PollingObject()
     self._proc_lock = threading.RLock()
开发者ID:karolaug,项目名称:openbci,代码行数:10,代码来源:subprocess_monitor.py

示例9: broadcast_server

def broadcast_server(server_uuid, rep_port, pub_port, bcast_port):
    mtool = OBCIMessageTool(message_templates)

    msg = mtool.fill_msg("server_broadcast", sender_ip=gethostname(), sender=server_uuid,
                         rep_port=rep_port, pub_port=pub_port)
    msg += u'\n'
    str_msg = msg.encode('utf-8')

    s = socket(AF_INET, SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)

    # introduction
    for i in range(10):
        try:
            s.sendto(str_msg, ('<broadcast>', bcast_port))
        except error, e:
            pass
        time.sleep(0.3)
开发者ID:BrainTech,项目名称:openbci,代码行数:19,代码来源:server_scanner.py

示例10: __init__

    def __init__(self, srv_addrs, ctx, client_push_address, nearby_servers):
        self.ctx = ctx
        self.server_req_socket = self.ctx.socket(zmq.REQ)
        for addr in srv_addrs:
            self.server_req_socket.connect(addr)

        self.poller = PollingObject()
        self.mtool = OBCIMessageTool(message_templates)
        self.nearby_servers = nearby_servers
        self._amplified_cache = {}
开发者ID:mroja,项目名称:openbci,代码行数:10,代码来源:eeg_experiment_finder.py

示例11: kill

    def kill(self):
        # send "kill" to the process or kill request to its supervisor?
        self.stop_monitoring()
        if not self._ctx:
            self._ctx = zmq.Context()
        rq_sock = self._ctx.socket(zmq.REQ)
        try:
            rq_sock.connect(self.rq_address)
            mtool = OBCIMessageTool(message_templates)
            poller = PollingObject()
            send_msg(rq_sock, mtool.fill_msg("kill_process", pid=self.pid, machine=self.machine_ip))
            res, _ = poller.poll_recv(rq_sock, timeout=5000)
        finally:
            rq_sock.close()
        if res:
            res = mtool.unpack_msg(res)
            print "Response to kill request: ", res

            with self._status_lock:
                self._status = TERMINATED
开发者ID:BrainTech,项目名称:openbci,代码行数:20,代码来源:remote_process.py

示例12: __init__

 def __init__(self, address):
     self.context = zmq.Context.instance()
     templates = launcher_messages.message_templates
     self.msg_factory = OBCIMessageTool(msg_templates=templates)
     self.socket = self.context.socket(zmq.REQ)
     self.socket.connect(address)
     
     # disabled bc Ubuntu LTS uses archaic zmq version
     # self.socket.RCVTIMEO = 7000
     self.poller = zmq.Poller()
     self.poller.register(self.socket, zmq.POLLIN)
     
     self.open = True
开发者ID:BrainTech,项目名称:psychopy,代码行数:13,代码来源:obci_connection.py

示例13: __init__

    def __init__(self, server_addresses, zmq_context=None):
        self.ctx = zmq_context if zmq_context else zmq.Context()

        self.server_addresses = server_addresses
        self.server_req_socket = None
        self.init_server_socket(server_addresses)

        # self = zmq.Poller()
        # self.register(self.server_req_socket, zmq.POLLIN)
        self.poller = PollingObject()

        self.mtool = OBCIMessageTool(message_templates)
        self.dns = net.DNS()
开发者ID:mroja,项目名称:openbci,代码行数:13,代码来源:obci_client.py

示例14: ConfigServer

class ConfigServer(BaseMultiplexerServer):
    @log_crash
    def __init__(self, addresses):
        super(ConfigServer, self).__init__(addresses=addresses, type=peers.CONFIG_SERVER)
        self._configs = {}
        self._ext_configs = {}
        self._ready_peers = []
        self.__to_all = False
        self.mtool = OBCIMessageTool(message_templates)
        self.launcher_sock = None
        params, other_params = PeerCmd().parse_cmd()

        self.addr = params['local_params'].get('launcher_socket_addr', '')

        self.exp_uuid = params['local_params'].get('experiment_uuid', '')
        self.log_dir = params['local_params'].get('log_dir', None)
        self.logger = get_logger('config_server', log_dir=self.log_dir,
                                conn=self.conn,
                                file_level=params['local_params'].get('file_log_level', None),
                                mx_level=params['local_params'].get('mx_log_level', None),
                                stream_level=params['local_params'].get('console_log_level', None))
        self._old_configs = self._stored_config()
        self._restore_peers = params['local_params'].get('restore_peers', '').split()

        for peer in self._restore_peers:
            if peer in self._old_configs["local"]:
                self._configs[peer] = dict(self._old_configs["local"][peer])
                self._ready_peers.append(peer)
            if peer in self._old_configs["ext"]:
                self._ext_configs[peer] = dict(self._old_configs["ext"][peer])

        if self.addr != '':
            self.ctx = zmq.Context()
            self.launcher_sock = self.ctx.socket(zmq.PUSH)
            try:
                self.launcher_sock.connect(self.addr)

            except Exception, e:
                self.logger.error("failed to connect to address " +\
                                             self.addr + " !!!")
                self.launcher_sock = None
            else:
                self.logger.info("OK: connected to " + self.addr)

                send_msg(self.launcher_sock, self.mtool.fill_msg("config_server_ready"))
        self.logger.info("connections count ::::::::: %s", self.conn.connections_count())
开发者ID:BrainTech,项目名称:openbci,代码行数:46,代码来源:config_server.py

示例15: __init__

    def __init__(self, preset_data=None, launcher_data=None, ctx=None):
        self.preset_data = preset_data
        self.launch_file = None
        self.launcher_data = launcher_data
        self.name = None
        self.info = ""
        self.public_params = []
        self.origin_machine = ''
        self.unsupervised_peers = {}
        self.old_uid = None

        self.ctx = ctx
        self.exp_req = None
        self.mtool = OBCIMessageTool(message_templates)
        self.poller = PollingObject()

        self.category = DEFAULT_CATEGORY

        if preset_data is not None:
            self.setup_from_preset(preset_data)

        elif launcher_data is not None:
            self.setup_from_launcher(launcher_data)
        super(ExperimentEngineInfo, self).__init__()
开发者ID:mroja,项目名称:openbci,代码行数:24,代码来源:experiment_engine_info.py


注:本文中的obci.control.common.message.OBCIMessageTool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。