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:
- 113:001ad47df8ec
- Parent:
- 102:715f754cf5a8
- Child:
- 117:a4a61da3de36
--- a/src/CommandParser/cmd.cpp Thu Sep 22 16:10:01 2016 +0000
+++ b/src/CommandParser/cmd.cpp Thu Sep 22 18:44:57 2016 +0000
@@ -153,13 +153,22 @@
printf("\rusage: cat <filename>\n");
return;
}
- char data_buf[1024];
- bool rc = GLOBAL_mdot->readUserFile(argv[1], data_buf, sizeof(data_buf));
+ mDot::mdot_file file = GLOBAL_mdot->openUserFile(argv[1], mDot::FM_RDONLY);
+ if ( file.fd < 0 ) {
+ printf("\rFailed to open %s\n", argv[1]);
+ return;
+ }
+ char *data_buf = (char*) malloc(file.size);
+ bool rc = GLOBAL_mdot->readUserFile(file, data_buf, file.size);
if ( rc != true ) {
printf("\rFailed to read %s\n", argv[1]);
- return;
+ goto cleanup;
}
printf("%s\n", data_buf);
+
+cleanup:
+ free(data_buf);
+ GLOBAL_mdot->closeUserFile(file);
}
/*****************************************************************************
* Function: cmd_help
@@ -409,7 +418,7 @@
"\"lalert\": \"85\", "
"\"hfs\": \"130\","
"\"lfs\": \"70\", "
- "\"tol\": \"%s\" ", argv[2], argv[3], argv[4], argv[5], argv[6]
+ "\"tol\": \"%s\" }", argv[2], argv[3], argv[4], argv[5], argv[6]
);
bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 1024);
@@ -459,7 +468,7 @@
"\"duration\": \"0\", "
"\"setpoint\": \"0\", "
"\"state\": \"%d\", "
- "\"percent\": \"100\" ", argv[2], argv[3], atoi(argv[4])
+ "\"percent\": \"100\" }", argv[2], argv[3], atoi(argv[4])
);
bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 1024);
@@ -553,7 +562,7 @@
"\"duration\": \"30\", " // seconds
"\"setpoint\": \"2000.0\", "
"\"state\": \"1\", "
- "\"percent\": \"100\", ", argv[2]
+ "\"percent\": \"100\", }", argv[2]
);
@@ -581,23 +590,6 @@
}
char data_buf[1024];
-#if 0
- snprintf(data_buf, sizeof(data_buf),
- "{ "
- "\"id\": \"o_r05\", "
- "\"name\": \"Relay 5\", "
- "\"min\": \"0\", "
- "\"max\": \"300\", "
- "\"node\": \"20\", "
- "\"reg\": \"21\", "
- "\"rtype\": \"1\", "
- "\"type\": \"16\", "
- "\"fmt\": \"%%.2f\", "
- "\"toperiod\": \"0\", "
- "\"scalelo\": \"0\", "
- "\"scalehi\": \"100\" }"
- );
-#endif
snprintf(data_buf, sizeof(data_buf),
"{ "
