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
RXTX/XBeeApiTxFrame.cpp@44:85a66d56e176, 2014-07-06 (annotated)
- Committer:
- johnb
- Date:
- Sun Jul 06 20:59:58 2014 +0000
- Revision:
- 44:85a66d56e176
- Parent:
- 27:6356ef5fe39b
- Child:
- 46:a1abbc66f157
Expand argument list on XBeeApiTxFrame constructor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnb | 9:ba90e9efd68b | 1 | /** |
johnb | 9:ba90e9efd68b | 2 | |
johnb | 9:ba90e9efd68b | 3 | Copyright 2014 John Bailey |
johnb | 9:ba90e9efd68b | 4 | |
johnb | 9:ba90e9efd68b | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
johnb | 9:ba90e9efd68b | 6 | you may not use this file except in compliance with the License. |
johnb | 9:ba90e9efd68b | 7 | You may obtain a copy of the License at |
johnb | 9:ba90e9efd68b | 8 | |
johnb | 9:ba90e9efd68b | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
johnb | 9:ba90e9efd68b | 10 | |
johnb | 9:ba90e9efd68b | 11 | Unless required by applicable law or agreed to in writing, software |
johnb | 9:ba90e9efd68b | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
johnb | 9:ba90e9efd68b | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
johnb | 9:ba90e9efd68b | 14 | See the License for the specific language governing permissions and |
johnb | 9:ba90e9efd68b | 15 | limitations under the License. |
johnb | 9:ba90e9efd68b | 16 | |
johnb | 9:ba90e9efd68b | 17 | */ |
johnb | 9:ba90e9efd68b | 18 | |
johnb | 9:ba90e9efd68b | 19 | #include "XBeeApiTxFrame.hpp" |
johnb | 9:ba90e9efd68b | 20 | |
johnb | 44:85a66d56e176 | 21 | XBeeApiTxFrame::XBeeApiTxFrame( XBeeDevice* p_device, |
johnb | 44:85a66d56e176 | 22 | const uint8_t* p_data, |
johnb | 44:85a66d56e176 | 23 | const size_t p_dataLen, |
johnb | 44:85a66d56e176 | 24 | const uint64_t p_addr, |
johnb | 44:85a66d56e176 | 25 | const XBeeDevice::XBeeApiAddrType_t p_type ) : |
johnb | 44:85a66d56e176 | 26 | XBeeApiFrame(), XBeeApiFrameDecoder( p_device ), |
johnb | 44:85a66d56e176 | 27 | m_addr( p_addr ), |
johnb | 12:58319a467943 | 28 | m_ack( true ), |
johnb | 12:58319a467943 | 29 | m_panBroadcast( false ) |
johnb | 9:ba90e9efd68b | 30 | { |
johnb | 44:85a66d56e176 | 31 | setDestAddrType( p_type ); |
johnb | 44:85a66d56e176 | 32 | setDataPtr( p_data, p_dataLen ); |
johnb | 9:ba90e9efd68b | 33 | } |
johnb | 12:58319a467943 | 34 | |
johnb | 12:58319a467943 | 35 | |
johnb | 12:58319a467943 | 36 | XBeeApiTxFrame::~XBeeApiTxFrame( void ) |
johnb | 12:58319a467943 | 37 | { |
johnb | 12:58319a467943 | 38 | } |
johnb | 12:58319a467943 | 39 | |
johnb | 16:8095c43a2a6e | 40 | uint8_t XBeeApiTxFrame::getFrameId( void ) const |
johnb | 16:8095c43a2a6e | 41 | { |
johnb | 16:8095c43a2a6e | 42 | return 'T'; |
johnb | 16:8095c43a2a6e | 43 | } |
johnb | 16:8095c43a2a6e | 44 | |
johnb | 16:8095c43a2a6e | 45 | uint16_t XBeeApiTxFrame::getCmdLen( void ) const |
johnb | 16:8095c43a2a6e | 46 | { |
johnb | 16:8095c43a2a6e | 47 | /* Length of the data payload plus the API ID, frame ID and option byte */ |
johnb | 16:8095c43a2a6e | 48 | uint16_t ret_val = m_dataLen + 3U; |
johnb | 16:8095c43a2a6e | 49 | |
johnb | 16:8095c43a2a6e | 50 | if( m_apiId == XBEE_CMD_TX_16B_ADDR ) |
johnb | 16:8095c43a2a6e | 51 | { |
johnb | 16:8095c43a2a6e | 52 | ret_val += 2U; |
johnb | 16:8095c43a2a6e | 53 | } |
johnb | 16:8095c43a2a6e | 54 | else |
johnb | 16:8095c43a2a6e | 55 | { |
johnb | 16:8095c43a2a6e | 56 | ret_val += 8U; |
johnb | 16:8095c43a2a6e | 57 | } |
johnb | 16:8095c43a2a6e | 58 | |
johnb | 16:8095c43a2a6e | 59 | return ret_val; |
johnb | 16:8095c43a2a6e | 60 | } |
johnb | 16:8095c43a2a6e | 61 | |
johnb | 16:8095c43a2a6e | 62 | |
johnb | 16:8095c43a2a6e | 63 | void XBeeApiTxFrame::getDataPtr( const uint16_t p_start, const uint8_t** p_buff, uint16_t* const p_len ) |
johnb | 12:58319a467943 | 64 | { |
johnb | 13:302e7c1ea0b3 | 65 | if( p_start == 0 ) |
johnb | 13:302e7c1ea0b3 | 66 | { |
johnb | 16:8095c43a2a6e | 67 | /* Need to keep the XBEE_API_TX_FRAME_BUFFER_SIZE limit in mind when writing to m_buffer */ |
johnb | 16:8095c43a2a6e | 68 | |
johnb | 16:8095c43a2a6e | 69 | uint8_t len = 0; |
johnb | 16:8095c43a2a6e | 70 | m_buffer[ len++ ] = getFrameId(); // Frame ID |
johnb | 16:8095c43a2a6e | 71 | |
johnb | 16:8095c43a2a6e | 72 | /* Pack the destination address depending on whether it's 16 or 64-bit addressed */ |
johnb | 16:8095c43a2a6e | 73 | if( m_apiId == XBEE_CMD_TX_16B_ADDR ) |
johnb | 16:8095c43a2a6e | 74 | { |
johnb | 16:8095c43a2a6e | 75 | m_buffer[ len++ ] = m_addr >> 8U; |
johnb | 16:8095c43a2a6e | 76 | m_buffer[ len++ ] = m_addr; |
johnb | 16:8095c43a2a6e | 77 | } |
johnb | 16:8095c43a2a6e | 78 | else |
johnb | 16:8095c43a2a6e | 79 | { |
johnb | 16:8095c43a2a6e | 80 | m_buffer[ len++ ] = m_addr >> 56U; |
johnb | 16:8095c43a2a6e | 81 | m_buffer[ len++ ] = m_addr >> 48U; |
johnb | 16:8095c43a2a6e | 82 | m_buffer[ len++ ] = m_addr >> 32U; |
johnb | 16:8095c43a2a6e | 83 | m_buffer[ len++ ] = m_addr >> 24U; |
johnb | 16:8095c43a2a6e | 84 | m_buffer[ len++ ] = m_addr >> 16U; |
johnb | 16:8095c43a2a6e | 85 | m_buffer[ len++ ] = m_addr >> 8U; |
johnb | 16:8095c43a2a6e | 86 | m_buffer[ len++ ] = m_addr; |
johnb | 16:8095c43a2a6e | 87 | } |
johnb | 16:8095c43a2a6e | 88 | |
johnb | 16:8095c43a2a6e | 89 | /* Frame options */ |
johnb | 16:8095c43a2a6e | 90 | m_buffer[ len++ ] = m_ack? (0x00U):(0x01U) |
johnb | 16:8095c43a2a6e | 91 | | m_panBroadcast?(0x04U):(0x00U); |
johnb | 16:8095c43a2a6e | 92 | |
johnb | 13:302e7c1ea0b3 | 93 | *p_buff = &( m_buffer[0] ); |
johnb | 16:8095c43a2a6e | 94 | *p_len = len; |
johnb | 16:8095c43a2a6e | 95 | } |
johnb | 16:8095c43a2a6e | 96 | else |
johnb | 16:8095c43a2a6e | 97 | { |
johnb | 16:8095c43a2a6e | 98 | *p_buff = m_data; |
johnb | 16:8095c43a2a6e | 99 | *p_len = m_dataLen; |
johnb | 13:302e7c1ea0b3 | 100 | } |
johnb | 12:58319a467943 | 101 | } |
johnb | 12:58319a467943 | 102 | |
johnb | 16:8095c43a2a6e | 103 | bool XBeeApiTxFrame::setDataPtr( const uint8_t* const p_buff, const uint16_t p_len ) |
johnb | 16:8095c43a2a6e | 104 | { |
johnb | 16:8095c43a2a6e | 105 | bool ret_val = false; |
johnb | 16:8095c43a2a6e | 106 | if( p_len < XBEE_API_MAX_TX_PAYLOAD_LEN ) |
johnb | 16:8095c43a2a6e | 107 | { |
johnb | 16:8095c43a2a6e | 108 | m_data = p_buff; |
johnb | 16:8095c43a2a6e | 109 | m_dataLen = p_len; |
johnb | 16:8095c43a2a6e | 110 | } |
johnb | 16:8095c43a2a6e | 111 | return ret_val; |
johnb | 16:8095c43a2a6e | 112 | } |
johnb | 12:58319a467943 | 113 | |
johnb | 12:58319a467943 | 114 | void XBeeApiTxFrame::setDestAddrType( const XBeeDevice::XBeeApiAddrType_t p_type ) |
johnb | 12:58319a467943 | 115 | { |
johnb | 12:58319a467943 | 116 | if( p_type == XBeeDevice::XBEE_API_ADDR_TYPE_16BIT ) |
johnb | 12:58319a467943 | 117 | { |
johnb | 12:58319a467943 | 118 | m_apiId = XBEE_CMD_TX_16B_ADDR; |
johnb | 12:58319a467943 | 119 | } |
johnb | 12:58319a467943 | 120 | else |
johnb | 12:58319a467943 | 121 | { |
johnb | 12:58319a467943 | 122 | m_apiId = XBEE_CMD_TX_64B_ADDR; |
johnb | 12:58319a467943 | 123 | } |
johnb | 12:58319a467943 | 124 | } |
johnb | 9:ba90e9efd68b | 125 | |
johnb | 9:ba90e9efd68b | 126 | void XBeeApiTxFrame::setDestAddr( uint64_t p_addr ) |
johnb | 9:ba90e9efd68b | 127 | { |
johnb | 9:ba90e9efd68b | 128 | m_addr = p_addr; |
johnb | 9:ba90e9efd68b | 129 | } |
johnb | 9:ba90e9efd68b | 130 | |
johnb | 9:ba90e9efd68b | 131 | void XBeeApiTxFrame::setDestAddrBroadcast( void ) |
johnb | 9:ba90e9efd68b | 132 | { |
johnb | 27:6356ef5fe39b | 133 | m_addr = XBEE_BROADCAST_ADDR; |
johnb | 9:ba90e9efd68b | 134 | } |
johnb | 9:ba90e9efd68b | 135 | |
johnb | 9:ba90e9efd68b | 136 | void XBeeApiTxFrame::setPanBroadcast( const bool p_bc ) |
johnb | 9:ba90e9efd68b | 137 | { |
johnb | 9:ba90e9efd68b | 138 | m_panBroadcast = p_bc; |
johnb | 9:ba90e9efd68b | 139 | } |
johnb | 9:ba90e9efd68b | 140 | |
johnb | 9:ba90e9efd68b | 141 | bool XBeeApiTxFrame::decodeCallback( const uint8_t* const p_data, size_t p_len ) |
johnb | 9:ba90e9efd68b | 142 | { |
johnb | 9:ba90e9efd68b | 143 | bool ret_val = false; |
johnb | 16:8095c43a2a6e | 144 | |
johnb | 9:ba90e9efd68b | 145 | if( XBEE_CMD_TX_STATUS == p_data[ XBEE_CMD_POSN_API_ID ] ) |
johnb | 9:ba90e9efd68b | 146 | { |
johnb | 15:ff9f12e38f44 | 147 | /* Data transmitted call-back */ |
johnb | 16:8095c43a2a6e | 148 | frameTxCallback( (XBeeApiTxStatus_e)(p_data[ XBEE_CMD_POSN_ID_SPECIFIC_DATA + 1U ]) ); |
johnb | 9:ba90e9efd68b | 149 | ret_val = true; |
johnb | 9:ba90e9efd68b | 150 | } |
johnb | 9:ba90e9efd68b | 151 | |
johnb | 9:ba90e9efd68b | 152 | return ret_val; |
johnb | 9:ba90e9efd68b | 153 | } |
johnb | 15:ff9f12e38f44 | 154 | |
johnb | 15:ff9f12e38f44 | 155 | void XBeeApiTxFrame::frameTxCallback( const XBeeApiTxStatus_e p_status ) |
johnb | 15:ff9f12e38f44 | 156 | { |
johnb | 16:8095c43a2a6e | 157 | /* TODO */ |
johnb | 15:ff9f12e38f44 | 158 | } |