Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CircularBuffer FixedLengthList
Dependents: XBeeApiTest XBeeApiSimpleATCmdsExample XBeeApiBroadcastExample XBeeApiBroadcastExampleRTOS ... more
Base/XBeeApiFrame.hpp@5:b40a6fd3a334, 2014-01-29 (annotated)
- Committer:
- johnb
- Date:
- Wed Jan 29 20:19:59 2014 +0000
- Revision:
- 5:b40a6fd3a334
- Child:
- 6:3cb62daace78
Documentation update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnb | 5:b40a6fd3a334 | 1 | /** |
johnb | 5:b40a6fd3a334 | 2 | @file |
johnb | 5:b40a6fd3a334 | 3 | @brief Class to abstract commands send to the XBee API |
johnb | 5:b40a6fd3a334 | 4 | |
johnb | 5:b40a6fd3a334 | 5 | @author John Bailey |
johnb | 5:b40a6fd3a334 | 6 | |
johnb | 5:b40a6fd3a334 | 7 | @copyright Copyright 2013 John Bailey |
johnb | 5:b40a6fd3a334 | 8 | |
johnb | 5:b40a6fd3a334 | 9 | @section LICENSE |
johnb | 5:b40a6fd3a334 | 10 | |
johnb | 5:b40a6fd3a334 | 11 | Licensed under the Apache License, Version 2.0 (the "License"); |
johnb | 5:b40a6fd3a334 | 12 | you may not use this file except in compliance with the License. |
johnb | 5:b40a6fd3a334 | 13 | You may obtain a copy of the License at |
johnb | 5:b40a6fd3a334 | 14 | |
johnb | 5:b40a6fd3a334 | 15 | http://www.apache.org/licenses/LICENSE-2.0 |
johnb | 5:b40a6fd3a334 | 16 | |
johnb | 5:b40a6fd3a334 | 17 | Unless required by applicable law or agreed to in writing, software |
johnb | 5:b40a6fd3a334 | 18 | distributed under the License is distributed on an "AS IS" BASIS, |
johnb | 5:b40a6fd3a334 | 19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
johnb | 5:b40a6fd3a334 | 20 | See the License for the specific language governing permissions and |
johnb | 5:b40a6fd3a334 | 21 | limitations under the License. |
johnb | 5:b40a6fd3a334 | 22 | |
johnb | 5:b40a6fd3a334 | 23 | */ |
johnb | 5:b40a6fd3a334 | 24 | |
johnb | 5:b40a6fd3a334 | 25 | #if !defined XBEEAPICMD_HPP |
johnb | 5:b40a6fd3a334 | 26 | #define XBEEAPICMD_HPP |
johnb | 5:b40a6fd3a334 | 27 | |
johnb | 5:b40a6fd3a334 | 28 | #include <stdint.h> |
johnb | 5:b40a6fd3a334 | 29 | #include <stddef.h> // for size_t |
johnb | 5:b40a6fd3a334 | 30 | |
johnb | 5:b40a6fd3a334 | 31 | /** API identifiers - the first byte in the API-specific structure within an API frame which provides an indication as to the type of data which follows */ |
johnb | 5:b40a6fd3a334 | 32 | typedef enum |
johnb | 5:b40a6fd3a334 | 33 | { |
johnb | 5:b40a6fd3a334 | 34 | XBEE_CMD_TX_64B_ADDR = 0x00, |
johnb | 5:b40a6fd3a334 | 35 | XBEE_CMD_TX_16B_ADDR = 0x01, |
johnb | 5:b40a6fd3a334 | 36 | XBEE_CMD_AT_CMD = 0x08, |
johnb | 5:b40a6fd3a334 | 37 | XBEE_CMD_QUEUE_PARAM_VAL = 0x09, |
johnb | 5:b40a6fd3a334 | 38 | XBEE_CMD_REMOTE_AT_CMD = 0x17, |
johnb | 5:b40a6fd3a334 | 39 | XBEE_CMD_RX_64B_ADDR = 0x80, |
johnb | 5:b40a6fd3a334 | 40 | XBEE_CMD_RX_16B_ADDR = 0x81, |
johnb | 5:b40a6fd3a334 | 41 | XBEE_CMD_AT_RESPONSE = 0x88, |
johnb | 5:b40a6fd3a334 | 42 | XBEE_CMD_TX_STATUS = 0x89, |
johnb | 5:b40a6fd3a334 | 43 | XBEE_CMD_MODEM_STATUS = 0x8A, |
johnb | 5:b40a6fd3a334 | 44 | XBEE_CMD_REMOTE_AT_RESPONSE = 0x97, |
johnb | 5:b40a6fd3a334 | 45 | XBEE_CMD_INVALID = 0xFFF |
johnb | 5:b40a6fd3a334 | 46 | } XBeeApiIdentifier_e; |
johnb | 5:b40a6fd3a334 | 47 | |
johnb | 5:b40a6fd3a334 | 48 | /** Position of fixed meaning bytes within the API frame, relative to the start of the frame */ |
johnb | 5:b40a6fd3a334 | 49 | enum |
johnb | 5:b40a6fd3a334 | 50 | { |
johnb | 5:b40a6fd3a334 | 51 | /** Start delimiter, should be equal to XBEE_SB_FRAME_DELIMITER */ |
johnb | 5:b40a6fd3a334 | 52 | XBEE_CMD_POSN_SDELIM = 0x00, |
johnb | 5:b40a6fd3a334 | 53 | /** High byte of the 16-bit length field */ |
johnb | 5:b40a6fd3a334 | 54 | XBEE_CMD_POSN_LEN_HI = 0x01, |
johnb | 5:b40a6fd3a334 | 55 | /** Low byte of the 16-bit length field */ |
johnb | 5:b40a6fd3a334 | 56 | XBEE_CMD_POSN_LEN_LO = 0x02, |
johnb | 5:b40a6fd3a334 | 57 | /** API identifier for the data which follows - see XBeeApiIdentifier_e */ |
johnb | 5:b40a6fd3a334 | 58 | XBEE_CMD_POSN_API_ID = 0x03 |
johnb | 5:b40a6fd3a334 | 59 | }; |
johnb | 5:b40a6fd3a334 | 60 | |
johnb | 5:b40a6fd3a334 | 61 | /** Helper macro to retrieve the frame payload length (i.e. excluding overhead - see XBEE_API_FRAME_OVERHEAD) from a buffer. |
johnb | 5:b40a6fd3a334 | 62 | |
johnb | 5:b40a6fd3a334 | 63 | \param _b Pointer to a buffer containing a received API frame. |
johnb | 5:b40a6fd3a334 | 64 | \returns Length of the frame payload excluding overhead */ |
johnb | 5:b40a6fd3a334 | 65 | #define MSG_LEN_IN_BUFFER( _b ) ((((uint16_t)_b[ XBEE_CMD_POSN_LEN_HI ]) << 8U) + _b[XBEE_CMD_POSN_LEN_LO]) |
johnb | 5:b40a6fd3a334 | 66 | |
johnb | 5:b40a6fd3a334 | 67 | /** The number of 'overhead' bytes in an API frame (i.e. those not included in the frame payload, namely the start delimiter, 2 length bytes & checksum */ |
johnb | 5:b40a6fd3a334 | 68 | #define XBEE_API_FRAME_OVERHEAD 4U |
johnb | 5:b40a6fd3a334 | 69 | |
johnb | 5:b40a6fd3a334 | 70 | /** Class which represents an API frame, exchanged with the XBee. |
johnb | 5:b40a6fd3a334 | 71 | This class in itself will not create a valid API frame and needs to be sub-classed. |
johnb | 5:b40a6fd3a334 | 72 | */ |
johnb | 5:b40a6fd3a334 | 73 | class XBeeApiFrame |
johnb | 5:b40a6fd3a334 | 74 | { |
johnb | 5:b40a6fd3a334 | 75 | private: |
johnb | 5:b40a6fd3a334 | 76 | static const uint8_t m_cmdHeaderLen = 1; |
johnb | 5:b40a6fd3a334 | 77 | |
johnb | 5:b40a6fd3a334 | 78 | protected: |
johnb | 5:b40a6fd3a334 | 79 | /** API identifier for the data in the frame */ |
johnb | 5:b40a6fd3a334 | 80 | XBeeApiIdentifier_e m_apiId; |
johnb | 5:b40a6fd3a334 | 81 | |
johnb | 5:b40a6fd3a334 | 82 | /** API identifier specific data */ |
johnb | 5:b40a6fd3a334 | 83 | const uint8_t* m_data; |
johnb | 5:b40a6fd3a334 | 84 | |
johnb | 5:b40a6fd3a334 | 85 | /** Length of the data pointed to by m_data */ |
johnb | 5:b40a6fd3a334 | 86 | uint16_t m_dataLen; |
johnb | 5:b40a6fd3a334 | 87 | |
johnb | 5:b40a6fd3a334 | 88 | public: |
johnb | 5:b40a6fd3a334 | 89 | |
johnb | 5:b40a6fd3a334 | 90 | /** Constructor */ |
johnb | 5:b40a6fd3a334 | 91 | XBeeApiFrame( void ); |
johnb | 5:b40a6fd3a334 | 92 | |
johnb | 5:b40a6fd3a334 | 93 | /** Return the length of the API-specific structure represented by this frame. i.e. the API frame without the overhead - see XBEE_API_FRAME_OVERHEAD */ |
johnb | 5:b40a6fd3a334 | 94 | uint16_t getCmdLen( void ) const; |
johnb | 5:b40a6fd3a334 | 95 | |
johnb | 5:b40a6fd3a334 | 96 | /** Retrieve the API identifier for this frame */ |
johnb | 5:b40a6fd3a334 | 97 | XBeeApiIdentifier_e getApiId( void ) const; |
johnb | 5:b40a6fd3a334 | 98 | |
johnb | 5:b40a6fd3a334 | 99 | /** Return a pointer to the API-specific data (i.e. that which follows the API identifier in the frame */ |
johnb | 5:b40a6fd3a334 | 100 | const uint8_t* getDataPtr( void ) const; |
johnb | 5:b40a6fd3a334 | 101 | }; |
johnb | 5:b40a6fd3a334 | 102 | |
johnb | 5:b40a6fd3a334 | 103 | /* Forward declare this as XBeeDevice is dependent upon XBeeApiFrameDecoder */ |
johnb | 5:b40a6fd3a334 | 104 | class XBeeDevice; |
johnb | 5:b40a6fd3a334 | 105 | |
johnb | 5:b40a6fd3a334 | 106 | class XBeeApiFrameDecoder |
johnb | 5:b40a6fd3a334 | 107 | { |
johnb | 5:b40a6fd3a334 | 108 | protected: |
johnb | 5:b40a6fd3a334 | 109 | XBeeDevice* m_device; |
johnb | 5:b40a6fd3a334 | 110 | |
johnb | 5:b40a6fd3a334 | 111 | public: |
johnb | 5:b40a6fd3a334 | 112 | |
johnb | 5:b40a6fd3a334 | 113 | XBeeApiFrameDecoder(); |
johnb | 5:b40a6fd3a334 | 114 | |
johnb | 5:b40a6fd3a334 | 115 | virtual ~XBeeApiFrameDecoder(); |
johnb | 5:b40a6fd3a334 | 116 | |
johnb | 5:b40a6fd3a334 | 117 | virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len ) = 0; |
johnb | 5:b40a6fd3a334 | 118 | |
johnb | 5:b40a6fd3a334 | 119 | void registerCallback( XBeeDevice* const p_device ); |
johnb | 5:b40a6fd3a334 | 120 | |
johnb | 5:b40a6fd3a334 | 121 | void unregisterCallback( void ); |
johnb | 5:b40a6fd3a334 | 122 | }; |
johnb | 5:b40a6fd3a334 | 123 | |
johnb | 5:b40a6fd3a334 | 124 | #endif |