code d'envoie de trame

Dependencies:   mbed ConfigFile

Fork of app4-router by APP Team

Files at this revision

API Documentation at this revision

Comitter:
trixrabbit
Date:
Tue Feb 25 18:32:33 2014 +0000
Parent:
7:0f107e48147d
Child:
9:9b874294a381
Commit message:
version final;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Feb 25 05:00:28 2014 +0000
+++ b/main.cpp	Tue Feb 25 18:32:33 2014 +0000
@@ -28,9 +28,10 @@
 LocalFileSystem local("local");
 ConfigFile cfg;
 
-string AccelData;
-int period_ms;
-string panID;
+//variables globales
+
+int period_ms; //frequence que l'on obtien dans config file
+string panID; //panID que l'on obtient dans config file
  
  
  
@@ -58,39 +59,41 @@
      
     if (cfg.getValue(key1, &value[0], sizeof(value))) 
     {
-        std::stringstream panID_s(value); 
-        panID_s >> panID;
+        std::stringstream panID_s(value); //transforme la valeur du panID en string
+        panID_s >> panID; //place le string dans la variable globale
     }
     
     if (cfg.getValue(key2, &value[0], sizeof(value))) 
     {
-        std::stringstream freq_s(value); 
-        freq_s >> period_ms;
+        std::stringstream freq_s(value);  //transforme la frequence en string
+        freq_s >> period_ms; //place le string dans la variable globale
     }
 }
 
 void xbee_init() //fonction de config du module xBee
 {
-    reset = 0;
+    reset = 0; //initialisation
     wait_ms(400);
     reset = 1;
     wait(4);
+    //variables
     int panID_size;
     int panID_array[8];
     int i;
     long int panID_d;
+    
     panID_size = panID.length(); //vérifie si le panID est pair ou impair
     if(panID_size%2 != 0)
     {
-        panID_size++;
+        panID_size++; //si impair size++ (i.e. on veut que 5/2 = 3 au lieu de 2)
         panID = "0" + panID;
     }
     
     panID_d = strtol(panID.c_str(),NULL,16); //converti le panID en chiffre
     for(i=0;i<panID_size/2;i++)
     {
-        panID_array[i] = panID_d%256; //decoupe en packet de 8 bytes (2 characteres)
-        panID_d = panID_d >> 8;
+        panID_array[i] = panID_d%256; //decoupe en packet de 8 bytes (2 characteres) et place dans tableau
+        panID_d = panID_d >> 8;       //à partir de la fin (i.e. CAFE --> array[0] = FE, array[1] = CA )
         
         
     }
@@ -109,15 +112,14 @@
     xbee.putc(0x44); //AT command : (ID)
     checkSum = checkSum + 0x09 + 0x47 + 0x49 + 0x44;
     while(i>=0)
-    {
-        pc.printf(" \n\r valeur = %d",panID_array[i]);
-        xbee.putc(panID_array[i]);
-        checkSum += panID_array[i];
-        i--;
+    {                                                  
+        xbee.putc(panID_array[i]);                   //putc avec les valeur du tableau 
+        checkSum += panID_array[i];      //les valeurs sont mises à l'envers dans le tableau               
+        i--;//on doit donc décrémenter le i
     }
     checkSum = 0xff - checkSum;
     xbee.putc(checkSum); // checksum
-    pc.printf("\n\r %d %x", checkSum,checkSum);
+    
 
     xbee.putc(0x7E); // start delimeter
     xbee.putc(0x00); // length
@@ -140,7 +142,7 @@
 
 }
 
-char i2c_read_reg(char address)
+char i2c_read_reg(char address) //fonction i2c pour l'accelerometre
 {   
     // Read from selected register adress
     i2c.start();                                         
@@ -155,7 +157,7 @@
     return data;   
 }
 
-bool initAccel()
+bool initAccel() //fonction qui initialise l'accelerometre avec i2c
 {
     // Start I2C communication   
     char data = i2c_read_reg(WHO_AM_I);
@@ -181,14 +183,13 @@
     return true;     
 }
 
-
-unsigned short getAccelValue(char MSB_addr)
+unsigned short getAccelValue(char MSB_addr) //fonction qui lit les registres de données de l'accelerometre
 {
     return i2c_read_reg(MSB_addr);           // Read MSB data from MSB register
 }
 
 
-
+//fonction qui construit la string a envoyer par xbee de l'accelerometre
 string getAccelData()
 {
     unsigned short x, y, z; 
@@ -200,12 +201,13 @@
     
     return "AX" + convertInt(x) + " AY" + convertInt(y) + " AZ" + convertInt(z);  
 }
-
+//fonction qui construit la string a envoyer par xbee du pusb button
 string getPushButtonData()
 {
      return "PB" + convertInt(pb1);
 }
 
+//fonction d'envoie de trame xbee
 void xbee_transmit(string data_s)
 {
        
@@ -232,8 +234,8 @@
     
     for (int i=0;i<data_s.length();i++)  //data
     {
-        xbee.putc(data_s[i]);
-        checkSum += data_s[i];
+        xbee.putc(data_s[i]); //envoie le data de la string passée en parametre
+        checkSum += data_s[i]; //additionne le checksum de chaque data
     }
     checkSum = 0xff - checkSum;
     xbee.putc(checkSum); // checksum
@@ -242,9 +244,10 @@
 
 int main() 
 {
-    configInit();
-    xbee_init();
-    initAccel();
+    //appelle des fonctions d'initialisations
+    configInit();   //fichier de config
+    xbee_init();    //xbee
+    initAccel();    //accelerometre
     
     myled = 0;