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/TimerControl.cpp@35:6235ef67faa1, 2016-09-09 (annotated)
- Committer:
- jmarkel44
- Date:
- Fri Sep 09 13:33:54 2016 +0000
- Revision:
- 35:6235ef67faa1
- Parent:
- 28:c410a61238bb
- Child:
- 46:4cb96ab2d1c8
load() implementation for timer control;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 19:9bc8fabeddfa | 1 | /****************************************************************************** |
jmarkel44 | 19:9bc8fabeddfa | 2 | * |
jmarkel44 | 35:6235ef67faa1 | 3 | * File: TimerCntrol.cpp |
jmarkel44 | 35:6235ef67faa1 | 4 | * Desciption: ICE Timer Control Class implementation |
jmarkel44 | 19:9bc8fabeddfa | 5 | * |
jmarkel44 | 19:9bc8fabeddfa | 6 | *****************************************************************************/ |
jmarkel44 | 19:9bc8fabeddfa | 7 | #include "TimerControl.h" |
jmarkel44 | 19:9bc8fabeddfa | 8 | #include "mDot.h" |
jmarkel44 | 35:6235ef67faa1 | 9 | #include "MbedJSONValue.h" |
jmarkel44 | 35:6235ef67faa1 | 10 | #include <string> |
jmarkel44 | 19:9bc8fabeddfa | 11 | |
jmarkel44 | 19:9bc8fabeddfa | 12 | extern mDot *GLOBAL_mdot; |
jmarkel44 | 19:9bc8fabeddfa | 13 | |
jmarkel44 | 35:6235ef67faa1 | 14 | bool TimerControl::load(string _controlFile) |
jmarkel44 | 35:6235ef67faa1 | 15 | { |
jmarkel44 | 35:6235ef67faa1 | 16 | MbedJSONValue json_value; |
jmarkel44 | 35:6235ef67faa1 | 17 | controlFile = _controlFile; |
jmarkel44 | 35:6235ef67faa1 | 18 | |
jmarkel44 | 19:9bc8fabeddfa | 19 | // try to open the control file |
jmarkel44 | 19:9bc8fabeddfa | 20 | mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY); |
jmarkel44 | 35:6235ef67faa1 | 21 | if ( file.fd < 0 ) |
jmarkel44 | 35:6235ef67faa1 | 22 | return false; |
jmarkel44 | 35:6235ef67faa1 | 23 | |
jmarkel44 | 35:6235ef67faa1 | 24 | // read the data into a buffer |
jmarkel44 | 35:6235ef67faa1 | 25 | char dataBuf[1024]; |
jmarkel44 | 35:6235ef67faa1 | 26 | |
jmarkel44 | 35:6235ef67faa1 | 27 | int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf)); |
jmarkel44 | 35:6235ef67faa1 | 28 | if ( bytes_read != sizeof(dataBuf) ) { |
jmarkel44 | 35:6235ef67faa1 | 29 | logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str()); |
jmarkel44 | 35:6235ef67faa1 | 30 | return false; |
jmarkel44 | 35:6235ef67faa1 | 31 | } |
jmarkel44 | 35:6235ef67faa1 | 32 | |
jmarkel44 | 35:6235ef67faa1 | 33 | // close the file |
jmarkel44 | 35:6235ef67faa1 | 34 | GLOBAL_mdot->closeUserFile(file); |
jmarkel44 | 35:6235ef67faa1 | 35 | |
jmarkel44 | 35:6235ef67faa1 | 36 | parse(json_value, dataBuf); |
jmarkel44 | 35:6235ef67faa1 | 37 | |
jmarkel44 | 35:6235ef67faa1 | 38 | // { |
jmarkel44 | 35:6235ef67faa1 | 39 | // "tcontrol": { |
jmarkel44 | 35:6235ef67faa1 | 40 | // "id": "Timer1", |
jmarkel44 | 35:6235ef67faa1 | 41 | // "name": "Acid Cleaning Cycle", |
jmarkel44 | 35:6235ef67faa1 | 42 | // "priority":"800", |
jmarkel44 | 35:6235ef67faa1 | 43 | // "dow":"127", |
jmarkel44 | 35:6235ef67faa1 | 44 | // "strtw":"1", |
jmarkel44 | 35:6235ef67faa1 | 45 | // "output":"o_r4", |
jmarkel44 | 35:6235ef67faa1 | 46 | // "freq":"1", |
jmarkel44 | 35:6235ef67faa1 | 47 | // "tod": { |
jmarkel44 | 35:6235ef67faa1 | 48 | // "start":"420", |
jmarkel44 | 35:6235ef67faa1 | 49 | // "int":"1" |
jmarkel44 | 35:6235ef67faa1 | 50 | // } |
jmarkel44 | 35:6235ef67faa1 | 51 | // } |
jmarkel44 | 35:6235ef67faa1 | 52 | |
jmarkel44 | 35:6235ef67faa1 | 53 | // parse the json data |
jmarkel44 | 35:6235ef67faa1 | 54 | id = json_value["id"].get<string>(); |
jmarkel44 | 35:6235ef67faa1 | 55 | name = json_value["name"].get<string>(); |
jmarkel44 | 35:6235ef67faa1 | 56 | priority = atoi(json_value["priority"].get<string>().c_str()); |
jmarkel44 | 35:6235ef67faa1 | 57 | dayOfWeek = atoi(json_value["dow"].get<string>().c_str()); |
jmarkel44 | 35:6235ef67faa1 | 58 | startWeek = atoi(json_value["strtw"].get<string>().c_str()); |
jmarkel44 | 35:6235ef67faa1 | 59 | output = json_value["output"].get<string>().c_str(); |
jmarkel44 | 35:6235ef67faa1 | 60 | freq = atoi(json_value["freq"].get<string>().c_str()); |
jmarkel44 | 35:6235ef67faa1 | 61 | |
jmarkel44 | 35:6235ef67faa1 | 62 | // TODO extract |
jmarkel44 | 35:6235ef67faa1 | 63 | tod.start = 0; tod.interval = 0; |
jmarkel44 | 19:9bc8fabeddfa | 64 | |
jmarkel44 | 19:9bc8fabeddfa | 65 | return true; |
jmarkel44 | 35:6235ef67faa1 | 66 | } |