Projet_S5 / Mbed 2 deprecated Repo_Noeud_Mobile_refactor

Dependencies:   mbed-rtos mbed

Fork of Repo_Noeud_Mobile by Projet_S5

Revision:
19:19adf49351b0
Parent:
9:b8503f5ad3bd
Child:
22:cccb77300fd5
--- a/Communication/Xbee.cpp	Sat Mar 21 19:14:30 2015 +0000
+++ b/Communication/Xbee.cpp	Sat Mar 21 19:44:42 2015 +0000
@@ -26,6 +26,54 @@
     }
 }
 
+//function that generates the Transmit Request frame
+//and the data[] parameter is only the data we want to send
+void Xbee::EnvoyerDonnees(char data[], int messageSize)
+{
+    //Si possible le messageSize sera une constante en fonction de la struc qu'on envoie a chaque fois.
+    int size = 18 + messageSize; //18 bytes + message
+    int dataSize = 14 + messageSize; //14 bytes + message
+        
+    char length1 = dataSize >> 8; //get length char 1
+    char length2 = dataSize; //get length char 2
+    
+    char sum = 0x00; //to calculate the checksum char
+    
+    char command[size];
+    command[0] = 0x7E; //start delimiter
+    command[1] = length1; //length first char
+    command[2] = length2; //length second char
+    command[3] = 0x10; //frame type - Send Request
+    command[4] = 0x01; //frame ID
+    sum += 0x10;
+    sum += 0x01;
+    
+    //Blank
+    for(int i = 5; i <= 12; i++)
+    {
+        command[i] = 0x00; //64 bit address
+    }
+    
+    //Broadcast address
+    command[13] = 0xFF; //16 bit address
+    command[14] = 0xFE; //16 bit address
+    sum += 0xFF;
+    sum += 0xFE;
+    
+    command[15] = 0x00; //broadcast radius
+    command[16] = 0x00; //options
+    
+    for(int i = 17; i < size-1; i++) //data
+    {
+        command[i] = data[i-17]; //data
+        sum += command[i]; //keep calculating for checksum
+    }
+
+    command[size-1] = 0xFF - sum; //checksum
+
+    Envoyer(command, size); //send frame array to XBee
+}
+
 void Xbee::Recevoir()
 {
     Mobile_Vers_Fixe receivedData;