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/SetpointControl.cpp
- Revision:
- 28:c410a61238bb
- Parent:
- 20:653923c2f37a
- Child:
- 30:738359dfdab1
diff -r e7550516c6f6 -r c410a61238bb src/ConfigurationHandler/Controls/SetpointControl.cpp --- a/src/ConfigurationHandler/Controls/SetpointControl.cpp Thu Sep 08 15:32:50 2016 +0000 +++ b/src/ConfigurationHandler/Controls/SetpointControl.cpp Thu Sep 08 20:12:04 2016 +0000 @@ -7,29 +7,60 @@ #include "SetpointControl.h" #include "mDot.h" #include "MbedJSONValue.h" +#include <vector> +#include <cstdlib> +#include <string> extern mDot *GLOBAL_mdot; -bool SetpointControl::Load(string _controlFile) +bool SetpointControl::load(string _controlFile) { - controlFile = _controlFile; + controlFile = _controlFile; // try to open the control file mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY); - if ( file.fd < 0 ) return false; + if ( file.fd < 0 ) + return false; // read the data into a buffer - unsigned char dataBuf[1024]; + char dataBuf[1024]; + + 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()); + return false; + } + + // close the file + GLOBAL_mdot->closeUserFile(file); + + parse(json_value, dataBuf); - int bytes_read = GLOBAL_mdot->readUserFile(file, dataBuf, sizeof(dataBuf)); - if ( bytes_read ) { - printf("%s -> %s\n", __func__, dataBuf); - } else { - printf("%s: bytes_read = %d\n", __func__, bytes_read); - } - - // try to parse the file - //MbedJSONValue data; + // "spcontrol": { + // "id": "SP", + // "name": "TRASAR 3DTS85", + // "priority":"800", + // "input":"i_tra1" + // "output":"o_r5", + // "prodfact":"100", + // "halert":"115", + // "lalert":"85", + // "hfs":"130", + // "lfs":"70", + // "tol":"5", + + // parse the json data + id = json_value["id"].get<string>(); + name = json_value["name"].get<string>(); + priority = atoi(json_value["priority"].get<string>().c_str()); + input = json_value["input"].get<string>(); + output = json_value["output"].get<string>(); + productFactor = atof(json_value["prodfact"].get<string>().c_str()); + highAlert = atof(json_value["halert"].get<string>().c_str()); + lowAlert = atof(json_value["lalert"].get<string>().c_str()); + highFailsafe = atof(json_value["hfs"].get<string>().c_str()); + lowFailsafe = atof(json_value["lfs"].get<string>().c_str()); + tol = atof(json_value["tol"].get<string>().c_str()); return true; }