Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
195:21df85341cb3
Parent:
185:5ac6ab1ed875
Child:
212:289f63158d2b
--- a/src/OutputTask/OutputTask.cpp	Thu Oct 06 15:46:13 2016 +0000
+++ b/src/OutputTask/OutputTask.cpp	Thu Oct 06 19:31:13 2016 +0000
@@ -17,7 +17,7 @@
 // local functions
 static int  createOutput(const char *controlFile);
 static void loadPersistentOutputs(void);
-static void refreshOutputs(const string);
+static void writeOutputs(const std::string, const std::string);
 static int  enableOutputReq(OutputControlMsg_t *msg);
 static int  disableOutputReq(OutputControlMsg_t *msg);
 static int  unregisterControl(const char *id, unsigned int pri, const char *output);
@@ -36,7 +36,7 @@
 // the highest priority control is at the front (v.front()) of the
 // list.
 
-typedef std::map<string, vector<Control> > StringOutputVector_t;
+typedef std::map<std::string, vector<Control> > StringOutputVector_t;
 StringOutputVector_t outputMap;
 
 // operator for sorting the outputs vectors per output
@@ -110,7 +110,7 @@
             OutputMasterMailBox.free(msg);
 
             // refresh the outputs
-            refreshOutputs(msg->output_tag);
+            writeOutputs(msg->id, msg->output_tag);
         }
     }
 }
@@ -192,27 +192,29 @@
 }
 
 /*****************************************************************************
- * Function:            refreshOutputs
+ * Function:            writeOutputs
  * Description:         send a message to the modbus master of who's in control
  *
  *
  * @param               args -> not used
  * @return              none
  *****************************************************************************/
-static void refreshOutputs(const string output_tag)
+static void writeOutputs(const std::string id, const std::string output_tag)
 {
+    UNUSED(id);
+    
     if ( output_tag.empty() ) return;
 
-    //who's in control here?
     StringOutputVector_t::iterator pos;
 
+    // find the output 
     pos = outputMap.find(output_tag);
     if ( pos != outputMap.end() ) {
+        // we found the ouput, but nothing's controlling it... 
         if ( pos->second.empty() ) {
-            // play it safe
             ModbusMasterWriteRegister(pos->first, RELAY_STATUS_NOT_CONTROLLED);
             recordEvent(pos->first, NULL);
-        } else {
+        } else { 
             ModbusMasterWriteRegister(pos->first, pos->second.begin()->getMappedState());
             printf("\rDEBUG: wrote %u to the modbus map\n", pos->second.begin()->getMappedState());
             recordEvent(pos->first, (Control*)pos->second.begin());
@@ -268,9 +270,14 @@
 
     MbedJSONValue json_value;
     parse(json_value, dataBuf);
+    
+    if ( !json_value.hasMember("id") ) {
+        logError("Output file is missing expected tags");
+        return -1;
+    }
 
     // extract the relay information
-    string id = json_value["id"].get<string>();
+    std::string id = json_value["id"].get<string>();
 
     // maps don't allow duplicates, and the vector is empty for now
     vector<Control> v;
@@ -300,8 +307,8 @@
 
     if ( pos->second.empty() ) {
         // this is a new request
-        string cid(msg->id);
-        string input(msg->input_tag);
+        std::string cid(msg->id);
+        std::string input(msg->input_tag);
         Control c(cid, msg->controlType, input, msg->priority, CONTROL_ON);
         pos->second.push_back(c);
     } else {
@@ -315,8 +322,8 @@
         }
         if ( v == pos->second.end() ) {
             // this is a new request, so add it and sort the vector
-            string cid(msg->id);
-            string input(msg->input_tag);
+            std::string cid(msg->id);
+            std::string input(msg->input_tag);
             Control c(cid, msg->controlType, input, msg->priority, CONTROL_ON);
             pos->second.push_back(c);
             std::sort(pos->second.begin(), pos->second.end());
@@ -347,8 +354,8 @@
 
     // if the control list is empty, push this control on the list
     if ( pos->second.empty() ) {
-        string cid(msg->id);
-        string input(msg->input_tag);
+        std::string cid(msg->id);
+        std::string input(msg->input_tag);
         Control c(cid, msg->controlType, input, msg->priority, CONTROL_OFF);
         pos->second.push_back(c);
     } else {
@@ -363,8 +370,8 @@
 
         if ( v == pos->second.end() ) {
             // this is a new request, so add it and sort the vector
-            string cid(msg->id);
-            string input(msg->input_tag);
+            std::string cid(msg->id);
+            std::string input(msg->input_tag);
             Control c(cid, msg->controlType, input, msg->priority, CONTROL_OFF);
             pos->second.push_back(c);
             std::sort(pos->second.begin(), pos->second.end());
@@ -446,8 +453,13 @@
             }
 
             parse( json_value, scratchBuf );
+            
+            if ( !json_value.hasMember("id") ) {
+                logError("Output file %s is missing expected tags", i->name);
+                continue;
+            }
 
-            string id = json_value["id"].get<string>();
+            std::string id = json_value["id"].get<string>();
             printf("\r   output %s loaded\n", i->name);
 
             // emplace the empty control vector into the output map