Browse Source

enable silent compare of parameter (#12850)

Remove false errors after comparing parameters that doesn't exists.
as described in #12832
sbg
BazookaJoe1900 5 years ago committed by Julian Oes
parent
commit
02e861b16e
  1. 4
      ROMFS/px4fmu_common/init.d-posix/rcS
  2. 4
      ROMFS/px4fmu_common/init.d/rc.interface
  3. 2
      ROMFS/px4fmu_common/init.d/rc.logging
  4. 20
      ROMFS/px4fmu_common/init.d/rc.sensors
  5. 8
      ROMFS/px4fmu_common/init.d/rcS
  6. 48
      src/systemcmds/param/param.cpp

4
ROMFS/px4fmu_common/init.d-posix/rcS

@ -213,12 +213,12 @@ commander start
navigator start navigator start
if ! param compare MNT_MODE_IN -1 if ! param compare -s MNT_MODE_IN -1
then then
vmount start vmount start
fi fi
if param greater TRIG_MODE 0 if param greater -s TRIG_MODE 0
then then
camera_trigger start camera_trigger start
camera_feedback start camera_feedback start

4
ROMFS/px4fmu_common/init.d/rc.interface

@ -17,9 +17,9 @@ set OUTPUT_DEV none
# If mount (gimbal) control is enabled and output mode is AUX, set the aux # If mount (gimbal) control is enabled and output mode is AUX, set the aux
# mixer to mount (override the airframe-specific MIXER_AUX setting). # 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 then
if param compare MNT_MODE_OUT 0 if param compare -s MNT_MODE_OUT 0
then then
set MIXER_AUX mount set MIXER_AUX mount
fi fi

2
ROMFS/px4fmu_common/init.d/rc.logging

@ -4,7 +4,7 @@
# NOTE: Script variables are declared/initialized/unset in the rcS script. # 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 then
# Reduce logger buffer to free up some RAM for UAVCAN servers. # Reduce logger buffer to free up some RAM for UAVCAN servers.
set LOGGER_BUF 6 set LOGGER_BUF 6

20
ROMFS/px4fmu_common/init.d/rc.sensors

@ -47,13 +47,13 @@ then
fi fi
fi fi
if param compare SENS_EN_BATT 1 if param compare -s SENS_EN_BATT 1
then then
batt_smbus start -X batt_smbus start -X
fi fi
# Sensors on the PWM interface bank # Sensors on the PWM interface bank
if param compare SENS_EN_LL40LS 1 if param compare -s SENS_EN_LL40LS 1
then then
if pwm_input start if pwm_input start
then then
@ -62,49 +62,49 @@ then
fi fi
# Lidar-Lite on I2C # Lidar-Lite on I2C
if param compare SENS_EN_LL40LS 2 if param compare -s SENS_EN_LL40LS 2
then then
ll40ls start i2c -a ll40ls start i2c -a
fi fi
# mappydot lidar sensor # mappydot lidar sensor
if param compare SENS_EN_MPDT 1 if param compare -s SENS_EN_MPDT 1
then then
mappydot start -a mappydot start -a
fi fi
# mb12xx sonar sensor # mb12xx sonar sensor
if param greater SENS_EN_MB12XX 0 if param greater -s SENS_EN_MB12XX 0
then then
mb12xx start -a mb12xx start -a
fi fi
# pga460 sonar sensor # pga460 sonar sensor
if param greater SENS_EN_PGA460 0 if param greater -s SENS_EN_PGA460 0
then then
pga460 start pga460 start
fi fi
# Lightware i2c lidar sensor # Lightware i2c lidar sensor
if param greater SENS_EN_SF1XX 0 if param greater -s SENS_EN_SF1XX 0
then then
sf1xx start -a sf1xx start -a
fi fi
# Heater driver for temperature regulated IMUs. # Heater driver for temperature regulated IMUs.
if param compare SENS_EN_THERMAL 1 if param compare -s SENS_EN_THERMAL 1
then then
heater start heater start
fi fi
# Teraranger one tof sensor # Teraranger one tof sensor
if param greater SENS_EN_TRANGER 0 if param greater -s SENS_EN_TRANGER 0
then then
teraranger start -a teraranger start -a
fi fi
# Possible pmw3901 optical flow sensor # Possible pmw3901 optical flow sensor
if param greater SENS_EN_PMW3901 0 if param greater -s SENS_EN_PMW3901 0
then then
pmw3901 start pmw3901 start
fi fi

8
ROMFS/px4fmu_common/init.d/rcS

@ -299,7 +299,7 @@ else
# #
# Set USE_IO flag. # Set USE_IO flag.
# #
if param compare SYS_USE_IO 1 if param compare -s SYS_USE_IO 1
then then
set USE_IO yes set USE_IO yes
fi fi
@ -347,7 +347,7 @@ else
fi fi
# Sensors on the PWM interface bank. # Sensors on the PWM interface bank.
if param compare SENS_EN_LL40LS 1 if param compare -s SENS_EN_LL40LS 1
then then
# Clear pins 5 and 6. # Clear pins 5 and 6.
set FMU_MODE pwm4 set FMU_MODE pwm4
@ -374,7 +374,7 @@ else
# #
# Check if UAVCAN is enabled, default to it for ESCs. # Check if UAVCAN is enabled, default to it for ESCs.
# #
if param greater UAVCAN_ENABLE 0 if param greater -s UAVCAN_ENABLE 0
then then
# Start core UAVCAN module. # Start core UAVCAN module.
if uavcan start if uavcan start
@ -426,7 +426,7 @@ else
sh /etc/init.d/rc.vehicle_setup sh /etc/init.d/rc.vehicle_setup
# Camera capture driver # Camera capture driver
if param greater CAM_CAP_FBACK 0 if param greater -s CAM_CAP_FBACK 0
then then
if camera_capture start if camera_capture start
then then

48
src/systemcmds/param/param.cpp

@ -65,11 +65,17 @@ __BEGIN_DECLS
__EXPORT int param_main(int argc, char *argv[]); __EXPORT int param_main(int argc, char *argv[]);
__END_DECLS __END_DECLS
enum COMPARE_OPERATOR { enum class COMPARE_OPERATOR {
COMPARE_OPERATOR_EQUAL = 0, EQUAL = 0,
COMPARE_OPERATOR_GREATER = 1, GREATER = 1,
}; };
enum class COMPARE_ERROR_LEVEL {
DO_ERROR = 0,
SILENT = 1,
};
#ifdef __PX4_QURT #ifdef __PX4_QURT
#define PARAM_PRINT PX4_INFO #define PARAM_PRINT PX4_INFO
#else #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 int do_show_index(const char *index, bool used_index);
static void do_show_print(void *arg, param_t param); 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_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_reset(const char *excludes[], int num_excludes);
static int do_touch(const char *params[], int num_params); static int do_touch(const char *params[], int num_params);
static int do_reset_nostart(const char *excludes[], int num_excludes); 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_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_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_ARG("<param_name> <value>", "Parameter name and value to compare", false);
PRINT_MODULE_USAGE_COMMAND_DESCR("greater", PRINT_MODULE_USAGE_COMMAND_DESCR("greater",
"Compare a param with a value. Command will succeed if param is greater than the value"); "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_ARG("<param_name> <value>", "Parameter name and value to compare", false);
PRINT_MODULE_USAGE_COMMAND_DESCR("touch", "Mark a parameter as used"); 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 (!strcmp(argv[1], "compare")) {
if (argc >= 4) { if(argc >= 5 && !strcmp(argv[2], "-s")) {
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_EQUAL); 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 { } else {
PX4_ERR("not enough arguments.\nTry 'param compare PARAM_NAME 3'"); PX4_ERR("not enough arguments.\nTry 'param compare PARAM_NAME 3'");
return 1; return 1;
@ -280,9 +292,10 @@ param_main(int argc, char *argv[])
} }
if (!strcmp(argv[1], "greater")) { if (!strcmp(argv[1], "greater")) {
if (argc >= 4) { if(argc >= 5 && !strcmp(argv[2], "-s")) {
return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_GREATER); 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 { } else {
PX4_ERR("not enough arguments.\nTry 'param greater PARAM_NAME 3'"); PX4_ERR("not enough arguments.\nTry 'param greater PARAM_NAME 3'");
return 1; return 1;
@ -708,7 +721,7 @@ do_set(const char *name, const char *val, bool fail_on_not_found)
} }
static int 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; int32_t i;
float f; 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 */ /* set nothing if parameter cannot be found */
if (param == PARAM_INVALID) { if (param == PARAM_INVALID) {
/* param not found */ /* 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; 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); int j = strtol(vals[k], &end, 10);
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (i == j)) || if (((cmp_op == COMPARE_OPERATOR::EQUAL) && (i == j)) ||
((cmp_op == COMPARE_OPERATOR_GREATER) && (i > j))) { ((cmp_op == COMPARE_OPERATOR::GREATER) && (i > j))) {
PX4_DEBUG(" %ld: ", (long)i); PX4_DEBUG(" %ld: ", (long)i);
ret = 0; ret = 0;
} }
@ -758,8 +774,8 @@ do_compare(const char *name, char *vals[], unsigned comparisons, enum COMPARE_OP
float g = strtod(vals[k], &end); float g = strtod(vals[k], &end);
if (((cmp_op == COMPARE_OPERATOR_EQUAL) && (fabsf(f - g) < 1e-7f)) || if (((cmp_op == COMPARE_OPERATOR::EQUAL) && (fabsf(f - g) < 1e-7f)) ||
((cmp_op == COMPARE_OPERATOR_GREATER) && (f > g))) { ((cmp_op == COMPARE_OPERATOR::GREATER) && (f > g))) {
PX4_DEBUG(" %4.4f: ", (double)f); PX4_DEBUG(" %4.4f: ", (double)f);
ret = 0; ret = 0;
} }

Loading…
Cancel
Save