GDP group 24 node core
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue
Diff: main.cpp
- Revision:
- 6:92ddc620a78f
- Parent:
- 4:0bab12a0cc9a
- Child:
- 7:5ae1d99d2b69
--- a/main.cpp Mon Dec 15 12:50:26 2014 +0000 +++ b/main.cpp Mon Dec 15 15:02:43 2014 +0000 @@ -23,6 +23,8 @@ snail xbee = snail(); Ticker networkParametersTimeout; +queue<snail::sensordata> messageQueue; + void handleJoinNetworkReply(snail::message& message) { pc.printf("[MAIN] Got join network reply...\r\n"); @@ -204,8 +206,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) @@ -238,8 +251,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);