mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-28 03:00:36 +08:00
param command: Support greater comparison
This commit is contained in:
@@ -59,6 +59,11 @@
|
||||
|
||||
__EXPORT int param_main(int argc, char *argv[]);
|
||||
|
||||
enum COMPARE_OPERATOR {
|
||||
COMPARE_OPERATOR_EQUAL = 0,
|
||||
COMPARE_OPERATOR_GREATER = 1,
|
||||
};
|
||||
|
||||
static int do_save(const char *param_file_name);
|
||||
static int do_load(const char *param_file_name);
|
||||
static int do_import(const char *param_file_name);
|
||||
@@ -66,7 +71,7 @@ static int do_show(const char *search_string);
|
||||
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);
|
||||
static int do_compare(const char *name, char *vals[], unsigned comparisons);
|
||||
static int do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OPERATOR cmd_op);
|
||||
static int do_reset(const char *excludes[], int num_excludes);
|
||||
static int do_reset_nostart(const char *excludes[], int num_excludes);
|
||||
|
||||
@@ -147,7 +152,7 @@ param_main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "compare")) {
|
||||
if (argc >= 4) {
|
||||
return do_compare(argv[2], &argv[3], argc - 3);
|
||||
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_EQUAL);
|
||||
|
||||
} else {
|
||||
warnx("not enough arguments.\nTry 'param compare PARAM_NAME 3'");
|
||||
@@ -155,6 +160,16 @@ param_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "greater")) {
|
||||
if (argc >= 4) {
|
||||
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_GREATER);
|
||||
|
||||
} else {
|
||||
warnx("not enough arguments.\nTry 'param greater PARAM_NAME 3'");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "reset")) {
|
||||
if (argc >= 3) {
|
||||
return do_reset((const char **) &argv[2], argc - 2);
|
||||
@@ -472,7 +487,7 @@ do_set(const char *name, const char *val, bool fail_on_not_found)
|
||||
}
|
||||
|
||||
static int
|
||||
do_compare(const char *name, char *vals[], unsigned comparisons)
|
||||
do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OPERATOR cmp_op)
|
||||
{
|
||||
int32_t i;
|
||||
float f;
|
||||
@@ -502,7 +517,8 @@ do_compare(const char *name, char *vals[], unsigned comparisons)
|
||||
|
||||
int j = strtol(vals[k], &end, 10);
|
||||
|
||||
if (i == j) {
|
||||
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (i == j)) ||
|
||||
((cmp_op == COMPARE_OPERATOR_GREATER) && (i > j))) {
|
||||
printf(" %ld: ", (long)i);
|
||||
ret = 0;
|
||||
}
|
||||
@@ -521,7 +537,8 @@ do_compare(const char *name, char *vals[], unsigned comparisons)
|
||||
|
||||
float g = strtod(vals[k], &end);
|
||||
|
||||
if (fabsf(f - g) < 1e-7f) {
|
||||
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (fabsf(f - g) < 1e-7f)) ||
|
||||
((cmp_op == COMPARE_OPERATOR_GREATER) && (f > g))) {
|
||||
printf(" %4.4f: ", (double)f);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user