Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/OutputTask/OutputTask.cpp
- Revision:
- 66:db1425574b58
- Parent:
- 63:0ded43237b22
- Child:
- 67:49f266601d83
--- a/src/OutputTask/OutputTask.cpp Thu Sep 15 21:45:29 2016 +0000 +++ b/src/OutputTask/OutputTask.cpp Thu Sep 15 22:26:28 2016 +0000 @@ -1,11 +1,19 @@ #include "global.h" +#include "MbedJSONValue.h" +static int createOutput(const char *controlFile); +static void loadPersistentOutputs(void); +typedef std::map<string, string> StringOutputVector_t; + +StringOutputVector_t outputMap; void OutputTask(void const *args) { UNUSED(args); + loadPersistentOutputs(); + while (true) { // wait for an event osEvent evt = OutputMasterMailBox.get(); @@ -19,8 +27,9 @@ switch ( msg->action ) { case ACTION_NEW: // read the file and and create an output entry + (void) createOutput(msg->controlFile); break; - case ACTION_CONTROL_REQ: + case ACTION_CONTROL_REQ: default: break; } @@ -29,4 +38,71 @@ OutputMasterMailBox.free(msg); } } -} \ No newline at end of file +} + +void DisplayOutputs(void) +{ + StringOutputVector_t::iterator pos; + + for ( pos = outputMap.begin(); pos != outputMap.end(); ++pos ) { + printf("\r [%s] [ %s]\n", pos->first.c_str(), pos->second.c_str()); + } + printf("\r\n"); +} + +static int createOutput(const char *controlFile) +{ + mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile, mDot::FM_RDONLY); + if ( file.fd < 0 ) { + logError("%s: failed to open file %s", __func__, controlFile); + return -1; + } + + char dataBuf[1024]; + int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf)); + if ( bytes_read != sizeof(dataBuf) ) { + logError("%s failed to read %s", __func__, controlFile); + return -1; + } + + MbedJSONValue json_value; + parse(json_value, dataBuf); + + // extract the relay information + string id = json_value["id"].get<string>(); + + // maps shouldnt' allow duplicates + outputMap[id] = "Null for now"; + + return 0; + +} + +static void loadPersistentOutputs(void) +{ + bool status; + MbedJSONValue json_value; + + std::vector<mDot::mdot_file> file_list = GLOBAL_mdot->listUserFiles(); + for (std::vector<mDot::mdot_file>::iterator i = file_list.begin(); i != file_list.end(); ++i) { + if( strncmp( i->name, "output", (strlen("input")-1)) == 0 ) { + + logInfo("%s: FOUND OUTPUT FILE: %s", __func__, i->name); + + char scratchBuf[1024]; + + status = GLOBAL_mdot->readUserFile(i->name, scratchBuf, 1024); + if( status != true ) { + logInfo("(%d)read file failed, status=%d", __LINE__, status); + } else { + logInfo("(%d)Read File SUCCESS: %s", __LINE__, scratchBuf ); + } + + parse( json_value, scratchBuf ); + + string id = json_value["id"].get<string>(); + outputMap[id] = "Null for now"; + + } + } +}