예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
def find_eeg_experiments_and_push_results(ctx, srv_addrs, rq_message, nearby_servers):
    LOGGER = logger.get_logger("eeg_experiment_finder", "info")
    finder = EEGExperimentFinder(srv_addrs, ctx, rq_message.client_push_address, nearby_servers)
    exps = finder.find_amplified_experiments()
    mpoller = PollingObject()

    checked = rq_message.checked_srvs
    if not isinstance(checked, list):
        checked = []

    nrb = {}
    for uid, srv in nearby_servers.snapshot().iteritems():
        if srv.ip not in checked:
            nrb[uid] = srv

    if not checked and nearby_servers.dict_snapshot():
        my_addr = nearby_servers.ip(hostname=socket.gethostname())
        LOGGER.info("checking other servers")
        print [(srv.hostname, srv.ip) for srv in nrb.values()]
예제 #4
0
def find_eeg_experiments_and_push_results(ctx, srv_addrs, rq_message,
                                          nearby_servers):
    LOGGER = logger.get_logger("eeg_experiment_finder", "info")
    finder = EEGExperimentFinder(srv_addrs, ctx,
                                 rq_message.client_push_address,
                                 nearby_servers)
    exps = finder.find_amplified_experiments()
    mpoller = PollingObject()

    checked = rq_message.checked_srvs
    if not isinstance(checked, list):
        checked = []

    nrb = {}
    for uid, srv in nearby_servers.snapshot().iteritems():
        if srv.ip not in checked:
            nrb[uid] = srv

    if not checked and nearby_servers.dict_snapshot():
        my_addr = nearby_servers.ip(hostname=socket.gethostname())
        LOGGER.info("checking other servers")
        print[(srv.hostname, srv.ip) for srv in nrb.values()]

        ip_list = [srv.ip for srv in nrb.values() if \
                            srv.ip != my_addr]
        LOGGER.info("number of servers to query: " + str(len(ip_list)))

        exps += _gather_other_server_results(ctx, my_addr, ip_list)

    else:
        LOGGER.info("not checking other servers")

    LOGGER.info("return to:  " + rq_message.client_push_address)
    to_client = ctx.socket(zmq.PUSH)
    to_client.connect(rq_message.client_push_address)

    send_msg(
        to_client,
        finder.mtool.fill_msg('eeg_experiments',
                              sender_ip=socket.gethostname(),
                              experiment_list=exps))
    LOGGER.info("sent exp data... " + str(exps)[:500] + ' [...]')
    time.sleep(0.1)
예제 #5
0
def find_eeg_experiments_and_push_results(ctx, srv_addrs, rq_message, nearby_servers):
    LOGGER = logger.get_logger("eeg_experiment_finder", "info")
    finder = EEGExperimentFinder(srv_addrs, ctx, rq_message.client_push_address, nearby_servers)
    exps = finder.find_amplified_experiments()

    checked = rq_message.checked_srvs
    if not isinstance(checked, list):
        checked = []

    nrb = {}
    for uid, srv in nearby_servers.snapshot().items():
        if srv.ip not in checked:
            nrb[uid] = srv

    if not checked and nearby_servers.dict_snapshot():
        my_addr = nearby_servers.ip(hostname=socket.gethostname())
        LOGGER.info("checking other servers")
        print([(srv.hostname, srv.ip) for srv in nrb.values()])

        ip_list = [srv.ip for srv in nrb.values() if
                   srv.ip != my_addr]
        LOGGER.info("number of servers to query: " + str(len(ip_list)))

        exps += _gather_other_server_results(ctx, my_addr, ip_list)

    else:
        LOGGER.info("not checking other servers")

    LOGGER.info("return to:  " + rq_message.client_push_address)
    to_client = ctx.socket(zmq.PUSH)
    to_client.connect(rq_message.client_push_address)

    send_msg(to_client, finder.mtool.fill_msg('eeg_experiments', sender_ip=socket.gethostname(),
                                              experiment_list=exps))
    LOGGER.info("sent exp data... " + str(exps)[:500] + ' [...]')
    time.sleep(0.1)
예제 #6
0
import zmq
import time
import socket

import obci.control.common.net_tools as net
from obci.control.common.message import OBCIMessageTool, send_msg, recv_msg, PollingObject
from obci.control.launcher.launcher_messages import message_templates

import obci.control.launcher.launcher_logging as logger
import obci.control.launcher.launcher_tools as launcher_tools
from obci.control.common.obci_control_settings import PORT_RANGE

from obci.drivers.eeg.driver_discovery.driver_discovery import find_drivers, \
    find_bluetooth_amps, find_virtual_amps, find_usb_amps

LOGGER = logger.get_logger("eeg_experiment_finder", "info")


class EEGExperimentFinder(object):

    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 = {}
예제 #7
0
import json
import zmq
import time
import socket

import obci.control.common.net_tools as net
from obci.control.common.message import OBCIMessageTool, send_msg, recv_msg, PollingObject
from obci.control.launcher.launcher_messages import message_templates, error_codes
from obci.control.launcher.obci_client import OBCIClient

import obci.control.launcher.launcher_logging as logger
import obci.control.launcher.launcher_tools
from obci.control.common.obci_control_settings import PORT_RANGE
from obci.control.peer import peer_cmd

LOGGER = logger.get_logger("start_eeg_signal", "info")

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)]
예제 #8
0
import zmq
import time
import socket

import obci.control.common.net_tools as net
from obci.control.common.message import OBCIMessageTool, send_msg, recv_msg, PollingObject
from obci.control.launcher.launcher_messages import message_templates, error_codes
from obci.control.launcher.obci_client import OBCIClient

import obci.control.launcher.launcher_logging as logger
import obci.control.launcher.launcher_tools
from obci.control.common.obci_control_settings import PORT_RANGE
from obci.control.peer import peer_cmd
from obci.control.peer.config_defaults import CONFIG_DEFAULTS

LOGGER = logger.get_logger("start_eeg_signal", "info")


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():
예제 #9
0
import zmq
import time
import socket

import obci.control.common.net_tools as net
from obci.control.common.message import OBCIMessageTool, send_msg, recv_msg, PollingObject
from obci.control.launcher.launcher_messages import message_templates, error_codes

import obci.control.launcher.launcher_logging as logger
import obci.control.launcher.launcher_tools as launcher_tools
from obci.control.common.obci_control_settings import PORT_RANGE

from obci.drivers.eeg.driver_discovery.driver_discovery import find_drivers, \
find_bluetooth_amps, find_virtual_amps, find_usb_amps

LOGGER = logger.get_logger("eeg_experiment_finder", "info")


class EEGExperimentFinder(object):
    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 = {}

    def _running_experiments(self):