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
Diff: RXTX/XBeeApiRxFrame.cpp
- Revision:
- 45:dde04adb8791
- Parent:
- 44:85a66d56e176
- Child:
- 46:a1abbc66f157
--- a/RXTX/XBeeApiRxFrame.cpp Sun Jul 06 20:59:58 2014 +0000
+++ b/RXTX/XBeeApiRxFrame.cpp Sun Jul 06 21:47:31 2014 +0000
@@ -18,71 +18,46 @@
#include "XBeeApiRxFrame.hpp"
-XBeeApiRxFrame::XBeeApiRxFrame( XBeeDevice* p_device ) : XBeeApiFrame(), XBeeApiFrameDecoder( p_device )
+XBeeApiRxFrame::XBeeApiRxFrame( void ) : XBeeApiFrame(),
+ m_dataIsMallocd ( false )
+{
+}
+
+/** Constructor */
+XBeeApiRxFrame::XBeeApiRxFrame( XBeeApiIdentifier_e p_id,
+ const uint8_t* const p_data,
+ const size_t p_dataLen ) : XBeeApiFrame( p_id, p_data, p_dataLen ),
+ m_dataIsMallocd ( false )
{
}
XBeeApiRxFrame::~XBeeApiRxFrame( void )
{
+ if( m_dataIsMallocd )
+ {
+ free( m_mallocdData );
+ }
}
-
-bool XBeeApiRxFrame::decodeCallback( const uint8_t* const p_data, size_t p_len )
+
+bool XBeeApiRxFrame::deepCopyFrom( const XBeeApiRxFrame& p_frame )
{
- bool ret_val = false;
-
- /* TODO: Length check */
-
- if(( XBEE_CMD_RX_64B_ADDR == p_data[ XBEE_CMD_POSN_API_ID ] ) ||
- ( XBEE_CMD_RX_16B_ADDR == p_data[ XBEE_CMD_POSN_API_ID ] ))
+ /* TODO: need to catch assignment operator and free data if data is already malloc'd */
+ if( m_dataIsMallocd )
{
- size_t pos = XBEE_CMD_POSN_ID_SPECIFIC_DATA;
-
- m_apiId = (XBeeApiIdentifier_e)(p_data[ XBEE_CMD_POSN_API_ID ]);
-
- /* Depending on the frame type, decode either a 64- or 16-bit address */
- if( XBEE_CMD_RX_64B_ADDR == p_data[ XBEE_CMD_POSN_API_ID ] )
- {
- m_addr = (((uint64_t)p_data[ pos ]) << 54U ) |
- (((uint64_t)p_data[ pos+1 ]) << 48U ) |
- (((uint64_t)p_data[ pos+2 ]) << 40U ) |
- (((uint64_t)p_data[ pos+3 ]) << 32U ) |
- (((uint64_t)p_data[ pos+4 ]) << 24U ) |
- (((uint64_t)p_data[ pos+5 ]) << 16U ) |
- (((uint64_t)p_data[ pos+6 ]) << 8U ) |
- p_data[ pos+7 ];
- pos += sizeof( uint64_t );
- m_addrIs16bit = false;
- }
- else
- {
- m_addr = (((uint16_t)p_data[ pos ]) << 8U ) |
- p_data[ pos+1 ];
- pos += sizeof( uint16_t );
- m_addrIs16bit = true;
- }
-
- m_rssi += p_data[ pos++ ];
-
- m_addressBroadcast = p_data[ pos ] & 2U;
- m_panBroadcast = p_data[ pos ] & 4U;
- pos++;
-
- m_data = &( p_data[ pos ] );
-
- /* -1 to account for the checksum */
- m_dataLen = p_len - pos - 1;
-
- frameRxCallback();
-
- // TODO: m_data pointing to p_data here, which will be going away ..
-
- ret_val = true;
+ free( m_mallocdData );
+ m_dataIsMallocd = false;
}
-
- return ret_val;
-}
-
-bool XBeeApiRxFrame::frameRxCallback( void )
-{
- return true;
+ *this = p_frame;
+ m_mallocdData = (uint8_t*)malloc( p_frame.m_dataLen );
+ if( m_mallocdData )
+ {
+ m_dataIsMallocd = true;
+ memcpy( m_mallocdData, p_frame.m_data, m_dataLen );
+ m_data = m_mallocdData;
+ }
+ else
+ {
+ m_data = NULL;
+ }
+ return( m_mallocdData != NULL );
}
\ No newline at end of file