Gestion du Traffic Adaptatif- Code du mbed coordinateur

Dependencies:   XBeeLib mbed mbed-rtos EthernetInterface

Revision:
22:c3b22291cb9d
Parent:
21:5adfcfd83e95
Child:
23:2a6ea31d8e23
--- a/main.cpp	Sun Nov 18 16:40:36 2018 +0000
+++ b/main.cpp	Sun Nov 18 21:15:36 2018 +0000
@@ -26,8 +26,10 @@
     //vert
 DigitalOut feux_gauche_vert(p16);
 
+DigitalOut led1(LED1);
+
 //Nombre de voitures au feu
-int nombreDeVoiture = 0;
+int voituresFeu1 = 0;
 DigitalIn boutonPlus(p24);
 DigitalIn boutonMoins(p23);
 Thread t_nbVoiture;
@@ -55,19 +57,20 @@
 
     /*for (int i = 0; i < len; i++)
         log_serial->printf("%02x ", data[i]);*/
-    if (data[0]==0x76){
-        feux_gauche_rouge = 1;
-        feux_gauche_vert = 0;
-        }
-    if (data[0]==0x72){
-        feux_gauche_rouge = 0;
-        feux_gauche_vert = 1;
-        }
+        
+    if (data[0]==0x6D && voituresFeu1!=0){
+        voituresFeu1--;
+        printf("Nombre de voitures : %d",voituresFeu1);
+    }
+    if (data[0]==0x70){
+        voituresFeu1++;
+        printf("Nombre de voitures : %d",voituresFeu1);
+    }
 
     log_serial->printf("\r\n");
 }
 
-void nbVoiture() {
+/*void nbVoiture() {
     while(1) {
         if(boutonPlus){
             nombreDeVoiture++;  
@@ -77,9 +80,9 @@
         }
         printf("Nombre de voitures : %d \r\n", nombreDeVoiture);
     }
-}
+}*/
 
-/*static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message){
+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;
@@ -92,42 +95,37 @@
     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)
+        /*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);
+            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)
+        /*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);
+            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)
+        /*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);
+            log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);*/
     }
-   
-    
-}*/
+}
 
-
-int main()
+XBeeZB connect_Xbee()
 {
     log_serial = new Serial(DEBUG_TX, DEBUG_RX);
     log_serial->baud(9600);
     log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBeeZB\r\n\r\n");
     log_serial->printf(XB_LIB_BANNER);
     
-
-
-#if defined(ENABLE_LOGGING)
+    #if defined(ENABLE_LOGGING)
     new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
-#endif
+    #endif
 
     XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
 
@@ -144,13 +142,20 @@
         log_serial->printf(".");
     }
     log_serial->printf("OK\r\n");
+    return xbee;
+}
+
+int main()
+{
+    XBeeZB xbee = connect_Xbee();
     
-    t_nbVoiture.start(nbVoiture);
-    t_receive.start(receive_cb);
+    //t_nbVoiture.start(nbVoiture);
+    //t_receive.start(receive_cb);
+    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");
@@ -160,14 +165,21 @@
         
         //partie gestion des feux a mettre sur le coordinateur 
         /////////////////////////////////////////////
-      //  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;
-            //}
+        if(i==10){
+            send_explicit_data_to_remote_node(xbee, remoteDevice,1);
+            feux_gauche_rouge = 0;
+            feux_gauche_vert = 1;
+        }
+        if(i==20){
+            send_explicit_data_to_remote_node(xbee, remoteDevice,0);
+            feux_gauche_rouge = 1;
+            feux_gauche_vert = 0;
+            i=0;
+        }
         ////////////////////////////////////////////
+        
+        if(voituresFeu1 >= 10){led1=1;}
+        else{led1=0;}
     }
 
    // delete(log_serial);