routeur done

Dependencies:   mbed

Fork of APP4 by S5info_H14

Files at this revision

API Documentation at this revision

Comitter:
joGenie
Date:
Mon Feb 24 15:40:33 2014 +0000
Parent:
2:7515831bb5f5
Child:
4:aac38b016952
Commit message:
NEW;

Changed in this revision

coordinateur.hpp Show annotated file Show diff for this revision Revisions of this file
readfile.cpp Show annotated file Show diff for this revision Revisions of this file
readfile.hpp Show annotated file Show diff for this revision Revisions of this file
trame.cpp Show annotated file Show diff for this revision Revisions of this file
trame.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/coordinateur.hpp	Mon Feb 24 14:08:10 2014 +0000
+++ b/coordinateur.hpp	Mon Feb 24 15:40:33 2014 +0000
@@ -12,6 +12,8 @@
     // Constructeur
     Coordinateur(PinName _tx, PinName _rx);
     
+    void setPanId(string _pan) { pan = _pan); }
+    
 private:
     Trame trame;
     string pan;
--- a/readfile.cpp	Mon Feb 24 14:08:10 2014 +0000
+++ b/readfile.cpp	Mon Feb 24 15:40:33 2014 +0000
@@ -3,7 +3,30 @@
 ReadFile::ReadFile()
 {}
 
-void ReadFile::setConfigCoord(Coordinateur *coord, const string filename)
+bool ReadFile::setConfigCoord(Coordinateur *coord, const string filename)
+{
+    string line;
+    ifstream myfile(filename.c_str());
+    if (myfile.is_open())
+    {
+        while (getline(myfile,line))
+        {
+            if (line[0] != "#")
+            {
+                if (line.find("PANID") != string::npos)
+                    ://coord->setPanID(line.substr(
+            }
+        }
+        
+        myfile.close(); 
+        
+        return true;
+    }  
+    
+    return false;  
+}
+
+bool ReadFile::setConfigRouteur(Routeur *rout, const string filename)
 {
     string line;
     ifstream myfile(filename.c_str());
@@ -14,19 +37,9 @@
         }
         
         myfile.close(); 
-    }    
-}
-
-void ReadFile::setConfigRouteur(Routeur *rout, const string filename)
-{
-    string line;
-    ifstream myfile(filename.c_str());
-    if (myfile.is_open())
-    {
-        while (getline(myfile,line))
-        {
-        }
         
-        myfile.close(); 
+        return true;
     } 
+    
+    return false;
 }
\ No newline at end of file
--- a/readfile.hpp	Mon Feb 24 14:08:10 2014 +0000
+++ b/readfile.hpp	Mon Feb 24 15:40:33 2014 +0000
@@ -19,10 +19,10 @@
     ReadFile();
     
     //Set information of the coordinateur
-    void setConfigCoord(Coordinateur *coord, const string filename);
+    bool setConfigCoord(Coordinateur *coord, const string filename);
     
     //Set information of the routeur
-    void setConfigRouteur(Routeur *rout, const string filename);
+    bool setConfigRouteur(Routeur *rout, const string filename);
 };
 
 #endif
\ No newline at end of file
--- a/trame.cpp	Mon Feb 24 14:08:10 2014 +0000
+++ b/trame.cpp	Mon Feb 24 15:40:33 2014 +0000
@@ -6,8 +6,65 @@
 {
 }
 
-void Trame::sendATCommand(const char* command, int data)
+void Trame::sendATCommand(const char* command, const char* data, int length)
 {
+    int tmp = length + 8;
+    char* trm = new char[tmp];
+    
+    trm[0] = 0x7E;      // Delimiter
+    trm[1] = static_cast<char>((tmp >> 8) & 0xFF);   // MSB de length
+    trm[2] = static_cast<char>(tmp & 0xFF); // LSB length
+    trm[3] = 0x08;      // Type
+    trm[4] = 0x01;      // API
+    trm[5] = command[0];
+    trm[6] = command[1];
+    for (int i = 0; i < length; i++)
+        trm[7+i] = data[i]; //Data
+    trm[7+length] = crc8(trm, tmp - 1);
+    
     Serial xbee(tx, rx);
-    xbee.putc(0x10);
+    for (int i = 0; i < tmp; i++)
+        xbee.putc(trm[i]);
+        
+    wait(0.01);
+    delete trm;
+}
+
+void Trame::sendTransmitRequest(const char* destination, const char* data, int length)
+{
+    int tmp = length + 18;
+    char* trm = new char[tmp];
+    
+    trm[0] = 0x7E;      // Delimiter
+    trm[1] = static_cast<char>((tmp >> 8) & 0xFF);   // MSB de length
+    trm[2] = static_cast<char>(tmp & 0xFF); // LSB length
+    trm[3] = 0x10;      // Type
+    trm[4] = 0x01;      // API
+    for (int i = 0; i < 8; i++)
+        trm[5 + i] = destination[i]; //Destination
+    trm[13] = 0x00;     // 16 bits address
+    trm[14] = 0x00;     // 16 bits address
+    trm[15] = 0x00;     // Radius
+    trm[16] = 0x00;     // Options
+        
+    for (int i = 0; i < length; i++)
+        trm[17 + i] = data[i]; // Data
+        
+    trm[17 + length] = crc8(trm, tmp - 1);
+    
+    Serial xbee(tx, rx);
+    for (int i = 0; i < tmp; i++)
+        xbee.putc(trm[i]);
+        
+    wait(0.01);
+    delete trm;
+}
+
+unsigned char Trame::crc8(const char* data, int length)
+{
+    unsigned char crc = 0;
+    for (int i = 1; i < length; i++)
+        crc += data[i];
+    
+    return (0xFF - crc);
 }
\ No newline at end of file
--- a/trame.hpp	Mon Feb 24 14:08:10 2014 +0000
+++ b/trame.hpp	Mon Feb 24 15:40:33 2014 +0000
@@ -11,9 +11,15 @@
     // Constructeur
     Trame(PinName _tx, PinName _rx);
     
-    void sendATCommand(const char* command, int data = 0);
+    // Envoie une trame pour une commande AT
+    void sendATCommand(const char* command, const char* data, int length);
     
-    unsigned int checksum();
+    // Envoie une trame pour une requete transmition
+    void sendTransmitRequest(const char* destination, const char* data, int length);
+    
+    //Effectue le checksum d'un AT command
+    unsigned char crc8(const char* data, int length);
+    
 private:
     PinName tx, rx;
 };