Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Committer:
jmarkel44
Date:
Tue Sep 20 13:46:01 2016 +0000
Revision:
84:7b7cad3ba139
Parent:
80:b12b0adfcdc2
Child:
86:189c125d8878
refresh output functionality;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmarkel44 70:7427f4959201 1 /******************************************************************************
jmarkel44 70:7427f4959201 2 *
jmarkel44 70:7427f4959201 3 * File: OutputTask.cpp
jmarkel44 70:7427f4959201 4 * Desciption: source for the ICE Output task
jmarkel44 70:7427f4959201 5 *
jmarkel44 70:7427f4959201 6 *****************************************************************************/
jmarkel44 67:49f266601d83 7 #include "OutputTask.h"
jmarkel44 48:1c7861d80d16 8 #include "global.h"
jmarkel44 66:db1425574b58 9 #include "MbedJSONValue.h"
jmarkel44 70:7427f4959201 10 #include <vector>
jmarkel44 77:43e0a3d9e536 11 #include <string>
jmarkel44 77:43e0a3d9e536 12 #include <algorithm>
jmarkel44 48:1c7861d80d16 13
jmarkel44 84:7b7cad3ba139 14 // local functions
jmarkel44 67:49f266601d83 15 static int createOutput(const char *controlFile);
jmarkel44 66:db1425574b58 16 static void loadPersistentOutputs(void);
jmarkel44 84:7b7cad3ba139 17 static void refreshOutputs(void);
jmarkel44 77:43e0a3d9e536 18 static int enableOutputReq (const char* id, unsigned int pri, const char* output);
jmarkel44 77:43e0a3d9e536 19 static int disableOutputReq (const char *id, unsigned int pri, const char *output);
jmarkel44 72:3754b352f156 20 static int unregisterControl(const char *id, unsigned int pri, const char *output);
jmarkel44 71:34856d21f2bf 21
jmarkel44 84:7b7cad3ba139 22 // The Output Map
jmarkel44 84:7b7cad3ba139 23 //
jmarkel44 84:7b7cad3ba139 24 // this is the main data structure used to distinguish which control has
jmarkel44 84:7b7cad3ba139 25 // priority of an output. the layout is as-follows:
jmarkel44 84:7b7cad3ba139 26 //
jmarkel44 84:7b7cad3ba139 27 // outputMap["o_rly1"]-> Control<"ManCtrl_rly1", 100, ON >
jmarkel44 84:7b7cad3ba139 28 // Control<"SetpointCtrl_rly1", 800, OFF>
jmarkel44 84:7b7cad3ba139 29 // outputMap["o_rly2"]-> Control<"SetpointCtrl_rly2", 800, ON >
jmarkel44 84:7b7cad3ba139 30 // outputMap["o_rly3"]-> Control<"TimerControl_rl3", 500, ON>
jmarkel44 84:7b7cad3ba139 31 //
jmarkel44 84:7b7cad3ba139 32 // The Control Vector (per relay) is always sorted by priority, whereas
jmarkel44 84:7b7cad3ba139 33 // the highest priority control is at the beginning (v.begin()) of the
jmarkel44 84:7b7cad3ba139 34 // list.
jmarkel44 84:7b7cad3ba139 35
jmarkel44 71:34856d21f2bf 36 typedef std::map<string, vector<Control> > StringOutputVector_t;
jmarkel44 77:43e0a3d9e536 37 StringOutputVector_t outputMap;
jmarkel44 66:db1425574b58 38
jmarkel44 84:7b7cad3ba139 39 // operator for sorting the outputs vectors per output
jmarkel44 80:b12b0adfcdc2 40 bool operator<(const Control &control1, const Control &control2)
jmarkel44 80:b12b0adfcdc2 41 {
jmarkel44 77:43e0a3d9e536 42 return control1.getPriority() < control2.getPriority();
jmarkel44 77:43e0a3d9e536 43 }
jmarkel44 63:0ded43237b22 44
jmarkel44 70:7427f4959201 45 /*****************************************************************************
jmarkel44 70:7427f4959201 46 * Function: OutputTask
jmarkel44 70:7427f4959201 47 * Description: Main entry point for the Output Task
jmarkel44 70:7427f4959201 48 *
jmarkel44 70:7427f4959201 49 * @param args -> not used
jmarkel44 70:7427f4959201 50 * @return none
jmarkel44 70:7427f4959201 51 *****************************************************************************/
jmarkel44 48:1c7861d80d16 52 void OutputTask(void const *args)
jmarkel44 48:1c7861d80d16 53 {
jmarkel44 80:b12b0adfcdc2 54 int rc;
jmarkel44 51:66b820f203a5 55 UNUSED(args);
jmarkel44 70:7427f4959201 56
jmarkel44 67:49f266601d83 57 printf("\r%s has started...\n", __func__);
jmarkel44 63:0ded43237b22 58
jmarkel44 66:db1425574b58 59 loadPersistentOutputs();
jmarkel44 75:96512ccc0443 60 osSignalSet(mainThreadId, sig_output_continue);
jmarkel44 75:96512ccc0443 61
jmarkel44 48:1c7861d80d16 62 while (true) {
jmarkel44 51:66b820f203a5 63 // wait for an event
jmarkel44 56:225786c56315 64 osEvent evt = OutputMasterMailBox.get();
jmarkel44 51:66b820f203a5 65 if (evt.status == osEventMail) {
jmarkel44 80:b12b0adfcdc2 66
jmarkel44 63:0ded43237b22 67 OutputControlMsg_t *msg = (OutputControlMsg_t*) evt.value.p;
jmarkel44 63:0ded43237b22 68
jmarkel44 63:0ded43237b22 69 switch ( msg->action ) {
jmarkel44 63:0ded43237b22 70 case ACTION_NEW:
jmarkel44 63:0ded43237b22 71 // read the file and and create an output entry
jmarkel44 80:b12b0adfcdc2 72 rc = createOutput(msg->controlFile);
jmarkel44 80:b12b0adfcdc2 73 if ( rc != 0 ) {
jmarkel44 80:b12b0adfcdc2 74 logError("%s: failed to create output %s\n",
jmarkel44 80:b12b0adfcdc2 75 __func__, msg->controlFile);
jmarkel44 80:b12b0adfcdc2 76 }
jmarkel44 63:0ded43237b22 77 break;
jmarkel44 71:34856d21f2bf 78 case ACTION_CONTROL_ON:
jmarkel44 77:43e0a3d9e536 79 logInfo("%s is requesting ON control of %s", msg->id, msg->output);
jmarkel44 80:b12b0adfcdc2 80 rc = enableOutputReq(msg->id, msg->priority, msg->output);
jmarkel44 80:b12b0adfcdc2 81 if ( rc != 0 ) {
jmarkel44 80:b12b0adfcdc2 82 logError("%s: failed to enabled output for %s",
jmarkel44 80:b12b0adfcdc2 83 __func__, msg->id);
jmarkel44 80:b12b0adfcdc2 84 }
jmarkel44 71:34856d21f2bf 85 break;
jmarkel44 71:34856d21f2bf 86 case ACTION_CONTROL_OFF:
jmarkel44 77:43e0a3d9e536 87 logInfo("%s is requesting OFF control of %s", msg->id, msg->output);
jmarkel44 80:b12b0adfcdc2 88 rc = disableOutputReq(msg->id, msg->priority, msg->output);
jmarkel44 80:b12b0adfcdc2 89 if ( rc != 0 ) {
jmarkel44 80:b12b0adfcdc2 90 printf("%s: failed to disabled output for %s",
jmarkel44 80:b12b0adfcdc2 91 __func__, msg->id);
jmarkel44 80:b12b0adfcdc2 92 }
jmarkel44 71:34856d21f2bf 93 break;
jmarkel44 72:3754b352f156 94 case ACTION_CONTROL_UNREGISTER:
jmarkel44 77:43e0a3d9e536 95 logInfo("%s is requesting its deletion from %s", msg->id, msg->output);
jmarkel44 80:b12b0adfcdc2 96 rc = unregisterControl(msg->id, msg->priority, msg->output);
jmarkel44 80:b12b0adfcdc2 97 if ( rc != 0 ) {
jmarkel44 80:b12b0adfcdc2 98 printf("%s: failed to unregister control %s",
jmarkel44 84:7b7cad3ba139 99 __func__, msg->id);
jmarkel44 80:b12b0adfcdc2 100 }
jmarkel44 72:3754b352f156 101 break;
jmarkel44 63:0ded43237b22 102 default:
jmarkel44 63:0ded43237b22 103 break;
jmarkel44 63:0ded43237b22 104 }
jmarkel44 63:0ded43237b22 105
jmarkel44 56:225786c56315 106 // free the message
jmarkel44 56:225786c56315 107 OutputMasterMailBox.free(msg);
jmarkel44 84:7b7cad3ba139 108 refreshOutputs();
jmarkel44 84:7b7cad3ba139 109 }
jmarkel44 84:7b7cad3ba139 110 }
jmarkel44 84:7b7cad3ba139 111 }
jmarkel44 84:7b7cad3ba139 112
jmarkel44 84:7b7cad3ba139 113
jmarkel44 84:7b7cad3ba139 114 /*****************************************************************************
jmarkel44 84:7b7cad3ba139 115 * Function: refreshOutputs
jmarkel44 84:7b7cad3ba139 116 * Description: send a message to the modbus master of who's in control
jmarkel44 84:7b7cad3ba139 117 *
jmarkel44 84:7b7cad3ba139 118 *
jmarkel44 84:7b7cad3ba139 119 * @param args -> not used
jmarkel44 84:7b7cad3ba139 120 * @return none
jmarkel44 84:7b7cad3ba139 121 *****************************************************************************/
jmarkel44 84:7b7cad3ba139 122 static void refreshOutputs(void)
jmarkel44 84:7b7cad3ba139 123 {
jmarkel44 84:7b7cad3ba139 124 //who's in control here?
jmarkel44 84:7b7cad3ba139 125 StringOutputVector_t::iterator pos;
jmarkel44 84:7b7cad3ba139 126
jmarkel44 84:7b7cad3ba139 127 for ( pos = outputMap.begin(); pos != outputMap.end(); ++pos ) {
jmarkel44 84:7b7cad3ba139 128 if ( pos->second.empty() ) {
jmarkel44 84:7b7cad3ba139 129 printf("\r%s: No controls for %s\n", __func__, pos->first.c_str());
jmarkel44 84:7b7cad3ba139 130 } else {
jmarkel44 84:7b7cad3ba139 131 // a control is tied to this output
jmarkel44 84:7b7cad3ba139 132 printf("\r%s: %s is controlling %s\n",
jmarkel44 84:7b7cad3ba139 133 __func__, pos->second.begin()->getId().c_str(), pos->first.c_str());
jmarkel44 84:7b7cad3ba139 134 // TODO: send a message to the modbus master of who's in control
jmarkel44 84:7b7cad3ba139 135 // foo(pos->second->getId().c_str();
jmarkel44 51:66b820f203a5 136 }
jmarkel44 48:1c7861d80d16 137 }
jmarkel44 66:db1425574b58 138 }
jmarkel44 66:db1425574b58 139
jmarkel44 70:7427f4959201 140 /*****************************************************************************
jmarkel44 70:7427f4959201 141 * Function: DisplayOutputs
jmarkel44 70:7427f4959201 142 * Description: Display a list of outputs and its controls
jmarkel44 70:7427f4959201 143 *
jmarkel44 70:7427f4959201 144 * @param args -> not used
jmarkel44 70:7427f4959201 145 * @return none
jmarkel44 70:7427f4959201 146 *****************************************************************************/
jmarkel44 66:db1425574b58 147 void DisplayOutputs(void)
jmarkel44 66:db1425574b58 148 {
jmarkel44 66:db1425574b58 149 StringOutputVector_t::iterator pos;
jmarkel44 66:db1425574b58 150
jmarkel44 66:db1425574b58 151 for ( pos = outputMap.begin(); pos != outputMap.end(); ++pos ) {
jmarkel44 71:34856d21f2bf 152 if ( pos->second.empty() ) {
jmarkel44 71:34856d21f2bf 153 printf("\r [%s]->[no controls]\n", pos->first.c_str());
jmarkel44 71:34856d21f2bf 154 } else {
jmarkel44 71:34856d21f2bf 155 printf("\r [%s]->", pos->first.c_str());
jmarkel44 71:34856d21f2bf 156 vector<Control>::iterator i;
jmarkel44 71:34856d21f2bf 157 for ( i = pos->second.begin(); i != pos->second.end(); ++i ) {
jmarkel44 71:34856d21f2bf 158 i->display();
jmarkel44 71:34856d21f2bf 159 }
jmarkel44 71:34856d21f2bf 160 printf("\n");
jmarkel44 71:34856d21f2bf 161 }
jmarkel44 66:db1425574b58 162 }
jmarkel44 66:db1425574b58 163 printf("\r\n");
jmarkel44 66:db1425574b58 164 }
jmarkel44 66:db1425574b58 165
jmarkel44 71:34856d21f2bf 166
jmarkel44 71:34856d21f2bf 167 /*****************************************************************************
jmarkel44 72:3754b352f156 168 * Function: createOutput
jmarkel44 72:3754b352f156 169 * Description:
jmarkel44 71:34856d21f2bf 170 *
jmarkel44 77:43e0a3d9e536 171 * @param controlFile -> name of output file
jmarkel44 71:34856d21f2bf 172 * @return none
jmarkel44 71:34856d21f2bf 173 *****************************************************************************/
jmarkel44 77:43e0a3d9e536 174 static int createOutput(const char *outputFile)
jmarkel44 66:db1425574b58 175 {
jmarkel44 66:db1425574b58 176 char dataBuf[1024];
jmarkel44 77:43e0a3d9e536 177 int status = GLOBAL_mdot->readUserFile(outputFile, (void *)dataBuf, sizeof(dataBuf));
jmarkel44 67:49f266601d83 178 if ( status != true ) {
jmarkel44 77:43e0a3d9e536 179 logError("%s failed to read %s", __func__, outputFile);
jmarkel44 66:db1425574b58 180 return -1;
jmarkel44 66:db1425574b58 181 }
jmarkel44 66:db1425574b58 182
jmarkel44 66:db1425574b58 183 MbedJSONValue json_value;
jmarkel44 66:db1425574b58 184 parse(json_value, dataBuf);
jmarkel44 66:db1425574b58 185
jmarkel44 66:db1425574b58 186 // extract the relay information
jmarkel44 66:db1425574b58 187 string id = json_value["id"].get<string>();
jmarkel44 66:db1425574b58 188
jmarkel44 77:43e0a3d9e536 189 // maps don't allow duplicates, and the vector is empty for now
jmarkel44 71:34856d21f2bf 190 vector<Control> v;
jmarkel44 71:34856d21f2bf 191 outputMap[id] = v;
jmarkel44 71:34856d21f2bf 192
jmarkel44 71:34856d21f2bf 193 return 0;
jmarkel44 71:34856d21f2bf 194 }
jmarkel44 71:34856d21f2bf 195
jmarkel44 71:34856d21f2bf 196
jmarkel44 71:34856d21f2bf 197 /*****************************************************************************
jmarkel44 72:3754b352f156 198 * Function: enableOutputReq
jmarkel44 71:34856d21f2bf 199 * Description: Display a list of outputs and its controls
jmarkel44 71:34856d21f2bf 200 *
jmarkel44 71:34856d21f2bf 201 * @param args -> not used
jmarkel44 71:34856d21f2bf 202 * @return none
jmarkel44 71:34856d21f2bf 203 *****************************************************************************/
jmarkel44 71:34856d21f2bf 204 static int enableOutputReq(const char *id, unsigned int priority, const char *output)
jmarkel44 71:34856d21f2bf 205 {
jmarkel44 71:34856d21f2bf 206 // attempt to find the output in the map
jmarkel44 71:34856d21f2bf 207 StringOutputVector_t::iterator pos;
jmarkel44 71:34856d21f2bf 208
jmarkel44 71:34856d21f2bf 209 pos = outputMap.find(output);
jmarkel44 71:34856d21f2bf 210 if ( pos == outputMap.end() ) {
jmarkel44 71:34856d21f2bf 211 printf("%s: failed to find the designated output %s\n",
jmarkel44 71:34856d21f2bf 212 __func__, output);
jmarkel44 71:34856d21f2bf 213 return -1;
jmarkel44 71:34856d21f2bf 214 }
jmarkel44 71:34856d21f2bf 215
jmarkel44 71:34856d21f2bf 216 if ( pos->second.empty() ) {
jmarkel44 71:34856d21f2bf 217 // this is a new request
jmarkel44 71:34856d21f2bf 218 string cid(id);
jmarkel44 71:34856d21f2bf 219 Control c(cid, priority, CONTROL_ON);
jmarkel44 71:34856d21f2bf 220 pos->second.push_back(c);
jmarkel44 71:34856d21f2bf 221 } else {
jmarkel44 71:34856d21f2bf 222 // find this control in the list
jmarkel44 71:34856d21f2bf 223 vector<Control>::iterator v;
jmarkel44 71:34856d21f2bf 224 for ( v = pos->second.begin(); v != pos->second.end(); ++v ) {
jmarkel44 71:34856d21f2bf 225 if ( strcmp(v->getId().c_str(), id) == 0 ) {
jmarkel44 71:34856d21f2bf 226 v->setState(CONTROL_ON);
jmarkel44 77:43e0a3d9e536 227 break;
jmarkel44 71:34856d21f2bf 228 }
jmarkel44 71:34856d21f2bf 229 }
jmarkel44 77:43e0a3d9e536 230 if ( v == pos->second.end() ) {
jmarkel44 77:43e0a3d9e536 231 // this is a new request, so add it and sort the vector
jmarkel44 77:43e0a3d9e536 232 string cid(id);
jmarkel44 77:43e0a3d9e536 233 Control c(cid, priority, CONTROL_ON);
jmarkel44 77:43e0a3d9e536 234 pos->second.push_back(c);
jmarkel44 77:43e0a3d9e536 235 std::sort(pos->second.begin(), pos->second.end());
jmarkel44 77:43e0a3d9e536 236 }
jmarkel44 71:34856d21f2bf 237 }
jmarkel44 71:34856d21f2bf 238
jmarkel44 71:34856d21f2bf 239 return 0;
jmarkel44 71:34856d21f2bf 240 }
jmarkel44 71:34856d21f2bf 241
jmarkel44 71:34856d21f2bf 242 /*****************************************************************************
jmarkel44 72:3754b352f156 243 * Function: disableOutputReq
jmarkel44 72:3754b352f156 244 * Description:
jmarkel44 71:34856d21f2bf 245 *
jmarkel44 71:34856d21f2bf 246 * @param args -> not used
jmarkel44 71:34856d21f2bf 247 * @return none
jmarkel44 71:34856d21f2bf 248 *****************************************************************************/
jmarkel44 71:34856d21f2bf 249 static int disableOutputReq(const char *id, unsigned int priority, const char *output)
jmarkel44 71:34856d21f2bf 250 {
jmarkel44 71:34856d21f2bf 251 // attempt to find the output in the map
jmarkel44 71:34856d21f2bf 252 StringOutputVector_t::iterator pos;
jmarkel44 71:34856d21f2bf 253
jmarkel44 71:34856d21f2bf 254 pos = outputMap.find(output);
jmarkel44 71:34856d21f2bf 255 if ( pos == outputMap.end() ) {
jmarkel44 71:34856d21f2bf 256 printf("%s: failed to find the designated output %s\n",
jmarkel44 71:34856d21f2bf 257 __func__, output);
jmarkel44 71:34856d21f2bf 258 return -1;
jmarkel44 71:34856d21f2bf 259 }
jmarkel44 71:34856d21f2bf 260
jmarkel44 80:b12b0adfcdc2 261 // if the control list is empty, push this control on the list
jmarkel44 71:34856d21f2bf 262 if ( pos->second.empty() ) {
jmarkel44 71:34856d21f2bf 263 string cid(id);
jmarkel44 71:34856d21f2bf 264 Control c(cid, priority, CONTROL_OFF);
jmarkel44 71:34856d21f2bf 265 pos->second.push_back(c);
jmarkel44 71:34856d21f2bf 266 } else {
jmarkel44 71:34856d21f2bf 267 // find this control in the list
jmarkel44 71:34856d21f2bf 268 vector<Control>::iterator v;
jmarkel44 71:34856d21f2bf 269 for ( v = pos->second.begin(); v != pos->second.end(); ++v ) {
jmarkel44 71:34856d21f2bf 270 if ( strcmp(v->getId().c_str(), id) == 0 ) {
jmarkel44 71:34856d21f2bf 271 v->setState(CONTROL_OFF);
jmarkel44 77:43e0a3d9e536 272 break;
jmarkel44 71:34856d21f2bf 273 }
jmarkel44 71:34856d21f2bf 274 }
jmarkel44 80:b12b0adfcdc2 275
jmarkel44 80:b12b0adfcdc2 276 if ( v == pos->second.end() ) {
jmarkel44 80:b12b0adfcdc2 277 // this is a new request, so add it and sort the vector
jmarkel44 80:b12b0adfcdc2 278 string cid(id);
jmarkel44 80:b12b0adfcdc2 279 Control c(cid, priority, CONTROL_OFF);
jmarkel44 80:b12b0adfcdc2 280 pos->second.push_back(c);
jmarkel44 80:b12b0adfcdc2 281 std::sort(pos->second.begin(), pos->second.end());
jmarkel44 80:b12b0adfcdc2 282 }
jmarkel44 71:34856d21f2bf 283 }
jmarkel44 66:db1425574b58 284
jmarkel44 66:db1425574b58 285 return 0;
jmarkel44 66:db1425574b58 286 }
jmarkel44 66:db1425574b58 287
jmarkel44 74:03ccf04998b5 288 /*****************************************************************************
jmarkel44 74:03ccf04998b5 289 * Function: unregisterControl
jmarkel44 74:03ccf04998b5 290 * Description:
jmarkel44 74:03ccf04998b5 291 *
jmarkel44 74:03ccf04998b5 292 * @param id -> control identifier
jmarkel44 74:03ccf04998b5 293 * @param pri -> priority
jmarkel44 74:03ccf04998b5 294 * @param output -> output (e.g. "o_rly5)
jmarkel44 74:03ccf04998b5 295 *
jmarkel44 74:03ccf04998b5 296 * @return 0 on success; -1 on error
jmarkel44 74:03ccf04998b5 297 *****************************************************************************/
jmarkel44 72:3754b352f156 298 static int unregisterControl(const char *id, unsigned int pri, const char *output)
jmarkel44 72:3754b352f156 299 {
jmarkel44 72:3754b352f156 300 // attempt to find the output in the map
jmarkel44 72:3754b352f156 301 StringOutputVector_t::iterator pos;
jmarkel44 80:b12b0adfcdc2 302 bool found = false;
jmarkel44 72:3754b352f156 303
jmarkel44 72:3754b352f156 304 pos = outputMap.find(output);
jmarkel44 72:3754b352f156 305 if ( pos == outputMap.end() ) {
jmarkel44 72:3754b352f156 306 printf("%s: failed to find the designated output %s\n",
jmarkel44 72:3754b352f156 307 __func__, output);
jmarkel44 72:3754b352f156 308 return -1;
jmarkel44 72:3754b352f156 309 }
jmarkel44 72:3754b352f156 310
jmarkel44 72:3754b352f156 311 // find the control in the list
jmarkel44 72:3754b352f156 312 vector<Control>::iterator v;
jmarkel44 72:3754b352f156 313 for ( v = pos->second.begin(); v != pos->second.end(); ++v) {
jmarkel44 72:3754b352f156 314 if ( strcmp(v->getId().c_str(), id) == 0 ) {
jmarkel44 72:3754b352f156 315 // delete this entry
jmarkel44 72:3754b352f156 316 pos->second.erase(v);
jmarkel44 80:b12b0adfcdc2 317 found = true;
jmarkel44 72:3754b352f156 318 break;
jmarkel44 72:3754b352f156 319 }
jmarkel44 74:03ccf04998b5 320 }
jmarkel44 80:b12b0adfcdc2 321 if ( !found ) {
jmarkel44 80:b12b0adfcdc2 322 logError("%s: failed to find control %s in list", __func__, id);
jmarkel44 80:b12b0adfcdc2 323 return -1;
jmarkel44 80:b12b0adfcdc2 324 }
jmarkel44 72:3754b352f156 325 return 0;
jmarkel44 72:3754b352f156 326 }
jmarkel44 72:3754b352f156 327
jmarkel44 72:3754b352f156 328 /*****************************************************************************
jmarkel44 72:3754b352f156 329 * Function: loadPersistentOutputs
jmarkel44 72:3754b352f156 330 * Description: pump up the output map based on persistent files
jmarkel44 72:3754b352f156 331 *
jmarkel44 72:3754b352f156 332 * @param args -> not used
jmarkel44 72:3754b352f156 333 * @return none
jmarkel44 72:3754b352f156 334 *****************************************************************************/
jmarkel44 66:db1425574b58 335 static void loadPersistentOutputs(void)
jmarkel44 66:db1425574b58 336 {
jmarkel44 66:db1425574b58 337 bool status;
jmarkel44 66:db1425574b58 338 MbedJSONValue json_value;
jmarkel44 71:34856d21f2bf 339
jmarkel44 77:43e0a3d9e536 340 printf("\rLoading persistent outputs:\n");
jmarkel44 66:db1425574b58 341
jmarkel44 66:db1425574b58 342 std::vector<mDot::mdot_file> file_list = GLOBAL_mdot->listUserFiles();
jmarkel44 70:7427f4959201 343
jmarkel44 66:db1425574b58 344 for (std::vector<mDot::mdot_file>::iterator i = file_list.begin(); i != file_list.end(); ++i) {
jmarkel44 67:49f266601d83 345 if( strncmp( i->name, OUTPUT_STR, strlen(OUTPUT_STR)) == 0 ) {
jmarkel44 66:db1425574b58 346
jmarkel44 66:db1425574b58 347 logInfo("%s: FOUND OUTPUT FILE: %s", __func__, i->name);
jmarkel44 66:db1425574b58 348
jmarkel44 66:db1425574b58 349 char scratchBuf[1024];
jmarkel44 66:db1425574b58 350
jmarkel44 66:db1425574b58 351 status = GLOBAL_mdot->readUserFile(i->name, scratchBuf, 1024);
jmarkel44 66:db1425574b58 352 if( status != true ) {
jmarkel44 66:db1425574b58 353 logInfo("(%d)read file failed, status=%d", __LINE__, status);
jmarkel44 66:db1425574b58 354 } else {
jmarkel44 66:db1425574b58 355 logInfo("(%d)Read File SUCCESS: %s", __LINE__, scratchBuf );
jmarkel44 66:db1425574b58 356 }
jmarkel44 66:db1425574b58 357
jmarkel44 66:db1425574b58 358 parse( json_value, scratchBuf );
jmarkel44 66:db1425574b58 359
jmarkel44 66:db1425574b58 360 string id = json_value["id"].get<string>();
jmarkel44 77:43e0a3d9e536 361 printf("\r output %s loaded\n", i->name);
jmarkel44 74:03ccf04998b5 362
jmarkel44 80:b12b0adfcdc2 363 // emplace the empty control vector into the output map
jmarkel44 71:34856d21f2bf 364 vector<Control> v;
jmarkel44 71:34856d21f2bf 365 outputMap[id] = v;
jmarkel44 66:db1425574b58 366 }
jmarkel44 66:db1425574b58 367 }
jmarkel44 70:7427f4959201 368 }