GDP group 24 node core
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue
Revision 8:fd531fe7637b, committed 2014-12-15
- Comitter:
- Trumple
- Date:
- Mon Dec 15 15:34:52 2014 +0000
- Parent:
- 5:ffef0c7a70a1
- Child:
- 9:f0030295ae9b
- Commit message:
- Include local I2C devices when requesting to join the network
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| sensorinterface.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 15 13:02:05 2014 +0000
+++ b/main.cpp Mon Dec 15 15:34:52 2014 +0000
@@ -4,6 +4,7 @@
#include "sdcard.h"
#include "http.h"
#include "MbedJSONValue.h"
+#include <map>
#define DEBUG
@@ -14,6 +15,8 @@
bool isBasenode = false;
http h = http();
+sensorinterface* sif;
+
char localAddress[8];
char baseNodeAddress[8];
bool networkParametersUpdated = false;
@@ -104,12 +107,32 @@
pc.printf("[MAIN] Requesting to join network...\r\n");
#endif
+ //prepare for response from basenode
xbee.registerMessageCallback(MESSAGE_JOIN_NETWORK_REPLY, handleJoinNetworkReply);
+ //handle retrying after timeout
networkParametersTimeout.attach(&handleNetworkParametersTimeout, 30.0);
- snail::joinnetworkrequest::sensor sensors[32];
- snail::joinnetworkrequest request(sensors, 0);
+ //generate list of sensors attached
+ snail::joinnetworkrequest::sensor localSensors[32];
+ map<char, sensor>::iterator cs = sif->sensors.begin();
+ int i = 0;
+
+ //either loop until we reach the end of the sensors or until we hit the max
+ while (cs != sif->sensors.end() && i < 32)
+ {
+ localSensors[i].type = cs->second.type;
+ localSensors[i].id = cs->first;
+ i++;
+ cs++;
+ }
+
+ #ifdef DEBUG
+ pc.printf("[MAIN] Informing basenode of %i attached devices\r\n", i);
+ #endif
+
+ //construct joinnetworkrequest, including the number of sensors attached
+ snail::joinnetworkrequest request(localSensors, i);
xbee.send(request, sizeof(request));
@@ -133,6 +156,7 @@
pc.printf("%.2X", baseNodeAddress[i]);
pc.printf("\r\n");
#endif
+ //no longer need to handle timeout
networkParametersTimeout.detach();
}
@@ -197,8 +221,9 @@
}
}
else
- {
+ {
sensorinterface sensors = sensorinterface();
+ sif = &sensors;
getNetworkParameters();
while(1)
--- a/sensorinterface.h Mon Dec 15 13:02:05 2014 +0000
+++ b/sensorinterface.h Mon Dec 15 15:34:52 2014 +0000
@@ -25,12 +25,12 @@
class sensorinterface
{
public:
+ map<char, sensor> sensors;
sensorinterface();
void requestData();
bool isDataWaiting();
d_reply readData();
private:
- map<char, sensor> sensors;
map<char, sensor>::iterator currentSensor;
int update();
void error(int);
