GDP group 24 node core
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue
Diff: main.cpp
- Revision:
- 9:f0030295ae9b
- Parent:
- 8:fd531fe7637b
- Parent:
- 7:5ae1d99d2b69
- Child:
- 10:13176e7bd4c8
--- a/main.cpp Mon Dec 15 15:34:52 2014 +0000 +++ b/main.cpp Mon Dec 15 15:50:20 2014 +0000 @@ -26,6 +26,8 @@ snail xbee = snail(); Ticker networkParametersTimeout; +queue<snail::sensordata> messageQueue; + void handleJoinNetworkReply(snail::message& message) { pc.printf("[MAIN] Got join network reply...\r\n"); @@ -229,8 +231,19 @@ while(1) { xbee.processIncomingData(); - //TODO: if xbee interrupt has woken us up - //transmit 10 latest readings + + //TODO: if message queue exceeds MAX_QUEUE SIZE, write older readings to SD card. + + //if xbee is awake send contents of message queue + if (xbee.isCTS()) + { + while(!messageQueue.empty()) + { + snail::sensordata message = messageQueue.front(); + xbee.send(message, sizeof(message)); + messageQueue.pop(); + } + } //check if it's time to poll if (time(NULL) - lastPollTime > pollInterval) @@ -263,8 +276,7 @@ memcpy(readings, readings_str.c_str(), sizeof(readings)); snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, data.readings.size()); - - xbee.send(message, sizeof(message)); + messageQueue.push(message); //log //sd.write(static_cast<long int>(time(NULL)), data);