Gestion du Traffic Adaptatif- Code du mbed coordinateur
Dependencies: XBeeLib mbed mbed-rtos EthernetInterface
main.cpp@19:a302b82c4357, 2018-11-11 (annotated)
- Committer:
- pierreblouet
- Date:
- Sun Nov 11 21:13:34 2018 +0000
- Revision:
- 19:a302b82c4357
- Parent:
- 17:0694b399bd0d
on emmet 76 et 72
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pierreblouet | 17:0694b399bd0d | 1 | /** |
pierreblouet | 17:0694b399bd0d | 2 | * Copyright (c) 2015 Digi International Inc., |
pierreblouet | 17:0694b399bd0d | 3 | * All rights not expressly granted are reserved. |
pierreblouet | 17:0694b399bd0d | 4 | * |
pierreblouet | 17:0694b399bd0d | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
pierreblouet | 17:0694b399bd0d | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
pierreblouet | 17:0694b399bd0d | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
pierreblouet | 17:0694b399bd0d | 8 | * |
pierreblouet | 17:0694b399bd0d | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
pierreblouet | 17:0694b399bd0d | 10 | * ======================================================================= |
pierreblouet | 17:0694b399bd0d | 11 | */ |
pierreblouet | 16:b4d5eb2ee378 | 12 | |
pierreblouet | 17:0694b399bd0d | 13 | #include "mbed.h" |
pierreblouet | 17:0694b399bd0d | 14 | #include "XBeeLib.h" |
pierreblouet | 17:0694b399bd0d | 15 | #if defined(ENABLE_LOGGING) |
pierreblouet | 17:0694b399bd0d | 16 | #include "DigiLoggerMbedSerial.h" |
pierreblouet | 17:0694b399bd0d | 17 | using namespace DigiLog; |
pierreblouet | 17:0694b399bd0d | 18 | #endif |
leomerel | 12:9ec78b07c688 | 19 | |
leomerel | 12:9ec78b07c688 | 20 | |
pierreblouet | 17:0694b399bd0d | 21 | #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200) |
pierreblouet | 17:0694b399bd0d | 22 | |
pierreblouet | 17:0694b399bd0d | 23 | //#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)" |
pierreblouet | 19:a302b82c4357 | 24 | #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40E779AF) |
pierreblouet | 17:0694b399bd0d | 25 | |
pierreblouet | 17:0694b399bd0d | 26 | #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB) |
pierreblouet | 17:0694b399bd0d | 27 | |
pierreblouet | 17:0694b399bd0d | 28 | using namespace XBeeLib; |
pierreblouet | 17:0694b399bd0d | 29 | |
pierreblouet | 17:0694b399bd0d | 30 | //feux gauche |
pierreblouet | 17:0694b399bd0d | 31 | //rouge |
pierreblouet | 19:a302b82c4357 | 32 | DigitalOut feux_gauche_rouge(p30); |
pierreblouet | 17:0694b399bd0d | 33 | //orange |
pierreblouet | 19:a302b82c4357 | 34 | DigitalOut feux_gauche_orange(p28); |
pierreblouet | 17:0694b399bd0d | 35 | //vert |
pierreblouet | 19:a302b82c4357 | 36 | DigitalOut feux_gauche_vert(p26); |
leomerel | 12:9ec78b07c688 | 37 | |
pierreblouet | 17:0694b399bd0d | 38 | //liste des message a envoyer rouge et vert seulement pour le coordinateur |
pierreblouet | 17:0694b399bd0d | 39 | ////////////////////////// |
pierreblouet | 17:0694b399bd0d | 40 | ///// |
pierreblouet | 19:a302b82c4357 | 41 | char rouge[] = "r"; |
pierreblouet | 19:a302b82c4357 | 42 | char vert[] = "v"; |
pierreblouet | 17:0694b399bd0d | 43 | ///// |
pierreblouet | 17:0694b399bd0d | 44 | uint8_t ok = 0x02; |
pierreblouet | 17:0694b399bd0d | 45 | ////////////////////////// |
pierreblouet | 17:0694b399bd0d | 46 | |
pierreblouet | 17:0694b399bd0d | 47 | |
pierreblouet | 17:0694b399bd0d | 48 | Serial *log_serial; |
pierreblouet | 17:0694b399bd0d | 49 | |
pierreblouet | 17:0694b399bd0d | 50 | /** Callback function, invoked at packet reception */ |
pierreblouet | 17:0694b399bd0d | 51 | static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len) |
pierreblouet | 17:0694b399bd0d | 52 | { |
pierreblouet | 17:0694b399bd0d | 53 | const uint64_t remote_addr64 = remote.get_addr64(); |
pierreblouet | 17:0694b399bd0d | 54 | |
pierreblouet | 17:0694b399bd0d | 55 | 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 | 56 | |
pierreblouet | 17:0694b399bd0d | 57 | for (int i = 0; i < len; i++) |
pierreblouet | 17:0694b399bd0d | 58 | log_serial->printf("%02x ", data[i]); |
pierreblouet | 19:a302b82c4357 | 59 | |
pierreblouet | 17:0694b399bd0d | 60 | log_serial->printf("\r\n"); |
emilmont | 1:491820ee784d | 61 | } |
leomerel | 12:9ec78b07c688 | 62 | |
pierreblouet | 17:0694b399bd0d | 63 | |
pierreblouet | 19:a302b82c4357 | 64 | static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice,int message){ |
pierreblouet | 19:a302b82c4357 | 65 | |
pierreblouet | 19:a302b82c4357 | 66 | //const uint8_t data_len = strlen(data); |
pierreblouet | 17:0694b399bd0d | 67 | const uint8_t dstEP = 0xE8; |
pierreblouet | 17:0694b399bd0d | 68 | const uint8_t srcEP = 0xE8; |
pierreblouet | 17:0694b399bd0d | 69 | const uint16_t clusterID = 0x0011; |
pierreblouet | 17:0694b399bd0d | 70 | const uint16_t profileID = 0xC105; |
pierreblouet | 17:0694b399bd0d | 71 | |
pierreblouet | 19:a302b82c4357 | 72 | char data1[]="r"; |
pierreblouet | 19:a302b82c4357 | 73 | char data2[]="v"; |
pierreblouet | 19:a302b82c4357 | 74 | char data3[]="e"; |
pierreblouet | 19:a302b82c4357 | 75 | if (message ==0){ |
pierreblouet | 19:a302b82c4357 | 76 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data1, strlen(data1)); |
pierreblouet | 19:a302b82c4357 | 77 | if (txStatus == TxStatusSuccess) |
pierreblouet | 19:a302b82c4357 | 78 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 19:a302b82c4357 | 79 | else |
pierreblouet | 19:a302b82c4357 | 80 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 19:a302b82c4357 | 81 | } |
pierreblouet | 19:a302b82c4357 | 82 | else if (message ==1){ |
pierreblouet | 19:a302b82c4357 | 83 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data2, strlen(data2)); |
pierreblouet | 19:a302b82c4357 | 84 | if (txStatus == TxStatusSuccess) |
pierreblouet | 19:a302b82c4357 | 85 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 19:a302b82c4357 | 86 | else |
pierreblouet | 19:a302b82c4357 | 87 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 19:a302b82c4357 | 88 | } |
pierreblouet | 19:a302b82c4357 | 89 | else { |
pierreblouet | 19:a302b82c4357 | 90 | const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data3, strlen(data3)); |
pierreblouet | 19:a302b82c4357 | 91 | if (txStatus == TxStatusSuccess) |
pierreblouet | 19:a302b82c4357 | 92 | log_serial->printf("send_explicit_data_to_remote_node OK\r\n"); |
pierreblouet | 19:a302b82c4357 | 93 | else |
pierreblouet | 19:a302b82c4357 | 94 | log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus); |
pierreblouet | 19:a302b82c4357 | 95 | } |
pierreblouet | 19:a302b82c4357 | 96 | |
pierreblouet | 19:a302b82c4357 | 97 | |
emilmont | 1:491820ee784d | 98 | } |
leomerel | 12:9ec78b07c688 | 99 | |
pierreblouet | 17:0694b399bd0d | 100 | |
pierreblouet | 17:0694b399bd0d | 101 | int main() |
pierreblouet | 17:0694b399bd0d | 102 | { |
pierreblouet | 17:0694b399bd0d | 103 | log_serial = new Serial(DEBUG_TX, DEBUG_RX); |
pierreblouet | 17:0694b399bd0d | 104 | log_serial->baud(9600); |
pierreblouet | 17:0694b399bd0d | 105 | log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBeeZB\r\n\r\n"); |
pierreblouet | 17:0694b399bd0d | 106 | log_serial->printf(XB_LIB_BANNER); |
pierreblouet | 17:0694b399bd0d | 107 | |
pierreblouet | 17:0694b399bd0d | 108 | |
pierreblouet | 17:0694b399bd0d | 109 | |
pierreblouet | 17:0694b399bd0d | 110 | #if defined(ENABLE_LOGGING) |
pierreblouet | 17:0694b399bd0d | 111 | new DigiLoggerMbedSerial(log_serial, LogLevelInfo); |
pierreblouet | 17:0694b399bd0d | 112 | #endif |
pierreblouet | 17:0694b399bd0d | 113 | |
pierreblouet | 17:0694b399bd0d | 114 | XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); |
pierreblouet | 17:0694b399bd0d | 115 | |
pierreblouet | 17:0694b399bd0d | 116 | /* Register callbacks */ |
pierreblouet | 17:0694b399bd0d | 117 | xbee.register_receive_cb(&receive_cb); |
pierreblouet | 17:0694b399bd0d | 118 | |
pierreblouet | 17:0694b399bd0d | 119 | RadioStatus const radioStatus = xbee.init(); |
pierreblouet | 17:0694b399bd0d | 120 | MBED_ASSERT(radioStatus == Success); |
leomerel | 12:9ec78b07c688 | 121 | |
pierreblouet | 17:0694b399bd0d | 122 | /* Wait until the device has joined the network */ |
pierreblouet | 17:0694b399bd0d | 123 | log_serial->printf("Waiting for device to join the network: "); |
pierreblouet | 17:0694b399bd0d | 124 | while (!xbee.is_joined()) { |
pierreblouet | 17:0694b399bd0d | 125 | wait_ms(1000); |
pierreblouet | 17:0694b399bd0d | 126 | log_serial->printf("."); |
leomerel | 12:9ec78b07c688 | 127 | } |
pierreblouet | 17:0694b399bd0d | 128 | log_serial->printf("OK\r\n"); |
leomerel | 12:9ec78b07c688 | 129 | |
pierreblouet | 17:0694b399bd0d | 130 | int i =0; |
pierreblouet | 17:0694b399bd0d | 131 | const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64); |
pierreblouet | 17:0694b399bd0d | 132 | while (true) { |
pierreblouet | 17:0694b399bd0d | 133 | i++; |
pierreblouet | 17:0694b399bd0d | 134 | uint32_t receive_value = xbee.process_rx_frames(); |
pierreblouet | 17:0694b399bd0d | 135 | log_serial->printf("%d"); |
pierreblouet | 17:0694b399bd0d | 136 | wait_ms(100); |
pierreblouet | 17:0694b399bd0d | 137 | log_serial->printf("."); |
pierreblouet | 17:0694b399bd0d | 138 | |
leomerel | 12:9ec78b07c688 | 139 | |
pierreblouet | 17:0694b399bd0d | 140 | //partie gestion des feux a mettre sur le coordinateur |
pierreblouet | 17:0694b399bd0d | 141 | ///////////////////////////////////////////// |
pierreblouet | 17:0694b399bd0d | 142 | if(i==10){ |
pierreblouet | 19:a302b82c4357 | 143 | send_explicit_data_to_remote_node(xbee, remoteDevice,1); |
pierreblouet | 17:0694b399bd0d | 144 | } |
pierreblouet | 17:0694b399bd0d | 145 | if(i==20){ |
pierreblouet | 19:a302b82c4357 | 146 | send_explicit_data_to_remote_node(xbee, remoteDevice,0); |
pierreblouet | 17:0694b399bd0d | 147 | i=0; |
pierreblouet | 17:0694b399bd0d | 148 | } |
pierreblouet | 17:0694b399bd0d | 149 | //////////////////////////////////////////// |
leomerel | 12:9ec78b07c688 | 150 | } |
pierreblouet | 17:0694b399bd0d | 151 | |
pierreblouet | 17:0694b399bd0d | 152 | // delete(log_serial); |
pierreblouet | 17:0694b399bd0d | 153 | } |