Erick / Mbed 2 deprecated ICE-F412

Dependencies:   mbed-rtos mbed

ICE-Application/src/CommandParser/cmd_utils.cpp

Committer:
jmarkel44
Date:
2017-01-24
Revision:
0:61364762ee0e

File content as of revision 0:61364762ee0e:

#include "cmd_utils.h"
#include "global.h"


// create a virtual register
void createVregFile(VregFile_t &vreg_f)
{
    char buf[MAX_FILE_SIZE];
    snprintf(buf, sizeof(buf),
        "{" 
        "\"id\":\"%s\", "
        "\"value\":\"%f\" }", vreg_f.id.c_str(), vreg_f.value);
    bool rc = GLOBAL_mdot->saveUserFile(vreg_f.fname.c_str(), 
                                       (void*)buf,
                                       MAX_FILE_SIZE);
    if ( rc != true ) {
        printf("\rFailed to save %s\n", vreg_f.fname.c_str());
    } else { 
        printf("\r...generated %s\n", vreg_f.fname.c_str());
    }
}

// create an input/output file
void createIOFile(IOFile_t &io_file)
{
    char buf[MAX_FILE_SIZE];
    snprintf(buf, sizeof(buf),
           "{ "
             "\"id\":       \"%s\", "
             "\"name\":     \"%s\", "
             "\"units\":    \"PPM\", "
             "\"min\":      \"%f\", "
             "\"max\":      \"%f\", "
             "\"node\":     \"%u\", "
             "\"reg\":      \"%u\", "
             "\"rtype\":    \"%u\", "
             "\"type\":     \"%u\", "
             "\"size\":     \"%u\", "
             "\"order\":    \"%u\", "
             "\"rfreq\":    \"%u\", "
             "\"cmd\":       \"\","
             "\"args\":      [],"
             "\"fmt\":      \"%%.2f\" } ",  io_file.id.c_str(),
                                            io_file.name.c_str(),
                                            io_file.min,
                                            io_file.max,
                                            io_file.node,
                                            io_file.reg,
                                            io_file.rtype,
                                            io_file.type,
                                            io_file.size,
                                            io_file.order,
                                            io_file.rfreq);
    bool rc = GLOBAL_mdot->saveUserFile(io_file.fname.c_str(), (void *)buf, MAX_FILE_SIZE);
    if( rc != true ) {
        printf("(%d)save file failed, status=%d", __LINE__, rc);
    } else {
        printf("\r...generated %s\n", io_file.fname.c_str());
    }
}

// create a setpoint control file
void createSetpointControlFile(SetpointControlFile_t &sp_f)
{
    char buf[MAX_FILE_SIZE];
    snprintf(buf, sizeof(buf),
             "{ "
             "\"id\":           \"%s\", "
             "\"priority\":     \"%u\","
             "\"input\":        \"%s\", "
             "\"output\":       \"%s\", "
             "\"setpoint\":     \"%f\","
             "\"prodfact\":     \"%f\","
             "\"actingDir\":    \"%u\", "
             "\"tol\":          \"%f\"  }", sp_f.id.c_str(), 
                                            sp_f.priority,
                                            sp_f.input.c_str(),
                                            sp_f.output.c_str(),
                                            sp_f.setpoint,
                                            sp_f.productFactor,
                                            sp_f.actingDir,
                                            sp_f.tolerance);
    bool rc = GLOBAL_mdot->saveUserFile(sp_f.controlFile.c_str(), 
                                            (void *)buf, MAX_FILE_SIZE);
    if( rc != true ) {
        printf("(%d)save file failed, status=%d", __LINE__, rc);
        return;
    } else {
        printf("\r...generated %s\n", sp_f.controlFile.c_str());
    }
}

// create a timer control file 
void createTimerControlFile(TimerControlFile_t &timer_f)
{
    char buf[MAX_FILE_SIZE];
    snprintf(buf, sizeof(buf),
             "{ "
             "\"id\":        \"%s\", "
             "\"output\":    \"%s\", "
             "\"priority\":  \"%u\", "
             "\"day\":       \"%u\", "
             "\"startHour\": \"%u\", "
             "\"startMin\":  \"%u\", "
             "\"startSec\":  \"%u\", "
             "\"duration\":  \"%u\", "
             "\"week\":      \"%u\" } ",
                timer_f.id.c_str(),
                timer_f.output.c_str(),
                timer_f.priority,
                timer_f.day,
                timer_f.startHour,
                timer_f.startMin,
                timer_f.startSec,
                timer_f.duration,
                timer_f.week);
    bool rc = GLOBAL_mdot->saveUserFile(timer_f.controlFile.c_str(), (void *)buf, MAX_FILE_SIZE);
    if( rc != true ) {
        printf("(%d)save file failed, status=%d", __LINE__, rc);
        return;
    } else {
        printf("\r...generated %s\n", timer_f.controlFile.c_str());
    }
}