XBee API mode library

Revision:
17:2f728fd13bc0
Parent:
16:cdfcb63b2c4b
--- a/XBee.h	Wed Mar 20 00:28:27 2013 +0000
+++ b/XBee.h	Thu Mar 21 06:51:31 2013 +0000
@@ -25,14 +25,11 @@
 
 #include "mbed.h"
 #include "XBeeDataTypes.h"
+#include "rtos.h"
 
-#define min(x, y)       ((x) < (y) ? (x) : (y))
-#define INDEX(n)        ((n) % BUFSIZE)
-#define SIZE(b, i)      (b[i] << 8 | b[INDEX(i + 1)])
-
-const int BUFSIZE = 512;
 const char ESCAPE = 0x7D;
 const char PREAMBLE = 0x7E;
+const int BUFSIZE = 512;
 
 /**
  * class for XBee module API mode interface
@@ -199,30 +196,27 @@
      * creates an XBee interface object.
      *
      * @param ser Serial object through which XBee module is connected to mbed
-     * @param apiMode API mode either 1 or 2 (use escape; default)
-     * @param debug display debugging (I/O state) information through LEDs
+     * @param api API mode either 1 or 2 (use escape; default)
      */
-    XBee(Serial& ser, int apiMode = 2);
+    XBee(Serial& ser, int api = 2);
 
     /**
      * creates an XBee interface object.
      *
      * @param tx TX pin connected to XBee
      * @param rx RX pin connected to XBee
-     * @param apiMode API mode either 1 or 2 (use escape; default)
-     * @param debug display debugging (I/O state) information through LEDs
+     * @param api API mode either 1 or 2 (use escape; default)
      */
-    XBee(PinName tx, PinName rx, int apiMode = 2);
+    XBee(PinName tx, PinName rx, int api = 2);
 
     /**
      * creates an XBee interface object.
      *
      * @param ser Serial object through which XBee module is connected to mbed
      * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
-     * @param apiMode API mode either 1 or 2 (use escape; default)
-     * @param debug display debugging (I/O state) information through LEDs
+     * @param api API mode either 1 or 2 (use escape; default)
      */
-    XBee(Serial& ser, Serial& mon, int apiMode = 2);
+    XBee(Serial& ser, Serial& mon, int api = 2);
 
     /**
      * creates an XBee interface object.
@@ -230,10 +224,9 @@
      * @param tx TX pin connected to XBee
      * @param rx RX pin connected to XBee
      * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
-     * @param apiMode API mode either 1 or 2 (use escape; default)
-     * @param debug display debugging (I/O state) information through LEDs
+     * @param api API mode either 1 or 2 (use escape; default)
      */
-    XBee(PinName tx, PinName rx, Serial& mon, int apiMode = 2);
+    XBee(PinName tx, PinName rx, Serial& mon, int api = 2);
     
     /**
      * initializes XBee module.
@@ -400,21 +393,21 @@
      *
      * @param true if scan succeeded, false otherwise
      */
-    bool scan(XBeeFrameID& id) { return scan(XBee::FrameID, id.raw_address(), 1); }
-    bool scan(XBeeRetryCount& count) { return scan(XBee::RetryCount, count.raw_address(), 1); }
-    bool scan(XBeeStatus& status) { return scan(XBee::Status, status.raw_address(), 1); }
-    bool scan(XBeeDeliveryStatus& status) { return scan(XBee::DeliveryStatus, status.raw_address(), 1); }
-    bool scan(XBeeDiscoveryStatus& status) { return scan(XBee::DiscoveryStatus, status.raw_address(), 1); }
-    bool scan(XBeeReceiveOptions& options) { return scan(XBee::ReceiveOptions, options.raw_address(), 1); }
-    bool scan(XBeeDeviceType& device) { return scan(XBee::DeviceType, device.raw_address(), 1); }
-    bool scan(XBeeSourceEvent& event) { return scan(XBee::SourceEvent, event.raw_address(), 1); }
-    bool scan(XBeeAddress64& address64) { return scan(XBee::Address64, address64.raw_address(), 8); }
-    bool scan(XBeeAddress16& address16) { return scan(XBee::Address16, address16.raw_address(), 2); }
-    bool scan(XBeeATCommand& command) { return scan(XBee::ATCommand, command.raw_address(), 3); }
-    bool scan(XBeeCommandData& data) { return scan(XBee::CommandData, data.raw_address(), data.capacity, &data.size); }
-    bool scan(XBeeReceivedData& data) { return scan(XBee::ReceivedData, data.raw_address(), data.capacity, &data.size); }
-    bool scan(XBeeNodeIdentifier& ni) { return scan(XBee::NIString, ni.raw_address(), ni.capacity, &ni.size); }
-    bool scan(XBeeRawData& data) { return scan(XBee::RawData, data.raw_address(), data.capacity, &data.size); }
+    bool scan(XBeeFrameID& id);
+    bool scan(XBeeRetryCount& count);
+    bool scan(XBeeStatus& status);
+    bool scan(XBeeDeliveryStatus& status);
+    bool scan(XBeeDiscoveryStatus& status);
+    bool scan(XBeeReceiveOptions& options);
+    bool scan(XBeeDeviceType& device);
+    bool scan(XBeeSourceEvent& event);
+    bool scan(XBeeAddress64& address64);
+    bool scan(XBeeAddress16& address16);
+    bool scan(XBeeATCommand& command);
+    bool scan(XBeeCommandData& data);
+    bool scan(XBeeReceivedData& data);
+    bool scan(XBeeNodeIdentifier& ni);
+    bool scan(XBeeRawData& data);
     
     /**
      * scan received data according to the specified format.
@@ -443,13 +436,6 @@
     char getFrameID();
 
     /**
-    * sets to run in debug mode.
-    *
-    * @param debug true to display debugging information
-    */
-    void setDebug(bool debug);
-
-    /**
     * displays received data in dump format.
     */
     void dump();
@@ -468,14 +454,15 @@
 
 private:
     Serial mon;
-    int apiMode;
+    Timer timer;
+    Semaphore sem;
+    int api;
     volatile int cur, in, out, received, free;
     char frame_id;
     float sendConfirmation;
     char destination64[8];
     char destination16[2];
     char buf[BUFSIZE];
-    bool debug;
 
     void send(char c);
     void send2(char c);