Gestion du Traffic Adaptatif- Code du mbed coordinateur

Dependencies:   XBeeLib mbed mbed-rtos EthernetInterface

Revision:
18:972fb2937e41
Parent:
17:0694b399bd0d
Child:
20:2a94c9200119
--- a/main.cpp	Sun Nov 11 19:40:46 2018 +0000
+++ b/main.cpp	Sun Nov 11 21:15:33 2018 +0000
@@ -29,17 +29,17 @@
 
 //feux gauche
     //rouge
-DigitalOut feux_gauche_rouge(p29);
+DigitalOut feux_gauche_rouge(p30);
     //orange
-DigitalOut feux_gauche_orange(p27);
+DigitalOut feux_gauche_orange(p28);
     //vert
-DigitalOut feux_gauche_vert(p25);
+DigitalOut feux_gauche_vert(p26);
 
     //liste des message a envoyer rouge et vert seulement pour le coordinateur
     ////////////////////////// 
     /////
-    char rouge = 'r';
-    char vert = 'v';
+    char rouge[] = "r";
+    char vert[] = "v";
     /////
     uint8_t ok = 0x02;
     //////////////////////////
@@ -56,25 +56,51 @@
 
     for (int i = 0; i < len; i++)
         log_serial->printf("%02x ", data[i]);
+   /* if (data[0]==0x76){
+        feux_gauche_rouge = 0;
+        }
+    if (data[0}==0x72){
+        feux_gauche_vert = 1;
+        }*/
 
     log_serial->printf("\r\n");
 }
 
 
-static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,char message)
-{
-
-    const uint8_t data_len = 0x01;
+static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message){
+    
+    //const uint8_t data_len = strlen(data);
     const uint8_t dstEP = 0xE8;
     const uint8_t srcEP = 0xE8;
     const uint16_t clusterID = 0x0011;
     const uint16_t profileID = 0xC105;
 
-    const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)message, data_len);
-    if (txStatus == TxStatusSuccess)
-        log_serial->printf("send_explicit_data_to_remote_node OK\r\n");
-    else
-        log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);
+    char data1[]="r";
+    char data2[]="v";
+    char data3[]="e";
+    if (message ==0){
+        const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data1, strlen(data1)); 
+        if (txStatus == TxStatusSuccess)
+            log_serial->printf("send_explicit_data_to_remote_node OK\r\n");
+        else
+            log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);
+    }
+    else if (message ==1){
+        const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data2, strlen(data2)); 
+        if (txStatus == TxStatusSuccess)
+            log_serial->printf("send_explicit_data_to_remote_node OK\r\n");
+        else
+            log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);
+    }
+    else {
+        const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data3, strlen(data3));
+        if (txStatus == TxStatusSuccess)
+            log_serial->printf("send_explicit_data_to_remote_node OK\r\n");
+        else
+            log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);
+    }
+   
+    
 }
 
 
@@ -110,8 +136,9 @@
     int i =0;
     const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
     while (true) {
-        i++;
+        
         uint32_t receive_value = xbee.process_rx_frames();
+        
         log_serial->printf("%d");
         wait_ms(100);
         log_serial->printf(".");
@@ -119,13 +146,13 @@
         
         //partie gestion des feux a mettre sur le coordinateur 
         /////////////////////////////////////////////
-        if(i==10){
-            send_explicit_data_to_remote_node(xbee, remoteDevice,rouge);
-            }
-        if(i==20){
-            send_explicit_data_to_remote_node(xbee, remoteDevice,vert);
-            i=0;
-            }
+      //  if(i==10){
+      //      send_explicit_data_to_remote_node(xbee, remoteDevice,1);
+      //      }
+       // if(i==20){
+        //    send_explicit_data_to_remote_node(xbee, remoteDevice,0);
+          //  i=0;
+            //}
         ////////////////////////////////////////////
     }