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:
- 207:55aabde2d4bf
- Parent:
- 203:9d735375f218
- Child:
- 208:784c46652863
--- a/src/CommandParser/cmd.cpp Fri Oct 07 17:56:23 2016 +0000 +++ b/src/CommandParser/cmd.cpp Mon Oct 10 12:51:32 2016 +0000 @@ -42,6 +42,7 @@ #include "mDot.h" #include "rtos.h" #include "rtc.h" +#include "MbedJSONValue.h" Serial serial(USBTX, USBRX); ntshell_t ntshell; @@ -75,7 +76,7 @@ {"ins-log", "insert log event", cmd_inslog }, {"log-level", "get/set mDot log level", cmd_logLevel }, {"ls", "list user files", cmd_ls }, - {"modify-control", "modify a control", cmd_modify }, + {"modify-sp", "modify a setpoint control", cmd_modifySetpoint }, {"modmap", "dump modbus register map", cmd_modmap }, {"mod-cmd", "send command to modbus master", cmd_modbusCmd }, {"peep", "push EEP", cmd_peep }, @@ -780,20 +781,6 @@ __heapstats((__heapprt)fprintf,stderr); // print initial free heap size } -/***************************************************************************** - * Function: cmd_modify - * Description: modify an active control - * - * @param argc (not used) - * @param argv (not used) - * @return none - *****************************************************************************/ -void cmd_modify(int argc, char **argv) -{ - // stubbed - printf("\rNot yet implemented.\n"); - return; -} /***************************************************************************** * Function: cmd_stats @@ -976,6 +963,56 @@ } /***************************************************************************** + * Function: cmd_modifySetpoint + * Description: modify a setpoint control + *****************************************************************************/ +void cmd_modifySetpoint(int argc, char**argv) +{ + if ( argc != 4) { + printf("\rusage: modify-sp <controlFile> <setpoint> <tol>\n"); + printf("\rexample: modify-sp control_sp_1.json 2200 10\n"); + return; + } + + // read the file + char buf[MAX_FILE_SIZE]; + bool rc = GLOBAL_mdot->readUserFile(argv[1], (void*)buf, MAX_FILE_SIZE); + if ( rc != true ) { + printf("\rFailed to read %s\n", argv[1]); + return; + } + + MbedJSONValue json_value; + parse(json_value, buf); + + json_value["setpoint"] = argv[2]; + json_value["tol"] = argv[3]; + + std::string s = json_value.serialize(); + + rc = GLOBAL_mdot->saveUserFile(argv[1], (void*)s.c_str(), MAX_FILE_SIZE); + if ( rc != true ) { + printf("\rFailed to write %s\n", argv[1]); + 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_MODIFY; + msg->control = CONTROL_SETPOINT; + strncpy(msg->controlFile, argv[1], sizeof(msg->controlFile)-1); + + printf("%s: Sending a MODIFY request for control %s type = %u\r\n", + __func__, msg->controlFile, msg->control); + + MailBox.put(msg); + printf("\r\n"); + return; + +} + +/***************************************************************************** * Function: cmd_time * Description: display real-time clock ****************************************************************************/ @@ -1107,7 +1144,7 @@ SimulateInputMap["i_tra01"].up_step = 0; SimulateInputMap["i_tra01"].down_step = 0; SimulateInputMap["i_tra01"].moving_up = true; - + ModbusRegisterMap["i_tag01"].simulated = true; SimulateInputMap["i_tag01"].start_value = 100; SimulateInputMap["i_tag01"].min = 0; @@ -1123,7 +1160,7 @@ SimulateInputMap["i_bdcond01"].up_step = 0; SimulateInputMap["i_bdcond01"].down_step = 0; SimulateInputMap["i_bdcond01"].moving_up = true; - + ModbusRegisterMap["i_cond_temp01"].simulated = true; SimulateInputMap["i_cond_temp01"].start_value = 25.0; SimulateInputMap["i_cond_temp01"].min = 0; @@ -1131,7 +1168,7 @@ SimulateInputMap["i_cond_temp01"].up_step = 0; SimulateInputMap["i_cond_temp01"].down_step = 0; SimulateInputMap["i_cond_temp01"].moving_up = true; - + ModbusRegisterMap["i_ph01"].simulated = true; SimulateInputMap["i_ph01"].start_value = 8; SimulateInputMap["i_ph01"].min = 0; @@ -1139,7 +1176,7 @@ SimulateInputMap["i_ph01"].up_step = 0; SimulateInputMap["i_ph01"].down_step = 0; SimulateInputMap["i_ph01"].moving_up = true; - + ModbusRegisterMap["i_ph_temp01"].simulated = true; SimulateInputMap["i_ph_temp01"].start_value = 25.0; SimulateInputMap["i_ph_temp01"].min = 0; @@ -1147,7 +1184,7 @@ SimulateInputMap["i_ph_temp01"].up_step = 0; SimulateInputMap["i_ph_temp01"].down_step = 0; SimulateInputMap["i_ph_temp01"].moving_up = true; - + ModbusRegisterMap["i_orp01"].simulated = true; SimulateInputMap["i_orp01"].start_value = 350; SimulateInputMap["i_orp01"].min = 0; @@ -1171,7 +1208,7 @@ SimulateInputMap["i_tra01"].max = 140; SimulateInputMap["i_tra01"].up_step = 1; SimulateInputMap["i_tra01"].down_step = .25; - + ModbusRegisterMap["i_tag01"].simulated = true; SimulateInputMap["i_tag01"].start_value = 100; SimulateInputMap["i_tag01"].min = 90; @@ -1185,14 +1222,14 @@ SimulateInputMap["i_bdcond01"].max = 1875; SimulateInputMap["i_bdcond01"].up_step = 1; SimulateInputMap["i_bdcond01"].down_step = 5; - + ModbusRegisterMap["i_ph01"].simulated = true; SimulateInputMap["i_ph01"].start_value = 8; SimulateInputMap["i_ph01"].min = 7.25; SimulateInputMap["i_ph01"].max = 8.75; SimulateInputMap["i_ph01"].up_step = .05; SimulateInputMap["i_ph01"].down_step = .1; - + ModbusRegisterMap["i_orp01"].simulated = true; SimulateInputMap["i_orp01"].start_value = 350; SimulateInputMap["i_orp01"].min = 300; @@ -1394,8 +1431,8 @@ ModbusMasterMailBox.put(mail); Thread::wait(5000); - - // INPUT: pH Temperature + + // INPUT: pH Temperature snprintf(buf, sizeof(buf), "{ " "\"id\": \"i_ph_temp01\"," @@ -1426,8 +1463,8 @@ ModbusMasterMailBox.put(mail); Thread::wait(5000); - - // INPUT: pH + + // INPUT: pH snprintf(buf, sizeof(buf), "{ " "\"id\": \"i_ph01\"," @@ -1458,8 +1495,8 @@ ModbusMasterMailBox.put(mail); Thread::wait(5000); - - // INPUT: ORP + + // INPUT: ORP snprintf(buf, sizeof(buf), "{ " "\"id\": \"i_orp01\"," @@ -1490,8 +1527,8 @@ ModbusMasterMailBox.put(mail); Thread::wait(5000); - - // INPUT: Flow Switch + + // INPUT: Flow Switch snprintf(buf, sizeof(buf), "{ " "\"id\": \"i_flowsw01\"," @@ -1610,8 +1647,8 @@ OutputMasterMailBox.put(output_mail); Thread::wait(2000); - - // OUTPUT: Relay 03 + + // OUTPUT: Relay 03 snprintf(buf, sizeof(buf), "{ " "\"id\": \"o_rly03\", " @@ -1654,8 +1691,8 @@ OutputMasterMailBox.put(output_mail); Thread::wait(2000); - - // OUTPUT: Relay 04 + + // OUTPUT: Relay 04 snprintf(buf, sizeof(buf), "{ " "\"id\": \"o_rly04\", " @@ -1698,7 +1735,7 @@ OutputMasterMailBox.put(output_mail); Thread::wait(2000); - + // SETPOINT: Blowdown snprintf(buf, sizeof(buf), @@ -1765,8 +1802,8 @@ MailBox.put(sp_msg); Thread::wait(2000); - - // SETPOINT: Acid Base + + // SETPOINT: Acid Base snprintf(buf, sizeof(buf), "{ " "\"id\": \"ACID_BASE_01\", " @@ -1798,8 +1835,8 @@ MailBox.put(sp_msg); Thread::wait(2000); - - // SETPOINT: MicroBio + + // SETPOINT: MicroBio snprintf(buf, sizeof(buf), "{ " "\"id\": \"MICRO_BIO_01\", "