Пример #1
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);
        }