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@55:610aa4a2ed3b, 2014-08-02 (annotated)
- Committer:
- johnb
- Date:
- Sat Aug 02 16:41:14 2014 +0000
- Revision:
- 55:610aa4a2ed3b
- Parent:
- 54:9f5b7652943e
- Child:
- 56:7fe74b03e6b1
Add support for "Restore Defaults" AT command.; Support in XbeeDeviceRemoteAt for re-association with a different XBee.
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 | 50:f76b7e7959a2 | 23 | template< typename T > |
johnb | 50:f76b7e7959a2 | 24 | class XBeeApiCmdAtRemoteSet : public XBeeApiFrame { |
johnb | 50:f76b7e7959a2 | 25 | uint8_t m_buffer[ XBEE_API_CMD_REMOTE_REQ_HEADER_LEN + sizeof( T ) ]; |
johnb | 50:f76b7e7959a2 | 26 | public: |
johnb | 50:f76b7e7959a2 | 27 | /** Constructor |
johnb | 50:f76b7e7959a2 | 28 | |
johnb | 50:f76b7e7959a2 | 29 | \param p_data Pointer to a buffer of length 2 bytes identifying |
johnb | 50:f76b7e7959a2 | 30 | the command, e.g. 'V', 'R' would set up a version |
johnb | 50:f76b7e7959a2 | 31 | request |
johnb | 50:f76b7e7959a2 | 32 | \param p_val New value for the parameter |
johnb | 50:f76b7e7959a2 | 33 | */ |
johnb | 50:f76b7e7959a2 | 34 | XBeeApiCmdAtRemoteSet( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 35 | const uint16_t p_addr16Bit, |
johnb | 50:f76b7e7959a2 | 36 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 37 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 51:a7d0d2ef9261 | 38 | const bool p_applyChanges, |
johnb | 50:f76b7e7959a2 | 39 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 40 | const T p_val ); |
johnb | 50:f76b7e7959a2 | 41 | /** Destructor */ |
johnb | 50:f76b7e7959a2 | 42 | virtual ~XBeeApiCmdAtRemoteSet(); |
johnb | 50:f76b7e7959a2 | 43 | }; |
johnb | 50:f76b7e7959a2 | 44 | |
johnb | 50:f76b7e7959a2 | 45 | class XBeeApiCmdAtRemoteReq : public XBeeApiFrame { |
johnb | 50:f76b7e7959a2 | 46 | uint8_t m_buffer[ XBEE_API_CMD_REMOTE_REQ_HEADER_LEN ]; |
johnb | 50:f76b7e7959a2 | 47 | public: |
johnb | 50:f76b7e7959a2 | 48 | /** Constructor |
johnb | 50:f76b7e7959a2 | 49 | |
johnb | 50:f76b7e7959a2 | 50 | \param p_data Pointer to a buffer of length 2 bytes identifying |
johnb | 50:f76b7e7959a2 | 51 | the command, e.g. 'V', 'R' would set up a version |
johnb | 50:f76b7e7959a2 | 52 | request |
johnb | 50:f76b7e7959a2 | 53 | \param p_val New value for the parameter |
johnb | 50:f76b7e7959a2 | 54 | */ |
johnb | 50:f76b7e7959a2 | 55 | XBeeApiCmdAtRemoteReq( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 56 | const uint16_t p_addr16Bit, |
johnb | 50:f76b7e7959a2 | 57 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 58 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 50:f76b7e7959a2 | 59 | const uint8_t* const p_data ); |
johnb | 50:f76b7e7959a2 | 60 | /** Destructor */ |
johnb | 50:f76b7e7959a2 | 61 | virtual ~XBeeApiCmdAtRemoteReq(); |
johnb | 50:f76b7e7959a2 | 62 | }; |
johnb | 50:f76b7e7959a2 | 63 | |
johnb | 50:f76b7e7959a2 | 64 | XBeeDeviceRemoteAt::XBeeDeviceRemoteAt( XBeeDevice* p_device, |
johnb | 50:f76b7e7959a2 | 65 | const uint16_t& p_addr16Bit, |
johnb | 51:a7d0d2ef9261 | 66 | const uint64_t& p_addr64Bit, |
johnb | 52:0950b05d5270 | 67 | const bool p_applyChanges ) : XBeeApiCmdAt( p_device ), m_applyChanges( p_applyChanges ) |
johnb | 50:f76b7e7959a2 | 68 | { |
johnb | 55:610aa4a2ed3b | 69 | setAddress( p_addr16Bit, p_addr64Bit ); |
johnb | 55:610aa4a2ed3b | 70 | } |
johnb | 55:610aa4a2ed3b | 71 | |
johnb | 55:610aa4a2ed3b | 72 | void XBeeDeviceRemoteAt::setAddress( const uint16_t& p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 73 | const uint64_t& p_addr64Bit ) |
johnb | 55:610aa4a2ed3b | 74 | { |
johnb | 52:0950b05d5270 | 75 | if( p_addr16Bit != XBEE_USE_64BIT_ADDR ) |
johnb | 52:0950b05d5270 | 76 | { |
johnb | 52:0950b05d5270 | 77 | m_sourceAddress = p_addr16Bit; |
johnb | 52:0950b05d5270 | 78 | m_have_sourceAddress = true; |
johnb | 54:9f5b7652943e | 79 | m_snLow = m_snHigh = 0; |
johnb | 55:610aa4a2ed3b | 80 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_16BIT; |
johnb | 52:0950b05d5270 | 81 | } else |
johnb | 52:0950b05d5270 | 82 | { |
johnb | 52:0950b05d5270 | 83 | m_snLow = (p_addr64Bit & 0xFFFFFFFF); |
johnb | 52:0950b05d5270 | 84 | m_snHigh = ((p_addr64Bit >> 32U) & 0xFFFFFFFF); |
johnb | 52:0950b05d5270 | 85 | m_sourceAddress = XBEE_USE_64BIT_ADDR; |
johnb | 52:0950b05d5270 | 86 | m_have_snLow = m_have_snHigh = true; |
johnb | 55:610aa4a2ed3b | 87 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_64BIT; |
johnb | 55:610aa4a2ed3b | 88 | } |
johnb | 50:f76b7e7959a2 | 89 | } |
johnb | 55:610aa4a2ed3b | 90 | |
johnb | 55:610aa4a2ed3b | 91 | void XBeeDeviceRemoteAt::reassociate( const uint16_t& p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 92 | const uint64_t& p_addr64Bit ) |
johnb | 55:610aa4a2ed3b | 93 | { |
johnb | 55:610aa4a2ed3b | 94 | resetCachedData(); |
johnb | 55:610aa4a2ed3b | 95 | setAddress( p_addr16Bit, p_addr64Bit ); |
johnb | 55:610aa4a2ed3b | 96 | } |
johnb | 55:610aa4a2ed3b | 97 | |
johnb | 50:f76b7e7959a2 | 98 | |
johnb | 50:f76b7e7959a2 | 99 | XBeeDeviceRemoteAt::~XBeeDeviceRemoteAt( void ) |
johnb | 50:f76b7e7959a2 | 100 | { |
johnb | 50:f76b7e7959a2 | 101 | } |
johnb | 50:f76b7e7959a2 | 102 | |
johnb | 51:a7d0d2ef9261 | 103 | void XBeeDeviceRemoteAt::setApplyChanges( const bool p_apply ) |
johnb | 51:a7d0d2ef9261 | 104 | { |
johnb | 51:a7d0d2ef9261 | 105 | m_applyChanges = p_apply; |
johnb | 51:a7d0d2ef9261 | 106 | } |
johnb | 50:f76b7e7959a2 | 107 | |
johnb | 50:f76b7e7959a2 | 108 | #define XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS (XBEE_CMD_POSN_ID_SPECIFIC_DATA+1) |
johnb | 50:f76b7e7959a2 | 109 | #define XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS (XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + sizeof( uint64_t)) |
johnb | 50:f76b7e7959a2 | 110 | #define XBEE_REMOTE_AT_RESPONSE_STATUS (17U) |
johnb | 50:f76b7e7959a2 | 111 | |
johnb | 50:f76b7e7959a2 | 112 | size_t XBeeDeviceRemoteAt::getResponseStatusPos( void ) const |
johnb | 50:f76b7e7959a2 | 113 | { |
johnb | 50:f76b7e7959a2 | 114 | return XBEE_REMOTE_AT_RESPONSE_STATUS; |
johnb | 50:f76b7e7959a2 | 115 | } |
johnb | 50:f76b7e7959a2 | 116 | |
johnb | 50:f76b7e7959a2 | 117 | bool XBeeDeviceRemoteAt::decodeCallback( const uint8_t* const p_data, size_t p_len ) |
johnb | 50:f76b7e7959a2 | 118 | { |
johnb | 50:f76b7e7959a2 | 119 | bool ret_val = false; |
johnb | 50:f76b7e7959a2 | 120 | |
johnb | 50:f76b7e7959a2 | 121 | /* TODO: Length check */ |
johnb | 50:f76b7e7959a2 | 122 | |
johnb | 50:f76b7e7959a2 | 123 | if( XBEE_CMD_REMOTE_AT_RESPONSE == p_data[ XBEE_CMD_POSN_API_ID ] ) |
johnb | 50:f76b7e7959a2 | 124 | { |
johnb | 52:0950b05d5270 | 125 | uint32_t srcAddrHigh = (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS ]) << 24U) | |
johnb | 52:0950b05d5270 | 126 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 1 ]) << 16U) | |
johnb | 52:0950b05d5270 | 127 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 2 ]) << 8U) | |
johnb | 52:0950b05d5270 | 128 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 3 ])); |
johnb | 52:0950b05d5270 | 129 | uint32_t srcAddrLow = (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 4 ]) << 24U) | |
johnb | 50:f76b7e7959a2 | 130 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 5 ]) << 16U) | |
johnb | 50:f76b7e7959a2 | 131 | (((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 6 ]) << 8U) | |
johnb | 50:f76b7e7959a2 | 132 | ((uint64_t)p_data[ XBEE_REMOTE_AT_RESPONSE_64BIT_ADDRESS + 7 ]); |
johnb | 52:0950b05d5270 | 133 | |
johnb | 50:f76b7e7959a2 | 134 | uint16_t src16BitAddr = (((uint16_t)p_data[ XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS ]) << 8U) | |
johnb | 50:f76b7e7959a2 | 135 | p_data[ XBEE_REMOTE_AT_RESPONSE_16BIT_ADDRESS + 1 ]; |
johnb | 52:0950b05d5270 | 136 | |
johnb | 52:0950b05d5270 | 137 | if((( m_have_sourceAddress ) && ( m_sourceAddress == src16BitAddr )) || |
johnb | 52:0950b05d5270 | 138 | ( m_have_snHigh && m_have_snLow && ( srcAddrHigh == m_snHigh ) && ( srcAddrLow == m_snLow ))) |
johnb | 50:f76b7e7959a2 | 139 | { |
johnb | 50:f76b7e7959a2 | 140 | ret_val = processResponseFrame( p_data, p_len ); |
johnb | 50:f76b7e7959a2 | 141 | } |
johnb | 50:f76b7e7959a2 | 142 | } |
johnb | 52:0950b05d5270 | 143 | else |
johnb | 51:a7d0d2ef9261 | 144 | { |
johnb | 54:9f5b7652943e | 145 | ret_val = XBeeApiCmdAt::decodeCallback( p_data, p_len ); |
johnb | 51:a7d0d2ef9261 | 146 | } |
johnb | 51:a7d0d2ef9261 | 147 | |
johnb | 50:f76b7e7959a2 | 148 | return ret_val; |
johnb | 50:f76b7e7959a2 | 149 | } |
johnb | 50:f76b7e7959a2 | 150 | |
johnb | 50:f76b7e7959a2 | 151 | void XBeeDeviceRemoteAt::SendCmd_uint8_t( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 152 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 153 | const uint8_t& p_val ) |
johnb | 50:f76b7e7959a2 | 154 | { |
johnb | 52:0950b05d5270 | 155 | uint64_t addr64Bit = (((uint64_t)m_snHigh) << 32U) | (uint64_t)m_snLow; |
johnb | 52:0950b05d5270 | 156 | /* TODO: Add option to force usage of 16 or 64-bit addressing */ |
johnb | 55:610aa4a2ed3b | 157 | XBeeApiCmdAtRemoteSet<uint8_t> req( p_frameId, m_sourceAddress, addr64Bit, m_addressingType, m_applyChanges, p_data, p_val ); |
johnb | 50:f76b7e7959a2 | 158 | m_device->SendFrame( &req ); |
johnb | 50:f76b7e7959a2 | 159 | } |
johnb | 50:f76b7e7959a2 | 160 | |
johnb | 50:f76b7e7959a2 | 161 | void XBeeDeviceRemoteAt::SendCmd_uint16_t( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 162 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 163 | const uint16_t& p_val ) |
johnb | 50:f76b7e7959a2 | 164 | { |
johnb | 52:0950b05d5270 | 165 | uint64_t addr64Bit = (((uint64_t)m_snHigh) << 32U) | (uint64_t)m_snLow; |
johnb | 55:610aa4a2ed3b | 166 | XBeeApiCmdAtRemoteSet<uint16_t> req( p_frameId, m_sourceAddress, addr64Bit, m_addressingType, m_applyChanges, p_data, p_val ); |
johnb | 51:a7d0d2ef9261 | 167 | m_device->SendFrame( &req ); |
johnb | 51:a7d0d2ef9261 | 168 | } |
johnb | 51:a7d0d2ef9261 | 169 | |
johnb | 51:a7d0d2ef9261 | 170 | void XBeeDeviceRemoteAt::SendCmd_uint32_t( const uint8_t p_frameId, |
johnb | 51:a7d0d2ef9261 | 171 | const uint8_t* const p_data, |
johnb | 51:a7d0d2ef9261 | 172 | const uint32_t& p_val ) |
johnb | 51:a7d0d2ef9261 | 173 | { |
johnb | 52:0950b05d5270 | 174 | uint64_t addr64Bit = (((uint64_t)m_snHigh) << 32U) | (uint64_t)m_snLow; |
johnb | 55:610aa4a2ed3b | 175 | XBeeApiCmdAtRemoteSet<uint32_t> req( p_frameId, m_sourceAddress, addr64Bit, m_addressingType, m_applyChanges, p_data, p_val ); |
johnb | 50:f76b7e7959a2 | 176 | m_device->SendFrame( &req ); |
johnb | 50:f76b7e7959a2 | 177 | } |
johnb | 50:f76b7e7959a2 | 178 | |
johnb | 50:f76b7e7959a2 | 179 | void XBeeDeviceRemoteAt::SendReq( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 180 | const uint8_t* p_data ) |
johnb | 50:f76b7e7959a2 | 181 | { |
johnb | 52:0950b05d5270 | 182 | uint64_t addr64Bit = (((uint64_t)m_snHigh) << 32U) | (uint64_t)m_snLow; |
johnb | 55:610aa4a2ed3b | 183 | XBeeApiCmdAtRemoteReq req( p_frameId, m_sourceAddress, addr64Bit, m_addressingType, p_data ); |
johnb | 52:0950b05d5270 | 184 | m_device->SendFrame( &req ); |
johnb | 50:f76b7e7959a2 | 185 | } |
johnb | 50:f76b7e7959a2 | 186 | |
johnb | 55:610aa4a2ed3b | 187 | bool XBeeDeviceRemoteAt::setAddressingType( const XBeeDevice::XBeeApiAddrType_t p_type ) |
johnb | 55:610aa4a2ed3b | 188 | { |
johnb | 55:610aa4a2ed3b | 189 | bool ret_val = false; |
johnb | 55:610aa4a2ed3b | 190 | |
johnb | 55:610aa4a2ed3b | 191 | switch( p_type ) |
johnb | 55:610aa4a2ed3b | 192 | { |
johnb | 55:610aa4a2ed3b | 193 | case XBeeDevice::XBEE_API_ADDR_TYPE_16BIT: |
johnb | 55:610aa4a2ed3b | 194 | if( m_have_sourceAddress ) |
johnb | 55:610aa4a2ed3b | 195 | { |
johnb | 55:610aa4a2ed3b | 196 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_16BIT; |
johnb | 55:610aa4a2ed3b | 197 | ret_val = true; |
johnb | 55:610aa4a2ed3b | 198 | } |
johnb | 55:610aa4a2ed3b | 199 | break; |
johnb | 55:610aa4a2ed3b | 200 | case XBeeDevice::XBEE_API_ADDR_TYPE_64BIT: |
johnb | 55:610aa4a2ed3b | 201 | if( m_have_snLow && m_have_snHigh ) |
johnb | 55:610aa4a2ed3b | 202 | { |
johnb | 55:610aa4a2ed3b | 203 | m_addressingType = XBeeDevice::XBEE_API_ADDR_TYPE_64BIT; |
johnb | 55:610aa4a2ed3b | 204 | ret_val = true; |
johnb | 55:610aa4a2ed3b | 205 | } |
johnb | 55:610aa4a2ed3b | 206 | break; |
johnb | 55:610aa4a2ed3b | 207 | } |
johnb | 55:610aa4a2ed3b | 208 | |
johnb | 55:610aa4a2ed3b | 209 | return ret_val; |
johnb | 55:610aa4a2ed3b | 210 | } |
johnb | 55:610aa4a2ed3b | 211 | |
johnb | 55:610aa4a2ed3b | 212 | static void writeAddressToBuffer( uint8_t* const p_buffer, |
johnb | 55:610aa4a2ed3b | 213 | const uint16_t p_addr16Bit, |
johnb | 55:610aa4a2ed3b | 214 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 215 | const XBeeDevice::XBeeApiAddrType_t p_type ) |
johnb | 55:610aa4a2ed3b | 216 | { |
johnb | 55:610aa4a2ed3b | 217 | if( p_type == XBeeDevice::XBEE_API_ADDR_TYPE_64BIT ) |
johnb | 55:610aa4a2ed3b | 218 | { |
johnb | 55:610aa4a2ed3b | 219 | p_buffer[0] = p_addr64Bit >> 56U; |
johnb | 55:610aa4a2ed3b | 220 | p_buffer[1] = p_addr64Bit >> 48U; |
johnb | 55:610aa4a2ed3b | 221 | p_buffer[2] = p_addr64Bit >> 40U; |
johnb | 55:610aa4a2ed3b | 222 | p_buffer[3] = p_addr64Bit >> 32U; |
johnb | 55:610aa4a2ed3b | 223 | p_buffer[4] = p_addr64Bit >> 24U; |
johnb | 55:610aa4a2ed3b | 224 | p_buffer[5] = p_addr64Bit >> 16U; |
johnb | 55:610aa4a2ed3b | 225 | p_buffer[6] = p_addr64Bit >> 8U; |
johnb | 55:610aa4a2ed3b | 226 | p_buffer[7] = p_addr64Bit; |
johnb | 55:610aa4a2ed3b | 227 | |
johnb | 55:610aa4a2ed3b | 228 | p_buffer[8] = (uint8_t)(XBEE_USE_64BIT_ADDR >> 8U); |
johnb | 55:610aa4a2ed3b | 229 | p_buffer[9] = (uint8_t)(XBEE_USE_64BIT_ADDR & 0xFF); |
johnb | 55:610aa4a2ed3b | 230 | } |
johnb | 55:610aa4a2ed3b | 231 | else |
johnb | 55:610aa4a2ed3b | 232 | { |
johnb | 55:610aa4a2ed3b | 233 | |
johnb | 55:610aa4a2ed3b | 234 | p_buffer[0] = 0; |
johnb | 55:610aa4a2ed3b | 235 | p_buffer[1] = 0; |
johnb | 55:610aa4a2ed3b | 236 | p_buffer[2] = 0; |
johnb | 55:610aa4a2ed3b | 237 | p_buffer[3] = 0; |
johnb | 55:610aa4a2ed3b | 238 | p_buffer[4] = 0; |
johnb | 55:610aa4a2ed3b | 239 | p_buffer[5] = 0; |
johnb | 55:610aa4a2ed3b | 240 | p_buffer[6] = 0; |
johnb | 55:610aa4a2ed3b | 241 | p_buffer[7] = 0; |
johnb | 55:610aa4a2ed3b | 242 | |
johnb | 55:610aa4a2ed3b | 243 | p_buffer[8] = p_addr16Bit >> 8U; |
johnb | 55:610aa4a2ed3b | 244 | p_buffer[9] = p_addr16Bit; |
johnb | 55:610aa4a2ed3b | 245 | } |
johnb | 55:610aa4a2ed3b | 246 | } |
johnb | 55:610aa4a2ed3b | 247 | |
johnb | 50:f76b7e7959a2 | 248 | template < typename T > |
johnb | 50:f76b7e7959a2 | 249 | XBeeApiCmdAtRemoteSet<T>::XBeeApiCmdAtRemoteSet( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 250 | const uint16_t p_addr16Bit, |
johnb | 50:f76b7e7959a2 | 251 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 252 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 51:a7d0d2ef9261 | 253 | const bool p_applyChanges, |
johnb | 50:f76b7e7959a2 | 254 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 255 | const T p_val ) : XBeeApiFrame( ) |
johnb | 50:f76b7e7959a2 | 256 | { |
johnb | 50:f76b7e7959a2 | 257 | size_t s; |
johnb | 50:f76b7e7959a2 | 258 | uint8_t* dest; |
johnb | 50:f76b7e7959a2 | 259 | const uint8_t* src = (uint8_t*)(&p_val); |
johnb | 50:f76b7e7959a2 | 260 | |
johnb | 50:f76b7e7959a2 | 261 | m_apiId = XBEE_CMD_REMOTE_AT_CMD; |
johnb | 50:f76b7e7959a2 | 262 | |
johnb | 50:f76b7e7959a2 | 263 | m_buffer[0] = p_frameId; |
johnb | 50:f76b7e7959a2 | 264 | |
johnb | 55:610aa4a2ed3b | 265 | writeAddressToBuffer( &(m_buffer[1]), p_addr16Bit, p_addr64Bit, p_type ); |
johnb | 50:f76b7e7959a2 | 266 | |
johnb | 51:a7d0d2ef9261 | 267 | m_buffer[11] = p_applyChanges << 1; |
johnb | 50:f76b7e7959a2 | 268 | |
johnb | 50:f76b7e7959a2 | 269 | m_buffer[12] = p_data[0]; |
johnb | 50:f76b7e7959a2 | 270 | m_buffer[13] = p_data[1]; |
johnb | 50:f76b7e7959a2 | 271 | |
johnb | 50:f76b7e7959a2 | 272 | m_dataLen = sizeof( m_buffer ); |
johnb | 50:f76b7e7959a2 | 273 | |
johnb | 50:f76b7e7959a2 | 274 | /* TODO: This copy code isn't portable - it's assuming that the data in |
johnb | 50:f76b7e7959a2 | 275 | * p_data is little endian */ |
johnb | 50:f76b7e7959a2 | 276 | |
johnb | 50:f76b7e7959a2 | 277 | dest = &( m_buffer[ m_dataLen - 1 ] ); |
johnb | 50:f76b7e7959a2 | 278 | |
johnb | 50:f76b7e7959a2 | 279 | for( s = 0; |
johnb | 50:f76b7e7959a2 | 280 | s < sizeof( T ); |
johnb | 50:f76b7e7959a2 | 281 | s++, dest--, src++ ) { |
johnb | 50:f76b7e7959a2 | 282 | *dest = *src; |
johnb | 50:f76b7e7959a2 | 283 | } |
johnb | 50:f76b7e7959a2 | 284 | |
johnb | 50:f76b7e7959a2 | 285 | m_data = m_buffer; |
johnb | 50:f76b7e7959a2 | 286 | } |
johnb | 50:f76b7e7959a2 | 287 | |
johnb | 50:f76b7e7959a2 | 288 | template < typename T > |
johnb | 50:f76b7e7959a2 | 289 | XBeeApiCmdAtRemoteSet<T>::~XBeeApiCmdAtRemoteSet() |
johnb | 50:f76b7e7959a2 | 290 | { |
johnb | 50:f76b7e7959a2 | 291 | } |
johnb | 50:f76b7e7959a2 | 292 | |
johnb | 50:f76b7e7959a2 | 293 | XBeeApiCmdAtRemoteReq::XBeeApiCmdAtRemoteReq( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 294 | const uint16_t p_addr16Bit, |
johnb | 50:f76b7e7959a2 | 295 | const uint64_t p_addr64Bit, |
johnb | 55:610aa4a2ed3b | 296 | const XBeeDevice::XBeeApiAddrType_t p_type, |
johnb | 50:f76b7e7959a2 | 297 | const uint8_t* const p_data ) |
johnb | 50:f76b7e7959a2 | 298 | { |
johnb | 50:f76b7e7959a2 | 299 | m_apiId = XBEE_CMD_REMOTE_AT_CMD; |
johnb | 50:f76b7e7959a2 | 300 | |
johnb | 50:f76b7e7959a2 | 301 | m_buffer[0] = p_frameId; |
johnb | 50:f76b7e7959a2 | 302 | |
johnb | 55:610aa4a2ed3b | 303 | writeAddressToBuffer( &(m_buffer[1]), p_addr16Bit, p_addr64Bit, p_type ); |
johnb | 50:f76b7e7959a2 | 304 | |
johnb | 50:f76b7e7959a2 | 305 | m_buffer[11] = 0; |
johnb | 50:f76b7e7959a2 | 306 | |
johnb | 50:f76b7e7959a2 | 307 | m_buffer[12] = p_data[0]; |
johnb | 50:f76b7e7959a2 | 308 | m_buffer[13] = p_data[1]; |
johnb | 50:f76b7e7959a2 | 309 | |
johnb | 50:f76b7e7959a2 | 310 | m_dataLen = sizeof( m_buffer ); |
johnb | 50:f76b7e7959a2 | 311 | m_data = m_buffer; |
johnb | 50:f76b7e7959a2 | 312 | } |
johnb | 50:f76b7e7959a2 | 313 | |
johnb | 50:f76b7e7959a2 | 314 | XBeeApiCmdAtRemoteReq::~XBeeApiCmdAtRemoteReq() |
johnb | 50:f76b7e7959a2 | 315 | { |
johnb | 50:f76b7e7959a2 | 316 | } |