def handle_message(self, mxmsg): if mxmsg.type == types.ETR_CALIBRATION_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) data = res.channels self.logger.debug("GOT ETR CALIBRATION RESULTS: " + str(data)) self.handle_calibration_mesage(data) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: " + str(l_msg)) dec, ugm = self.handle_etr_message(l_msg) if dec >= 0: self.logger.debug("Sending dec message...") self.conn.send_message(message=str(dec), type=types.DECISION_MESSAGE, flush=True) elif ugm is not None: self.logger.debug("Sending ugm message...") ugm_helper.send_config(self.conn, ugm, 1) else: self.logger.info("Got notihing from manager...") self.no_response()
def handle_message(self, mxmsg): if mxmsg.type == types.ETR_SIGNAL_MESSAGE: l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) self._data_proxy.data_received(l_msg.x) self._data_proxy.data_received(l_msg.y) self.no_response()
def handle_message(self, mxmsg): #~ self.logger.info("EtrAnalysis\n") if mxmsg.type == types.ETR_CALIBRATION_RESULTS: #### What to do when receive ETR_MATRIX information res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) self.logger.debug("GOT ETR CALIBRATION RESULTS: "+str(res.channels)) #process blinks only when hold_time passed if self._last_dec_time > 0: t = time.time() - self._last_dec_time if t > self.hold_after_dec: self._last_dec_time = 0 else: self.no_response() return # What to do after everything is done... if mxmsg.type == types.DECISION_MESSAGE: self._last_dec_time = time.time() if mxmsg.type == types.ETR_SIGNAL_MESSAGE: #### What to do when receive ETR_SIGNAL information msg = variables_pb2.Sample2D() msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: "+str(msg)) # Save positions x, y = msg.x, msg.y self._update_buffor(np.array([[x],[y]])) # Turn position into heatmap m = self._calc_metric(x,y) self._update_heatmap(m) ugm = self.ugm_mgr.get_ugm_updates(self.feeds, msg) ugm_helper.send_config(self.conn, ugm, 1) self.nCount += 1 if self.nCount % self.nRefresh == 0: # Calc heatmap as probabilty density pdf = self._calc_pdf() # Send results to decision modul self._send_results() #~ elif mxmsg.type == types.BLINK_MESSAGE: #### What to do when receive BLINK_NO information #~ blink = variables_pb2.Blink() #~ blink.ParseFromString(mxmsg.message) #~ self.logger.debug("GOT BLINK: "+str(blink.index)+" / "+str(blink.timestamp)) self.no_response()
def get_msg(self, s): msg = variables_pb2.Sample2D() data = np.array([[s.channels[self.l_x_ind], s.channels[self.l_y_ind]], [s.channels[self.r_x_ind], s.channels[self.r_y_ind]] ]) * self.track data = np.sum(data, axis=0) if np.sum(self.track) == 4: data /= 2 msg.x = 1 - data[0] msg.y = data[1] msg.timestamp = s.timestamp return msg
def run(self): while True: time.sleep(self._sleep_s) l_msg = variables_pb2.Sample2D() if self._mode == "const": l_msg.x = self._mode_value l_msg.y = self._mode_value elif self._mode == "rand": l_msg.x = random.random() l_msg.y = random.random() l_msg.timestamp = time.time() self.process_message(l_msg)
def handle_message(self, mxmsg): if mxmsg.type == self.in_mx_signal_type: v = variables_pb2.SampleVector() v.ParseFromString(mxmsg.message) for s in v.samples: msg = variables_pb2.Sample2D() msg.x = s.channels[self.x_ind] msg.y = s.channels[self.y_ind] msg.timestamp = s.timestamp self.conn.send_message( message=msg.SerializeToString(), type=self.out_mx_signal_type, flush=True) self.no_response()
def handle_message(self, mxmsg): if mxmsg.type == self.in_mx_signal_type: v = variables_pb2.SampleVector() v.ParseFromString(mxmsg.message) for s in v.samples: msg = variables_pb2.Sample2D() x, y = wii_utils.get_x_y(s.channels[0], s.channels[1], s.channels[2], s.channels[3]) msg.x = 0.5 - x * 0.5 msg.y = 0.5 - y * 0.5 msg.timestamp = s.timestamp self.conn.send_message(message=msg.SerializeToString(), type=self.out_mx_signal_type, flush=True) self.no_response()
def handle_message(self, mxmsg): LOGGER.info("EtrAnalysis\n") if mxmsg.type == types.ETR_CALIBRATION_RESULTS: #### What to do when receive ETR_MATRIX information res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) LOGGER.debug("GOT ETR CALIBRATION RESULTS: " + str(res.channels)) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: #### What to do when receive ETR_SIGNAL information l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) LOGGER.debug("GOT MESSAGE: " + str(l_msg)) # Change shape of data x, y = l_msg.x, l_msg.y xy = np.array([[x], [y]]) self._update_buffor(xy) # Caunt metric m = self.metric(xy) self._update_heatmap(m) # Calc heatmap as probabilty density pdf = self._calc_pdf() ##self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) l_msg.ParseFromString(mxmsg.message) LOGGER.debug("GOT MESSAGE: " + str(l_msg)) #zrob cos z sygnalem elif mxmsg.type == types.BLINK_MESSAGE: #### What to do when receive BLINK_NO information blink = variables_pb2.Blink() blink.ParseFromString(mxmsg.message) LOGGER.debug("GOT BLINK: " + str(blink.index) + " / " + str(blink.timestamp)) self.no_response()
def _get_mx_message_from_etr(self, p_data): l_msg = variables_pb2.Sample2D() lst = p_data.split() if (len(lst) != 4): self.logger.info( "WARNING! Received data length != 4. Message ommited.") return None if lst[0] == 'x': try: l_msg.x = float(str(lst[1]).replace(",", ".")) except: self.logger.info( "WARNING! Error while unpacking x message. Message ommited." ) return None else: self.logger.info( "WARNING! received key different from x. Meesage ommited.") return None if lst[2] == 'y': try: l_msg.y = float(str(lst[3]).replace(",", ".")) except: self.logger.info( "WARNING! Error while unpacking y message. Message ommited." ) return None else: self.logger.info( "WARNING! received key different from y. Meesage ommited.") return None l_msg.timestamp = time.time() return l_msg