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 22:14:48 2014 +0000
Parent:
26:f5df80e990f4
Child:
28:e22f61badee3
Commit message:
RX message decoding

Changed in this revision

Base/XBeeApiFrame.hpp Show annotated file Show diff for this revision Revisions of this file
RXTX/XBeeApiRxFrame.cpp Show annotated file Show diff for this revision Revisions of this file
RXTX/XBeeApiRxFrame.hpp Show annotated file Show diff for this revision Revisions of this file
RXTX/XBeeApiTxFrame.cpp Show annotated file Show diff for this revision Revisions of this file
RXTX/XBeeApiTxFrame.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/Base/XBeeApiFrame.hpp	Wed Feb 05 21:31:10 2014 +0000
+++ b/Base/XBeeApiFrame.hpp	Wed Feb 05 22:14:48 2014 +0000
@@ -177,4 +177,8 @@
         virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len ) = 0;    
 };
 
+/** Value which represents the broadcast address */
+#define XBEE_BROADCAST_ADDR 0xFFFF
+
+
 #endif
\ No newline at end of file
--- a/RXTX/XBeeApiRxFrame.cpp	Wed Feb 05 21:31:10 2014 +0000
+++ b/RXTX/XBeeApiRxFrame.cpp	Wed Feb 05 22:14:48 2014 +0000
@@ -30,13 +30,53 @@
 {
     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 ] ))
     {
-        extern Serial pc;
-        pc.printf("WOOT\r\n");
-        /* TODO */
+        size_t pos = XBEE_CMD_POSN_ID_SPECIFIC_DATA;
+
+        /* 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();
+        
+        ret_val = true;
     }
     
     return ret_val;
 }
+
+void XBeeApiRxFrame::frameRxCallback( void )
+{
+}
\ No newline at end of file
--- a/RXTX/XBeeApiRxFrame.hpp	Wed Feb 05 21:31:10 2014 +0000
+++ b/RXTX/XBeeApiRxFrame.hpp	Wed Feb 05 22:14:48 2014 +0000
@@ -30,23 +30,49 @@
 
 #include <stdint.h>
 
-/** Class to represent a frame of data being received by the XBee */
+/** Class to represent a frame of data being received by the XBee.
+
+    The message data content is accessed via the inherited m_data 
+    and m_dataLen members 
+*/
 class XBeeApiRxFrame : public XBeeApiFrame, public XBeeApiFrameDecoder
 {
     protected:
-       /** Called by XBeeDevice in order to offer frame data to the object for
-           decoding
+        /** The source address of the packet */
+        uint64_t m_addr;
+    
+        /** Indicate whether or not the address in m_addr is 16- or 64-bit */ 
+        bool m_addrIs16bit;
+    
+        /** The Received Signal Strength Indicator (RSSI) associated with the
+            message, in -dBm.  i.e. m_rssi == 40 indicates -40dBm */
+        uint8_t m_rssi;
+    
+        /** Indicate whether or not the message was address broadcast */
+        bool m_addressBroadcast;
+        
+        /** Indicate whether or not the message was PAN broadcase */
+        bool m_panBroadcast;
+    
+        /** Called by XBeeDevice in order to offer frame data to the object for
+            decoding
            
-           \param p_data Pointer to the content of the received data
-           \param p_len Length of the data pointed to by p_data
-       */
-       virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
+            \param p_data Pointer to the content of the received data
+            \param p_len Length of the data pointed to by p_data
+        */
+        virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
 
     public:
-       /** Constructor */
-       XBeeApiRxFrame( XBeeDevice* p_device = NULL );
-       /** Destructor */
-       virtual ~XBeeApiRxFrame( void );     
+        /** Constructor */
+        XBeeApiRxFrame( XBeeDevice* p_device = NULL );
+        /** Destructor */
+        virtual ~XBeeApiRxFrame( void ); 
+
+        /* Callback which is invoked when a frame is successfully decoded.  The
+           contents of the frame decode can be inspected via the class member
+           variables */       
+        virtual void frameRxCallback( void );
+    
 };
 
 #endif
\ No newline at end of file
--- a/RXTX/XBeeApiTxFrame.cpp	Wed Feb 05 21:31:10 2014 +0000
+++ b/RXTX/XBeeApiTxFrame.cpp	Wed Feb 05 22:14:48 2014 +0000
@@ -18,10 +18,8 @@
 
 #include "XBeeApiTxFrame.hpp"
 
-#define BROADCAST_ADDR (0xFFFFU)
-
 XBeeApiTxFrame::XBeeApiTxFrame( XBeeDevice* p_device ) : XBeeApiFrame(), XBeeApiFrameDecoder( p_device ),
-                                                         m_addr( BROADCAST_ADDR ), 
+                                                         m_addr( XBEE_BROADCAST_ADDR ),
                                                          m_ack( true ), 
                                                          m_panBroadcast( false )
 {
@@ -126,7 +124,7 @@
 
 void XBeeApiTxFrame::setDestAddrBroadcast( void )
 {
-    m_addr = BROADCAST_ADDR;
+    m_addr = XBEE_BROADCAST_ADDR;
 }
 
 void XBeeApiTxFrame::setPanBroadcast( const bool p_bc )
--- a/RXTX/XBeeApiTxFrame.hpp	Wed Feb 05 21:31:10 2014 +0000
+++ b/RXTX/XBeeApiTxFrame.hpp	Wed Feb 05 22:14:48 2014 +0000
@@ -38,8 +38,9 @@
 class XBeeApiTxFrame : public XBeeApiFrame, public XBeeApiFrameDecoder
 {
     protected:
-       /** Destination address of the frame */
-       uint64_t          m_addr;
+        /** Destination address of the frame */
+        uint64_t          m_addr;
+        
        /** Whether or not an acknowledgement of the frame is requested */ 
        bool              m_ack;
        /** Whether or not the frame is a PAN broadcast */