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:
- 242:3b0086a6d625
- Parent:
- 232:8a86b5bf38f7
- Child:
- 253:ae850c19cf81
diff -r 1308c7b3daad -r 3b0086a6d625 src/ConfigurationHandler/Controls/CompositeControl.cpp
--- a/src/ConfigurationHandler/Controls/CompositeControl.cpp Thu Oct 20 14:13:31 2016 +0000
+++ b/src/ConfigurationHandler/Controls/CompositeControl.cpp Thu Oct 20 15:30:21 2016 +0000
@@ -7,7 +7,7 @@
#include "CompositeControl.h"
#include "ConfigurationHandler.h"
#include "mDot.h"
-#include "MbedJSONValue.h"
+#include "cJSON.h"
#include "ModbusMasterApi.h"
#include "global.h"
#include <string>
@@ -25,10 +25,8 @@
//
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 ) {
@@ -49,35 +47,18 @@
// close the file
GLOBAL_mdot->closeUserFile(file);
- parse(json_value, dataBuf);
-
- if ( !json_value.hasMember("id") ||
- !json_value.hasMember("tag") ||
- !json_value.hasMember("priority") ||
- !json_value.hasMember("ca") ||
- !json_value.hasMember("entries") ) {
- printf("\rComposite control is missing expected tags\n");
- return false;
- }
-
- id = json_value ["id"].get<string>();
- tag = json_value ["tag"].get<string>();
- priority = atoi(json_value["priority"].get<string>().c_str());
- ca = json_value ["ca"].get<string>();
-
-
- int entries = atoi(json_value["entries"].get<string>().c_str());
-
- // populate the outputs
- for ( int i = 0; i < entries; ++i ) {
- std::string tag = json_value["outputs"][i]["tag"].get<string>();
- std::string response = json_value["outputs"][i]["responseA"].get<string>();
- if ( !tag.empty() && !response.empty() ) {
- OutputElement x = { tag, response };
- outputs.push_back(x);
- } else {
- return false;
- }
+ cJSON * root = cJSON_Parse(dataBuf);
+ id = cJSON_GetObjectItem(root,"id")->valuestring;
+ tag = cJSON_GetObjectItem(root, "tag")->valuestring;
+ priority = atoi(cJSON_GetObjectItem(root, "priority")->valuestring);
+ ca = cJSON_GetObjectItem(root, "ca")->valuestring;
+ cJSON *array = cJSON_GetObjectItem(root, "outputs");
+ for ( int i = 0; i < cJSON_GetArraySize(array); ++i ) {
+ cJSON *subitem = cJSON_GetArrayItem(array, i);
+ std::string tag = cJSON_GetObjectItem(subitem, "tag")->valuestring;
+ std::string response = cJSON_GetObjectItem(subitem, "responseA")->valuestring;
+ OutputElement x = { tag, response };
+ outputs.push_back(x);
}
return true;
@@ -307,9 +288,10 @@
const char *mapper[] = { "INIT",
"START",
"CONTROL_OFF",
- "CONTROL_ON" };
+ "CONTROL_ON"
+ };
- printf("\r\n");
+ printf("\r\n");
std::cout << left << setw(10) << setfill(' ') << "composite: ";
std::cout << left << setw(32) << setfill(' ') << controlFile;
std::cout << left << setw(20) << setfill(' ') << id;
