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 19:58:36 2016 +0000
Revision:
95:42f92b03f1b8
Parent:
94:18ae2fd82638
Child:
109:bb4ef6a4bd0a
Child:
114:c24aebb8b473
cleanup of refreshOutputs();

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