xbee lib changé

Dependents:   Labo_TRSE_Drone

Fork of xbee_lib by Tristan Hughes

Files at this revision

API Documentation at this revision

Comitter:
tristanjph
Date:
Wed Aug 29 14:04:27 2012 +0000
Parent:
2:cb627ea9b817
Child:
4:ede20c047d8b
Commit message:
Added reset, general fixes

Changed in this revision

xbee.cpp Show annotated file Show diff for this revision Revisions of this file
xbee.h Show annotated file Show diff for this revision Revisions of this file
--- a/xbee.cpp	Wed Aug 29 13:27:02 2012 +0000
+++ b/xbee.cpp	Wed Aug 29 14:04:27 2012 +0000
@@ -1,10 +1,11 @@
 #include "xbee.h"
 
 
-xbee::xbee(PinName tx, PinName rx)
+xbee::xbee(PinName tx, PinName rx, PinName reset)
 {
     _tx = tx;
     _rx = rx;
+    _reset = reset;
 }
 
 xbee::~xbee()
@@ -49,14 +50,14 @@
     return 1;
 }
 
-int xbee::SetKey(char* key)
+int xbee::SetKey(int* key)
 {
     Serial DATA(_tx,_rx);
     DATA.printf("ATEE 1 \r");
 
     DATA.scanf ("%*s");
     wait_ms(1);
-    DATA.printf("ATKY %s \r",key);
+    DATA.printf("ATKY %x \r",key);
     DATA.scanf ("%*s");
     return 1;
 }
@@ -96,7 +97,8 @@
     while(numchar!=count) {
         if(DATA.readable()) {
             *data_buf = DATA.getc();
-            data_buf+=1; count++;
+            data_buf+=1;
+            count++;
         }
 
     }
@@ -110,3 +112,14 @@
     DATA.scanf ("%*s");
     return 1;
 }
+
+void xbee::Reset()
+{
+    DigitalOut rssi(_reset);
+    rssi = 0;
+    wait_ms(10);
+    rssi = 1;
+    wait_ms(1);
+}
+
+
--- a/xbee.h	Wed Aug 29 13:27:02 2012 +0000
+++ b/xbee.h	Wed Aug 29 14:04:27 2012 +0000
@@ -6,12 +6,14 @@
 private:
     PinName _tx;
     PinName _rx;
+    PinName _reset;
 public:
     /** Configure serial data pin.
       * @param tx The serial tx pin the xbee is conected to.
       * @param rx The serial rx pin the xbee is conected to.
+      * @param reset The pin connected to the Xbee reset pin.
       */
-    xbee(PinName tx, PinName rx);
+    xbee(PinName tx, PinName rx, PinName reset);
     ~xbee();
     /** Puts the Xbee into config mode.
       * @return Returns 1 on success.
@@ -26,7 +28,7 @@
       * @param key Pointer to the network key to set.
       * @return Returns 1 on success.
       */
-    int SetKey(char*);
+    int SetKey(int*);
     /** Sets the id of the PAN network for the Xbee to use
       * @param pan_id The id of the PAN for the Xbee to use.
       * @return Returns 1 on success.
@@ -51,5 +53,8 @@
       * @param numchar Number of characters to read. If 0, will use the size of data_buf.
       */
     void RecieveData(char*, int);
+        /** Resets the Xbee.
+      */
+    void Reset();
 
 };
\ No newline at end of file