def __init__(self): self.connection = connect_client(type=peers.AMPLIFIER) # We need to get basic configuration from hashtable as # other modules will expect the same configuration.. # sampling rate self.sampling_rate = int( self.connection.query(message="SamplingRate", type=types.DICT_GET_REQUEST_MESSAGE).message) self.num_of_channels = int( self.connection.query(message="NumOfChannels", type=types.DICT_GET_REQUEST_MESSAGE).message) sampleVector = variables_pb2.SampleVector() for x in range(self.num_of_channels): samp = sampleVector.samples.add() samp.value = float(x) samp.timestamp = time.time() self.msg1 = sampleVector.SerializeToString() sampleVector = variables_pb2.SampleVector() for x in range(self.num_of_channels): samp = sampleVector.samples.add() samp.value = float(x * -1) samp.timestamp = time.time() self.msg2 = sampleVector.SerializeToString() self.num_of_samples = 0 self.msg_type = 0
def __init__(self, addresses, context=ctx.get_dummy_context('UgmBlinkingConnection')): self.connection = connect_client(type=peers.UGM_ENGINE, addresses=addresses) self.context = context self.blink_msg = variables_pb2.Blink()
def run(): configs = configurer.Configurer(settings.MULTIPLEXER_ADDRESSES).get_configs(['SPELLER_TEXT_ID', 'PEER_READY'+str(peers.UGM)]) msg = {'id': int(configs['SPELLER_TEXT_ID']), 'message': "" } msgs = [] msgs.append( msg) conn = connect_client(type = peers.ETR_AMPLIFIER) l_ugm_msg = variables_pb2.UgmUpdate() l_ugm_msg.type = 1 l_ugm_msg.value = "" prev = os.popen('xsel -b').read() while True: s = os.popen('xsel -b').read() if s != prev: print(s) msg['message'] = s.decode('utf-8') l_ugm_msg.value = str(msgs) conn.send_message( message = l_ugm_msg.SerializeToString(), type=types.UGM_UPDATE_MESSAGE, flush=True) prev = s time.sleep(SLEEP_TIME)
def __init__(self): self.connection = connect_client(type = peers.AMPLIFIER) # We need to get basic configuration from hashtable as # other modules will expect the same configuration.. # sampling rate self.sampling_rate = int(self.connection.query( message="SamplingRate", type=types.DICT_GET_REQUEST_MESSAGE).message) self.num_of_channels = int(self.connection.query( message="NumOfChannels", type=types.DICT_GET_REQUEST_MESSAGE).message) sampleVector = variables_pb2.SampleVector() for x in range(self.num_of_channels): samp = sampleVector.samples.add() samp.value = float(x) samp.timestamp = time.time() self.msg1 = sampleVector.SerializeToString() sampleVector = variables_pb2.SampleVector() for x in range(self.num_of_channels): samp = sampleVector.samples.add() samp.value = float(x*-1) samp.timestamp = time.time() self.msg2 = sampleVector.SerializeToString() self.num_of_samples = 0 self.msg_type = 0
def __init__(self, addresses, type, external_config_file=None): self.conn = connect_client(addresses=addresses, type=type) self.ready_to_work = False self.external_config_file = external_config_file self.config = PeerControl(peer=self) self.logger = get_logger(self.config.peer_id, file_level=self.get_param('file_log_level'), stream_level=self.get_param('console_log_level'), mx_level=self.get_param('mx_log_level'), conn=self.conn, log_dir=self.get_param('log_dir')) self.config.logger = self.logger self.config.connection = self.conn self.config.peer_validate_params = self.validate_params self.config.peer_params_change = self.params_changed result, details = self.config.initialize_config(self.conn) if not result: self.logger.critical( 'Config initialisation FAILED: {0}'.format(details)) sys.exit(1) else: self.validate_params(self.config.param_values())
def configure_amplifier(number_of_channels, sampling, values_type): print("Start configuring amplifier...") c = connect_client(type=peers.AMPLIFIER) set_hashtable_value(c, "SamplingRate", str(sampling)) set_hashtable_value(c, "NumOfChannels", str(number_of_channels)) set_hashtable_value(c, "Gain", ' '.join(['1.0'] * number_of_channels)) set_hashtable_value(c, "Offset", ' '.join(['0.0'] * number_of_channels)) if values_type == 1: #set last channel to sample number ... set_hashtable_value( c, "ChannelsNames", ';'.join([str(i) for i in range(number_of_channels - 1)] + ['SAMPLE_NUMBER'])) set_hashtable_value( c, "AmplifierChannelsToRecord", ' '.join([str(i) for i in range(number_of_channels - 1)] + ['sample'])) else: set_hashtable_value( c, "ChannelsNames", ';'.join([str(i) for i in range(number_of_channels)])) set_hashtable_value( c, "AmplifierChannelsToRecord", ' '.join([str(i) for i in range(number_of_channels)])) print("Amplifier configured!")
def __init__(self, peer=None, connection=None, param_validate_method=None, param_change_method=None): self.core = peer_config.PeerConfig() self.peer = peer self.peer_validate_params = param_validate_method self.peer_params_changed = param_change_method self.peer_id = None self.base_config_path = None self.connection = connection self.query_conn = conn = connect_client( type=peers.CONFIGURER, addresses=settings.MULTIPLEXER_ADDRESSES) self.cmd_overrides = {} self.file_list = [] self.logger = LOGGER # parse command line self.process_command_line() self._load_provided_configs() if self.peer_validate_params: if self.connection: self.initialize_config(self.connection) else: self.initialize_config_locally()
def __init__(self, addresses, type, external_config_file=None): self.conn = connect_client(addresses=addresses, type=type) self.ready_to_work = False self.external_config_file = external_config_file self.config = PeerControl(peer=self) self.logger = get_logger( self.config.peer_id, file_level=self.get_param('file_log_level'), stream_level=self.get_param('console_log_level'), mx_level=self.get_param('mx_log_level'), sentry_level=self.get_param('sentry_log_level'), conn=self.conn, log_dir=self.get_param('log_dir'), obci_peer=self) self.config.logger = self.logger self.config.connection = self.conn self.config.peer_validate_params = self.validate_params self.config.peer_params_change = self.params_changed result, details = self.config.initialize_config(self.conn) if not result: self.logger.critical( 'Config initialisation FAILED: {0}'.format(details)) sys.exit(1) else: self.validate_params(self.config.param_values())
def run(): configs = configurer.Configurer( settings.MULTIPLEXER_ADDRESSES).get_configs( ['SPELLER_TEXT_ID', 'PEER_READY' + str(peers.UGM)]) msg = {'id': int(configs['SPELLER_TEXT_ID']), 'message': ""} msgs = [] msgs.append(msg) conn = connect_client(type=peers.ETR_AMPLIFIER) l_ugm_msg = variables_pb2.UgmUpdate() l_ugm_msg.type = 1 l_ugm_msg.value = "" prev = os.popen('xsel -b').read() while True: s = os.popen('xsel -b').read() if s != prev: print(s) msg['message'] = s.decode('utf-8') l_ugm_msg.value = str(msgs) conn.send_message(message=l_ugm_msg.SerializeToString(), type=types.UGM_UPDATE_MESSAGE, flush=True) prev = s time.sleep(SLEEP_TIME)
def __init__(self, peer=None, connection=None, param_validate_method=None, param_change_method=None): self.core = peer_config.PeerConfig() self.peer = peer self.peer_validate_params = param_validate_method self.peer_params_changed = param_change_method self.peer_id = None self.base_config_path = None self.connection = connection self.query_conn = conn = connect_client(type=peers.CONFIGURER, addresses=settings.MULTIPLEXER_ADDRESSES) self.cmd_overrides = {} self.file_list = [] self.logger = LOGGER # parse command line self.process_command_line() self._load_provided_configs() if self.peer_validate_params: if self.connection: self.initialize_config(self.connection) else: self.initialize_config_locally()
def __init__(self): self.connection = connect_client(type=peers.AMPLIFIER) self.device_name = self.connection.query( message="BraintronicsDeviceName", type=types.DICT_GET_REQUEST_MESSAGE).message self.channel_numbers = [int(x) for x in \ self.connection.query(message="AmplifierChannelsToRecord", type=types.DICT_GET_REQUEST_MESSAGE).message.split(" ")] self.device = serial.Serial(self.device_name, baudrate=921600, timeout=3)
def __init__(self, channel_number): QtGui.QWidget.__init__(self, None) self.channel_number = channel_number timer = QtCore.QTimer(self) self.connect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()")) timer.start(250) self.setWindowTitle(self.tr("Spectrum of channel " + str(channel_number))) self.resize(680, 540) self.connection = connect_client(type = peers.MONITOR) self.sampling_rate = int(self.connection.query(message="SamplingRate", type=types.DICT_GET_REQUEST_MESSAGE).message)
def __init__(self): self._connection = connect_client(type = peers.LOGIC) self._long_mgr = UgmConfigManager() self._long_mgr.update_from_file(LONG_FILE, True) self._word_mgr = UgmConfigManager() self._word_mgr.update_from_file(WORD_FILE, True) self.fixation = '+' self.mask = 'XXXXXXXXXXXXXX' self.available_keys = ['1','2','3','4','5'] self.word_config = {'id':5555, 'message':''} self.img_config = {'id':6666, 'image_path':''} self.data_manager = DataManager() self.run_tag = {}
def __init__(self): self._connection = connect_client(type=peers.LOGIC) self._long_mgr = UgmConfigManager() self._long_mgr.update_from_file(LONG_FILE, True) self._word_mgr = UgmConfigManager() self._word_mgr.update_from_file(WORD_FILE, True) self.fixation = '+' self.mask = 'XXXXXXXXXXXXXX' self.available_keys = ['1', '2', '3', '4', '5'] self.word_config = {'id': 5555, 'message': ''} self.img_config = {'id': 6666, 'image_path': ''} self.data_manager = DataManager() self.run_tag = {}
def run(self): conn = connect_client(type=peers.CONFIGURER, addresses=settings.MULTIPLEXER_ADDRESSES) time.sleep(4) for i in range(5): msg = cmsg.fill_msg(types.UPDATE_PARAMS, sender="p_a") params = dict(p=str(i)) cmsg.dict2params(params, msg) try: conn.send_message(message=msg, type=types.UPDATE_PARAMS) resp, sth = conn.receive_message() msg = cmsg.unpack_msg(resp.type, resp.message) print "got ", msg except Exception as e: print "error: ", e.args, " ", type(e) print i
def configure_amplifier(number_of_channels, sampling, values_type): print("Start configuring amplifier...") c = connect_client(type = peers.AMPLIFIER) set_hashtable_value(c, "SamplingRate", str(sampling)) set_hashtable_value(c, "NumOfChannels", str(number_of_channels)) set_hashtable_value(c, "Gain", ' '.join(['1.0']*number_of_channels)) set_hashtable_value(c, "Offset", ' '.join(['0.0']*number_of_channels)) if values_type == 1: #set last channel to sample number ... set_hashtable_value(c, "ChannelsNames", ';'.join([str(i) for i in range(number_of_channels-1)]+['SAMPLE_NUMBER'])) set_hashtable_value(c, "AmplifierChannelsToRecord", ' '.join([str(i) for i in range(number_of_channels-1)]+['sample'])) else: set_hashtable_value(c, "ChannelsNames", ';'.join([str(i) for i in range(number_of_channels)])) set_hashtable_value(c, "AmplifierChannelsToRecord", ' '.join([str(i) for i in range(number_of_channels)])) print("Amplifier configured!")
def send_to_ugm(self): if USE_MULTIPLEXER: l_type = 0 l_msg = variables_pb2.UgmUpdate() l_msg.type = int(l_type) l_msg.value = self.config_manager.config_to_message() # Everything done :) All that is left is to establish connection if needed... if not self._connection: self._connection = connect_client(type=peers.LOGIC) # ...and send message to UGM self._connection.send_message(message=l_msg.SerializeToString(), type=types.UGM_UPDATE_MESSAGE, flush=True) else: self.config_manager.update_to_file('ugm_config', True)
def __init__(self, number_of_channels, sampling_frequency, duration, values_type): self.number_of_channels = number_of_channels self.sampling_frequency = sampling_frequency if duration == 0: self.duration = sys.float_info.max else: self.duration = duration #0 - sequential number, 1 - random numbers self.values_type = values_type self._configurer = configurer.Configurer(settings.MULTIPLEXER_ADDRESSES) self._samples_per_vector = int(self._configurer.get_configs(["SamplesPerVector"])['SamplesPerVector']) self._init_configuration() self._init_rest() self.connection = connect_client(type = peers.AMPLIFIER) self._configurer.set_configs({"PEER_READY":str(peers.AMPLIFIER)}, self.connection)
def send_to_ugm(self): if USE_MULTIPLEXER: l_type = 0 l_msg = variables_pb2.UgmUpdate() l_msg.type = int(l_type) l_msg.value = self.config_manager.config_to_message() # Everything done :) All that is left is to establish connection if needed... if not self._connection: self._connection = connect_client(type = peers.LOGIC) # ...and send message to UGM self._connection.send_message( message = l_msg.SerializeToString(), type=types.UGM_UPDATE_MESSAGE, flush=True) else: self.config_manager.update_to_file('ugm_config', True)
def update_diode_freqs(self, p_freqs): l_freq_str = p_freqs if not isinstance(p_freqs, basestring): l_freq_str = " ".join(['%s' % i for i in p_freqs]) if USE_MULTIPLEXER: l_msg = variables_pb2.Variable() l_msg.key = "Freqs" l_msg.value = l_freq_str # Everything done :) All that is left is to establish connection if needed... if not self._connection: self._connection = connect_client(type=peers.LOGIC) # ...and send message to diode control self._connection.send_message(message=l_msg.SerializeToString(), type=types.DIODE_UPDATE_MESSAGE, flush=True)
def __init__(self, channel_number): QtGui.QWidget.__init__(self, None) self.channel_number = channel_number timer = QtCore.QTimer(self) self.connect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()")) timer.start(100) self.setWindowTitle(self.tr("Monitor of channel " + str(channel_number))) self.resize(512, 512) self.connection = connect_client(type = peers.MONITOR) self.sampling_rate = int(self.connection.query(message="SamplingRate", \ type=types.DICT_GET_REQUEST_MESSAGE).message) self.vec = variables_pb2.SampleVector()
def update_diode_freqs(self, p_freqs): l_freq_str = p_freqs if not isinstance(p_freqs, basestring): l_freq_str = " ".join(['%s' % i for i in p_freqs]) if USE_MULTIPLEXER: l_msg = variables_pb2.Variable() l_msg.key = "Freqs" l_msg.value = l_freq_str # Everything done :) All that is left is to establish connection if needed... if not self._connection: self._connection = connect_client(type = peers.LOGIC) # ...and send message to diode control self._connection.send_message( message = l_msg.SerializeToString(), type=types.DIODE_UPDATE_MESSAGE, flush=True)
def __init__(self, channel_number): QtGui.QWidget.__init__(self, None) self.channel_number = channel_number timer = QtCore.QTimer(self) self.connect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()")) timer.start(250) self.setWindowTitle( self.tr("Spectrum of channel " + str(channel_number))) self.resize(680, 540) self.connection = connect_client(type=peers.MONITOR) self.sampling_rate = int( self.connection.query(message="SamplingRate", type=types.DICT_GET_REQUEST_MESSAGE).message)
def __init__(self, channel_number): QtGui.QWidget.__init__(self, None) self.channel_number = channel_number timer = QtCore.QTimer(self) self.connect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()")) timer.start(100) self.setWindowTitle( self.tr("Monitor of channel " + str(channel_number))) self.resize(512, 512) self.connection = connect_client(type=peers.MONITOR) self.sampling_rate = int(self.connection.query(message="SamplingRate", \ type=types.DICT_GET_REQUEST_MESSAGE).message) self.vec = variables_pb2.SampleVector()
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.spare_conn = connect_client(addresses=addresses, type=peers.CONFIGURER) 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)
def __init__(self, number_of_channels, sampling_frequency, duration, values_type): self.number_of_channels = number_of_channels self.sampling_frequency = sampling_frequency if duration == 0: self.duration = sys.float_info.max else: self.duration = duration #0 - sequential number, 1 - random numbers self.values_type = values_type self._configurer = configurer.Configurer( settings.MULTIPLEXER_ADDRESSES) self._samples_per_vector = int( self._configurer.get_configs(["SamplesPerVector" ])['SamplesPerVector']) self._init_configuration() self._init_rest() self.connection = connect_client(type=peers.AMPLIFIER) self._configurer.set_configs({"PEER_READY": str(peers.AMPLIFIER)}, self.connection)
def sendToUgm(self): """Sends currently edited config to UGM, if it's running""" # # Change config managers loaded config self.configManager.set_full_config(self.propertiesModel.createConfigNode()) # # We check whether we changed model structure: added or removed fields, # # changed ids, because if we did then we must send different message type if self.propertiesModel.structureModified: l_type = 0 self.propertiesModel.structureModified = False else: l_type = 1 l_msg = variables_pb2.UgmUpdate() l_msg.type = int(l_type) l_msg.value = self.configManager.config_to_message() # # # Everything done :) All that is left is to establish connection if needed... if not self._connection: self._connection = connect_client(type = peers.LOGIC_DECISION, addresses=settings.MULTIPLEXER_ADDRESSES) # ...and send message to UGM self._connection.send_message( message = l_msg.SerializeToString(), type=types.UGM_UPDATE_MESSAGE, flush=True)
def __init__(self): """Init connection to be used to send UGM_UPDATE_MESSAGES.""" self._connection = connect_client(type=peers.LOGIC)
def __init__(self): """Init connection to be used to send UGM_UPDATE_MESSAGES.""" self._connection = connect_client(type = peers.LOGIC)
def __init__(self, addresses,context=ctx.get_dummy_context('UgmBlinkingConnection')): self.connection = connect_client(type = peers.UGM_ENGINE, addresses=addresses) self.context = context self.blink_msg = variables_pb2.Blink()
def __init__(self): self.connection = connect_client(type = peers.AMPLIFIER) self.device_name = self.connection.query(message="BraintronicsDeviceName", type=types.DICT_GET_REQUEST_MESSAGE).message self.channel_numbers = [int(x) for x in \ self.connection.query(message="AmplifierChannelsToRecord", type=types.DICT_GET_REQUEST_MESSAGE).message.split(" ")] self.device = serial.Serial(self.device_name, baudrate=921600, timeout=3)