Test / example for the XBeeApi library

Dependencies:   XBeeApi mbed

Example program employing the XBeeApi library to configure and communicate with an XBee. See the notebook page here

Files at this revision

API Documentation at this revision

Comitter:
johnb
Date:
Fri Jan 31 01:18:47 2014 +0000
Parent:
0:132f26d3350b
Commit message:
Quick test of XBeeApi - needs additional structure/function

Changed in this revision

XBee.lib Show diff for this revision Revisions of this file
XBeeApi.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/XBee.lib	Sat Jan 18 19:44:28 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/johnb/code/XBee/#9d8397c69167
--- a/XBeeApi.lib	Sat Jan 18 19:44:28 2014 +0000
+++ b/XBeeApi.lib	Fri Jan 31 01:18:47 2014 +0000
@@ -1,1 +1,1 @@
-XBeeApi#1f3ffa394a1e
+http://mbed.org/users/johnb/code/XBeeApi/#1b48b619d7f6
--- a/main.cpp	Sat Jan 18 19:44:28 2014 +0000
+++ b/main.cpp	Fri Jan 31 01:18:47 2014 +0000
@@ -1,21 +1,27 @@
 #include "mbed.h"   
-#include "XBeeApi.hpp"           
 #include "XBeeDevice.hpp"
 #include "XBeeApiCmdAt.hpp"           
  
+/* Use the blocking API ... */
+#define USE_BLOCKING
+ 
 Serial pc(USBTX, USBRX); // tx, rx
  
-XBeeDevice xbeeDevice( PTA2, PTA1, NC, NC ); // tx, rx
- 
-XBeeApi xbeeApi(xbeeDevice);
-  
-  
-uint8_t foo = 0;  
+XBeeDevice xbeeDevice( PTA2, PTA1, NC, NC );
    
 int main() {
-    XBeeApiCmdAt cmd;
+#if defined USE_BLOCKING
+    XBeeApiCmdAtBlocking atIf;
+#else
+    XBeeApiCmdAt atIf;
+#endif
     XBeeDevice::XBeeDeviceReturn_t status;
     
+    if( ! ( xbeeDevice.registerDecoder( &atIf ) ))
+    {
+        /* TODO: Oh dear */
+    }
+    
     /* Get API mode 2 set up */
     status = xbeeDevice.setUpApi();
 
@@ -23,15 +29,49 @@
     {
         pc.printf("\r\n[%4d]: XBeeStatus: %d\r\n",__LINE__,status);
     }
+#if !defined USE_BLOCKING
     else
     {
-        /* If we got the API set up should be OK to send an API command */
-        xbeeDevice.SendCmd( &cmd );
+        /* If we got the API set up should be OK to send an API command
+           Request the Firmware and Hardware versions from the XBee */
+        atIf.requestFirmwareVersion();
+        atIf.requestHardwareVersion();
+        atIf.requestChannel();
     }
+#endif
 
     while( 1 ) {
+        uint16_t hwVer, fwVer;
+        uint8_t channel;
+
         wait(1);
+        
+        /* If we've now retrieved the HW and FW versions, proudly tell the
+           serial port */
+        
+        if( atIf.getHardwareVersion( &hwVer ) )
+        {
+            printf("HW VER: 0x%04x\r\n", hwVer);
+        }
+        if( atIf.getFirmwareVersion( &fwVer ) )
+        {
+            printf("FW VER: 0x%04x\r\n", fwVer);
+        }
+        if( atIf.getChannel( &channel ) )
+        {
+            printf("Channel: 0x%02x\r\n", channel);
+            if( channel != 0x0d ) 
+            {
+                atIf.setChannel( 0x0d );
+            }
+        }
+        
+        /* Any spare (i.e. unprocessed) bytes in the rx buffer to be 
+           worried about? */
         xbeeDevice.dumpRxBuffer( &pc, true );
     }
+    
+#if 0
     pc.printf("\r\n[%4d]: Done\r\n",__LINE__);
+#endif
 }
\ No newline at end of file