Projet_S5 / Mbed 2 deprecated Repo_Noeud_Mobile_refactor

Dependencies:   mbed-rtos mbed

Fork of Repo_Noeud_Mobile by Projet_S5

Files at this revision

API Documentation at this revision

Comitter:
groygirard
Date:
Sun Apr 12 18:59:37 2015 +0000
Parent:
57:ce80fbd67161
Commit message:
no workerino, no puterino

Changed in this revision

Communication/Xbee.cpp Show annotated file Show diff for this revision Revisions of this file
Communication/Xbee.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Communication/Xbee.cpp	Sun Apr 12 03:02:21 2015 +0000
+++ b/Communication/Xbee.cpp	Sun Apr 12 18:59:37 2015 +0000
@@ -1,7 +1,7 @@
 #include "Xbee.h"
 
 Serial x_pc(USBTX, USBRX);
-
+Serial XbeePin(p13, p14);
 inline void PrintChar(char c);
 inline void PrintEndline();
 
@@ -13,28 +13,28 @@
 
 Xbee::Xbee(short panId, PinName pinTx, PinName pinRx)
 {
-    this->XbeePin = new Serial(pinTx, pinRx);
     PanId = panId;
     SetPanId(PanId);
 }
 
 Xbee::~Xbee()
 {
-    delete XbeePin;
 }
 
 //send frames to XBee (to set PanID and do the WR)
 void Xbee::SendXBee(char array[], int size)//SendXbee
 {
-    for(int i = 0; i < size; i++) {
-        XbeePin->putc(array[i]);
+
+    for(int i = 0; i < size-1; i++) {
+        XbeePin.putc(array[i]);
+        x_pc.printf("%#X \n\r", array[i]);
     }
 }
 
 void Xbee::EnvoyerStructure(Mobile_Vers_Fixe mvf)
 {
     char data[2] = {0x00, 0x00};
-    //x_pc.printf(" \r\n Gants id %c", mvf->gants);
+    x_pc.printf(" \r\n Gants id %c \n\r", mvf.gants);
     data[0] = mvf.gants;
     mvf.flexSensor.index == 1 ? data[1] = 0x04 : data[1] = 0;
     mvf.flexSensor.majeur == 1 ? data[1] += 0x02 : data[1] += 0;
@@ -91,29 +91,32 @@
 {
     data* input;
     while(true) {
-        if(XbeePin->readable()) { //gets 1 full frame and store in mailbox
-            input = mailbox.alloc(); //alloc in mailbox
+        if(XbeePin.readable()) { //gets 1 full frame and store in mailbox
+            char c = XbeePin.getc(); //start delimiter
+            x_pc.printf("Char available on connection: %#X\r\n", c);
+            if(c == 0x7e) {
 
-            if(input != NULL) { //if alloc was successful
-                char c = XbeePin->getc(); //start delimiter
-                char c1 = XbeePin->getc(); //length byte 1
-                char c2 = XbeePin->getc(); //length byte 2
-                short length = c1 << 8 | c2; //calculate length
-                input->size = length + 4; //length = dataLength + start delimiter + length (2) + checksum
-                input->array[0] = c;
-                input->array[1] = c1;
-                input->array[2] = c2;
-                short pos = 3;
-                while(length+1 > 0) { //include checksum
-                    c = XbeePin->getc(); //get char
-                    input->array[pos] = c; //store data
-                    pos++; //current position
-                    length--; //length left until the end of frame
+                input = mailbox.alloc(); //alloc in mailbox
+                if(input != NULL) { //if alloc was successful
+                    char c1 = XbeePin.getc(); //length byte 1
+                    char c2 = XbeePin.getc(); //length byte 2
+                    short length = c1 << 8 | c2; //calculate length
+                    input->size = length + 4; //length = dataLength + start delimiter + length (2) + checksum
+                    input->array[0] = c;
+                    input->array[1] = c1;
+                    input->array[2] = c2;
+                    short pos = 3;
+                    while(length+1 > 0) { //include checksum
+                        c = XbeePin.getc(); //get char
+                        input->array[pos] = c; //store data
+                        pos++; //current position
+                        length--; //length left until the end of frame
+                    }
+
+                    mailbox.put(input); //put data in mailbox
+                } else { //if mailbox is full
+                    x_pc.printf("Mailbox is full!\r\n");
                 }
-
-                mailbox.put(input); //put data in mailbox
-            } else { //if mailbox is full
-                x_pc.printf("Mailbox is full!\r\n");
             }
         }
     }
@@ -163,12 +166,12 @@
 {
     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
@@ -177,64 +180,65 @@
     command[4] = 0x01; //frame ID
     sum += 0x10;
     sum += 0x01;
-    
-    for(int i = 5; i <= 12; i++)
-    {
+
+    for(int i = 5; i <= 12; i++) {
         command[i] = 0x00; //64 bit 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
-    {
+
+    for(int i = 17; i < size-1; i++) { //data
         command[i] = data[i-17]; //data
         sum += command[i]; //keep calculating for checksum
-        x_pc.printf("");
     }
 
     command[size-1] = 0xFF - sum; //checksum
 
     SendXBee(command, size); //send frame array to XBee
+    x_pc.printf("Sortie SendXbee\r\n");
 }
 
 //receive packet frame
 //this function analyses it and puts in wsMailbox to send to websocket
 void Xbee::ReceivePacket(data* trame)
 {
-    Fixe_Vers_Mobile* fvm = fvm_mailbox.alloc(); //alloc in mailbox
-
-    if(fvm != NULL) { //if alloc was successful
-        x_pc.printf("Receive Packet Info");
-
-        switch(trame->array[14]) { //print receive option
-            case 0x01:
-                x_pc.printf("\r\nPacket acknowledged");
-                break;
-            case 0x02:
-                x_pc.printf("\r\nPacket was a broadcast packet");
-                break;
-            case 0x20:
-                x_pc.printf("\r\nPacket encrypted with APS encryption");
-                break;
-            case 0x40:
-                x_pc.printf("\r\nPacket was sent from an end device");
-                break;
-            default:
-                x_pc.printf("\r\nUnknown option: %x", trame->array[14]);
-                break;
-        }
-        // Data aquisition
-        fvm->game = (GameMode_e)trame->array[15];
-
-        fvm_mailbox.put(fvm); //put data in mailbox
-    } else {
-        x_pc.printf("Mobile Vers Fixe mailbox is full!\r\n");
+    x_pc.printf("Receive Packet Info \n\r");
+    switch(trame->array[3]) {
+        case 0x01:
+            x_pc.printf("\r\nPacket acknowledged");
+            break;
+        case 0x02:
+            x_pc.printf("\r\nPacket was a broadcast packet");
+            break;
+        case 0x20:
+            x_pc.printf("\r\nPacket encrypted with APS encryption");
+            break;
+        case 0x40:
+            x_pc.printf("\r\nPacket was sent from an end device");
+            break;
+        case 0x88:
+            x_pc.printf("\r\n AT Command");
+            break;
+        case 0x90:
+            x_pc.printf("\r\n Received Transmit Data");
+            Fixe_Vers_Mobile* fvm = fvm_mailbox.alloc(); //alloc in mailbox
+            if(fvm != NULL) { //if alloc was successful
+                // Data aquisition
+                fvm->game = (GameMode_e)trame->array[17];
+                fvm_mailbox.put(fvm); //put data in mailbox
+            } else {
+                x_pc.printf("Fixe vers mobile mailbox is full!\r\n");
+            }
+            break;
+        default:
+            x_pc.printf("\r\n Unknown option: %x", trame->array[14]);
+            break;
     }
 }
 
--- a/Communication/Xbee.h	Sun Apr 12 03:02:21 2015 +0000
+++ b/Communication/Xbee.h	Sun Apr 12 18:59:37 2015 +0000
@@ -16,7 +16,7 @@
         Mail<Fixe_Vers_Mobile,100> fvm_mailbox;
        
     private:
-        Serial* XbeePin;
+
         short PanId;
         char HexToAscii[16];
         Mail<data,100> mailbox;
--- a/main.cpp	Sun Apr 12 03:02:21 2015 +0000
+++ b/main.cpp	Sun Apr 12 18:59:37 2015 +0000
@@ -47,7 +47,7 @@
 flex_t flex_data;
 Mobile_Vers_Fixe mail_mvf;
 //RtosTimer *sync;
-GameMode_e mode = WAITING;
+GameMode_e mode = RPS;
 AirGuitar_opMode_e opMode;
 short PanId;
 char GantID;
@@ -117,7 +117,7 @@
     threads[RPS] = rps_thread_ptr;
     threads[AirGuitar] = airguitar_thread_ptr;
     threads[XBEE_TRANSMIT] = transmit_xbee_data_thread_ptr;
-
+    configure_RPS();
     while(true) {
     }
 }
@@ -152,15 +152,15 @@
             xbee.fvm_mailbox.free(mail);
             switch(mode) {
                 case 0:
-                    m_pc.printf("Led Gunner Start! \n\r");
+                    m_pc.printf("Led Gunner Start! FVM \n\r");
                     configure_GUNNER();
                     break;
                 case 1:
-                    m_pc.printf("RPS Start! \n\r");
+                    m_pc.printf("RPS Start! FVM\n\r");
                     configure_RPS();
                     break;
                 case 2:
-                    m_pc.printf("Air Guitar Start! \n\r");
+                    m_pc.printf("Air Guitar Start! FVM\n\r");
                     configure_GUITAR();
                     break;
                 default:
@@ -226,9 +226,9 @@
             mail_mvf.gants = 'D'; // Gauche ou Droit
             m_pc.printf("Envoie de mail");
             threads[XBEE_TRANSMIT]->signal_set(0x01);
-            mail_mvf = mailGauche;
-            threads[XBEE_TRANSMIT]->signal_set(0x01);
-
+            /* mail_mvf = mailGauche;
+             threads[XBEE_TRANSMIT]->signal_set(0x01);
+            */
             // send data frame to the fixed mbed for analyze
         }
         accel.clear_TRANSIENT_INTERRUPT();