(self, packet)
Decode the packet and call the appropriate handler for the packet type.

        packet -- a list of bytes in the packet to decode.

        Raises an UnknownMessageType if the message could not be decoded.

        Returns a tuple of (PacketType, dict response data)

          BGAPI packet structure (as of 2012-11-07):
            Byte 0:
                  [7] - 1 bit, Message Type (MT)     Command/Response, 1 = Event
                [6:3] - 4 bits, Technology Type (TT)    0000 = BLE, 0001 = Wi-Fi
                [2:0] - 3 bits, Length High (LH)      Payload length (high bits)
            Byte 1:     8 bits, Length Low (LL)        Payload length (low bits)
            Byte 2:     8 bits, Class ID (CID)          Command class ID
            Byte 3:     8 bits, Command ID (CMD)         Command ID
            Bytes 4-n:  0 - 2048 Bytes, Payload (PL) Up to 2048 bytes of payload
Decode the packet and call the appropriate handler for the packet type.
Decode the packet and call the appropriate handler for the packet type .
def decode_packet(self, packet):
        """
        Decode the packet and call the appropriate handler for the packet type.

        packet -- a list of bytes in the packet to decode.

        Raises an UnknownMessageType if the message could not be decoded.

        Returns a tuple of (PacketType, dict response data)

          BGAPI packet structure (as of 2012-11-07):
            Byte 0:
                  [7] - 1 bit, Message Type (MT)     Command/Response, 1 = Event
                [6:3] - 4 bits, Technology Type (TT)    0000 = BLE, 0001 = Wi-Fi
                [2:0] - 3 bits, Length High (LH)      Payload length (high bits)
            Byte 1:     8 bits, Length Low (LL)        Payload length (low bits)
            Byte 2:     8 bits, Class ID (CID)          Command class ID
            Byte 3:     8 bits, Command ID (CMD)         Command ID
            Bytes 4-n:  0 - 2048 Bytes, Payload (PL) Up to 2048 bytes of payload
        """
        packet_id, payload_length, packet_class, packet_command = packet[:4]
        # TODO we are not parsing out the high bits of the payload length from
        # the first byte
        payload = bytearray(packet[4:])
        message_type = packet_id & 0x88
        if message_type == 0:
            return self._decode_response_packet(
                packet_class, packet_command, payload, payload_length)
        elif message_type == 0x80:
            return self._decode_event_packet(
                packet_class, packet_command, payload, payload_length)

        raise UnknownMessageType(
            "The message type '%d' is not recognized as the request or "
            "response type, and cannot be decoded" % message_type)
def decode_packet ( self , packet ) : packet_id , payload_length , packet_class , packet_command = packet [ : 4 ] # TODO we are not parsing out the high bits of the payload length from # the first byte payload = bytearray ( packet [ 4 : ] ) message_type = packet_id & 0x88 if message_type == 0 : return self . _decode_response_packet ( packet_class , packet_command , payload , payload_length ) elif message_type == 0x80 : return self . _decode_event_packet ( packet_class , packet_command , payload , payload_length ) raise UnknownMessageType ( "The message type '%d' is not recognized as the request or " "response type, and cannot be decoded" % message_type )