Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Coordinator_node Router_node
Diff: xbee.cpp
- Revision:
- 18:39c72589645f
- Parent:
- 13:e0c47bcc92e7
- Child:
- 19:8da8068315da
--- a/xbee.cpp	Tue Feb 14 22:28:49 2017 +0000
+++ b/xbee.cpp	Wed Feb 15 02:09:25 2017 +0000
@@ -1,5 +1,27 @@
 #include "xbee.h"
 
+char TransmissionNumber = 1;
+Mutex mTransmissionNumber;
+
+char GetTransmissionNumber()
+{
+    char nextnumber = 0;
+    
+    mTransmissionNumber.lock();
+    nextnumber = TransmissionNumber;
+    if(nextnumber == 255)
+    {
+        TransmissionNumber = 1;
+    }
+    else
+    {
+        TransmissionNumber++;
+    }
+    mTransmissionNumber.unlock();
+    
+    return nextnumber;
+}
+
 XBee::XBee(PinName reset, PinName transfer, PinName receive, Mail<char, 250>* m) : 
     rst(reset), comm(transfer, receive)
 {
@@ -8,7 +30,7 @@
     rst = 0;
     wait(0.4);
     rst = 1;
-    wait(3);    // waiting for initiation
+    wait(3);
 }
 
 char XBee::getChar()
@@ -108,7 +130,7 @@
     cmdtosend[1] = 0x00;
     cmdtosend[2] = 0x04 + paramLen;
     cmdtosend[3] = 0x08;
-    cmdtosend[4] = 0x52;
+    cmdtosend[4] = GetTransmissionNumber();
     cmdtosend[5] = firstChar;
     cmdtosend[6] = secondChar;
     
@@ -146,10 +168,8 @@
     wait(0.2);
 }
 
-char* XBee::InterpretMessage()
+void XBee::InterpretMessage()
 {
-    char *response = "\0";
-    
     if (comm.readable())
     {
         char start = getChar(); // = FRAMEDELIMITER
@@ -160,7 +180,6 @@
             char len_lsb = getChar();
     
             int len = ((int) len_msb << 4) + (int) len_lsb;
-            char frame_data[len];
             
             // Resolving frame type
             char type = getChar();
@@ -189,7 +208,6 @@
             pcPrint("Not valid Frame\r\n");
         }
     }
-    return response;
 }
 
 void XBee::ATCommandResponse(int len)
@@ -208,8 +226,9 @@
     int i = 0;
     len-= 4;
     char data[len];
-    
-    pcPrint("response to command \0");
+    pcPrint("ID:");
+    printHexa(id);
+    pcPrint(" response to command \0");
     mail->put(command0);
     mail->put(command1);
     pcPrint(" is \0");
@@ -424,10 +443,6 @@
     cmdtosend[15] = 0x00;       // Broadcast Radius
     cmdtosend[16] = 0x00;       // Options
     
-    pcPrint("lsb : ");
-    printHexa(adresse64lsb);
-    pcPrint("\r\n");
-    
     // Set RF DATA
     if(data != NULL)
     {