def handle_message(self, mxmsg): #always buffer signal if mxmsg.type == types.AMPLIFIER_SIGNAL_MESSAGE: l_msg = variables_pb2.SampleVector() l_msg.ParseFromString(mxmsg.message) #Supply buffer with sample data, the buffer will fire its #ret_func (that we defined as self.analysis.analyse) every 'every' samples self.buffer.handle_sample_vect(l_msg) if DEBUG: self.debug.next_sample() #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 ugm_helper.send_start_blinking(self.conn) else: self.no_response() return # What to do after everything is done... if mxmsg.type == types.DECISION_MESSAGE: self.buffer.clear_blinks() self._last_dec_time = time.time() self.analysis.newEpoch() ugm_helper.send_stop_blinking(self.conn) if mxmsg.type == types.BLINK_MESSAGE: l_msg = variables_pb2.Blink() l_msg.ParseFromString(mxmsg.message) self.buffer.handle_blink(l_msg) self.no_response()
def send_decision(self, dec): """Send dec message to the system (probably to LOGIC peer). dec is of integer type.""" self.logger.info("Sending dec message: "+str(dec)) self._last_dec_time = time.time() #self.buffer.clear() dont do it in p300 - just ignore some blinks sometimes ... self.buffer.clear_blinks() ugm_helper.send_stop_blinking(self.conn) self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True)