예제 #1
0
    def create_packet(raw, operating_mode):
        """
        Override method.
        
        Returns:
            :class:`.RX16IOPacket`.
            
        Raises:
            InvalidPacketException: if the bytearray length is less than 14. (start delim. + length (2 bytes) + frame
                type + 16bit addr. + rssi + receive options + rf data (5 bytes) + checksum = 14 bytes).
            InvalidPacketException: if the length field of 'raw' is different than its real length. (length field: bytes
                2 and 3)
            InvalidPacketException: if the first byte of 'raw' is not the header byte. See :class:`.SpecialByte`.
            InvalidPacketException: if the calculated checksum is different than the checksum field value (last byte).
            InvalidPacketException: if the frame type is different than :attr:`.ApiFrameType.RX_IO_16`.
            InvalidOperatingModeException: if ``operating_mode`` is not supported.
            
        .. seealso::
           | :meth:`.XBeePacket.create_packet`
           | :meth:`.XBeeAPIPacket._check_api_packet`
        """
        if operating_mode != OperatingMode.ESCAPED_API_MODE and operating_mode != OperatingMode.API_MODE:
            raise InvalidOperatingModeException(operating_mode.name +
                                                " is not supported.")

        if operating_mode == OperatingMode.ESCAPED_API_MODE:
            raw = XBeePacket.unescape_data(raw)

        XBeeAPIPacket._check_api_packet(
            raw, min_length=RX16IOPacket.__MIN_PACKET_LENGTH)

        if raw[3] != ApiFrameType.RX_IO_16.code:
            raise InvalidPacketException(
                "This packet is not an RX 16 IO packet.")

        return RX16IOPacket(XBee16BitAddress(raw[4:6]), raw[6], raw[7],
                            raw[8:-1])
예제 #2
0
    def create_packet(raw, operating_mode):
        """
        Override method.
        
        Returns:
            :class:`.TX64Packet`.
            
        Raises:
            InvalidPacketException: if the bytearray length is less than 15. (start delim. + length (2 bytes) + frame
                type + frame id + 64bit addr. + transmit options + checksum = 15 bytes).
            InvalidPacketException: if the length field of 'raw' is different than its real length. (length field: bytes
                2 and 3)
            InvalidPacketException: if the first byte of 'raw' is not the header byte. See :class:`.SpecialByte`.
            InvalidPacketException: if the calculated checksum is different than the checksum field value (last byte).
            InvalidPacketException: if the frame type is different than :attr:`.ApiFrameType.TX_64`.
            InvalidOperatingModeException: if ``operating_mode`` is not supported.
            
        .. seealso::
           | :meth:`.XBeePacket.create_packet`
           | :meth:`.XBeeAPIPacket._check_api_packet`
        """
        if operating_mode != OperatingMode.ESCAPED_API_MODE and operating_mode != OperatingMode.API_MODE:
            raise InvalidOperatingModeException(operating_mode.name +
                                                " is not supported.")

        if operating_mode == OperatingMode.ESCAPED_API_MODE:
            raw = XBeePacket.unescape_data(raw)

        XBeeAPIPacket._check_api_packet(
            raw, min_length=TX64Packet.__MIN_PACKET_LENGTH)

        if raw[3] != ApiFrameType.TX_64.code:
            raise InvalidPacketException("This packet is not a TX 64 packet.")

        return TX64Packet(raw[4], XBee64BitAddress(raw[5:13]), raw[13],
                          raw[14:-1])