mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-23 06:36:45 +08:00
param: use PX4_INFO_RAW and add 'param show -q <param_name' command
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
*/
|
||||
|
||||
#include <px4_config.h>
|
||||
#include <px4_log.h>
|
||||
#include <px4_module.h>
|
||||
#include <px4_posix.h>
|
||||
|
||||
@@ -72,7 +73,7 @@ enum COMPARE_OPERATOR {
|
||||
#ifdef __PX4_QURT
|
||||
#define PARAM_PRINT PX4_INFO
|
||||
#else
|
||||
#define PARAM_PRINT printf
|
||||
#define PARAM_PRINT PX4_INFO_RAW
|
||||
#endif
|
||||
|
||||
static int do_save(const char *param_file_name);
|
||||
@@ -80,6 +81,7 @@ static int do_save_default();
|
||||
static int do_load(const char *param_file_name);
|
||||
static int do_import(const char *param_file_name);
|
||||
static int do_show(const char *search_string, bool only_changed);
|
||||
static int do_show_quiet(const char *param_name);
|
||||
static int do_show_index(const char *index, bool used_index);
|
||||
static void do_show_print(void *arg, param_t param);
|
||||
static int do_set(const char *name, const char *val, bool fail_on_not_found);
|
||||
@@ -124,6 +126,7 @@ $ reboot
|
||||
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("show", "Show parameter values");
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('c', "Show only changed params", true);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('q', "quiet mode, print only param value (name needs to be exact)", true);
|
||||
PRINT_MODULE_USAGE_ARG("<filter>", "Filter by param name (wildcard at end allowed, eg. sys_*)", true);
|
||||
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("set", "Set parameter to a value");
|
||||
@@ -213,6 +216,10 @@ param_main(int argc, char *argv[])
|
||||
return do_show(nullptr, true);
|
||||
}
|
||||
|
||||
} else if (!strcmp(argv[2], "-q")) {
|
||||
if (argc >= 4) {
|
||||
return do_show_quiet(argv[3]);
|
||||
}
|
||||
} else {
|
||||
return do_show(argv[2], false);
|
||||
}
|
||||
@@ -419,6 +426,39 @@ do_show(const char *search_string, bool only_changed)
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int
|
||||
do_show_quiet(const char *param_name)
|
||||
{
|
||||
param_t param = param_find_no_notification(param_name);
|
||||
int32_t ii;
|
||||
float ff;
|
||||
// Print only the param value (can be used in scripts)
|
||||
|
||||
if (param == PARAM_INVALID) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (param_type(param)) {
|
||||
case PARAM_TYPE_INT32:
|
||||
if (!param_get(param, &ii)) {
|
||||
PARAM_PRINT("%ld", (long)ii);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PARAM_TYPE_FLOAT:
|
||||
if (!param_get(param, &ff)) {
|
||||
PARAM_PRINT("%4.4f", (double)ff);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
do_find(const char *name)
|
||||
|
||||
Reference in New Issue
Block a user