/**
         * Parses the given API payload to get the right API packet, depending
         * on its API type ({@code payload[0]}).
         *
         * @param payload The payload of the API frame.
         *
         * @return The corresponding API packet or {@code UnknownXBeePacket} if
         *         the frame API type is unknown.
         *
         * @throws InvalidPacketException if the payload is invalid for the
         *                                specified frame type.
         *
         * @see APIFrameType
         * @see XBeePacket
         */
        private XBeePacket ParsePayload(byte[] payload)         /*throws InvalidPacketException*/
        {
            // Get the API frame type.
            APIFrameType apiType = APIFrameType.GENERIC.Get(payload[0]);

            if (apiType == APIFrameType.UNKNOWN)
            {
                // Create unknown packet.
                return(UnknownXBeePacket.CreatePacket(payload));
            }

            // Parse API payload depending on API ID.
            XBeePacket packet = null;

            switch (apiType)
            {
            case APIFrameType.TX_64:
                packet = TX64Packet.CreatePacket(payload);
                break;

            case APIFrameType.TX_16:
                packet = TX16Packet.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND:
                packet = ATCommandPacket.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND_QUEUE:
                packet = ATCommandQueuePacket.CreatePacket(payload);
                break;

            case APIFrameType.TRANSMIT_REQUEST:
                packet = TransmitPacket.createPacket(payload);
                break;

            case APIFrameType.REMOTE_AT_COMMAND_REQUEST:
                packet = RemoteATCommandPacket.createPacket(payload);
                break;

            case APIFrameType.RX_64:
                packet = RX64Packet.CreatePacket(payload);
                break;

            case APIFrameType.RX_16:
                packet = RX16Packet.CreatePacket(payload);
                break;

            case APIFrameType.RX_IO_64:
                packet = RX64IOPacket.CreatePacket(payload);
                break;

            case APIFrameType.RX_IO_16:
                packet = RX16IOPacket.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND_RESPONSE:
                packet = ATCommandResponsePacket.createPacket(payload);
                break;

            case APIFrameType.TX_STATUS:
                packet = TXStatusPacket.createPacket(payload);
                break;

            case APIFrameType.MODEM_STATUS:
                packet = ModemStatusPacket.CreatePacket(payload);
                break;

            case APIFrameType.TRANSMIT_STATUS:
                packet = TransmitStatusPacket.createPacket(payload);
                break;

            case APIFrameType.RECEIVE_PACKET:
                packet = ReceivePacket.createPacket(payload);
                break;

            case APIFrameType.IO_DATA_SAMPLE_RX_INDICATOR:
                packet = IODataSampleRxIndicatorPacket.CreatePacket(payload);
                break;

            case APIFrameType.REMOTE_AT_COMMAND_RESPONSE:
                packet = RemoteATCommandResponsePacket.createPacket(payload);
                break;

            case APIFrameType.GENERIC:
            default:
                packet = GenericXBeePacket.CreatePacket(payload);
                break;
            }
            return(packet);
        }
Пример #2
0
        /// <summary>
        /// Parses the given API payload to get the right API packet, depending on its API
        /// type (<c><paramref name="payload"/>[0]</c>).
        /// </summary>
        /// <param name="payload">The payload of the API frame.</param>
        /// <returns>The corresponding API packet or <see cref="UnknownXBeePacket"/> if the frame API
        /// type is unknown.</returns>
        /// <exception cref="InvalidPacketException">If the payload is invalid for the specified
        /// frame type.</exception>
        /// <seealso cref="APIFrameType"/>
        /// <seealso cref="XBeePacket"/>
        private XBeePacket ParsePayload(byte[] payload)
        {
            // Get the API frame type.
            APIFrameType apiType = APIFrameType.UNKNOWN.Get(payload[0]);

            // Parse API payload depending on API ID.
            XBeePacket packet = null;

            switch (apiType)
            {
            case APIFrameType.TX_64:
                packet = TX64Packet.CreatePacket(payload);
                break;

            case APIFrameType.TX_16:
                packet = TX16Packet.CreatePacket(payload);
                break;

            case APIFrameType.BLE_UNLOCK:
                packet = BluetoothUnlockPacket.CreatePacket(payload);
                break;

            case APIFrameType.USER_DATA_RELAY:
                packet = UserDataRelayPacket.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND:
                packet = ATCommandPacket.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND_QUEUE:
                packet = ATCommandQueuePacket.CreatePacket(payload);
                break;

            case APIFrameType.TRANSMIT_REQUEST:
                packet = TransmitPacket.CreatePacket(payload);
                break;

            case APIFrameType.EXPLICIT_ADDRESSING_COMMAND_FRAME:
                packet = ExplicitAddressingPacket.CreatePacket(payload);
                break;

            case APIFrameType.REMOTE_AT_COMMAND_REQUEST:
                packet = RemoteATCommandPacket.CreatePacket(payload);
                break;

            case APIFrameType.TX_SMS:
                packet = TXSMSPacket.CreatePacket(payload);
                break;

            case APIFrameType.TX_IPV4:
                packet = TXIPv4Packet.CreatePacket(payload);
                break;

            case APIFrameType.TX_REQUEST_TLS_PROFILE:
                packet = TXTLSProfilePacket.CreatePacket(payload);
                break;

            case APIFrameType.RX_64:
                packet = RX64Packet.CreatePacket(payload);
                break;

            case APIFrameType.RX_16:
                packet = RX16Packet.CreatePacket(payload);
                break;

            case APIFrameType.RX_IO_64:
                packet = RX64IOPacket.CreatePacket(payload);
                break;

            case APIFrameType.RX_IO_16:
                packet = RX16IOPacket.CreatePacket(payload);
                break;

            case APIFrameType.AT_COMMAND_RESPONSE:
                packet = ATCommandResponsePacket.CreatePacket(payload);
                break;

            case APIFrameType.TX_STATUS:
                packet = TXStatusPacket.CreatePacket(payload);
                break;

            case APIFrameType.MODEM_STATUS:
                packet = ModemStatusPacket.CreatePacket(payload);
                break;

            case APIFrameType.TRANSMIT_STATUS:
                packet = TransmitStatusPacket.CreatePacket(payload);
                break;

            case APIFrameType.RECEIVE_PACKET:
                packet = ReceivePacket.CreatePacket(payload);
                break;

            case APIFrameType.EXPLICIT_RX_INDICATOR:
                packet = ExplicitRxIndicatorPacket.CreatePacket(payload);
                break;

            case APIFrameType.IO_DATA_SAMPLE_RX_INDICATOR:
                packet = IODataSampleRxIndicatorPacket.CreatePacket(payload);
                break;

            case APIFrameType.REMOTE_AT_COMMAND_RESPONSE:
                packet = RemoteATCommandResponsePacket.CreatePacket(payload);
                break;

            case APIFrameType.RX_SMS:
                packet = RXSMSPacket.CreatePacket(payload);
                break;

            case APIFrameType.BLE_UNLOCK_RESPONSE:
                packet = BluetoothUnlockResponsePacket.CreatePacket(payload);
                break;

            case APIFrameType.USER_DATA_RELAY_OUTPUT:
                packet = UserDataRelayOutputPacket.CreatePacket(payload);
                break;

            case APIFrameType.RX_IPV4:
                packet = RXIPv4Packet.CreatePacket(payload);
                break;

            case APIFrameType.UNKNOWN:
            default:
                packet = UnknownXBeePacket.CreatePacket(payload);
                break;
            }
            return(packet);
        }