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.

Revision:
55:610aa4a2ed3b
Parent:
53:7b65422d7a32
Child:
56:7fe74b03e6b1
--- a/Utility/XBeeApiCmdAt.cpp	Mon Jul 28 14:13:20 2014 +0000
+++ b/Utility/XBeeApiCmdAt.cpp	Sat Aug 02 16:41:14 2014 +0000
@@ -69,6 +69,7 @@
 #define CMD_RESPONSE_SET_AC  'K'
 #define CMD_RESPONSE_SET_FR  'L'
 #define CMD_RESPONSE_SET_IS  'M'
+#define CMD_RESPONSE_SET_RE  'N'
 
 /** Lowest channel supported by the XBee S1 */
 #define XBEE_CHAN_MIN 0x0b
@@ -169,6 +170,10 @@
 static const uint8_t cmd_is[] =        { 'I', 'S' };
 static const uint8_t cmd_is_set_fid =  CMD_RESPONSE_SET_IS;
 
+static const uint8_t cmd_re[] =        { 'R', 'E' };
+static const uint8_t cmd_re_set_fid =  CMD_RESPONSE_SET_RE;
+
+
 static const uint8_t cmd_d[ XBEE_API_DIO_CHANNEL_COUNT ][2] = {{ 'D', '0' },
                                                                { 'D', '1' },
                                                                { 'D', '2' },
@@ -229,30 +234,36 @@
         virtual ~XBeeApiCmdAtReq();
 };
 
-XBeeApiCmdAt::XBeeApiCmdAt( XBeeDevice* const p_device ) : XBeeApiFrameDecoder( p_device ) , 
-    m_have_hwVer( false ),
-    m_have_fwVer( false ),
-    m_have_chan( false ),
-    m_have_PANId( false ),
-    m_have_EDA( false ),
-    m_have_CE( false ),
-    m_have_sourceAddress( false ),
-    m_have_snLow( false ),
-    m_have_snHigh( false ),
-    m_have_retries( false ),
-    m_have_randomDelaySlots( false ),
-    m_have_macMode( false ),
-    m_have_dioChangeDetectMask( false ),
-    m_have_dioLevels( false ),
-    m_have_sampleRate( false ),
-    m_have_destHigh( false ),
-    m_have_destLow ( false ),
-    m_writeCount( 0 ),
-    m_applyCount( 0 ),
-    m_resetCount( 0 ),
-    m_sampleCount( 0 )
+void XBeeApiCmdAt::resetCachedData( void )
 {
     uint8_t i;
+    
+    m_have_hwVer = false;
+    m_have_fwVer = false;
+    m_have_chan = false;
+    m_have_PANId = false;
+    m_have_EDA = false;
+    m_have_CE = false;
+    m_have_sourceAddress = false;
+    m_have_retries = false;
+    m_have_randomDelaySlots = false;
+    m_have_macMode = false;
+    m_have_dioChangeDetectMask = false;
+    m_have_dioLevels = false;
+    m_have_sampleRate = false;
+    m_have_destHigh = false;
+    m_have_destLow = false;
+    m_writeCount = 0;
+    m_applyCount = 0;
+    m_resetCount = 0;
+    m_sampleCount = 0;
+    m_restoreCount = 0;
+    
+    /* We DO NOT reset m_have_snLow and m_have_snHigh here as
+       these are reset only in the custructor - we assume that if
+       we've received them then they can't change
+       TODO: Could be wrong - what about if we're re-using remote XBee? */
+    
     for( i = 0;
          i < XBEE_API_DIO_CHANNEL_COUNT;
          i++ )
@@ -268,6 +279,14 @@
     }
 }
 
+
+XBeeApiCmdAt::XBeeApiCmdAt( XBeeDevice* const p_device ) : XBeeApiFrameDecoder( p_device ) , 
+    m_have_snLow ( false ),
+    m_have_snHigh ( false )
+{
+    resetCachedData();
+}
+
 #define RESPONSE_OK( _data ) (_data[ statusPosn ] == 0)
 
 #define PROCESS_SET_RESPONSE( _type, _var ) \
@@ -375,6 +394,16 @@
             }
             ret_val = true;
             break;
+        case CMD_RESPONSE_SET_RE:
+            if( RESPONSE_OK( p_data )) 
+            {
+                /* If all settings have been reset, clear out any cached 
+                   data members in this class */
+                resetCachedData();
+                m_restoreCount++;
+            }
+            ret_val = true;
+            break;
         PROCESS_GET_RESPONSE_16BIT( HV, hwVer )
         PROCESS_GET_RESPONSE_16BIT( VR, fwVer )
         
@@ -577,6 +606,12 @@
     return true;
 }
 
+bool XBeeApiCmdAt::requestRestoreDefaults( void )
+{
+    SendReq( cmd_re_set_fid, cmd_re );
+    return true;
+}
+
 bool XBeeApiCmdAt::requestSerialNumber( void )
 {
     requestSerialNumberHigh();