def _handle_watch_message(self, message):
        """
        Processes a binary message received from the watch and broadcasts the relevant events.

        :param message: A raw message from the watch, without any transport framing.
        :type message: bytes
        """
        while len(message) >= 4:
            if self.log_protocol_level is not None:
                logger.log(self.log_protocol_level, "<- %s", hexlify(message).decode())
            packet, length = PebblePacket.parse_message(message)
            self.event_handler.broadcast_event("raw_inbound", message[:length])
            if self.log_packet_level is not None:
                logger.log(self.log_packet_level, "<- %s", packet)
            message = message[length:]
            self.event_handler.broadcast_event((_EventType.Watch, type(packet)), packet)
            if length == 0:
                break
    def _handle_watch_message(self, message):
        """
        Processes a binary message received from the watch and broadcasts the relevant events.

        :param message: A raw message from the watch, without any transport framing.
        :type message: bytes
        """
        while len(message) >= 4:
            if self.log_protocol_level is not None:
                logger.log(self.log_protocol_level, "<- %s",
                           hexlify(message).decode())
            packet, length = PebblePacket.parse_message(message)
            self.event_handler.broadcast_event("raw_inbound", message[:length])
            if self.log_packet_level is not None:
                logger.log(self.log_packet_level, "<- %s", packet)
            message = message[length:]
            self.event_handler.broadcast_event(
                (_EventType.Watch, type(packet)), packet)
            if length == 0:
                break
Exemple #3
0
    def _handle_watch_message(self, message):
        """
        Processes a binary message received from the watch and broadcasts the relevant events.

        :param message: A raw message from the watch, without any transport framing.
        :type message: bytes
        """
        if self.log_protocol_level is not None:
            logger.log(self.log_protocol_level, "<- %s",
                       hexlify(message).decode())
        message = self.pending_bytes + message

        while len(message) >= 4:
            try:
                packet, length = PebblePacket.parse_message(message)
            except IncompleteMessage:
                self.pending_bytes = message
                break
            except:
                # At this point we've failed to deconstruct the message via normal means, but we don't want to end
                # up permanently desynced (because we wiped a partial message), nor do we want to get stuck (because
                # we didn't wipe anything). We therefore parse the packet length manually and skip ahead that far.
                # If the expected length is 0, we wipe everything to ensure forward motion (but we are quite probably
                # screwed).
                expected_length, = struct.unpack('!H', message[:2])
                if expected_length == 0:
                    self.pending_bytes = b''
                else:
                    self.pending_bytes = message[expected_length + 4:]
                raise

            self.event_handler.broadcast_event("raw_inbound", message[:length])
            if self.log_packet_level is not None:
                logger.log(self.log_packet_level, "<- %s", packet)
            message = message[length:]
            self.event_handler.broadcast_event(
                (_EventType.Watch, type(packet)), packet)
            if length == 0:
                break
        self.pending_bytes = message
    def _handle_watch_message(self, message):
        """
        Processes a binary message received from the watch and broadcasts the relevant events.

        :param message: A raw message from the watch, without any transport framing.
        :type message: bytes
        """
        if self.log_protocol_level is not None:
            logger.log(self.log_protocol_level, "<- %s", hexlify(message).decode())
        message = self.pending_bytes + message

        while len(message) >= 4:
            try:
                packet, length = PebblePacket.parse_message(message)
            except IncompleteMessage:
                self.pending_bytes = message
                break
            except:
                # At this point we've failed to deconstruct the message via normal means, but we don't want to end
                # up permanently desynced (because we wiped a partial message), nor do we want to get stuck (because
                # we didn't wipe anything). We therefore parse the packet length manually and skip ahead that far.
                # If the expected length is 0, we wipe everything to ensure forward motion (but we are quite probably
                # screwed).
                expected_length, = struct.unpack('!H', message[:2])
                if expected_length == 0:
                    self.pending_bytes = b''
                else:
                    self.pending_bytes = message[expected_length + 4:]
                raise

            self.event_handler.broadcast_event("raw_inbound", message[:length])
            if self.log_packet_level is not None:
                logger.log(self.log_packet_level, "<- %s", packet)
            message = message[length:]
            self.event_handler.broadcast_event((_EventType.Watch, type(packet)), packet)
            if length == 0:
                break
        self.pending_bytes = message