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:
- 197:594afd088f32
- Parent:
- 190:af7ab603c9fe
- Child:
- 199:d65ed41d4dd4
--- a/src/CommandParser/cmd.cpp Thu Oct 06 15:24:10 2016 +0000
+++ b/src/CommandParser/cmd.cpp Thu Oct 06 20:59:59 2016 +0000
@@ -77,6 +77,7 @@
{"ls", "list user files", cmd_ls },
{"modify-control", "modify a control", cmd_modify },
{"modmap", "dump modbus register map", cmd_modmap },
+ {"mod-cmd", "send command to modbus master", cmd_modbusCmd },
{"peep", "push EEP", cmd_peep },
{"reset", "reset the controller", cmd_reset },
{"reset-stats", "reset current mDot statistics", cmd_resetStats },
@@ -1232,8 +1233,8 @@
ModbusMasterMailBox.put(mail);
Thread::wait(1000);
-
- // INPUT: Tag
+
+ // INPUT: Tag
snprintf(buf, sizeof(buf),
"{ "
"\"id\": \"i_tag01\","
@@ -1297,8 +1298,8 @@
ModbusMasterMailBox.put(mail);
Thread::wait(1000);
-
- // INPUT: Conductivity Temperature
+
+ // INPUT: Conductivity Temperature
snprintf(buf, sizeof(buf),
"{ "
"\"id\": \"i_temp01\","
@@ -1329,8 +1330,8 @@
ModbusMasterMailBox.put(mail);
Thread::wait(1000);
-
- // INPUT: Product Factor
+
+ // INPUT: Product Factor
snprintf(buf, sizeof(buf),
"{ "
"\"id\": \"i_pfac01\","
@@ -1565,40 +1566,41 @@
* @param argv-> filename
* @return none
*****************************************************************************/
-void cmd_createBDCond(int argc, char **argv)
+void cmd_modbusCmd(int argc, char **argv)
{
- if ( argc != 6 ) {
- printf("\rusage: createBDCond <fname> <input> <name> <node> <reg>\n");
- printf("\rexample: createBDCond input_i_bdcond.json i_bdcond01 TowerConductivity 21 18\n");
+ if ( (argc != 7) && (argc != 8)) {
+ printf("\r\nusage: modbusCmd <node> <func> <sreg> <nreg> <dtype> <order> <value>\r\n");
+ printf("example (read product factor): modbusCmd 1 3 40 2 0 2\r\n");
+ printf("example (write product factor): modbusCmd 1 16 40 2 0 2 100.0\r\n");
return;
}
- char data_buf[MAX_FILE_SIZE];
- snprintf(data_buf, sizeof(data_buf),
- "{ "
- "\"id\": \"%s\", "
- "\"name\": \"%s\", "
- "\"units\": \"uS\", "
- "\"min\": \"0\", "
- "\"max\": \"300\", "
- "\"node\": \"%s\", "
- "\"reg\": \"%s\", "
- "\"rtype\": \"1\", "
- "\"type\": \"0\", "
- "\"size\": \"2\", "
- "\"order\": \"2\", "
- "\"rfreq\": \"5\", "
- "\"vcmd\": \"\","
- "\"fmt\": \"%%.2f\" } ", argv[2], argv[3], argv[4], argv[5]);
+ char snd_buf[128];
- bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
- if( status != true ) {
- logInfo("(%d)save file failed, status=%d", __LINE__, status);
- }
+ memset( snd_buf, '\0', 128 );
+ snprintf(snd_buf, sizeof(snd_buf),
+ "{"
+ "\"id\":\"%s\","
+ "\"node\":\"%s\","
+ "\"func\":\"%s\","
+ "\"sreg\":\"%s\","
+ "\"nreg\":\"%s\","
+ "\"dtype\":\"%s\","
+ "\"order\":\"%s\","
+ "\"value\":\"%s\"}",
+ "READ_MODBUS",
+ argv[1],
+ argv[2],
+ argv[3],
+ argv[4],
+ argv[5],
+ argv[6],
+ argv[7]
+ );
- logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", argv[1]);
+ printf("Sending Command To ModbusMasterMailBox: %s : len=%d\r\n", snd_buf, strlen(snd_buf));
Message_t *mail = ModbusMasterMailBox.alloc();
- mail->action = ACTION_READ_FILE;
- strncpy( mail->controlFile, argv[1], (sizeof(mail->controlFile)-1));
+ mail->action = ACTION_EXEC_CMD;
+ strncpy( mail->controlFile, snd_buf, (sizeof(mail->controlFile)-1));
ModbusMasterMailBox.put(mail);
}
\ No newline at end of file
