forked from Archive/PX4-Autopilot
enable silent compare of parameter (#12850)
Remove false errors after comparing parameters that doesn't exists. as described in #12832
This commit is contained in:
parent
05446c0875
commit
02e861b16e
|
@ -213,12 +213,12 @@ commander start
|
|||
navigator start
|
||||
|
||||
|
||||
if ! param compare MNT_MODE_IN -1
|
||||
if ! param compare -s MNT_MODE_IN -1
|
||||
then
|
||||
vmount start
|
||||
fi
|
||||
|
||||
if param greater TRIG_MODE 0
|
||||
if param greater -s TRIG_MODE 0
|
||||
then
|
||||
camera_trigger start
|
||||
camera_feedback start
|
||||
|
|
|
@ -17,9 +17,9 @@ set OUTPUT_DEV none
|
|||
# If mount (gimbal) control is enabled and output mode is AUX, set the aux
|
||||
# mixer to mount (override the airframe-specific MIXER_AUX setting).
|
||||
#
|
||||
if ! param compare MNT_MODE_IN -1
|
||||
if ! param compare -s MNT_MODE_IN -1
|
||||
then
|
||||
if param compare MNT_MODE_OUT 0
|
||||
if param compare -s MNT_MODE_OUT 0
|
||||
then
|
||||
set MIXER_AUX mount
|
||||
fi
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# NOTE: Script variables are declared/initialized/unset in the rcS script.
|
||||
#
|
||||
|
||||
if param greater UAVCAN_ENABLE 1
|
||||
if param greater -s UAVCAN_ENABLE 1
|
||||
then
|
||||
# Reduce logger buffer to free up some RAM for UAVCAN servers.
|
||||
set LOGGER_BUF 6
|
||||
|
|
|
@ -47,13 +47,13 @@ then
|
|||
fi
|
||||
fi
|
||||
|
||||
if param compare SENS_EN_BATT 1
|
||||
if param compare -s SENS_EN_BATT 1
|
||||
then
|
||||
batt_smbus start -X
|
||||
fi
|
||||
|
||||
# Sensors on the PWM interface bank
|
||||
if param compare SENS_EN_LL40LS 1
|
||||
if param compare -s SENS_EN_LL40LS 1
|
||||
then
|
||||
if pwm_input start
|
||||
then
|
||||
|
@ -62,49 +62,49 @@ then
|
|||
fi
|
||||
|
||||
# Lidar-Lite on I2C
|
||||
if param compare SENS_EN_LL40LS 2
|
||||
if param compare -s SENS_EN_LL40LS 2
|
||||
then
|
||||
ll40ls start i2c -a
|
||||
fi
|
||||
|
||||
# mappydot lidar sensor
|
||||
if param compare SENS_EN_MPDT 1
|
||||
if param compare -s SENS_EN_MPDT 1
|
||||
then
|
||||
mappydot start -a
|
||||
fi
|
||||
|
||||
# mb12xx sonar sensor
|
||||
if param greater SENS_EN_MB12XX 0
|
||||
if param greater -s SENS_EN_MB12XX 0
|
||||
then
|
||||
mb12xx start -a
|
||||
fi
|
||||
|
||||
# pga460 sonar sensor
|
||||
if param greater SENS_EN_PGA460 0
|
||||
if param greater -s SENS_EN_PGA460 0
|
||||
then
|
||||
pga460 start
|
||||
fi
|
||||
|
||||
# Lightware i2c lidar sensor
|
||||
if param greater SENS_EN_SF1XX 0
|
||||
if param greater -s SENS_EN_SF1XX 0
|
||||
then
|
||||
sf1xx start -a
|
||||
fi
|
||||
|
||||
# Heater driver for temperature regulated IMUs.
|
||||
if param compare SENS_EN_THERMAL 1
|
||||
if param compare -s SENS_EN_THERMAL 1
|
||||
then
|
||||
heater start
|
||||
fi
|
||||
|
||||
# Teraranger one tof sensor
|
||||
if param greater SENS_EN_TRANGER 0
|
||||
if param greater -s SENS_EN_TRANGER 0
|
||||
then
|
||||
teraranger start -a
|
||||
fi
|
||||
|
||||
# Possible pmw3901 optical flow sensor
|
||||
if param greater SENS_EN_PMW3901 0
|
||||
if param greater -s SENS_EN_PMW3901 0
|
||||
then
|
||||
pmw3901 start
|
||||
fi
|
||||
|
|
|
@ -299,7 +299,7 @@ else
|
|||
#
|
||||
# Set USE_IO flag.
|
||||
#
|
||||
if param compare SYS_USE_IO 1
|
||||
if param compare -s SYS_USE_IO 1
|
||||
then
|
||||
set USE_IO yes
|
||||
fi
|
||||
|
@ -347,7 +347,7 @@ else
|
|||
fi
|
||||
|
||||
# Sensors on the PWM interface bank.
|
||||
if param compare SENS_EN_LL40LS 1
|
||||
if param compare -s SENS_EN_LL40LS 1
|
||||
then
|
||||
# Clear pins 5 and 6.
|
||||
set FMU_MODE pwm4
|
||||
|
@ -374,7 +374,7 @@ else
|
|||
#
|
||||
# Check if UAVCAN is enabled, default to it for ESCs.
|
||||
#
|
||||
if param greater UAVCAN_ENABLE 0
|
||||
if param greater -s UAVCAN_ENABLE 0
|
||||
then
|
||||
# Start core UAVCAN module.
|
||||
if uavcan start
|
||||
|
@ -426,7 +426,7 @@ else
|
|||
sh /etc/init.d/rc.vehicle_setup
|
||||
|
||||
# Camera capture driver
|
||||
if param greater CAM_CAP_FBACK 0
|
||||
if param greater -s CAM_CAP_FBACK 0
|
||||
then
|
||||
if camera_capture start
|
||||
then
|
||||
|
|
|
@ -65,11 +65,17 @@ __BEGIN_DECLS
|
|||
__EXPORT int param_main(int argc, char *argv[]);
|
||||
__END_DECLS
|
||||
|
||||
enum COMPARE_OPERATOR {
|
||||
COMPARE_OPERATOR_EQUAL = 0,
|
||||
COMPARE_OPERATOR_GREATER = 1,
|
||||
enum class COMPARE_OPERATOR {
|
||||
EQUAL = 0,
|
||||
GREATER = 1,
|
||||
};
|
||||
|
||||
enum class COMPARE_ERROR_LEVEL {
|
||||
DO_ERROR = 0,
|
||||
SILENT = 1,
|
||||
};
|
||||
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
#define PARAM_PRINT PX4_INFO
|
||||
#else
|
||||
|
@ -86,7 +92,8 @@ 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);
|
||||
static int do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OPERATOR cmd_op);
|
||||
static int do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OPERATOR cmd_op,
|
||||
enum COMPARE_ERROR_LEVEL err_level);
|
||||
static int do_reset(const char *excludes[], int num_excludes);
|
||||
static int do_touch(const char *params[], int num_params);
|
||||
static int do_reset_nostart(const char *excludes[], int num_excludes);
|
||||
|
@ -143,10 +150,14 @@ $ reboot
|
|||
PRINT_MODULE_USAGE_ARG("fail", "If provided, let the command fail if param is not found", true);
|
||||
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("compare", "Compare a param with a value. Command will succeed if equal");
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('s', "If provided, silent errors if parameter doesn't exists", true);
|
||||
PRINT_MODULE_USAGE_ARG("<param_name> <value>", "Parameter name and value to compare", false);
|
||||
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("greater",
|
||||
"Compare a param with a value. Command will succeed if param is greater than the value");
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('s', "If provided, silent errors if parameter doesn't exists", true);
|
||||
PRINT_MODULE_USAGE_ARG("<param_name> <value>", "Parameter name and value to compare", false);
|
||||
|
||||
PRINT_MODULE_USAGE_ARG("<param_name> <value>", "Parameter name and value to compare", false);
|
||||
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("touch", "Mark a parameter as used");
|
||||
|
@ -270,9 +281,10 @@ param_main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (!strcmp(argv[1], "compare")) {
|
||||
if (argc >= 4) {
|
||||
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_EQUAL);
|
||||
|
||||
if(argc >= 5 && !strcmp(argv[2], "-s")) {
|
||||
return do_compare(argv[3], &argv[4], argc - 4, COMPARE_OPERATOR::EQUAL, COMPARE_ERROR_LEVEL::SILENT);
|
||||
} else if (argc >= 4) {
|
||||
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR::EQUAL, COMPARE_ERROR_LEVEL::DO_ERROR);
|
||||
} else {
|
||||
PX4_ERR("not enough arguments.\nTry 'param compare PARAM_NAME 3'");
|
||||
return 1;
|
||||
|
@ -280,9 +292,10 @@ 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);
|
||||
|
||||
if(argc >= 5 && !strcmp(argv[2], "-s")) {
|
||||
return do_compare(argv[3], &argv[4], argc - 4, COMPARE_OPERATOR::GREATER, COMPARE_ERROR_LEVEL::SILENT);
|
||||
} else if (argc >= 4) {
|
||||
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR::GREATER, COMPARE_ERROR_LEVEL::DO_ERROR);
|
||||
} else {
|
||||
PX4_ERR("not enough arguments.\nTry 'param greater PARAM_NAME 3'");
|
||||
return 1;
|
||||
|
@ -708,7 +721,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, enum COMPARE_OPERATOR cmp_op)
|
||||
do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OPERATOR cmp_op, enum COMPARE_ERROR_LEVEL err_level)
|
||||
{
|
||||
int32_t i;
|
||||
float f;
|
||||
|
@ -717,7 +730,10 @@ do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OP
|
|||
/* set nothing if parameter cannot be found */
|
||||
if (param == PARAM_INVALID) {
|
||||
/* param not found */
|
||||
PX4_DEBUG("Parameter %s not found", name);
|
||||
if(err_level == COMPARE_ERROR_LEVEL::DO_ERROR)
|
||||
{
|
||||
PX4_ERR("Parameter %s not found", name);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -738,8 +754,8 @@ do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OP
|
|||
|
||||
int j = strtol(vals[k], &end, 10);
|
||||
|
||||
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (i == j)) ||
|
||||
((cmp_op == COMPARE_OPERATOR_GREATER) && (i > j))) {
|
||||
if (((cmp_op == COMPARE_OPERATOR::EQUAL) && (i == j)) ||
|
||||
((cmp_op == COMPARE_OPERATOR::GREATER) && (i > j))) {
|
||||
PX4_DEBUG(" %ld: ", (long)i);
|
||||
ret = 0;
|
||||
}
|
||||
|
@ -758,8 +774,8 @@ do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OP
|
|||
|
||||
float g = strtod(vals[k], &end);
|
||||
|
||||
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (fabsf(f - g) < 1e-7f)) ||
|
||||
((cmp_op == COMPARE_OPERATOR_GREATER) && (f > g))) {
|
||||
if (((cmp_op == COMPARE_OPERATOR::EQUAL) && (fabsf(f - g) < 1e-7f)) ||
|
||||
((cmp_op == COMPARE_OPERATOR::GREATER) && (f > g))) {
|
||||
PX4_DEBUG(" %4.4f: ", (double)f);
|
||||
ret = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue