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.
Diff: ICE-Application/src/CommandParser/cmd_utils.cpp
- Revision:
- 0:61364762ee0e
diff -r 000000000000 -r 61364762ee0e ICE-Application/src/CommandParser/cmd_utils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ICE-Application/src/CommandParser/cmd_utils.cpp Tue Jan 24 19:05:33 2017 +0000 @@ -0,0 +1,125 @@ +#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()); + } +} +