BraceletUS / Mbed 2 deprecated S05APP3

Dependencies:   ConfigFile EthernetInterface mbed-rtos mbed

Fork of S05APP3 by App S5

Revision:
3:fbd4b164e8ad
Parent:
2:3fbf13ba290e
Child:
4:393738672d08
--- a/main.cpp	Fri Feb 10 21:58:27 2017 +0000
+++ b/main.cpp	Sat Feb 11 01:54:57 2017 +0000
@@ -17,6 +17,8 @@
 uint16_t portNo = 0;
 char portNbValue[4];
 
+bool boolLED = false; 
+
 //Union créée pour mettre deux 8 bits en un 16 bits.
 uint16_t getLength(uint8_t value1, uint8_t value2) {
     union {
@@ -30,6 +32,28 @@
     return length.u16_value;
 }
 
+void toogleLED() {
+    
+    //Numéro 64 bit = 00 13 A2 00 40 8B 41 6E
+    //uint8_t high[20] = {0x7E, 0x00, 0x10, 0x17, 0x00, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8B, 0x41, 0x6E, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x05, 0x3D};
+    //uint8_t low[20]  = {0x7E, 0x00, 0x10, 0x17, 0x00, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8B, 0x41, 0x6E, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x04, 0x3E};
+    uint8_t high[20] = {0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8B, 0x41, 0x6E, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x05, 0x3C};
+    uint8_t low[20]  = {0x7E, 0x00, 0x10, 0x17, 0x02, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8B, 0x41, 0x6E, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x04, 0x3C};
+
+    for(int i = 0; i < 20;) {
+        if(uart.writeable()) {
+            if(boolLED) uart.putc(high[i]);
+            else uart.putc(low[i]);
+            i++; 
+        }   
+    }
+    
+    if(boolLED) pc.printf("Et un haut!\n");
+    else pc.printf("Et un bas!\n");
+    
+    boolLED = !boolLED;
+}
+
 //Read the config file
 void readConfigFile()
 {
@@ -43,14 +67,11 @@
         cfg.getValue(serverAddr, &serverAddrvalue[0], sizeof(serverAddrvalue));
         cfg.getValue(tempPortNo, &portNbValue[0], sizeof(portNbValue));
         portNo = (uint16_t)strtol(portNbValue, NULL, 10);
-        pc.printf("%i", portNo);
     }
 }
 
 void initSocket()
 {
-
-    
     //int repSize;
     //while (true) {
 
@@ -68,6 +89,18 @@
     //}
 }
 
+void checkForError()
+{
+    if(buffer[0] == 0x97) {
+        if(buffer[1] == 0x02) {
+            pc.printf("Erreur dans la remote AT command pour mettre la DEL a l'etat bas.\n");
+        }
+        else if(buffer[1] == 0x01) {
+            pc.printf("Erreur dans la remote AT command pour mettre la DEL a l'etat haut\n");
+        }
+    }
+}
+
 void verifyChecksum()
 {
     //Je valide le checksum pour voir si tout est correct.
@@ -77,6 +110,8 @@
     }
     if((0xFF - (checkSum & 0xFF)) != buffer[frameSize])
         pc.printf("Erreur dans le checksum. \n");
+        
+    checkForError();
 }
 
 void readFrame(){
@@ -103,6 +138,10 @@
             }
         }
         verifyChecksum();
+        //Debug seulement
+        for(int k = 0; k < frameSize; k++)
+            pc.printf("%X-", buffer[k]);
+        pc.printf("\n---------------\n");
     }
 }
 
@@ -117,19 +156,27 @@
     //Init RJ45 and use DHCP
     EthernetInterface eth;
     if(eth.init() != 0)
-        pc.prinf("Erreur d'initialisation du RJ45\n");
+        pc.printf("Erreur d'initialisation du RJ45.\n");
     if(eth.connect() != 0)
-        pc.prinf("Erreur de connection du RJ45\n"); 
+        pc.printf("Erreur de connection du RJ45\n"); 
 
     //Init Socket
     if(sock.connect(serverAddrvalue, portNo) != 0)
-        pc.printf("Erreur de socket\n");
+        pc.printf("Erreur de socket.\n");
 
     //sock.send_all(buffer, sizeof(buffer)-1);
     
     //initSocket();
+    
+    //Set ticker to blink LED at each 1 sec
+    //Ticker blinkLED;
+   // blinkLED.attach(&toogleLED, 1);
+    
+    pc.printf("Pret a recevoir des trames! \n");
     while(1) {
         readFrame();
+        wait_ms(1000);
+        toogleLED();
     }
 }