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/ConfigurationHandler/Controls/CompositeControl.cpp
- Revision:
- 220:dbe21411f962
- Parent:
- 164:7cecd731882e
- Child:
- 221:2a5e9902003c
--- a/src/ConfigurationHandler/Controls/CompositeControl.cpp Tue Oct 11 18:39:43 2016 +0000
+++ b/src/ConfigurationHandler/Controls/CompositeControl.cpp Fri Oct 14 13:32:47 2016 +0000
@@ -13,12 +13,84 @@
extern mDot *GLOBAL_mdot;
-bool CompositeControl::load(std::string controlFile)
+bool CompositeControl::load(std::string _controlFile)
{
+ MbedJSONValue json_value; // JSON parsing element
+ controlFile = _controlFile;
+
+ // open and read from the control file
+ mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY);
+ if ( file.fd < 0 ) {
+ logError("%s: failed to open %s\n", __func__, controlFile.c_str());
+ return false;
+ }
+
+ // read the data into a buffer
+ char dataBuf[MAX_FILE_SIZE];
+
+ int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf));
+ if ( bytes_read != sizeof(dataBuf) ) {
+ logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str());
+ // caller should destroy the object
+ return false;
+ }
+
+ // close the file
+ GLOBAL_mdot->closeUserFile(file);
+
+ parse(json_value, dataBuf);
+
+ if ( !json_value.hasMember("id") ||
+ !json_value.hasMember("input") ||
+ !json_value.hasMember("ca") ||
+ !json_value.hasMember("priority") ||
+ !json_value.hasMember("entries") ) {
+ printf("\rComposite control is missing expected tags\n");
+ return false;
+ }
+
+ id = json_value["id"].get<string>();
+ std::string input = json_value["input"].get<string>();
+ priority = atoi(json_value["priority"].get<string>().c_str());
+ inputs.push_back(input);
+ ca = json_value["ca"].get<string>();
+
+ int entries = atoi(json_value["entries"].get<string>().c_str());
+
+ for ( int i = 0; i < entries; ++i ) {
+ std::string tag = json_value["outputs"][i]["tag"].get<string>();
+ std::string response = json_value["outputs"][i]["response"].get<string>();
+ if ( !tag.empty() && !response.empty() ) {
+ OutputElement x = { tag, response };
+ outputs.push_back(x);
+ } else {
+ return false;
+ }
+ }
+
return true;
}
// unregister the control with the output task
void CompositeControl::unregisterControl(void)
{
+}
+
+void CompositeControl::display(void)
+{
+ printf("\r control file : %s\n", controlFile.c_str());
+ printf("\r id : %s\n", id.c_str());
+ printf("\r priority : %u\n", priority);
+ printf("\r ca : %s\n", ca.c_str());
+ vector<std::string>::iterator pos;
+ for ( pos = inputs.begin(); pos != inputs.end(); ++pos ) {
+ printf("\r input : %s\n", (*pos).c_str());
+ }
+ vector<OutputElement>::iterator it;
+ printf("\r outputs :\n");
+ for ( it = outputs.begin(); it != outputs.end(); ++it ) {
+ printf("\r tag-> %s\n", (*it).tag.c_str());
+ printf("\r response-> %s\n", (*it).response.c_str());
+ }
+ printf("\r\n");
}
\ No newline at end of file
