Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

src/ConfigurationHandler/Controls/TimerControl.cpp

Committer:
jmarkel44
Date:
2016-09-22
Revision:
111:d31b3a347e6a
Parent:
46:4cb96ab2d1c8

File content as of revision 111:d31b3a347e6a:

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

extern mDot *GLOBAL_mdot;

//
// method:      load
// description: load the pertienent data from the timer json file to this object
//
// @param       controlFile -> the timer control file
// @return      true on success; false on failure

bool TimerControl::load(string _controlFile)
{
    MbedJSONValue json_value;           // json parsing element
    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);

    id          = json_value["id"].get<string>();
    priority    = atoi(json_value["priority"].get<string>().c_str());
    dayOfWeek   = atoi(json_value["dow"].get<string>().c_str());
    startWeek   = atoi(json_value["startw"].get<string>().c_str());
    output      = atoi(json_value["output"].get<string>().c_str());
    startTime   = atoi(json_value["starttime"].get<string>().c_str());
    duration    = atoi(json_value["duration"].get<string>().c_str());

    return true;
}

//
// method:      start
// description: start a timer control
//
// @param       none
// @return      none
int TimerControl::start(void)
{
    return 0;
}

//
// method:      update
// description: update a timer control
//
// @param       none
// @return      none
int TimerControl::update(void)
{
    return 0;
}

//
// method:      unregisterControl
// description: unregister a control with the output task
//
// @param       none
// @return      none
int TimerControl::unregisterControl(void)
{
    return 0;
}

//
// method:      display
// description: display the data
//
// @param       none
// @return      none
//
void TimerControl::display(void)
{
    printf("\r      controlFile : %s   \n", controlFile.c_str());
    printf("\r               id : %s   \n", id.c_str());
    printf("\r         priority : %d   \n", priority);
    printf("\r        dayOfWeek : %u   \n", dayOfWeek);
    printf("\r        startWeek : %u   \n", startWeek);
    printf("\r           output : %s   \n", output.c_str());
    printf("\r        startTime : %u   \n", startTime);
    printf("\r         duration : %u   \n", duration);

    printf("\r\n");
}