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.

Files at this revision

API Documentation at this revision

Comitter:
johnb
Date:
Wed Feb 05 21:05:10 2014 +0000
Parent:
24:2cd1094c4fd7
Child:
26:f5df80e990f4
Commit message:
Add XBeeApiCmdAtSet to replace various classes in XBeeApiCmdAt

Changed in this revision

Utility/XBeeApiCmdAt.cpp Show annotated file Show diff for this revision Revisions of this file
Utility/XBeeApiCmdAt.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/Utility/XBeeApiCmdAt.cpp	Wed Feb 05 18:56:58 2014 +0000
+++ b/Utility/XBeeApiCmdAt.cpp	Wed Feb 05 21:05:10 2014 +0000
@@ -195,7 +195,8 @@
 
 bool XBeeApiCmdAt::setChannel( uint8_t const p_chan )
 {
-    XBeeApiCmdAt::XBeeApiCmdAtChannelSet req( p_chan );
+    XBeeApiCmdAtSet<uint8_t> req( cmd_set_ch, p_chan );
+
     m_chanPend = p_chan;
     m_device->SendFrame( &req );
     return true;
@@ -284,10 +285,11 @@
 
 bool XBeeApiCmdAt::setCoordinatorEnabled( const bool p_en )
 {
-    XBeeApiCmdAt::XBeeApiCmdAtCESet ce( p_en );
+    XBeeApiCmdAtSet<bool> req( cmd_set_ce, p_en );
+
     m_haveCE = false;
     m_CEPend = p_en;
-    m_device->SendFrame( &ce );
+    m_device->SendFrame( &req );
     return true;
 }
 
@@ -300,7 +302,8 @@
 }
 bool XBeeApiCmdAt::setEndDeviceAssociationEnabled( const bool p_en  )
 {
-    XBeeApiCmdAt::XBeeApiCmdAtEDASet req( p_en );
+    XBeeApiCmdAtSet<bool> req( cmd_set_eda, p_en );
+
     m_haveEDA = false;
     m_EDAPend = p_en;
     m_device->SendFrame( &req );
@@ -317,7 +320,8 @@
 }
 bool XBeeApiCmdAt::setPanId( const panId_t p_chan )
 {
-    XBeeApiCmdAt::XBeeApiCmdAtPANIdSet panid( p_chan );
+    XBeeApiCmdAtSet<panId_t> panid( cmd_set_pid, p_chan );
+
     m_havePANId = false;
     m_PANIdPend = p_chan;
     m_device->SendFrame( &panid );
@@ -478,47 +482,33 @@
                   panId_t );
 }
 
-XBeeApiCmdAt::XBeeApiCmdAtChannelSet::XBeeApiCmdAtChannelSet( const uint8_t p_chan ) : XBeeApiFrame( )
+template < typename T >
+XBeeApiCmdAt::XBeeApiCmdAtSet<T>::XBeeApiCmdAtSet( const uint8_t* const p_data,
+                                                   const T p_val ) : XBeeApiFrame( )
 {
+    size_t s;
+    uint8_t* dest;
+    const uint8_t* src = (uint8_t*)(&p_val);
+    
     m_apiId = XBEE_CMD_AT_CMD;
-    m_buffer[0] = cmd_set_ch[0];
-    m_buffer[1] = cmd_set_ch[1];
-    m_buffer[2] = cmd_set_ch[2];
-    m_buffer[3] = p_chan;
+    
+    m_buffer[0] = p_data[0];
+    m_buffer[1] = p_data[1];
+    m_buffer[2] = p_data[2];
+    
+    dest = &( m_buffer[3] );
+    
+    for( s = 0;
+         s < sizeof( T );
+         s++, dest++, src++ ) {
+        *dest = *src;         
+    }
+    
     m_data = m_buffer;
-    m_dataLen = sizeof( cmd_set_ch );
-}
-
-XBeeApiCmdAt::XBeeApiCmdAtCESet::XBeeApiCmdAtCESet( const bool p_en ) : XBeeApiFrame( )
-{
-    m_apiId = XBEE_CMD_AT_CMD;
-    m_buffer[0] = cmd_set_ce[0];
-    m_buffer[1] = cmd_set_ce[1];
-    m_buffer[2] = cmd_set_ce[2];
-    m_buffer[3] = p_en;
-    m_data = m_buffer;
-    m_dataLen = sizeof( cmd_set_ce );
+    m_dataLen = sizeof( m_buffer );
 }
 
-XBeeApiCmdAt::XBeeApiCmdAtEDASet::XBeeApiCmdAtEDASet( const bool p_en ) : XBeeApiFrame( )
+template < typename T >
+XBeeApiCmdAt::XBeeApiCmdAtSet<T>::~XBeeApiCmdAtSet()
 {
-    m_apiId = XBEE_CMD_AT_CMD;
-    m_buffer[0] = cmd_set_eda[0];
-    m_buffer[1] = cmd_set_eda[1];
-    m_buffer[2] = cmd_set_eda[2];
-    m_buffer[3] = p_en;
-    m_data = m_buffer;
-    m_dataLen = sizeof( cmd_set_eda );
-}
-
-XBeeApiCmdAt::XBeeApiCmdAtPANIdSet::XBeeApiCmdAtPANIdSet( const panId_t p_id ) : XBeeApiFrame( )
-{
-    m_apiId = XBEE_CMD_AT_CMD;
-    m_buffer[0] = cmd_set_pid[0];
-    m_buffer[1] = cmd_set_pid[1];
-    m_buffer[2] = cmd_set_pid[2];
-    m_buffer[3] = p_id >> 8U;
-    m_buffer[4] = p_id;
-    m_data = m_buffer;
-    m_dataLen = sizeof( cmd_set_pid );
-}
+}
\ No newline at end of file
--- a/Utility/XBeeApiCmdAt.hpp	Wed Feb 05 18:56:58 2014 +0000
+++ b/Utility/XBeeApiCmdAt.hpp	Wed Feb 05 21:05:10 2014 +0000
@@ -61,35 +61,13 @@
         bool m_CE;
         bool m_CEPend;
 
-        class XBeeApiCmdAtChannelSet : public XBeeApiFrame
-        {
-            uint8_t m_buffer[ 10 ];
-            public:
-                XBeeApiCmdAtChannelSet( const uint8_t p_chan );
-        };
-
-        class XBeeApiCmdAtCESet : public XBeeApiFrame
-        {
-            /* TODO: Magic number */
-            uint8_t m_buffer[ 10 ];
+        template< typename T >
+        class XBeeApiCmdAtSet : public XBeeApiFrame {
+            uint8_t m_buffer[ 3 + sizeof( T ) ];
             public:
-                XBeeApiCmdAtCESet( const bool p_en );
-        };
-
-        class XBeeApiCmdAtPANIdSet : public XBeeApiFrame
-        {
-            /* TODO: Magic number */
-            uint8_t m_buffer[ 10 ];
-            public:
-                XBeeApiCmdAtPANIdSet( const panId_t p_chan );
-        };
-
-        class XBeeApiCmdAtEDASet : public XBeeApiFrame
-        {
-            /* TODO: Magic number */
-            uint8_t m_buffer[ 10 ];
-            public:
-                XBeeApiCmdAtEDASet( const bool p_en );
+                XBeeApiCmdAtSet( const uint8_t* const p_data,
+                                 const T p_val );
+            virtual ~XBeeApiCmdAtSet();
         };
 
     public: