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/TimerControl.cpp
- Revision:
- 33:cb765aefa1b5
- Parent:
- 28:c410a61238bb
--- a/src/ConfigurationHandler/Controls/TimerControl.cpp Thu Sep 08 21:07:47 2016 +0000 +++ b/src/ConfigurationHandler/Controls/TimerControl.cpp Thu Sep 08 21:24:34 2016 +0000 @@ -1,21 +1,62 @@ /****************************************************************************** * * File: TimerControl.cpp - * Desciption: ICE Setpoint Control Class implementation + * Desciption: ICE Timer Control Class implementation * *****************************************************************************/ #include "TimerControl.h" #include "mDot.h" +#include "MbedJSONValue.h" +#include <string> extern mDot *GLOBAL_mdot; -bool TimerControl::load(string _controlFile){ - controlFile = _controlFile; - +bool TimerControl::load(string _controlFile) +{ + MbedJSONValue json_value; + 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 + 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); + + // "tcontrol": { + // "id": "Timer1", + // "name": "Acid Cleaning Cycle", + // "priority":"800", + // "dow":"127", + // "strtw":"1", + // "output":"o_r4", + // "freq":"1", + // "tod": { + // "start":"420", + // "int":"1" + // } + + + // 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()); + dayOfWeek = atoi(json_value["dow"].get<string>().c_str()); + startWeek = atoi(json_value["strtw"].get<string>().c_str()); + output = json_value["output"].get<string>(); + freq = atoi(json_value["freq"].get<string>().c_str()); + + return true; } -