Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

src/ConfigurationHandler/Controls/SetpointControl.cpp

Committer:
jmarkel44
Date:
2016-09-08
Revision:
33:cb765aefa1b5
Parent:
30:738359dfdab1

File content as of revision 33:cb765aefa1b5:

/******************************************************************************
 *
 * File:                SetpointControl.cpp
 * Desciption:          ICE Setpoint Control Class implementation
 *
 *****************************************************************************/
#include "SetpointControl.h"
#include "mDot.h"
#include "MbedJSONValue.h"
#include <string>

extern mDot *GLOBAL_mdot;

bool SetpointControl::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;

    // 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);

    // "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;
}