Beispiel #1
0
    def handle_message(self, mxmsg):
        if mxmsg.type == types.BLINK_MESSAGE:
            l_msg = variables_pb2.Blink()
            l_msg.ParseFromString(mxmsg.message)
            self.logger.debug("Got blink message: " + str(l_msg.index))
            self._curr_index = int(l_msg.index)
        elif mxmsg.type == types.SWITCH_MESSAGE:
            #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

            if self._curr_index < 0:
                self.logger.warning(
                    "Got switch message, but curr_index < 0. Do nothing!!!")
            else:
                self.logger.info("Got switch message, send curr index == " +
                                 str(self._curr_index))
                self._last_dec_time = time.time()
                self.conn.send_message(message=str(self._curr_index),
                                       type=types.DECISION_MESSAGE,
                                       flush=True)
        else:
            self.logger.warning("Got unrecognised message: " + str(mxmsg.type))
        self.no_response()
Beispiel #2
0
    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

        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 __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 _handle_blink(self, msg):
     b = variables_pb2.Blink()
     b.ParseFromString(msg)
     LOGGER.debug("GOT BLINK: " + str(b.timestamp) + " / " + str(b.index))
     tags_helper.send_tag(self.conn, b.timestamp,
                          b.timestamp + self.blink_duration, "blink", {
                              "index": b.index,
                              "target": self.current_target
                          })
 def handle_message(self, mxmsg):
     if mxmsg.type == types.BLINK_MESSAGE:
         b = variables_pb2.Blink()
         b.ParseFromString(mxmsg.message)
         self.logger.debug("GOT BLINK: "+str(b.timestamp)+" / "+str(b.index))
         tags_helper.send_tag(self.conn, 
                              b.timestamp, b.timestamp+self.blink_duration, "blink",
                              {"index" : b.index})
     self.no_response()
Beispiel #6
0
    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()
Beispiel #7
0
    def handle_message(self, mxmsg):
        """Internal method, fired every time message is received.

        Args:
            mxmsg: message data
        """
        if mxmsg.type == types.AMPLIFIER_SIGNAL_MESSAGE:
            # we have received part of the signal
            data = variables_pb2.SampleVector()
            data.ParseFromString(mxmsg.message)
            self.buffer.handle_sample_vect(data)

        elif mxmsg.type == types.BLINK_MESSAGE:
            # we have received a single blink
            data = variables_pb2.Blink()
            data.ParseFromString(mxmsg.message)
            self.buffer.handle_blink(data)

        else:
            self.logger.warning("Got unrecognised message type: " +
                                str(mxmsg.type))
        self.no_response()
Beispiel #8
0
 def _get_message(self, tag, ts):
     blink_msg = variables_pb2.Blink()
     blink_msg.timestamp = ts
     blink_msg.index = self.index_lambda(tag)
     return blink_msg