GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Revision:
8:fd531fe7637b
Parent:
5:ffef0c7a70a1
Child:
9:f0030295ae9b
--- 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)