API for communicating with XBee devices.
Dependencies: CircularBuffer FixedLengthList
Dependents: XBeeApiTest XBeeApiSimpleATCmdsExample XBeeApiBroadcastExample XBeeApiBroadcastExampleRTOS ... more
Overview
XBeeApi is intended to be a library for providing a high-level API interface to the XBee - for example getChannel()
and setChannel(2)
methods rather than needing to send( "ATCH" )
and send( "ATCH 2" )
- and then de-code the responses.
See the notebook page here for a description of how the API works & some details on the various classes.
Features:
- Support for transmission & reception of data packets
- Support for reading & changing settings
- Support for "Remote AT" interface to access settings & I/O channels on remote XBees
- XBeeApi should work if you're using mbed-rtos, though it is not currently threadsafe. Take a look at the XBeeApiBroadcastExampleRTOS example if you're including mbed-rtos.
Example Programs
There are also example programs available:
Transmit
Import programXBeeApiSimpleBroadcastExample
Simple example of how to use XBeeApi - set up the XBee, configure P2P networking then transmit a frame.
Import programXBeeApiBroadcastExample
Example for XBeeAPI; a little more involved than XBeeApiSimpleBroadcastExample with report on failure to set up the XBee and on the transmit status of the message.
Import programXBeeApiBroadcastExampleRTOS
Example of using the XBeeApi library to broadcast a message, based on XBeeApiBroadcastExample. This example shows how to use the library when using mbed-rtos. Before compiling you must open "XbeeApi\Config\XBeeApiCfg.hpp" and change the '#if 0' to '#if 1' on the line above the comment reading "Use RTOS features to make XBeeApi threadsafe"
Settings/Status
Import programXBeeApiSimpleATCmdsExample
Simple example of using XBeeApi to send AT-style commands to the XBee
Import programXBeeApiRemoteATCmdsExample
Example of using the XBeeApi library to send AT commands to remote XBee devices in order to read/write settings
Receive
Import programXBeeApiSimpleReceiveExample
Simple example of using XBeeApi to receive data packets via wireless
Import programXBeeApiReceiveCallbackExample
Example of using the XBeeApi library to receive a message via a callback method
Import programXBeeApiReceiveCallbackExampleRTOS
Example of using the XBeeApi library to receive a message via a callback method. This example shows how to use the library when using mbed-rtos. See the comment at the top of main.cpp
Remote I/O
Import programXBeeApiRemoteIOExample
Example of using the XBeeApi library to read inputs on a remote XBee
If you have 2 mbed connected XBees available then you can use XBeeApiSimpleReceiveExample and XBeeApiSimpleBroadcastExample as a pair.
Note that this is still a work in progress! XBeeApiTodoList tracks some of the functionality still to be added.
Remote/XBeeDeviceRemoteAt.cpp@56:7fe74b03e6b1, 2014-08-08 (annotated)
- Committer:
- johnb
- Date:
- Fri Aug 08 11:59:52 2014 +0000
- Revision:
- 56:7fe74b03e6b1
- Parent:
- 55:610aa4a2ed3b
Add support for setting up encrypted communications; Re-jig XBeeApiCmdAt virtual functions to make inheritance by XBeeDeviceRemoteAt cleaner.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnb | 50:f76b7e7959a2 | 1 | /** |
johnb | 50:f76b7e7959a2 | 2 | |
johnb | 50:f76b7e7959a2 | 3 | Copyright 2014 John Bailey |
johnb | 50:f76b7e7959a2 | 4 | |
johnb | 50:f76b7e7959a2 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
johnb | 50:f76b7e7959a2 | 6 | you may not use this file except in compliance with the License. |
johnb | 50:f76b7e7959a2 | 7 | You may obtain a copy of the License at |
johnb | 50:f76b7e7959a2 | 8 | |
johnb | 50:f76b7e7959a2 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
johnb | 50:f76b7e7959a2 | 10 | |
johnb | 50:f76b7e7959a2 | 11 | Unless required by applicable law or agreed to in writing, software |
johnb | 50:f76b7e7959a2 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
johnb | 50:f76b7e7959a2 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
johnb | 50:f76b7e7959a2 | 14 | See the License for the specific language governing permissions and |
johnb | 50:f76b7e7959a2 | 15 | limitations under the License. |
johnb | 50:f76b7e7959a2 | 16 | |
johnb | 50:f76b7e7959a2 | 17 | */ |
johnb | 50:f76b7e7959a2 | 18 | |
johnb | 50:f76b7e7959a2 | 19 | #include "XBeeDeviceRemoteAt.hpp" |
johnb | 50:f76b7e7959a2 | 20 | |
johnb | 50:f76b7e7959a2 | 21 | #define XBEE_API_CMD_REMOTE_REQ_HEADER_LEN 14U |
johnb | 50:f76b7e7959a2 | 22 | |
johnb | 56:7fe74b03e6b1 | 23 | class XBeeApiCmdAtRemoteFrame : public XBeeApiFrame { |
johnb | 56:7fe74b03e6b1 | 24 | uint8_t m_buffer[ XBEE_API_CMD_REMOTE_REQ_HEADER_LEN + XBEE_CMD_MAX_PARAM_LENGTH ]; |
johnb | 50:f76b7e7959a2 | 25 | public: |
johnb | 50:f76b7e7959a2 | 26 | /** Constructor |
johnb | 50:f76b7e7959a2 | 27 | |
johnb | 50:f76b7e7959a2 | 28 | \param p_data Pointer to a buffer of length 2 bytes identifying |
johnb | 50:f76b7e7959a2 | 29 | the command, e.g. 'V', 'R' would set up a version |
johnb | 50:f76b7e7959a2 | 30 | request |
johnb | 50:f76b7e7959a2 | 31 | \param p_val New value for the parameter |
johnb | 50:f76b7e7959a2 | 32 | */ |
johnb | 56:7fe74b03e6b1 | 33 | XBeeApiCmdAtRemoteFrame( const uint8_t p_frameId, |
johnb | 56:7fe74b03e6b1 | 34 | const uint16_t p_addr16Bit, |
johnb | 56:7fe74b03e6b1 | 35 | const uint64_t p_addr64Bit, |
johnb | 56:7fe74b03e6b1 | 36 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 56:7fe74b03e6b1 | 37 | const bool p_applyChanges, |
johnb | 56:7fe74b03e6b1 | 38 | const uint8_t* const p_data, |
johnb | 56:7fe74b03e6b1 | 39 | const uint8_t* const p_val, |
johnb | 56:7fe74b03e6b1 | 40 | const uint8_t p_len ); |
johnb | 50:f76b7e7959a2 | 41 | /** Destructor */ |
johnb | 56:7fe74b03e6b1 | 42 | virtual ~XBeeApiCmdAtRemoteFrame(); |
johnb | 50:f76b7e7959a2 | 43 | }; |
johnb | 50:f76b7e7959a2 | 44 | |
johnb | 50:f76b7e7959a2 | 45 | XBeeDeviceRemoteAt::XBeeDeviceRemoteAt( XBeeDevice* p_device, |
johnb | 50:f76b7e7959a2 | 46 | const uint16_t& p_addr16Bit, |
johnb | 51:a7d0d2ef9261 | 47 | const uint64_t& p_addr64Bit, |
johnb | 52:0950b05d5270 | 48 | const bool p_applyChanges ) : XBeeApiCmdAt( p_device ), m_applyChanges( p_applyChanges ) |
johnb | 50:f76b7e7959a2 | 49 | { |
johnb | 55:610aa4a2ed3b | 50 | setAddress( p_addr16Bit, p_addr64Bit ); |
johnb | 55:610aa4a2ed3b | 51 | } |
johnb | 55:610aa4a2ed3b | 52 | |
johnb | 55:610aa4a2ed3b | 53 | void XBeeDeviceRemoteAt::setAddress( const uint16_t& p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 54 | const uint64_t& p_addr64Bit ) |
johnb | 55:610aa4a2ed3b | 55 | { |
johnb | 52:0950b05d5270 | 56 | if( p_addr16Bit != XBEE_USE_64BIT_ADDR ) |
johnb | 52:0950b05d5270 | 57 | { |
johnb | 52:0950b05d5270 | 58 | m_sourceAddress = p_addr16Bit; |
johnb | 52:0950b05d5270 | 59 | m_have_sourceAddress = true; |
johnb | 54:9f5b7652943e | 60 | m_snLow = m_snHigh = 0; |
johnb | 55:610aa4a2ed3b | 61 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_16BIT; |
johnb | 52:0950b05d5270 | 62 | } else |
johnb | 52:0950b05d5270 | 63 | { |
johnb | 52:0950b05d5270 | 64 | m_snLow = (p_addr64Bit & 0xFFFFFFFF); |
johnb | 52:0950b05d5270 | 65 | m_snHigh = ((p_addr64Bit >> 32U) & 0xFFFFFFFF); |
johnb | 52:0950b05d5270 | 66 | m_sourceAddress = XBEE_USE_64BIT_ADDR; |
johnb | 52:0950b05d5270 | 67 | m_have_snLow = m_have_snHigh = true; |
johnb | 55:610aa4a2ed3b | 68 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_64BIT; |
johnb | 55:610aa4a2ed3b | 69 | } |
johnb | 50:f76b7e7959a2 | 70 | } |
johnb | 55:610aa4a2ed3b | 71 | |
johnb | 55:610aa4a2ed3b | 72 | void XBeeDeviceRemoteAt::reassociate( const uint16_t& p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 73 | const uint64_t& p_addr64Bit ) |
johnb | 55:610aa4a2ed3b | 74 | { |
johnb | 55:610aa4a2ed3b | 75 | resetCachedData(); |
johnb | 55:610aa4a2ed3b | 76 | setAddress( p_addr16Bit, p_addr64Bit ); |
johnb | 55:610aa4a2ed3b | 77 | } |
johnb | 55:610aa4a2ed3b | 78 | |
johnb | 50:f76b7e7959a2 | 79 | |
johnb | 50:f76b7e7959a2 | 80 | XBeeDeviceRemoteAt::~XBeeDeviceRemoteAt( void ) |
johnb | 50:f76b7e7959a2 | 81 | { |
johnb | 50:f76b7e7959a2 | 82 | } |
johnb | 50:f76b7e7959a2 | 83 | |
johnb | 51:a7d0d2ef9261 | 84 | void XBeeDeviceRemoteAt::setApplyChanges( const bool p_apply ) |
johnb | 51:a7d0d2ef9261 | 85 | { |
johnb | 51:a7d0d2ef9261 | 86 | m_applyChanges = p_apply; |
johnb | 51:a7d0d2ef9261 | 87 | } |
johnb | 50:f76b7e7959a2 | 88 | |
johnb | 50:f76b7e7959a2 | 89 | #define XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS (XBEE_CMD_POSN_ID_SPECIFIC_DATA+1) |
johnb | 50:f76b7e7959a2 | 90 | #define XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS (XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + sizeof( uint64_t)) |
johnb | 50:f76b7e7959a2 | 91 | #define XBEE_REMOTE_AT_RESPONSE_STATUS (17U) |
johnb | 50:f76b7e7959a2 | 92 | |
johnb | 50:f76b7e7959a2 | 93 | size_t XBeeDeviceRemoteAt::getResponseStatusPos( void ) const |
johnb | 50:f76b7e7959a2 | 94 | { |
johnb | 50:f76b7e7959a2 | 95 | return XBEE_REMOTE_AT_RESPONSE_STATUS; |
johnb | 50:f76b7e7959a2 | 96 | } |
johnb | 50:f76b7e7959a2 | 97 | |
johnb | 50:f76b7e7959a2 | 98 | bool XBeeDeviceRemoteAt::decodeCallback( const uint8_t* const p_data, size_t p_len ) |
johnb | 50:f76b7e7959a2 | 99 | { |
johnb | 50:f76b7e7959a2 | 100 | bool ret_val = false; |
johnb | 50:f76b7e7959a2 | 101 | |
johnb | 50:f76b7e7959a2 | 102 | /* TODO: Length check */ |
johnb | 50:f76b7e7959a2 | 103 | |
johnb | 50:f76b7e7959a2 | 104 | if( XBEE_CMD_REMOTE_AT_RESPONSE == p_data[ XBEE_CMD_POSN_API_ID ] ) |
johnb | 50:f76b7e7959a2 | 105 | { |
johnb | 52:0950b05d5270 | 106 | uint32_t srcAddrHigh = (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS ]) << 24U) | |
johnb | 52:0950b05d5270 | 107 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 1 ]) << 16U) | |
johnb | 52:0950b05d5270 | 108 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 2 ]) << 8U) | |
johnb | 52:0950b05d5270 | 109 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 3 ])); |
johnb | 52:0950b05d5270 | 110 | uint32_t srcAddrLow = (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 4 ]) << 24U) | |
johnb | 50:f76b7e7959a2 | 111 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 5 ]) << 16U) | |
johnb | 50:f76b7e7959a2 | 112 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 6 ]) << 8U) | |
johnb | 50:f76b7e7959a2 | 113 | ((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 7 ]); |
johnb | 52:0950b05d5270 | 114 | |
johnb | 50:f76b7e7959a2 | 115 | uint16_t src16BitAddr = (((uint16_t)p_data[ XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS ]) << 8U) | |
johnb | 50:f76b7e7959a2 | 116 | p_data[ XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS + 1 ]; |
johnb | 52:0950b05d5270 | 117 | |
johnb | 52:0950b05d5270 | 118 | if((( m_have_sourceAddress ) && ( m_sourceAddress == src16BitAddr )) || |
johnb | 52:0950b05d5270 | 119 | ( m_have_snHigh && m_have_snLow && ( srcAddrHigh == m_snHigh ) && ( srcAddrLow == m_snLow ))) |
johnb | 50:f76b7e7959a2 | 120 | { |
johnb | 50:f76b7e7959a2 | 121 | ret_val = processResponseFrame( p_data, p_len ); |
johnb | 50:f76b7e7959a2 | 122 | } |
johnb | 50:f76b7e7959a2 | 123 | } |
johnb | 52:0950b05d5270 | 124 | else |
johnb | 51:a7d0d2ef9261 | 125 | { |
johnb | 54:9f5b7652943e | 126 | ret_val = XBeeApiCmdAt::decodeCallback( p_data, p_len ); |
johnb | 51:a7d0d2ef9261 | 127 | } |
johnb | 51:a7d0d2ef9261 | 128 | |
johnb | 50:f76b7e7959a2 | 129 | return ret_val; |
johnb | 50:f76b7e7959a2 | 130 | } |
johnb | 50:f76b7e7959a2 | 131 | |
johnb | 56:7fe74b03e6b1 | 132 | void XBeeDeviceRemoteAt::SendCmd( const uint8_t p_frameId, |
johnb | 56:7fe74b03e6b1 | 133 | const uint8_t* const p_data, |
johnb | 56:7fe74b03e6b1 | 134 | const uint8_t* const p_val, |
johnb | 56:7fe74b03e6b1 | 135 | const uint8_t p_len ) |
johnb | 50:f76b7e7959a2 | 136 | { |
johnb | 52:0950b05d5270 | 137 | uint64_t addr64Bit = (((uint64_t)m_snHigh) << 32U) | (uint64_t)m_snLow; |
johnb | 52:0950b05d5270 | 138 | /* TODO: Add option to force usage of 16 or 64-bit addressing */ |
johnb | 56:7fe74b03e6b1 | 139 | XBeeApiCmdAtRemoteFrame req( p_frameId, m_sourceAddress, addr64Bit, m_addressingType, m_applyChanges, p_data, p_val, p_len ); |
johnb | 52:0950b05d5270 | 140 | m_device->SendFrame( &req ); |
johnb | 50:f76b7e7959a2 | 141 | } |
johnb | 50:f76b7e7959a2 | 142 | |
johnb | 55:610aa4a2ed3b | 143 | bool XBeeDeviceRemoteAt::setAddressingType( const XBeeDevice::XBeeApiAddrType_t p_type ) |
johnb | 55:610aa4a2ed3b | 144 | { |
johnb | 55:610aa4a2ed3b | 145 | bool ret_val = false; |
johnb | 55:610aa4a2ed3b | 146 | |
johnb | 55:610aa4a2ed3b | 147 | switch( p_type ) |
johnb | 55:610aa4a2ed3b | 148 | { |
johnb | 55:610aa4a2ed3b | 149 | case XBeeDevice::XBEE_API_ADDR_TYPE_16BIT: |
johnb | 55:610aa4a2ed3b | 150 | if( m_have_sourceAddress ) |
johnb | 55:610aa4a2ed3b | 151 | { |
johnb | 55:610aa4a2ed3b | 152 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_16BIT; |
johnb | 55:610aa4a2ed3b | 153 | ret_val = true; |
johnb | 55:610aa4a2ed3b | 154 | } |
johnb | 55:610aa4a2ed3b | 155 | break; |
johnb | 55:610aa4a2ed3b | 156 | case XBeeDevice::XBEE_API_ADDR_TYPE_64BIT: |
johnb | 55:610aa4a2ed3b | 157 | if( m_have_snLow && m_have_snHigh ) |
johnb | 55:610aa4a2ed3b | 158 | { |
johnb | 55:610aa4a2ed3b | 159 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_64BIT; |
johnb | 55:610aa4a2ed3b | 160 | ret_val = true; |
johnb | 55:610aa4a2ed3b | 161 | } |
johnb | 55:610aa4a2ed3b | 162 | break; |
johnb | 55:610aa4a2ed3b | 163 | } |
johnb | 55:610aa4a2ed3b | 164 | |
johnb | 55:610aa4a2ed3b | 165 | return ret_val; |
johnb | 55:610aa4a2ed3b | 166 | } |
johnb | 55:610aa4a2ed3b | 167 | |
johnb | 55:610aa4a2ed3b | 168 | static void writeAddressToBuffer( uint8_t* const p_buffer, |
johnb | 55:610aa4a2ed3b | 169 | const uint16_t p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 170 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 171 | const XBeeDevice::XBeeApiAddrType_t p_type ) |
johnb | 55:610aa4a2ed3b | 172 | { |
johnb | 55:610aa4a2ed3b | 173 | if( p_type == XBeeDevice::XBEE_API_ADDR_TYPE_64BIT ) |
johnb | 55:610aa4a2ed3b | 174 | { |
johnb | 55:610aa4a2ed3b | 175 | p_buffer[0] = p_addr64Bit >> 56U; |
johnb | 55:610aa4a2ed3b | 176 | p_buffer[1] = p_addr64Bit >> 48U; |
johnb | 55:610aa4a2ed3b | 177 | p_buffer[2] = p_addr64Bit >> 40U; |
johnb | 55:610aa4a2ed3b | 178 | p_buffer[3] = p_addr64Bit >> 32U; |
johnb | 55:610aa4a2ed3b | 179 | p_buffer[4] = p_addr64Bit >> 24U; |
johnb | 55:610aa4a2ed3b | 180 | p_buffer[5] = p_addr64Bit >> 16U; |
johnb | 55:610aa4a2ed3b | 181 | p_buffer[6] = p_addr64Bit >> 8U; |
johnb | 55:610aa4a2ed3b | 182 | p_buffer[7] = p_addr64Bit; |
johnb | 55:610aa4a2ed3b | 183 | |
johnb | 55:610aa4a2ed3b | 184 | p_buffer[8] = (uint8_t)(XBEE_USE_64BIT_ADDR >> 8U); |
johnb | 55:610aa4a2ed3b | 185 | p_buffer[9] = (uint8_t)(XBEE_USE_64BIT_ADDR & 0xFF); |
johnb | 55:610aa4a2ed3b | 186 | } |
johnb | 55:610aa4a2ed3b | 187 | else |
johnb | 55:610aa4a2ed3b | 188 | { |
johnb | 55:610aa4a2ed3b | 189 | |
johnb | 55:610aa4a2ed3b | 190 | p_buffer[0] = 0; |
johnb | 55:610aa4a2ed3b | 191 | p_buffer[1] = 0; |
johnb | 55:610aa4a2ed3b | 192 | p_buffer[2] = 0; |
johnb | 55:610aa4a2ed3b | 193 | p_buffer[3] = 0; |
johnb | 55:610aa4a2ed3b | 194 | p_buffer[4] = 0; |
johnb | 55:610aa4a2ed3b | 195 | p_buffer[5] = 0; |
johnb | 55:610aa4a2ed3b | 196 | p_buffer[6] = 0; |
johnb | 55:610aa4a2ed3b | 197 | p_buffer[7] = 0; |
johnb | 55:610aa4a2ed3b | 198 | |
johnb | 55:610aa4a2ed3b | 199 | p_buffer[8] = p_addr16Bit >> 8U; |
johnb | 55:610aa4a2ed3b | 200 | p_buffer[9] = p_addr16Bit; |
johnb | 55:610aa4a2ed3b | 201 | } |
johnb | 55:610aa4a2ed3b | 202 | } |
johnb | 55:610aa4a2ed3b | 203 | |
johnb | 56:7fe74b03e6b1 | 204 | XBeeApiCmdAtRemoteFrame::XBeeApiCmdAtRemoteFrame( const uint8_t p_frameId, |
johnb | 56:7fe74b03e6b1 | 205 | const uint16_t p_addr16Bit, |
johnb | 56:7fe74b03e6b1 | 206 | const uint64_t p_addr64Bit, |
johnb | 56:7fe74b03e6b1 | 207 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 56:7fe74b03e6b1 | 208 | const bool p_applyChanges, |
johnb | 56:7fe74b03e6b1 | 209 | const uint8_t* const p_data, |
johnb | 56:7fe74b03e6b1 | 210 | const uint8_t* const p_val, |
johnb | 56:7fe74b03e6b1 | 211 | const uint8_t p_len ) : XBeeApiFrame( ) |
johnb | 56:7fe74b03e6b1 | 212 | { |
johnb | 50:f76b7e7959a2 | 213 | m_apiId = XBEE_CMD_REMOTE_AT_CMD; |
johnb | 50:f76b7e7959a2 | 214 | |
johnb | 50:f76b7e7959a2 | 215 | m_buffer[0] = p_frameId; |
johnb | 50:f76b7e7959a2 | 216 | |
johnb | 55:610aa4a2ed3b | 217 | writeAddressToBuffer( &(m_buffer[1]), p_addr16Bit, p_addr64Bit, p_type ); |
johnb | 50:f76b7e7959a2 | 218 | |
johnb | 56:7fe74b03e6b1 | 219 | if( p_len ) |
johnb | 56:7fe74b03e6b1 | 220 | { |
johnb | 56:7fe74b03e6b1 | 221 | m_buffer[11] = p_applyChanges << 1; |
johnb | 56:7fe74b03e6b1 | 222 | } |
johnb | 56:7fe74b03e6b1 | 223 | else |
johnb | 56:7fe74b03e6b1 | 224 | { |
johnb | 56:7fe74b03e6b1 | 225 | m_buffer[11] = 0; |
johnb | 56:7fe74b03e6b1 | 226 | } |
johnb | 56:7fe74b03e6b1 | 227 | |
johnb | 50:f76b7e7959a2 | 228 | m_buffer[12] = p_data[0]; |
johnb | 50:f76b7e7959a2 | 229 | m_buffer[13] = p_data[1]; |
johnb | 50:f76b7e7959a2 | 230 | |
johnb | 56:7fe74b03e6b1 | 231 | m_data = m_buffer; |
johnb | 56:7fe74b03e6b1 | 232 | m_dataLen = XBEE_API_CMD_REMOTE_REQ_HEADER_LEN; |
johnb | 50:f76b7e7959a2 | 233 | |
johnb | 56:7fe74b03e6b1 | 234 | if(( p_val != NULL ) && |
johnb | 56:7fe74b03e6b1 | 235 | ( p_len <= XBEE_CMD_MAX_PARAM_LENGTH )) |
johnb | 56:7fe74b03e6b1 | 236 | { |
johnb | 56:7fe74b03e6b1 | 237 | size_t s = 0; |
johnb | 56:7fe74b03e6b1 | 238 | uint8_t* dest = &( m_buffer[ XBEE_API_CMD_REMOTE_REQ_HEADER_LEN ] ); |
johnb | 56:7fe74b03e6b1 | 239 | const uint8_t* src = p_val; |
johnb | 56:7fe74b03e6b1 | 240 | |
johnb | 56:7fe74b03e6b1 | 241 | for( s = 0; |
johnb | 56:7fe74b03e6b1 | 242 | s < p_len; |
johnb | 56:7fe74b03e6b1 | 243 | s++, dest++, src++ ) { |
johnb | 56:7fe74b03e6b1 | 244 | *dest = *src; |
johnb | 56:7fe74b03e6b1 | 245 | } |
johnb | 56:7fe74b03e6b1 | 246 | m_dataLen += p_len; |
johnb | 50:f76b7e7959a2 | 247 | } |
johnb | 50:f76b7e7959a2 | 248 | |
johnb | 56:7fe74b03e6b1 | 249 | #if 0 |
johnb | 56:7fe74b03e6b1 | 250 | /* Debugging code */ |
johnb | 56:7fe74b03e6b1 | 251 | extern Serial pc; |
johnb | 56:7fe74b03e6b1 | 252 | size_t x = 0; |
johnb | 56:7fe74b03e6b1 | 253 | pc.printf("\r\n[%02X][%02X][%02X]",(m_dataLen>>8U)&0xFF,m_dataLen&0xFF,m_apiId); |
johnb | 56:7fe74b03e6b1 | 254 | for( x = 0; x < m_dataLen; x++ ) |
johnb | 56:7fe74b03e6b1 | 255 | { |
johnb | 56:7fe74b03e6b1 | 256 | if(( x> 11 ) && ( x < 14 )) |
johnb | 56:7fe74b03e6b1 | 257 | { |
johnb | 56:7fe74b03e6b1 | 258 | pc.printf("%c",m_data[x]); |
johnb | 56:7fe74b03e6b1 | 259 | } |
johnb | 56:7fe74b03e6b1 | 260 | pc.printf("[%02X]",m_data[x]); |
johnb | 56:7fe74b03e6b1 | 261 | } |
johnb | 56:7fe74b03e6b1 | 262 | pc.printf("\r\n"); |
johnb | 56:7fe74b03e6b1 | 263 | #endif |
johnb | 50:f76b7e7959a2 | 264 | |
johnb | 50:f76b7e7959a2 | 265 | } |
johnb | 50:f76b7e7959a2 | 266 | |
johnb | 56:7fe74b03e6b1 | 267 | XBeeApiCmdAtRemoteFrame::~XBeeApiCmdAtRemoteFrame() |
johnb | 50:f76b7e7959a2 | 268 | { |
johnb | 50:f76b7e7959a2 | 269 | } |