aboutsummaryrefslogtreecommitdiff
path: root/apps/systemcmds
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-01-24 15:43:12 +0100
committerLorenz Meier <lm@inf.ethz.ch>2013-01-24 15:43:12 +0100
commit6d12f147b80c9e23c090830d2cbb64f20b7a2e89 (patch)
treef8968e846c527ebfbe615f621f718eda55bb0ac8 /apps/systemcmds
parentb60a744b773bb0752cb108b8d0bc2aad94c43b80 (diff)
downloadpx4-firmware-6d12f147b80c9e23c090830d2cbb64f20b7a2e89.tar.gz
px4-firmware-6d12f147b80c9e23c090830d2cbb64f20b7a2e89.tar.bz2
px4-firmware-6d12f147b80c9e23c090830d2cbb64f20b7a2e89.zip
Improved param command, show now allows to filter and set allows to set integer params (e.g. param set MAV_TYPE 2)
Diffstat (limited to 'apps/systemcmds')
-rw-r--r--apps/systemcmds/param/param.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/apps/systemcmds/param/param.c b/apps/systemcmds/param/param.c
index 210841604..56f5317e3 100644
--- a/apps/systemcmds/param/param.c
+++ b/apps/systemcmds/param/param.c
@@ -61,6 +61,7 @@ static void do_load(const char* param_file_name);
static void do_import(const char* param_file_name);
static void do_show(const char* search_string);
static void do_show_print(void *arg, param_t param);
+static void do_set(const char* name, const char* val);
int
param_main(int argc, char *argv[])
@@ -100,15 +101,24 @@ param_main(int argc, char *argv[])
exit(0);
}
- if (!strcmp(argv[1], "show"))
+ if (!strcmp(argv[1], "show")) {
if (argc >= 3) {
do_show(argv[2]);
} else {
do_show(NULL);
}
+ }
+
+ if (!strcmp(argv[1], "set")) {
+ if (argc >= 4) {
+ do_set(argv[2], argv[3]);
+ } else {
+ errx(1, "not enough arguments.\nTry 'param set PARAM_NAME 3'");
+ }
+ }
}
- errx(1, "expected a command, try 'load', 'import', 'show', 'select' or 'save'");
+ errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'select' or 'save'");
}
static void
@@ -185,9 +195,11 @@ do_show_print(void *arg, param_t param)
float f;
const char *search_string = (const char*)arg;
- /* print nothing if search string valid and not matching */
- if (arg != NULL && (strcmp(search_string, param_name(param) != 0)))
+ /* print nothing if search string is invalid and not matching */
+ if (!(arg == NULL || (!strcmp(search_string, param_name(param))))) {
+ /* param not found */
return;
+ }
printf("%c %s: ",
param_value_unsaved(param) ? '*' : (param_value_is_default(param) ? ' ' : '+'),
@@ -225,3 +237,61 @@ do_show_print(void *arg, param_t param)
printf("<error fetching parameter %d>\n", param);
}
+
+static void
+do_set(const char* name, const char* val)
+{
+ int32_t i;
+ float f;
+ param_t param = param_find(name);
+
+ /* set nothing if parameter cannot be found */
+ if (param == PARAM_INVALID) {
+ /* param not found */
+ errx(1, "Error: Parameter %s not found.", name);
+ }
+
+ printf("%c %s: ",
+ param_value_unsaved(param) ? '*' : (param_value_is_default(param) ? ' ' : '+'),
+ param_name(param));
+
+ /*
+ * Set parameter if type is known and conversion from string to value turns out fine
+ */
+
+ switch (param_type(param)) {
+ case PARAM_TYPE_INT32:
+ if (!param_get(param, &i)) {
+ printf("old: %d", i);
+
+ /* convert string */
+ char* end;
+ i = strtol(val,&end,10);
+ param_set(param, &i);
+ printf(" -> new: %d\n", i);
+
+ }
+
+ break;
+
+ case PARAM_TYPE_FLOAT:
+ if (!param_get(param, &f)) {
+ printf("float values are not yet supported.");
+ // printf("old: %4.4f", (double)f);
+
+ // /* convert string */
+ // char* end;
+ // f = strtof(val,&end);
+ // param_set(param, &f);
+ // printf(" -> new: %4.4f\n", f);
+
+ }
+
+ break;
+
+ default:
+ errx(1, "<unknown / unsupported type %d>\n", 0 + param_type(param));
+ }
+
+ exit(0);
+}