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 Jan 29 20:33:17 2014 +0000
Parent:
5:b40a6fd3a334
Child:
7:2f1e157cdd1c
Commit message:
Document API

Changed in this revision

Base/XBeeApiFrame.cpp Show annotated file Show diff for this revision Revisions of this file
Base/XBeeApiFrame.hpp Show annotated file Show diff for this revision Revisions of this file
Base/XBeeDevice.cpp Show annotated file Show diff for this revision Revisions of this file
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
Utility/XBeeApiSetupHelper.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Base/XBeeApiFrame.cpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Base/XBeeApiFrame.cpp	Wed Jan 29 20:33:17 2014 +0000
@@ -21,7 +21,7 @@
 
 #include <stdlib.h>
 
-XBeeApiFrame::XBeeApiFrame( void ) : m_apiId ( XBEE_CMD_INVALID ), m_dataLen( 0 ), m_data( NULL )
+XBeeApiFrame::XBeeApiFrame( void ) : m_apiId ( XBEE_CMD_INVALID ), m_data( NULL ), m_dataLen( 0 )
 {
 }
 
--- a/Base/XBeeApiFrame.hpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Base/XBeeApiFrame.hpp	Wed Jan 29 20:33:17 2014 +0000
@@ -103,22 +103,53 @@
 /* Forward declare this as XBeeDevice is dependent upon XBeeApiFrameDecoder */
 class XBeeDevice;
 
+/** Class which acts as a receiver for data from the XBee and takes care of decoding it.
+    This class needs to be sub-classed in order to create a valid decoder.
+    
+    An object implementing the XBeeApiFrameDecoder interface should be registered with
+    an XBeeDevice-type object using the registerDecoder() method.  If the class destructor
+    is called it will automatically un-register itself from the XBeeDevice.  Alternatively
+    unregisterDecoder() may be called */
 class XBeeApiFrameDecoder
 {
     protected:
+        /** Pointer to the XBeeDevice with which this decoder is associated.  Kept around
+            so that we know where to go at time of destruction and the XBeeDevice isn't
+            left with a pointer to an invalidated object */
         XBeeDevice* m_device;
         
     public:
         
+        /** Constructor */
         XBeeApiFrameDecoder();
         
+        /** Destructor.  Un-registers the decoder from any XBeeDevice object with which it is registered */
         virtual ~XBeeApiFrameDecoder();
     
-        virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len ) = 0;
-                
+    /** XBeeDevice is a friend so that it can access registerCallback and unregisterCallback */
+    friend class XBeeDevice;
+    
+    protected:      
+    
+        /** Called by an XBeeDevice object to let this object know that it's being associated with a device */      
         void registerCallback( XBeeDevice* const p_device );
 
+        /** Called by an XBeeDevice object to let this object know that it's no longer associated with the device */ 
         void unregisterCallback( void );
+
+        /** Called by an XBeeDevice in order to give this object the opportunity to examine and decode data received
+            from the XBee
+            
+            Note: When implementing this method in an inheriting class the method must only return true in the case that
+                  the data was intended for and was decoded by this class.  Returning true in other cases may result in
+                  other decoders being denied the opportunity to examine the data
+            
+            \param p_data Pointer to the first byte of the data buffer (i.e. XBEE_CMD_POSN_SDELIM)
+            \param p_len  Size of the data pointed to by p_data
+            \returns true in the case that the data was examined and decoded successfully
+                     false in the case that the data was not of interest or was not decoded successfully
+        */
+        virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len ) = 0;    
 };
 
 #endif
\ No newline at end of file
--- a/Base/XBeeDevice.cpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Base/XBeeDevice.cpp	Wed Jan 29 20:33:17 2014 +0000
@@ -203,7 +203,7 @@
     {
         sum += xbeeWrite(cmdData[i]);
     }
-    
+     
     /* Checksum is 0xFF - summation of bytes (excluding delimiter and length) */
     xbeeWrite( (uint8_t)0xFFU - sum );
     
--- a/Utility/XBeeApiCmdAt.cpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Utility/XBeeApiCmdAt.cpp	Wed Jan 29 20:33:17 2014 +0000
@@ -1,4 +1,4 @@
-/** 
+/**
 
 Copyright 2014 John Bailey
    
--- a/Utility/XBeeApiCmdAt.hpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Utility/XBeeApiCmdAt.hpp	Wed Jan 29 20:33:17 2014 +0000
@@ -88,7 +88,6 @@
        /* Implement XBeeApiCmdDecoder interface */
        
        virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
-       virtual uint8_t getCmdType( void ) const;
 
        typedef uint16_t panId_t;
        typedef uint8_t  channel_t;
--- a/Utility/XBeeApiSetupHelper.cpp	Wed Jan 29 20:19:59 2014 +0000
+++ b/Utility/XBeeApiSetupHelper.cpp	Wed Jan 29 20:33:17 2014 +0000
@@ -25,10 +25,12 @@
 {
     XBeeDevice::XBeeDeviceReturn_t ret_val = XBeeDevice::XBEEDEVICE_OK;
     
+#if 0
     p_xbeeCmd->setCoordinatorEnable( false );
     p_xbeeCmd->disableEndDeviceAssociation();
     p_xbeeCmd->setChannel( p_chan );
     p_xbeeCmd->setPanId( p_id );
+#endif 
     
     return ret_val;
 }