Gestion du Traffic Adaptatif- Code du mbed coordinateur
Dependencies: XBeeLib mbed mbed-rtos EthernetInterface
main.cpp@21:5adfcfd83e95, 2018-11-18 (annotated)
- Committer:
- leomerel
- Date:
- Sun Nov 18 16:40:36 2018 +0000
- Revision:
- 21:5adfcfd83e95
- Parent:
- 20:2a94c9200119
- Child:
- 22:c3b22291cb9d
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leomerel | 21:5adfcfd83e95 | 1 | //SQLUT |
pierreblouet | 16:b4d5eb2ee378 | 2 | |
pierreblouet | 17:0694b399bd0d | 3 | #include "mbed.h" |
pierreblouet | 17:0694b399bd0d | 4 | #include "XBeeLib.h" |
leomerel | 21:5adfcfd83e95 | 5 | #include "rtos.h" |
pierreblouet | 17:0694b399bd0d | 6 | #if defined(ENABLE_LOGGING) |
pierreblouet | 17:0694b399bd0d | 7 | #include "DigiLoggerMbedSerial.h" |
pierreblouet | 17:0694b399bd0d | 8 | using namespace DigiLog; |
pierreblouet | 17:0694b399bd0d | 9 | #endif |
leomerel | 12:9ec78b07c688 | 10 | |
leomerel | 12:9ec78b07c688 | 11 | |
pierreblouet | 17:0694b399bd0d | 12 | #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200) |
pierreblouet | 17:0694b399bd0d | 13 | |
pierreblouet | 17:0694b399bd0d | 14 | //#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)" |
pierreblouet | 17:0694b399bd0d | 15 | #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40C0E3A1) |
pierreblouet | 17:0694b399bd0d | 16 | |
pierreblouet | 17:0694b399bd0d | 17 | #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB) |
pierreblouet | 17:0694b399bd0d | 18 | |
pierreblouet | 17:0694b399bd0d | 19 | using namespace XBeeLib; |
pierreblouet | 17:0694b399bd0d | 20 | |
pierreblouet | 17:0694b399bd0d | 21 | //feux gauche |
pierreblouet | 17:0694b399bd0d | 22 | //rouge |
pierreblouet | 20:2a94c9200119 | 23 | DigitalOut feux_gauche_rouge(p12); |
pierreblouet | 17:0694b399bd0d | 24 | //orange |
pierreblouet | 20:2a94c9200119 | 25 | DigitalOut feux_gauche_orange(p14); |
pierreblouet | 17:0694b399bd0d | 26 | //vert |
pierreblouet | 20:2a94c9200119 | 27 | DigitalOut feux_gauche_vert(p16); |
leomerel | 12:9ec78b07c688 | 28 | |
leomerel | 21:5adfcfd83e95 | 29 | //Nombre de voitures au feu |
leomerel | 21:5adfcfd83e95 | 30 | int nombreDeVoiture = 0; |
leomerel | 21:5adfcfd83e95 | 31 | DigitalIn boutonPlus(p24); |
leomerel | 21:5adfcfd83e95 | 32 | DigitalIn boutonMoins(p23); |
leomerel | 21:5adfcfd83e95 | 33 | Thread t_nbVoiture; |
leomerel | 21:5adfcfd83e95 | 34 | |
leomerel | 21:5adfcfd83e95 | 35 | Thread t_receive; |
leomerel | 21:5adfcfd83e95 | 36 | |
pierreblouet | 17:0694b399bd0d | 37 | //liste des message a envoyer rouge et vert seulement pour le coordinateur |
pierreblouet | 17:0694b399bd0d | 38 | ////////////////////////// |
pierreblouet | 17:0694b399bd0d | 39 | ///// |
pierreblouet | 18:972fb2937e41 | 40 | char rouge[] = "r"; |
pierreblouet | 18:972fb2937e41 | 41 | char vert[] = "v"; |
pierreblouet | 17:0694b399bd0d | 42 | ///// |
pierreblouet | 17:0694b399bd0d | 43 | uint8_t ok = 0x02; |
pierreblouet | 17:0694b399bd0d | 44 | ////////////////////////// |
pierreblouet | 17:0694b399bd0d | 45 | |
pierreblouet | 17:0694b399bd0d | 46 | |
pierreblouet | 17:0694b399bd0d | 47 | Serial *log_serial; |
pierreblouet | 17:0694b399bd0d | 48 | |
pierreblouet | 17:0694b399bd0d | 49 | /** Callback function, invoked at packet reception */ |
pierreblouet | 17:0694b399bd0d | 50 | static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len) |
pierreblouet | 17:0694b399bd0d | 51 | { |
pierreblouet | 17:0694b399bd0d | 52 | const uint64_t remote_addr64 = remote.get_addr64(); |
pierreblouet | 17:0694b399bd0d | 53 | |
pierreblouet | 17:0694b399bd0d | 54 | 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); |
pierreblouet | 17:0694b399bd0d | 55 | |
pierreblouet | 20:2a94c9200119 | 56 | /*for (int i = 0; i < len; i++) |
pierreblouet | 20:2a94c9200119 | 57 | log_serial->printf("%02x ", data[i]);*/ |
pierreblouet | 20:2a94c9200119 | 58 | if (data[0]==0x76){ |
pierreblouet | 20:2a94c9200119 | 59 | feux_gauche_rouge = 1; |
pierreblouet | 20:2a94c9200119 | 60 | feux_gauche_vert = 0; |
pierreblouet | 20:2a94c9200119 | 61 | } |
pierreblouet | 20:2a94c9200119 | 62 | if (data[0]==0x72){ |
pierreblouet | 18:972fb2937e41 | 63 | feux_gauche_rouge = 0; |
pierreblouet | 20:2a94c9200119 | 64 | feux_gauche_vert = 1; |
pierreblouet | 18:972fb2937e41 | 65 | } |
pierreblouet | 17:0694b399bd0d | 66 | |
pierreblouet | 17:0694b399bd0d | 67 | log_serial->printf("\r\n"); |
emilmont | 1:491820ee784d | 68 | } |
leomerel | 12:9ec78b07c688 | 69 | |
leomerel | 21:5adfcfd83e95 | 70 | void nbVoiture() { |
leomerel | 21:5adfcfd83e95 | 71 | while(1) { |
leomerel | 21:5adfcfd83e95 | 72 | if(boutonPlus){ |
leomerel | 21:5adfcfd83e95 | 73 | nombreDeVoiture++; |
leomerel | 21:5adfcfd83e95 | 74 | } |
leomerel | 21:5adfcfd83e95 | 75 | if(boutonMoins && nombreDeVoiture>0){ |
leomerel | 21:5adfcfd83e95 | 76 | nombreDeVoiture--; |
leomerel | 21:5adfcfd83e95 | 77 | } |
leomerel | 21:5adfcfd83e95 | 78 | printf("Nombre de voitures : %d \r\n", nombreDeVoiture); |
leomerel | 21:5adfcfd83e95 | 79 | } |
leomerel | 21:5adfcfd83e95 | 80 | } |
pierreblouet | 17:0694b399bd0d | 81 | |
leomerel | 21:5adfcfd83e95 | 82 | /*static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message){ |
pierreblouet | 18:972fb2937e41 | 83 | |
pierreblouet | 18:972fb2937e41 | 84 | //const uint8_t data_len = strlen(data); |
pierreblouet | 17:0694b399bd0d | 85 | const uint8_t dstEP = 0xE8; |
pierreblouet | 17:0694b399bd0d | 86 | const uint8_t srcEP = 0xE8; |
pierreblouet | 17:0694b399bd0d | 87 | const uint16_t clusterID = 0x0011; |
pierreblouet | 17:0694b399bd0d | 88 | const uint16_t profileID = 0xC105; |
pierreblouet | 17:0694b399bd0d | 89 | |
pierreblouet | 18:972fb2937e41 | 90 | char data1[]="r"; |
pierreblouet | 18:972fb2937e41 | 91 | char data2[]="v"; |
pierreblouet | 18:972fb2937e41 | 92 | char data3[]="e"; |
pierreblouet | 18:972fb2937e41 | 93 | if (message ==0){ |
pierreblouet | 18:972fb2937e41 | 94 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data1, strlen(data1)); |
pierreblouet | 18:972fb2937e41 | 95 | if (txStatus == TxStatusSuccess) |
pierreblouet | 18:972fb2937e41 | 96 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 18:972fb2937e41 | 97 | else |
pierreblouet | 18:972fb2937e41 | 98 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 18:972fb2937e41 | 99 | } |
pierreblouet | 18:972fb2937e41 | 100 | else if (message ==1){ |
pierreblouet | 18:972fb2937e41 | 101 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data2, strlen(data2)); |
pierreblouet | 18:972fb2937e41 | 102 | if (txStatus == TxStatusSuccess) |
pierreblouet | 18:972fb2937e41 | 103 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 18:972fb2937e41 | 104 | else |
pierreblouet | 18:972fb2937e41 | 105 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 18:972fb2937e41 | 106 | } |
pierreblouet | 18:972fb2937e41 | 107 | else { |
pierreblouet | 18:972fb2937e41 | 108 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data3, strlen(data3)); |
pierreblouet | 18:972fb2937e41 | 109 | if (txStatus == TxStatusSuccess) |
pierreblouet | 18:972fb2937e41 | 110 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 18:972fb2937e41 | 111 | else |
pierreblouet | 18:972fb2937e41 | 112 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 18:972fb2937e41 | 113 | } |
pierreblouet | 18:972fb2937e41 | 114 | |
pierreblouet | 18:972fb2937e41 | 115 | |
leomerel | 21:5adfcfd83e95 | 116 | }*/ |
leomerel | 12:9ec78b07c688 | 117 | |
pierreblouet | 17:0694b399bd0d | 118 | |
pierreblouet | 17:0694b399bd0d | 119 | int main() |
pierreblouet | 17:0694b399bd0d | 120 | { |
pierreblouet | 17:0694b399bd0d | 121 | log_serial = new Serial(DEBUG_TX, DEBUG_RX); |
pierreblouet | 17:0694b399bd0d | 122 | log_serial->baud(9600); |
pierreblouet | 17:0694b399bd0d | 123 | log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBeeZB\r\n\r\n"); |
pierreblouet | 17:0694b399bd0d | 124 | log_serial->printf(XB_LIB_BANNER); |
pierreblouet | 17:0694b399bd0d | 125 | |
pierreblouet | 17:0694b399bd0d | 126 | |
pierreblouet | 17:0694b399bd0d | 127 | |
pierreblouet | 17:0694b399bd0d | 128 | #if defined(ENABLE_LOGGING) |
pierreblouet | 17:0694b399bd0d | 129 | new DigiLoggerMbedSerial(log_serial, LogLevelInfo); |
pierreblouet | 17:0694b399bd0d | 130 | #endif |
pierreblouet | 17:0694b399bd0d | 131 | |
pierreblouet | 17:0694b399bd0d | 132 | XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); |
pierreblouet | 17:0694b399bd0d | 133 | |
pierreblouet | 17:0694b399bd0d | 134 | /* Register callbacks */ |
pierreblouet | 17:0694b399bd0d | 135 | xbee.register_receive_cb(&receive_cb); |
pierreblouet | 17:0694b399bd0d | 136 | |
pierreblouet | 17:0694b399bd0d | 137 | RadioStatus const radioStatus = xbee.init(); |
pierreblouet | 17:0694b399bd0d | 138 | MBED_ASSERT(radioStatus == Success); |
leomerel | 12:9ec78b07c688 | 139 | |
pierreblouet | 17:0694b399bd0d | 140 | /* Wait until the device has joined the network */ |
pierreblouet | 17:0694b399bd0d | 141 | log_serial->printf("Waiting for device to join the network: "); |
pierreblouet | 17:0694b399bd0d | 142 | while (!xbee.is_joined()) { |
pierreblouet | 17:0694b399bd0d | 143 | wait_ms(1000); |
pierreblouet | 17:0694b399bd0d | 144 | log_serial->printf("."); |
leomerel | 12:9ec78b07c688 | 145 | } |
pierreblouet | 17:0694b399bd0d | 146 | log_serial->printf("OK\r\n"); |
leomerel | 21:5adfcfd83e95 | 147 | |
leomerel | 21:5adfcfd83e95 | 148 | t_nbVoiture.start(nbVoiture); |
leomerel | 21:5adfcfd83e95 | 149 | t_receive.start(receive_cb); |
leomerel | 21:5adfcfd83e95 | 150 | |
pierreblouet | 17:0694b399bd0d | 151 | const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64); |
pierreblouet | 17:0694b399bd0d | 152 | while (true) { |
pierreblouet | 18:972fb2937e41 | 153 | |
pierreblouet | 17:0694b399bd0d | 154 | uint32_t receive_value = xbee.process_rx_frames(); |
pierreblouet | 18:972fb2937e41 | 155 | |
pierreblouet | 17:0694b399bd0d | 156 | log_serial->printf("%d"); |
pierreblouet | 17:0694b399bd0d | 157 | wait_ms(100); |
pierreblouet | 17:0694b399bd0d | 158 | log_serial->printf("."); |
pierreblouet | 17:0694b399bd0d | 159 | |
leomerel | 12:9ec78b07c688 | 160 | |
pierreblouet | 17:0694b399bd0d | 161 | //partie gestion des feux a mettre sur le coordinateur |
pierreblouet | 17:0694b399bd0d | 162 | ///////////////////////////////////////////// |
pierreblouet | 18:972fb2937e41 | 163 | // if(i==10){ |
pierreblouet | 18:972fb2937e41 | 164 | // send_explicit_data_to_remote_node(xbee, remoteDevice,1); |
pierreblouet | 18:972fb2937e41 | 165 | // } |
pierreblouet | 18:972fb2937e41 | 166 | // if(i==20){ |
pierreblouet | 18:972fb2937e41 | 167 | // send_explicit_data_to_remote_node(xbee, remoteDevice,0); |
pierreblouet | 18:972fb2937e41 | 168 | // i=0; |
pierreblouet | 18:972fb2937e41 | 169 | //} |
pierreblouet | 17:0694b399bd0d | 170 | //////////////////////////////////////////// |
leomerel | 12:9ec78b07c688 | 171 | } |
pierreblouet | 17:0694b399bd0d | 172 | |
pierreblouet | 17:0694b399bd0d | 173 | // delete(log_serial); |
pierreblouet | 17:0694b399bd0d | 174 | } |