Exemplo n.º 1
0
    def __init__(self, api_frame_type):
        """
        Class constructor. Instantiates a new :class:`.XBeeAPIPacket` object with the provided parameters.
        
        Args:
            api_frame_type (:class:`.ApiFrameType` or Integer): The API frame type.

        .. seealso::
           | :class:`.ApiFrameType`
           | :class:`.XBeePacket`
        """
        super().__init__()
        # Check the type of the API frame type.
        if isinstance(api_frame_type, ApiFrameType):
            self._frame_type = api_frame_type
            self._frame_type_value = api_frame_type.code
        else:
            self._frame_type = ApiFrameType.get(api_frame_type)
            self._frame_type_value = api_frame_type
        self._frame_id = 0
Exemplo n.º 2
0
    def __init__(self, api_frame_type, op_mode=OperatingMode.API_MODE):
        """
        Class constructor. Instantiates a new :class:`.XBeeAPIPacket` object
        with the provided parameters.

        Args:
            api_frame_type (:class:`.ApiFrameType` or Integer): The API frame
                type.
            op_mode (:class:`.OperatingMode`, optional, default=`OperatingMode.API_MODE`):
                The mode in which the frame was captured.

        .. seealso::
           | :class:`.ApiFrameType`
           | :class:`.XBeePacket`
        """
        super().__init__(op_mode=op_mode)
        # Check the type of the API frame type.
        if isinstance(api_frame_type, ApiFrameType):
            self._frame_type = api_frame_type
            self._frame_type_value = api_frame_type.code
        else:
            self._frame_type = ApiFrameType.get(api_frame_type)
            self._frame_type_value = api_frame_type
        self._frame_id = 0
Exemplo n.º 3
0
def build_frame(packet_bytearray, operating_mode=OperatingMode.API_MODE):
    """
    Creates a packet from raw data.

    Args:
        packet_bytearray (Bytearray): the raw data of the packet to build.
        operating_mode (:class:`.OperatingMode`): the operating mode in which
            the raw data has been captured.

    .. seealso::
       | :class:`.OperatingMode`
    """
    if len(packet_bytearray) < 5:
        raise InvalidPacketException(
            message="Bytearray must have, at least, 5 bytes (header, length, "
                    "frameType, checksum)")

    frame_type = ApiFrameType.get(packet_bytearray[3])

    if frame_type == ApiFrameType.GENERIC:
        return GenericXBeePacket.create_packet(packet_bytearray,
                                               operating_mode=operating_mode)

    if frame_type == ApiFrameType.AT_COMMAND:
        return ATCommPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.AT_COMMAND_QUEUE:
        return ATCommQueuePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.AT_COMMAND_RESPONSE:
        return ATCommResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RECEIVE_PACKET:
        return ReceivePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_64:
        return RX64Packet.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_16:
        return RX16Packet.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST:
        return RemoteATCommandPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE:
        return RemoteATCommandResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.TRANSMIT_REQUEST:
        return TransmitPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.TRANSMIT_STATUS:
        return TransmitStatusPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.MODEM_STATUS:
        return ModemStatusPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.TX_STATUS:
        return TXStatusPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_IO_16:
        return RX16IOPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_IO_64:
        return RX64IOPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR:
        return IODataSampleRxIndicatorPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.EXPLICIT_ADDRESSING:
        return ExplicitAddressingPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.EXPLICIT_RX_INDICATOR:
        return ExplicitRXIndicatorPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.TX_SMS:
        return TXSMSPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.TX_IPV4:
        return TXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_SMS:
        return RXSMSPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.USER_DATA_RELAY_OUTPUT:
        return UserDataRelayOutputPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.RX_IPV4:
        return RXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST_WIFI:
        return RemoteATCommandWifiPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SEND_DATA_REQUEST:
        return SendDataRequestPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.DEVICE_RESPONSE:
        return DeviceResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.USER_DATA_RELAY_REQUEST:
        return UserDataRelayPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE_WIFI:
        return RemoteATCommandResponseWifiPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR_WIFI:
        return IODataSampleRxIndicatorWifiPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SEND_DATA_RESPONSE:
        return SendDataResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.DEVICE_REQUEST:
        return DeviceRequestPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.DEVICE_RESPONSE_STATUS:
        return DeviceResponseStatusPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.FRAME_ERROR:
        return FrameErrorPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REGISTER_JOINING_DEVICE:
        return RegisterJoiningDevicePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REGISTER_JOINING_DEVICE_STATUS:
        return RegisterDeviceStatusPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.ROUTE_RECORD_INDICATOR:
        return RouteRecordIndicatorPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CREATE:
        return SocketCreatePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CREATE_RESPONSE:
        return SocketCreateResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_OPTION_REQUEST:
        return SocketOptionRequestPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_OPTION_RESPONSE:
        return SocketOptionResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CONNECT:
        return SocketConnectPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CONNECT_RESPONSE:
        return SocketConnectResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CLOSE:
        return SocketClosePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_CLOSE_RESPONSE:
        return SocketCloseResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_SEND:
        return SocketSendPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_SENDTO:
        return SocketSendToPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_BIND:
        return SocketBindListenPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_LISTEN_RESPONSE:
        return SocketListenResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_NEW_IPV4_CLIENT:
        return SocketNewIPv4ClientPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_RECEIVE:
        return SocketReceivePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_RECEIVE_FROM:
        return SocketReceiveFromPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.SOCKET_STATE:
        return SocketStatePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.DIGIMESH_ROUTE_INFORMATION:
        return RouteInformationPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.FILE_SYSTEM_REQUEST:
        return FSRequestPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.FILE_SYSTEM_RESPONSE:
        return FSResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_FILE_SYSTEM_REQUEST:
        return RemoteFSRequestPacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.REMOTE_FILE_SYSTEM_RESPONSE:
        return RemoteFSResponsePacket.create_packet(packet_bytearray, operating_mode)

    if frame_type == ApiFrameType.OTA_FIRMWARE_UPDATE_STATUS:
        return OTAFirmwareUpdateStatusPacket.create_packet(packet_bytearray, operating_mode)

    return UnknownXBeePacket.create_packet(packet_bytearray, operating_mode=operating_mode)
Exemplo n.º 4
0
def build_frame(packet_bytearray, operating_mode=OperatingMode.API_MODE):
    """
    Creates a packet from raw data.
    
    Args:
        packet_bytearray (Bytearray): the raw data of the packet to build.
        operating_mode (:class:`.OperatingMode`): the operating mode in which the raw data has been captured.

    .. seealso::
       | :class:`.OperatingMode`
    """
    frame_type = ApiFrameType.get(packet_bytearray[3])

    if frame_type == ApiFrameType.GENERIC:
        return GenericXBeePacket.create_packet(packet_bytearray,
                                               operating_mode=operating_mode)

    elif frame_type == ApiFrameType.AT_COMMAND:
        return ATCommPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.AT_COMMAND_QUEUE:
        return ATCommQueuePacket.create_packet(packet_bytearray,
                                               operating_mode)

    elif frame_type == ApiFrameType.AT_COMMAND_RESPONSE:
        return ATCommResponsePacket.create_packet(packet_bytearray,
                                                  operating_mode)

    elif frame_type == ApiFrameType.RECEIVE_PACKET:
        return ReceivePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_64:
        return RX64Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_16:
        return RX16Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST:
        return RemoteATCommandPacket.create_packet(packet_bytearray,
                                                   operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE:
        return RemoteATCommandResponsePacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TRANSMIT_REQUEST:
        return TransmitPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TRANSMIT_STATUS:
        return TransmitStatusPacket.create_packet(packet_bytearray,
                                                  operating_mode)

    elif frame_type == ApiFrameType.MODEM_STATUS:
        return ModemStatusPacket.create_packet(packet_bytearray,
                                               operating_mode)

    elif frame_type == ApiFrameType.TX_STATUS:
        return TXStatusPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_IO_16:
        return RX16IOPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_IO_64:
        return RX64IOPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR:
        return IODataSampleRxIndicatorPacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.EXPLICIT_ADDRESSING:
        return ExplicitAddressingPacket.create_packet(packet_bytearray,
                                                      operating_mode)

    elif frame_type == ApiFrameType.EXPLICIT_RX_INDICATOR:
        return ExplicitRXIndicatorPacket.create_packet(packet_bytearray,
                                                       operating_mode)

    elif frame_type == ApiFrameType.TX_SMS:
        return TXSMSPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TX_IPV4:
        return TXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_SMS:
        return RXSMSPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.USER_DATA_RELAY_OUTPUT:
        return UserDataRelayOutputPacket.create_packet(packet_bytearray,
                                                       operating_mode)

    elif frame_type == ApiFrameType.RX_IPV4:
        return RXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST_WIFI:
        return RemoteATCommandWifiPacket.create_packet(packet_bytearray,
                                                       operating_mode)

    elif frame_type == ApiFrameType.SEND_DATA_REQUEST:
        return SendDataRequestPacket.create_packet(packet_bytearray,
                                                   operating_mode)

    elif frame_type == ApiFrameType.DEVICE_RESPONSE:
        return DeviceResponsePacket.create_packet(packet_bytearray,
                                                  operating_mode)

    elif frame_type == ApiFrameType.USER_DATA_RELAY_REQUEST:
        return UserDataRelayPacket.create_packet(packet_bytearray,
                                                 operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE_WIFI:
        return RemoteATCommandResponseWifiPacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR_WIFI:
        return IODataSampleRxIndicatorWifiPacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.SEND_DATA_RESPONSE:
        return SendDataResponsePacket.create_packet(packet_bytearray,
                                                    operating_mode)

    elif frame_type == ApiFrameType.DEVICE_REQUEST:
        return DeviceRequestPacket.create_packet(packet_bytearray,
                                                 operating_mode)

    elif frame_type == ApiFrameType.DEVICE_RESPONSE_STATUS:
        return DeviceResponseStatusPacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.FRAME_ERROR:
        return FrameErrorPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REGISTER_JOINING_DEVICE:
        return RegisterJoiningDevicePacket.create_packet(
            packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REGISTER_JOINING_DEVICE_STATUS:
        return RegisterDeviceStatusPacket.create_packet(
            packet_bytearray, operating_mode)

    else:
        return UnknownXBeePacket.create_packet(packet_bytearray,
                                               operating_mode=operating_mode)
Exemplo n.º 5
0
def build_frame(packet_bytearray, operating_mode=OperatingMode.API_MODE):
    """
    Creates a packet from raw data.
    
    Args:
        packet_bytearray (Bytearray): the raw data of the packet to build.
        operating_mode (:class:`.OperatingMode`): the operating mode in which the raw data has been captured.
    
    Raises:
        NotImplementedError: if the packet defined by the bytearray is not supported.

    .. seealso::
       | :class:`.OperatingMode`
    """
    frame_type = ApiFrameType.get(packet_bytearray[3])

    if frame_type == ApiFrameType.GENERIC:
        return GenericXBeePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.AT_COMMAND:
        return ATCommPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.AT_COMMAND_RESPONSE:
        return ATCommResponsePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RECEIVE_PACKET:
        return ReceivePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_64:
        return RX64Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_16:
        return RX16Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST:
        return RemoteATCommandPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE:
        return RemoteATCommandResponsePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TRANSMIT_REQUEST:
        return TransmitPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TRANSMIT_STATUS:
        return TransmitStatusPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.MODEM_STATUS:
        return ModemStatusPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TX_STATUS:
        return TXStatusPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_IO_16:
        return RX16IOPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_IO_64:
        return RX64IOPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR:
        return IODataSampleRxIndicatorPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.EXPLICIT_ADDRESSING:
        return ExplicitAddressingPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.EXPLICIT_RX_INDICATOR:
        return ExplicitRXIndicatorPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TX_SMS:
        return TXSMSPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.TX_IPV4:
        return TXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_SMS:
        return RXSMSPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.RX_IPV4:
        return RXIPv4Packet.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST_WIFI:
        return RemoteATCommandWifiPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.SEND_DATA_REQUEST:
        return SendDataRequestPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.DEVICE_RESPONSE:
        return DeviceResponsePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE_WIFI:
        return RemoteATCommandResponseWifiPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR_WIFI:
        return IODataSampleRxIndicatorWifiPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.SEND_DATA_RESPONSE:
        return SendDataResponsePacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.DEVICE_REQUEST:
        return DeviceRequestPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.DEVICE_RESPONSE_STATUS:
        return DeviceResponseStatusPacket.create_packet(packet_bytearray, operating_mode)

    elif frame_type == ApiFrameType.FRAME_ERROR:
        return FrameErrorPacket.create_packet(packet_bytearray, operating_mode)

    else:
        raise NotImplementedError("Frame type " + str(frame_type) + " is not supported.")