Gestion du Trafic Adaptatif - Code des mbed récepteurs
Dependencies: XBeeLib mbed mbed-rtos
Diff: main.cpp
- Revision:
- 22:d9287c62dd45
- Parent:
- 21:2ad11875542c
- Child:
- 23:296a2145c0fc
--- a/main.cpp Sun Nov 18 21:14:55 2018 +0000 +++ b/main.cpp Thu Nov 22 22:02:54 2018 +0000 @@ -20,30 +20,22 @@ //feux gauche //rouge -DigitalOut feux_gauche_rouge(p30); +DigitalOut feu_rouge(p30); //orange -DigitalOut feux_gauche_orange(p28); +DigitalOut feu_orange(p28); //vert -DigitalOut feux_gauche_vert(p26); +DigitalOut feu_vert(p26); Thread t_nbVoiture; +Thread t_feuRouge; DigitalIn boutonPlus(p24); DigitalIn boutonMoins(p23); - //liste des message a envoyer rouge et vert seulement pour le coordinateur - ////////////////////////// - ///// - char rouge[] = "r"; - char vert[] = "v"; - ///// - uint8_t ok = 0x02; - ////////////////////////// Serial *log_serial; XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64); - /** Callback function, invoked at packet reception */ static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len) { @@ -52,49 +44,40 @@ log_serial->printf("\r\nGot a %s RX packet [%08x:%08x|%04x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", UINT64_HI32(remote_addr64), UINT64_LO32(remote_addr64), remote.get_addr16(), len); if (data[0]==0x76){ - feux_gauche_rouge = 1; - feux_gauche_vert = 0; - } - if (data[0]==0x72){ - feux_gauche_rouge = 0; - feux_gauche_vert = 1; - } + t_feuRouge.signal_set(0x1); + } + else if (data[0]==0x72){ + feu_rouge = 0; + feu_orange = 0; + feu_vert = 1; + } log_serial->printf("\r\n"); } -static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message){ - - //const uint8_t data_len = strlen(data); +static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message) +{ const uint8_t dstEP = 0xE8; const uint8_t srcEP = 0xE8; const uint16_t clusterID = 0x0011; const uint16_t profileID = 0xC105; - char data1[]="m"; // m comme "moins" - une voiture de moins - char data2[]="p"; // p comme "plus" - une voiture de plus + char data0[]="m"; // m comme "moins" - une voiture de moins + char data1[]="p"; // p comme "plus" - une voiture de plus + char data2[]="r"; // r comme "rouge" - confirmation que le feu est rouge 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);*/ + const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data0, strlen(data0)); } else if (message ==1){ + const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data1, strlen(data1)); + } + else if (message ==2){ 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);*/ } @@ -111,8 +94,6 @@ new DigiLoggerMbedSerial(log_serial, LogLevelInfo); #endif - //xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); - /* Register callbacks */ xbee.register_receive_cb(&receive_cb); @@ -126,12 +107,28 @@ log_serial->printf("."); } log_serial->printf("OK\r\n"); - //return xbee; +} + +void set_feuRouge() +{ + while(1) + { + Thread::signal_wait(0x1); + feu_vert = 0; + feu_orange = 1; + Thread::wait(2000); + feu_orange = 0; + feu_rouge = 1; + send_explicit_data_to_remote_node(xbee, remoteDevice,2); + } } void nbVoiture() { - //TO DO : faire un compteur de voitures interne au recepteur et envoyer ce nombre - //au coordinateur -> plus fiable en cas de perte de donnees dans un envoi + //TO DO : + // - faire un compteur de voitures interne au recepteur et envoyer ce nombre + // au coordinateur -> plus fiable en cas de perte de donnees dans un envoi + // - faire un buffer pour envoyer les donnees + // while(1) { if(boutonPlus){ send_explicit_data_to_remote_node(xbee, remoteDevice,1); @@ -149,34 +146,8 @@ { connect_Xbee(); t_nbVoiture.start(nbVoiture); + t_feuRouge.start(set_feuRouge); while (true) { uint32_t receive_value = xbee.process_rx_frames(); - /*log_serial->printf("%d"); - wait_ms(100); - log_serial->printf(".");*/ - - /*if(boutonPlus){ - send_explicit_data_to_remote_node(xbee, remoteDevice,1); - } - if(boutonMoins){ - send_explicit_data_to_remote_node(xbee, remoteDevice,0); - }*/ - - //partie gestion des feux a mettre sur le coordinateur - ///////////////////////////////////////////// - /*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; - }*/ - //////////////////////////////////////////// } - - // delete(log_serial); }