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
src/ConfigurationHandler/Controls/SetpointControl.cpp@33:cb765aefa1b5, 2016-09-08 (annotated)
- Committer:
- jmarkel44
- Date:
- Thu Sep 08 21:24:34 2016 +0000
- Revision:
- 33:cb765aefa1b5
- Parent:
- 30:738359dfdab1
merging;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 14:cc916fa8dd11 | 1 | /****************************************************************************** |
jmarkel44 | 14:cc916fa8dd11 | 2 | * |
jmarkel44 | 19:9bc8fabeddfa | 3 | * File: SetpointControl.cpp |
jmarkel44 | 20:653923c2f37a | 4 | * Desciption: ICE Setpoint Control Class implementation |
jmarkel44 | 14:cc916fa8dd11 | 5 | * |
jmarkel44 | 14:cc916fa8dd11 | 6 | *****************************************************************************/ |
jmarkel44 | 13:c80c283f9db2 | 7 | #include "SetpointControl.h" |
jmarkel44 | 14:cc916fa8dd11 | 8 | #include "mDot.h" |
jmarkel44 | 20:653923c2f37a | 9 | #include "MbedJSONValue.h" |
jmarkel44 | 28:c410a61238bb | 10 | #include <string> |
jmarkel44 | 13:c80c283f9db2 | 11 | |
jmarkel44 | 14:cc916fa8dd11 | 12 | extern mDot *GLOBAL_mdot; |
jmarkel44 | 14:cc916fa8dd11 | 13 | |
jmarkel44 | 28:c410a61238bb | 14 | bool SetpointControl::load(string _controlFile) |
jmarkel44 | 20:653923c2f37a | 15 | { |
jmarkel44 | 30:738359dfdab1 | 16 | MbedJSONValue json_value; |
jmarkel44 | 33:cb765aefa1b5 | 17 | controlFile = _controlFile; |
jmarkel44 | 33:cb765aefa1b5 | 18 | |
jmarkel44 | 19:9bc8fabeddfa | 19 | // try to open the control file |
jmarkel44 | 14:cc916fa8dd11 | 20 | mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY); |
jmarkel44 | 28:c410a61238bb | 21 | if ( file.fd < 0 ) |
jmarkel44 | 28:c410a61238bb | 22 | return false; |
jmarkel44 | 20:653923c2f37a | 23 | |
jmarkel44 | 20:653923c2f37a | 24 | // read the data into a buffer |
jmarkel44 | 28:c410a61238bb | 25 | char dataBuf[1024]; |
jmarkel44 | 28:c410a61238bb | 26 | int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf)); |
jmarkel44 | 28:c410a61238bb | 27 | if ( bytes_read != sizeof(dataBuf) ) { |
jmarkel44 | 28:c410a61238bb | 28 | logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str()); |
jmarkel44 | 28:c410a61238bb | 29 | return false; |
jmarkel44 | 28:c410a61238bb | 30 | } |
jmarkel44 | 28:c410a61238bb | 31 | |
jmarkel44 | 28:c410a61238bb | 32 | // close the file |
jmarkel44 | 28:c410a61238bb | 33 | GLOBAL_mdot->closeUserFile(file); |
jmarkel44 | 28:c410a61238bb | 34 | |
jmarkel44 | 28:c410a61238bb | 35 | parse(json_value, dataBuf); |
jmarkel44 | 20:653923c2f37a | 36 | |
jmarkel44 | 28:c410a61238bb | 37 | // "spcontrol": { |
jmarkel44 | 28:c410a61238bb | 38 | // "id": "SP", |
jmarkel44 | 28:c410a61238bb | 39 | // "name": "TRASAR 3DTS85", |
jmarkel44 | 28:c410a61238bb | 40 | // "priority":"800", |
jmarkel44 | 28:c410a61238bb | 41 | // "input":"i_tra1" |
jmarkel44 | 28:c410a61238bb | 42 | // "output":"o_r5", |
jmarkel44 | 28:c410a61238bb | 43 | // "prodfact":"100", |
jmarkel44 | 28:c410a61238bb | 44 | // "halert":"115", |
jmarkel44 | 28:c410a61238bb | 45 | // "lalert":"85", |
jmarkel44 | 28:c410a61238bb | 46 | // "hfs":"130", |
jmarkel44 | 28:c410a61238bb | 47 | // "lfs":"70", |
jmarkel44 | 28:c410a61238bb | 48 | // "tol":"5", |
jmarkel44 | 28:c410a61238bb | 49 | |
jmarkel44 | 28:c410a61238bb | 50 | // parse the json data |
jmarkel44 | 28:c410a61238bb | 51 | id = json_value["id"].get<string>(); |
jmarkel44 | 28:c410a61238bb | 52 | name = json_value["name"].get<string>(); |
jmarkel44 | 28:c410a61238bb | 53 | priority = atoi(json_value["priority"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 54 | input = json_value["input"].get<string>(); |
jmarkel44 | 28:c410a61238bb | 55 | output = json_value["output"].get<string>(); |
jmarkel44 | 28:c410a61238bb | 56 | productFactor = atof(json_value["prodfact"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 57 | highAlert = atof(json_value["halert"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 58 | lowAlert = atof(json_value["lalert"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 59 | highFailsafe = atof(json_value["hfs"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 60 | lowFailsafe = atof(json_value["lfs"].get<string>().c_str()); |
jmarkel44 | 28:c410a61238bb | 61 | tol = atof(json_value["tol"].get<string>().c_str()); |
jmarkel44 | 20:653923c2f37a | 62 | |
jmarkel44 | 19:9bc8fabeddfa | 63 | return true; |
jmarkel44 | 19:9bc8fabeddfa | 64 | } |
jmarkel44 | 19:9bc8fabeddfa | 65 |