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:
50:f76b7e7959a2
Parent:
32:af4e495afd62
Child:
51:a7d0d2ef9261
diff -r 37bba77ee73f -r f76b7e7959a2 Utility/XBeeApiCmdAt.hpp
--- a/Utility/XBeeApiCmdAt.hpp	Mon Jul 07 19:14:46 2014 +0000
+++ b/Utility/XBeeApiCmdAt.hpp	Sun Jul 13 15:47:40 2014 +0000
@@ -37,6 +37,9 @@
 #include <stdint.h>
 
 #define XBEE_API_CMD_SET_HEADER_LEN 3U
+#define XBEE_API_CMD_REQ_HEADER_LEN 3U
+
+#define XBEE_API_DIO_CHANNEL_COUNT 8U
 
 /** Class to access the configuration interface of the XBee.
     Requests to the XBee are non-blocking meaning that code
@@ -63,6 +66,17 @@
             XBEE_API_MAC_MODE_DIGI_NO_ACK     = 3,
         } XBeeApiMACMode_e;
     
+        typedef enum
+        {
+            XBEE_API_DIO_DISABLED             = 0,
+            XBEE_API_DIO_SPECIAL              = 1,
+            XBEE_API_DIO_INPUT                = 3,
+            XBEE_API_DIO_OUT_LOW              = 4,
+            XBEE_API_DIO_OUT_HIGH             = 5,
+            XBEE_API_DIO_RS485_TX_LOW         = 6,
+            XBEE_API_DIO_RS485_TX_HIGH        = 7
+        } XBeeApiDioConfig_e;
+    
     protected:
         /** Indicates whether or not m_hwVer contains data retrieved from the XBee */
         bool m_have_hwVer;
@@ -82,6 +96,7 @@
         bool m_have_retries;
         bool m_have_randomDelaySlots;
         bool m_have_macMode;
+        bool m_have_d[ XBEE_API_DIO_CHANNEL_COUNT ];
         
         uint16_t m_hwVer;
         uint16_t m_fwVer;
@@ -101,33 +116,28 @@
         uint8_t  m_retriesPend;
         uint8_t  m_randomDelaySlots;
         uint8_t  m_randomDelaySlotsPend;
-        XBeeApiMACMode_e m_macMode;
-        XBeeApiMACMode_e m_macModePend;
+        XBeeApiMACMode_e   m_macMode;
+        XBeeApiMACMode_e   m_macModePend;
+        XBeeApiDioConfig_e m_d[ XBEE_API_DIO_CHANNEL_COUNT ];
+        XBeeApiDioConfig_e m_dPend[ XBEE_API_DIO_CHANNEL_COUNT ];
 
-        /** Template class to create an XBeeApiFrame which can be used to change
-            the value of one of the XBee parameters.  This class is used by the
-            setXXX methods in XBeeApiCmdAt */
-        template< typename T >
-        class XBeeApiCmdAtSet : public XBeeApiFrame {
-            uint8_t m_buffer[ XBEE_API_CMD_SET_HEADER_LEN + sizeof( T ) ];
-            public:
-                /** Constructor
-                   
-                    \param p_data Pointer to a buffer of length 3 bytes containing a 
-                                  single byte frame ID followed by 2 bytes identifying
-                                  the command, e.g. '0', 'V', 'R' would set up a version
-                                  request with a frame identifier of 48 (ASCII value of 
-                                  '0').
-                    \param p_val New value for the parameter 
-                */
-                XBeeApiCmdAtSet( const uint8_t* const p_data,
-                                 const T p_val );
-                /** Destructor */
-                virtual ~XBeeApiCmdAtSet();
-        };
+        virtual void SendCmd_uint8_t( const uint8_t        p_frameId,
+                                      const uint8_t* const p_data,
+                                      const uint8_t&       p_val );
+        virtual void SendCmd_uint16_t( const uint8_t        p_frameId,
+                                       const uint8_t* const p_data,
+                                       const uint16_t&       p_val );
+        virtual void SendReq( const uint8_t             p_frameId,
+                              const uint8_t*            p_data );
 
-       /* Implement XBeeApiCmdDecoder interface */
-       virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
+        virtual size_t getResponseStatusPos( void ) const;
+
+
+        /* Implement XBeeApiCmdDecoder interface */
+        virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
+
+        virtual bool processResponseFrame( const uint8_t* const p_data, size_t p_len );
+
 
     public:
 
@@ -151,6 +161,11 @@
         bool requestPanId( void );
         bool requestSourceAddress( void );
         bool requestSerialNumber( void );
+        bool requestSerialNumberHigh( void );
+        bool requestSerialNumberLow( void );
+        bool requestDioConfig( const uint8_t p_chanNo );
+
+        
         /** Request the number of retries the XBee is configured to make.
             Note that the 802.15.4 MAC already allows 3 retries, so this parameter
             specifies an additional multiple of 3 retries
@@ -205,7 +220,10 @@
         virtual bool setRandomDelaySlots( const uint8_t p_addr );       
 
         virtual bool getMacMode( XBeeApiMACMode_e* const p_mode );       
-        virtual bool setMacMode( const XBeeApiMACMode_e p_mode );       
+        virtual bool setMacMode( const XBeeApiMACMode_e p_mode );  
+        
+        virtual bool getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf );
+        virtual bool setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf );
 };
 
 /** Class to access the configuration interface of the XBee.
@@ -249,24 +267,24 @@
  
        /* Implement XBeeApiCmdAt's virtual methods */
        
-       virtual bool getHardwareVersion( uint16_t* const p_ver );
-       virtual bool getFirmwareVersion( uint16_t* const p_ver );
+        virtual bool getHardwareVersion( uint16_t* const p_ver );
+        virtual bool getFirmwareVersion( uint16_t* const p_ver );
         virtual bool getSerialNumber( uint64_t* const p_sn );
 
-       virtual bool getChannel( uint8_t* const p_chan );
-       virtual bool setChannel( uint8_t const p_chan );
+        virtual bool getChannel( uint8_t* const p_chan );
+        virtual bool setChannel( uint8_t const p_chan );
         
-       virtual bool getCoordinatorEnabled( bool* constp_en );
-       virtual bool setCoordinatorEnabled( const bool p_en );
+        virtual bool getCoordinatorEnabled( bool* constp_en );
+        virtual bool setCoordinatorEnabled( const bool p_en );
        
-       virtual bool getEndDeviceAssociationEnabled( bool* const p_en ); 
-       virtual bool setEndDeviceAssociationEnabled( const bool p_en  );
+        virtual bool getEndDeviceAssociationEnabled( bool* const p_en ); 
+        virtual bool setEndDeviceAssociationEnabled( const bool p_en  );
        
-       virtual bool getPanId( panId_t* const p_id );       
-       virtual bool setPanId( const panId_t p_id );
+        virtual bool getPanId( panId_t* const p_id );       
+        virtual bool setPanId( const panId_t p_id );
 
-       virtual bool getSourceAddress( uint16_t* const p_addr );       
-       virtual bool setSourceAddress( const uint16_t p_addr );  
+        virtual bool getSourceAddress( uint16_t* const p_addr );       
+        virtual bool setSourceAddress( const uint16_t p_addr );  
        
         virtual bool getRetries( uint8_t* const p_addr );       
         virtual bool setRetries( const uint8_t p_addr );       
@@ -275,7 +293,11 @@
         virtual bool setRandomDelaySlots( const uint8_t p_addr );       
 
         virtual bool getMacMode( XBeeApiMACMode_e* const p_mode );       
-        virtual bool setMacMode( const XBeeApiMACMode_e p_mode );       
+        virtual bool setMacMode( const XBeeApiMACMode_e p_mode );  
+        
+        virtual bool getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf );
+        virtual bool setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf );
+     
 };
 
 #endif
\ No newline at end of file