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:
- 208:784c46652863
- Parent:
- 207:55aabde2d4bf
- Child:
- 211:bca3e42bd4de
- Child:
- 212:289f63158d2b
diff -r 55aabde2d4bf -r 784c46652863 src/CommandParser/cmd.cpp
--- a/src/CommandParser/cmd.cpp Mon Oct 10 12:51:32 2016 +0000
+++ b/src/CommandParser/cmd.cpp Mon Oct 10 13:55:23 2016 +0000
@@ -76,6 +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-mn", "modify a manual control", cmd_modifyManual },
{"modify-sp", "modify a setpoint control", cmd_modifySetpoint },
{"modmap", "dump modbus register map", cmd_modmap },
{"mod-cmd", "send command to modbus master", cmd_modbusCmd },
@@ -963,6 +964,66 @@
}
/*****************************************************************************
+ * Function: cmd_modifyManual
+ * Description: modify a manual control
+ *****************************************************************************/
+void cmd_modifyManual(int argc, char **argv)
+{
+ std::string relayState;
+
+ if ( argc != 3 ) {
+ printf("\rusage: modify-mn <controlFile> <state>\n");
+ printf("\rexample: modify-mn control_mn_rly1.json on\n");
+ return;
+ }
+
+ string state(argv[2]);
+ if ( state == "on" ) {
+ relayState = "1";
+ } else if ( state == "off" ) {
+ relayState = "0";
+ }
+ else {
+ printf("\r<state> must be ON or OFF\n");
+ return;
+ }
+
+ 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["state"] = relayState;
+
+ 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_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_modifySetpoint
* Description: modify a setpoint control
*****************************************************************************/
