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/Algorithms/CompositeAlgorithm.cpp@221:2a5e9902003c, 2016-10-14 (annotated)
- Committer:
- jmarkel44
- Date:
- Fri Oct 14 21:30:21 2016 +0000
- Revision:
- 221:2a5e9902003c
- Child:
- 244:26074095e389
composite control and composite algorithm implementation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmarkel44 | 221:2a5e9902003c | 1 | #include "global.h" |
| jmarkel44 | 221:2a5e9902003c | 2 | #include "MbedJSONValue.h" |
| jmarkel44 | 221:2a5e9902003c | 3 | #include "CompositeAlgorithm.h" |
| jmarkel44 | 221:2a5e9902003c | 4 | |
| jmarkel44 | 221:2a5e9902003c | 5 | bool CompositeAlgorithm::load(const std::string _controlFile) |
| jmarkel44 | 221:2a5e9902003c | 6 | { |
| jmarkel44 | 221:2a5e9902003c | 7 | MbedJSONValue json_value; // JSON parsing element |
| jmarkel44 | 221:2a5e9902003c | 8 | controlFile = _controlFile; |
| jmarkel44 | 221:2a5e9902003c | 9 | |
| jmarkel44 | 221:2a5e9902003c | 10 | // open and read from the control file |
| jmarkel44 | 221:2a5e9902003c | 11 | mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY); |
| jmarkel44 | 221:2a5e9902003c | 12 | if ( file.fd < 0 ) { |
| jmarkel44 | 221:2a5e9902003c | 13 | logError("%s: failed to open %s\n", __func__, controlFile.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 14 | return false; |
| jmarkel44 | 221:2a5e9902003c | 15 | } |
| jmarkel44 | 221:2a5e9902003c | 16 | |
| jmarkel44 | 221:2a5e9902003c | 17 | // read the data into a buffer |
| jmarkel44 | 221:2a5e9902003c | 18 | char dataBuf[MAX_FILE_SIZE]; |
| jmarkel44 | 221:2a5e9902003c | 19 | |
| jmarkel44 | 221:2a5e9902003c | 20 | int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf)); |
| jmarkel44 | 221:2a5e9902003c | 21 | if ( bytes_read != sizeof(dataBuf) ) { |
| jmarkel44 | 221:2a5e9902003c | 22 | logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 23 | // caller should destroy the object |
| jmarkel44 | 221:2a5e9902003c | 24 | return false; |
| jmarkel44 | 221:2a5e9902003c | 25 | } |
| jmarkel44 | 221:2a5e9902003c | 26 | |
| jmarkel44 | 221:2a5e9902003c | 27 | // close the file |
| jmarkel44 | 221:2a5e9902003c | 28 | GLOBAL_mdot->closeUserFile(file); |
| jmarkel44 | 221:2a5e9902003c | 29 | |
| jmarkel44 | 221:2a5e9902003c | 30 | // parse the JSON data |
| jmarkel44 | 221:2a5e9902003c | 31 | parse(json_value, dataBuf); |
| jmarkel44 | 221:2a5e9902003c | 32 | |
| jmarkel44 | 221:2a5e9902003c | 33 | if ( !json_value.hasMember("id") || |
| jmarkel44 | 221:2a5e9902003c | 34 | !json_value.hasMember("opr") || |
| jmarkel44 | 221:2a5e9902003c | 35 | !json_value.hasMember("op") || |
| jmarkel44 | 221:2a5e9902003c | 36 | !json_value.hasMember("true") || |
| jmarkel44 | 221:2a5e9902003c | 37 | !json_value.hasMember("false") ) { |
| jmarkel44 | 221:2a5e9902003c | 38 | printf("%s: failed to extract expected tags\n", __func__); |
| jmarkel44 | 221:2a5e9902003c | 39 | return false; |
| jmarkel44 | 221:2a5e9902003c | 40 | } |
| jmarkel44 | 221:2a5e9902003c | 41 | |
| jmarkel44 | 221:2a5e9902003c | 42 | id = json_value["id"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 43 | opr = json_value["opr"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 44 | op = json_value["op"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 45 | resultTrue = json_value["true"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 46 | resultFalse = json_value["false"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 47 | |
| jmarkel44 | 221:2a5e9902003c | 48 | return true; |
| jmarkel44 | 221:2a5e9902003c | 49 | } |
| jmarkel44 | 221:2a5e9902003c | 50 | |
| jmarkel44 | 221:2a5e9902003c | 51 | void CompositeAlgorithm::display(void) |
| jmarkel44 | 221:2a5e9902003c | 52 | { |
| jmarkel44 | 221:2a5e9902003c | 53 | printf("\r id : %s\n", id.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 54 | printf("\r opr : %s\n", opr.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 55 | printf("\r op : %s\n", op.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 56 | printf("\r true : %s\n", resultTrue.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 57 | printf("\r false : %s\n", resultFalse.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 58 | printf("\r\n"); |
| jmarkel44 | 221:2a5e9902003c | 59 | } |
