Handle RF messages.

        :param data: RF message to parse
        :type data: string

        :returns: :py:class:`~alarmdecoder.messages.RFMessage`
334827
def _handle_rfx(self, data):
        
        msg = RFMessage(data)

        self.on_rfx_message(message=msg)

        return msg
973125
def raw_data(self, event):
        

        self.log('Received raw data from bus', lvl=events)
        if not parse:
            return

        nmea_time = event.data[0]
        try:
            parsed_data = parse(event.data[1])
        except Exception as e:
            self.log('Unparseable sentence:', event.data[1], e, type(e),
                     exc=True, lvl=warn)
            self.unparsable += event
            return

        bus = event.bus

        sensor_data_package = self._handle(parsed_data)

        self.log("Sensor data:", sensor_data_package, lvl=verbose)

        if sensor_data_package:
            # pprint(sensor_data_package)
            self.fireEvent(sensordata(sensor_data_package, nmea_time, bus),
                           "navdata")
203917
def logic(self, data):
        
        try:
            msg = Message(data, self)
            msg.validate(self.protocol_version)
        except (ValueError, vol.Invalid) as exc:
            _LOGGER.warning('Not a valid message: %s', exc)
            return None

        message_type = self.const.MessageType(msg.type)
        handler = message_type.get_handler(self.handlers)
        ret = handler(msg)
        ret = self._route_message(ret)
        ret = ret.encode() if ret else None
        return ret
114563
def _handle_heartbeat(self, sender, data):
        
        # Format of packet
        parsed, data = self._unpack("<B", data)
        format = parsed[0]
        if format == PACKET_FORMAT_VERSION:
            # Kind of beat
            parsed, data = self._unpack("<B", data)
            kind = parsed[0]
            if kind == PACKET_TYPE_HEARTBEAT:
                # Extract content
                parsed, data = self._unpack("<H", data)
                port = parsed[0]
                path, data = self._unpack_string(data)
                uid, data = self._unpack_string(data)
                node_uid, data = self._unpack_string(data)
                try:
                    app_id, data = self._unpack_string(data)
                except struct.error:
                    # Compatibility with previous version
                    app_id = herald.DEFAULT_APPLICATION_ID

            elif kind == PACKET_TYPE_LASTBEAT:
                # Peer is going away
                uid, data = self._unpack_string(data)
                app_id, data = self._unpack_string(data)
                port = -1
                path = None
                node_uid = None

            else:
                _logger.warning("Unknown kind of packet: %d", kind)
                return

            try:
                self._callback(kind, uid, node_uid, app_id, sender[0], port, path)
            except Exception as ex:
                _logger.exception("Error handling heart beat: %s", ex)
406504
def handleTickString(self, msg):
        

        df2use = self.marketData
        if self.contracts[msg.tickerId].m_secType in ("OPT", "FOP"):
            df2use = self.optionsData

        # create tick holder for ticker
        if msg.tickerId not in df2use.keys():
            df2use[msg.tickerId] = df2use[0].copy()

        # update timestamp
        if msg.tickType == dataTypes["FIELD_LAST_TIMESTAMP"]:
            ts = datetime.fromtimestamp(int(msg.value)) \
                .strftime(dataTypes["DATE_TIME_FORMAT_LONG_MILLISECS"])
            df2use[msg.tickerId].index = [ts]
            # self.log.debug("[TICK TS]: %s", ts)

            # handle trailing stop orders
            if self.contracts[msg.tickerId].m_secType not in ("OPT", "FOP"):
                self.triggerTrailingStops(msg.tickerId)
                self.handleTrailingStops(msg.tickerId)

            # fire callback
            self.ibCallback(caller="handleTickString", msg=msg)

        elif (msg.tickType == dataTypes["FIELD_RTVOLUME"]):

            # log handler msg
            # self.log_msg("rtvol", msg)

            tick = dict(dataTypes["RTVOL_TICKS"])
            (tick['price'], tick['size'], tick['time'], tick['volume'],
                tick['wap'], tick['single']) = msg.value.split(';')

            try:
                tick['last']       = float(tick['price'])
                tick['lastsize']   = float(tick['size'])
                tick['volume']     = float(tick['volume'])
                tick['wap']        = float(tick['wap'])
                tick['single']     = tick['single'] == 'true'
                tick['instrument'] = self.tickerSymbol(msg.tickerId)

                # parse time
                s, ms = divmod(int(tick['time']), 1000)
                tick['time'] = '{}.{:03d}'.format(
                    time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(s)), ms)

                # add most recent bid/ask to "tick"
                tick['bid']     = df2use[msg.tickerId]['bid'][0]
                tick['bidsize'] = int(df2use[msg.tickerId]['bidsize'][0])
                tick['ask']     = df2use[msg.tickerId]['ask'][0]
                tick['asksize'] = int(df2use[msg.tickerId]['asksize'][0])

                # self.log.debug("%s: %s\n%s", tick['time'], self.tickerSymbol(msg.tickerId), tick)

                # fire callback
                self.ibCallback(caller="handleTickString", msg=msg, tick=tick)

            except Exception:
                pass

        else:
            # self.log.info("tickString-%s", msg)
            # fire callback
            self.ibCallback(caller="handleTickString", msg=msg)
1324998
def _unpack(self, data):
        
        msg_magic, msg_length, msg_type = self._unpack_header(data)
        msg_size = self._struct_header_size + msg_length
        # XXX: Message shouldn't be any longer than the data
        payload = data[self._struct_header_size:msg_size]
        return payload.decode('utf-8', 'replace')
1280562
async def _string_data(self, data):
        
        reply = ''
        data = data[1:-1]
        for x in data:
            reply_data = x
            if reply_data:
                reply += chr(reply_data)
        if self.log_output:
            logging.info(reply)
        else:
            print(reply)
259530
def feed(self, data):
        
        assert isinstance(data, binary_type)

        self.parser.feed(data)

        # Render again.
        self.cli._redraw()

        # When a return value has been set (enter was pressed), handle command.
        if self.cli.is_returning:
            try:
                return_value = self.cli.return_value()
            except (EOFError, KeyboardInterrupt) as e:
                # Control-D or Control-C was pressed.
                logger.info('%s, closing connection.', type(e).__name__)
                self.close()
                return

            # Handle CLI command
            self._handle_command(return_value)
1294526
def _parse_message(self, data):
        
        match = self._regex.match(str(data))

        if match is None:
            raise InvalidMessageError('Received invalid message: {0}'.format(data))

        header, self.bitfield, self.numeric_code, self.panel_data, alpha = match.group(1, 2, 3, 4, 5)

        is_bit_set = lambda bit: not self.bitfield[bit] == "0"

        self.ready = is_bit_set(1)
        self.armed_away = is_bit_set(2)
        self.armed_home = is_bit_set(3)
        self.backlight_on = is_bit_set(4)
        self.programming_mode = is_bit_set(5)
        self.beeps = int(self.bitfield[6], 16)
        self.zone_bypassed = is_bit_set(7)
        self.ac_power = is_bit_set(8)
        self.chime_on = is_bit_set(9)
        self.alarm_event_occurred = is_bit_set(10)
        self.alarm_sounding = is_bit_set(11)
        self.battery_low = is_bit_set(12)
        self.entry_delay_off = is_bit_set(13)
        self.fire_alarm = is_bit_set(14)
        self.check_zone = is_bit_set(15)
        self.perimeter_only = is_bit_set(16)
        self.system_fault = is_bit_set(17)
        if self.bitfield[18] in list(PANEL_TYPES):
            self.panel_type = PANEL_TYPES[self.bitfield[18]]
        # pos 20-21 - Unused.
        self.text = alpha.strip('"')
        self.mask = int(self.panel_data[3:3+8], 16)

        if self.panel_type in (ADEMCO, DSC):
            if int(self.panel_data[19:21], 16) & 0x01 > 0:
                # Current cursor location on the alpha display.
                self.cursor_location = int(self.panel_data[21:23], 16)
301796
def _parse_message(self, data):
        
        try:
            header, values = data.split(':')
            address, channel, value = values.split(',')

            self.address = int(address)
            self.channel = int(channel)
            self.value = int(value)

        except ValueError:
            raise InvalidMessageError('Received invalid message: {0}'.format(data))

        if header == '!EXP':
            self.type = ExpanderMessage.ZONE
        elif header == '!REL':
            self.type = ExpanderMessage.RELAY
        else:
            raise InvalidMessageError('Unknown expander message header: {0}'.format(data))
533691
def _parse_message_to_mqtt(self, data):
        
        msg = Message(data, self)
        payload = str(msg.payload)
        msg.payload = ''
        # prefix/node/child/type/ack/subtype : payload
        return ('{}/{}'.format(self._out_prefix, msg.encode('/'))[:-2],
                payload, msg.ack)
1306042
def next(self, data=None):
        '''
        
        '''
        if data is None:
            if self.stream:
                data = self.stream.readline()
            else:
                return

        lines = (self.buffer + data).split('\n')
        self.buffer = lines.pop()

        for line in lines:
            try:
                msg = nmea.NMEASentence.parse(line)
                yield msg
            except nmea.ParseError as e:
                if self.errors == 'raise':
                    raise e
                if self.errors == 'yield':
                    yield e
                if self.errors == 'ignore':
                    pass
303961
def handle(self, data):
        
        self.dataResponseCode.append(self._doPut(self.sendURL + '/data', data=data))
306703
def parse(self, data):
        
        parsed_data = self.yacc.parse(
            data, lexer=self.lexer.get_yacc_compat_lexer(), debug=self.debug)
        self.errors = self.lexer.errors + self.errors
        return parsed_data, self.errors
734220
def dataReceived(self, data):
        
        self.stompBuffer.appendData(data)

        while True:
           msg = self.stompBuffer.getOneMessage()
           if msg is None:
               break

           returned = self.react(msg)
           if returned:
               self.transport.write(returned)
16586
def dataReceived(self, data):
        
        def write(result):
            print "Writing %r" % result
            self.transport.write(result)
        d = self.d()
        d.addCallback(write)  # errors are silently ignored!
        d.callback(data)
1365837
function (data) {
    var self = this;

    if (typeof data === 'object') {
      data = EJSON.stringify(data);
    }

    _.each(self.callbacks['message'], function (cb) {
      cb(data);
    });
  }