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
Diff: src/CommandParser/cmd.cpp
- Revision:
- 97:5cf6ab71dcd0
- Parent:
- 96:807f04bd5256
- Child:
- 98:8eab18d03ac2
diff -r 807f04bd5256 -r 5cf6ab71dcd0 src/CommandParser/cmd.cpp --- a/src/CommandParser/cmd.cpp Wed Sep 21 12:54:41 2016 +0000 +++ b/src/CommandParser/cmd.cpp Wed Sep 21 16:17:12 2016 +0000 @@ -55,7 +55,8 @@ // see cmd.h const command_table_t cmdlist[] = { {"?", "help command", cmd_help }, - //{"create-control", "create a control", cmd_create }, + {"create-manual", "create a manual control", cmd_createManual }, + //{"create-control", "create a control", cmd_create }, {"create-setpoint", "create a setpoint control", cmd_createSetpoint }, {"destroy-control", "destroy a control", cmd_destroy }, {"cif", "create a test input file", cmd_cif }, @@ -417,6 +418,55 @@ } /***************************************************************************** + * Function: cmd_createManual + * Description: create a manual control + * + * @param argc-> number of args + * @param argv-> filename + * @return none + *****************************************************************************/ +void cmd_createManual(int argc, char **argv) +{ + if ( argc != 4 ) { + printf("\rusage: create-manual <filename> <output> <state>\n"); + printf("\rexample: create-manual control_mn_1.json o_rly1 1\n"); + return; + } + + char data_buf[1024]; + snprintf(data_buf, sizeof(data_buf), + "{ " + "\"id\": \"%s\", " + "\"type\": \"1\"," + "\"priority\": \"100\", " + "\"duration\": \"0\", " + "\"setpoint\": \"0\"," + "\"state\": \"%d\"," + "\"percent\": \"100\" ", argv[2], atoi(argv[3]) + ); + + bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 1024); + if( status != true ) { + logInfo("(%d)save file failed, status=%d", __LINE__, status); + return; + } + + // send a message to the configuration handler to create the control + Message_t *msg = MailBox.alloc(); + memset(msg, 0, sizeof(Message_t)); + msg->action = ACTION_CREATE; + msg->control = CONTROL_MANUAL; + strncpy(msg->controlFile, argv[1], sizeof(msg->controlFile)-1); + + printf("%s: Sending a create request for control %s type = %u\r\n", + __func__, msg->controlFile, msg->control); + + MailBox.put(msg); + printf("\r\n"); + return; +} + +/***************************************************************************** * Function: cmd_cif * Description: create input file *