PRINT_MODULE_USAGE_PARAM_{INT,FLOAT}: add support to ignore the default value

This commit is contained in:
Beat Küng 2019-01-31 07:17:45 +01:00
parent c3d6a042e6
commit d8b013355c
8 changed files with 24 additions and 15 deletions

View File

@ -92,7 +92,8 @@ class ModuleDocumentation(object):
description = self._get_string(args[4]) description = self._get_string(args[4])
if self._is_bool_true(args[5]): if self._is_bool_true(args[5]):
self._usage_string += " [-%s <val>] %s\n" % (option_char, description) self._usage_string += " [-%s <val>] %s\n" % (option_char, description)
self._usage_string += " default: %i\n" % default_val if default_val != -1:
self._usage_string += " default: %i\n" % default_val
else: else:
self._usage_string += " -%s <val> %s\n" % (option_char, description) self._usage_string += " -%s <val> %s\n" % (option_char, description)
@ -103,7 +104,8 @@ class ModuleDocumentation(object):
description = self._get_string(args[4]) description = self._get_string(args[4])
if self._is_bool_true(args[5]): if self._is_bool_true(args[5]):
self._usage_string += " [-%s <val>] %s\n" % (option_char, description) self._usage_string += " [-%s <val>] %s\n" % (option_char, description)
self._usage_string += " default: %.1f\n" % default_val if not math.isnan(default_val):
self._usage_string += " default: %.1f\n" % default_val
else: else:
self._usage_string += " -%s <val> %s\n" % (option_char, description) self._usage_string += " -%s <val> %s\n" % (option_char, description)

View File

@ -3067,7 +3067,7 @@ $ mavlink stream -u 14556 -s HIGHRES_IMU -r 50
PRINT_MODULE_USAGE_COMMAND_DESCR("stream", "Configure the sending rate of a stream for a running instance"); PRINT_MODULE_USAGE_COMMAND_DESCR("stream", "Configure the sending rate of a stream for a running instance");
#if defined(CONFIG_NET) || defined(__PX4_POSIX) #if defined(CONFIG_NET) || defined(__PX4_POSIX)
PRINT_MODULE_USAGE_PARAM_INT('u', 0, 0, 65536, "Select Mavlink instance via local Network Port", true); PRINT_MODULE_USAGE_PARAM_INT('u', -1, 0, 65536, "Select Mavlink instance via local Network Port", true);
#endif #endif
PRINT_MODULE_USAGE_PARAM_STRING('d', nullptr, "<file:dev>", "Select Mavlink instance via Serial Device", true); PRINT_MODULE_USAGE_PARAM_STRING('d', nullptr, "<file:dev>", "Select Mavlink instance via Serial Device", true);
PRINT_MODULE_USAGE_PARAM_STRING('s', nullptr, nullptr, "Mavlink stream to configure", false); PRINT_MODULE_USAGE_PARAM_STRING('s', nullptr, nullptr, "Mavlink stream to configure", false);

View File

@ -76,7 +76,7 @@ static void usage(const char *name)
PRINT_MODULE_USAGE_PARAM_STRING('t', "UART", "UART|UDP", "Transport protocol", true); PRINT_MODULE_USAGE_PARAM_STRING('t', "UART", "UART|UDP", "Transport protocol", true);
PRINT_MODULE_USAGE_PARAM_STRING('d', "/dev/ttyACM0", "<file:dev>", "Select Serial Device", true); PRINT_MODULE_USAGE_PARAM_STRING('d', "/dev/ttyACM0", "<file:dev>", "Select Serial Device", true);
PRINT_MODULE_USAGE_PARAM_INT('b', 460800, 9600, 3000000, "Baudrate (can also be p:<param_name>)", true); PRINT_MODULE_USAGE_PARAM_INT('b', 460800, 9600, 3000000, "Baudrate (can also be p:<param_name>)", true);
PRINT_MODULE_USAGE_PARAM_INT('p', 1, 1, 1000, "Poll timeout for UART in ms", true); PRINT_MODULE_USAGE_PARAM_INT('p', -1, 1, 1000, "Poll timeout for UART in ms", true);
PRINT_MODULE_USAGE_PARAM_INT('u', 0, 0, 10000, PRINT_MODULE_USAGE_PARAM_INT('u', 0, 0, 10000,
"Interval in ms to limit the update rate of all sent topics (0=unlimited)", true); "Interval in ms to limit the update rate of all sent topics (0=unlimited)", true);
PRINT_MODULE_USAGE_PARAM_INT('l', 10000, -1, 100000, "Limit number of iterations until the program exits (-1=infinite)", PRINT_MODULE_USAGE_PARAM_INT('l', 10000, -1, 100000, "Limit number of iterations until the program exits (-1=infinite)",

View File

@ -41,6 +41,7 @@
#endif #endif
#include <px4_module.h> #include <px4_module.h>
#include <px4_defines.h>
#include <px4_log.h> #include <px4_log.h>
pthread_mutex_t px4_modules_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t px4_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -88,7 +89,10 @@ void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val
{ {
if (is_optional) { if (is_optional) {
PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description); PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description);
PX4_INFO_RAW(" default: %i\n", default_val);
if (default_val != -1) {
PX4_INFO_RAW(" default: %i\n", default_val);
}
} else { } else {
PX4_INFO_RAW(" -%c <val> %s\n", option_char, description); PX4_INFO_RAW(" -%c <val> %s\n", option_char, description);
@ -100,7 +104,10 @@ void PRINT_MODULE_USAGE_PARAM_FLOAT(char option_char, float default_val, float m
{ {
if (is_optional) { if (is_optional) {
PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description); PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description);
PX4_INFO_RAW(" default: %.1f\n", (double)default_val);
if (PX4_ISFINITE(default_val)) {
PX4_INFO_RAW(" default: %.1f\n", (double)default_val);
}
} else { } else {
PX4_INFO_RAW(" -%c <val> %s\n", option_char, description); PX4_INFO_RAW(" -%c <val> %s\n", option_char, description);

View File

@ -499,7 +499,7 @@ __EXPORT void PRINT_MODULE_USAGE_COMMAND_DESCR(const char *name, const char *des
/** /**
* @brief Prints an integer parameter. * @brief Prints an integer parameter.
* @param option_char The option character. * @param option_char The option character.
* @param default_val The parameter default value. * @param default_val The parameter default value (set to -1 if not applicable).
* @param min_val The parameter minimum value. * @param min_val The parameter minimum value.
* @param max_val The parameter value. * @param max_val The parameter value.
* @param description Pointer to the usage description. * @param description Pointer to the usage description.
@ -511,7 +511,7 @@ __EXPORT void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, in
/** /**
* @brief Prints a float parameter. * @brief Prints a float parameter.
* @note See PRINT_MODULE_USAGE_PARAM_INT(). * @note See PRINT_MODULE_USAGE_PARAM_INT().
* @param default_val The parameter default value. * @param default_val The parameter default value (set to NaN if not applicable).
* @param min_val The parameter minimum value. * @param min_val The parameter minimum value.
* @param max_val The parameter maximum value. * @param max_val The parameter maximum value.
* @param description Pointer to the usage description. Pointer to the usage description. * @param description Pointer to the usage description. Pointer to the usage description.

View File

@ -84,7 +84,7 @@ usage(const char *reason)
PRINT_MODULE_USAGE_PARAM_INT('h', 2000, 0, 3000, "High PWM value in us", true); PRINT_MODULE_USAGE_PARAM_INT('h', 2000, 0, 3000, "High PWM value in us", true);
PRINT_MODULE_USAGE_PARAM_STRING('c', NULL, NULL, "select channels in the form: 1234 (1 digit per channel, 1=first)", PRINT_MODULE_USAGE_PARAM_STRING('c', NULL, NULL, "select channels in the form: 1234 (1 digit per channel, 1=first)",
true); true);
PRINT_MODULE_USAGE_PARAM_INT('m', 0, 0, 4096, "Select channels via bitmask (eg. 0xF, 3)", true); PRINT_MODULE_USAGE_PARAM_INT('m', -1, 0, 4096, "Select channels via bitmask (eg. 0xF, 3)", true);
PRINT_MODULE_USAGE_PARAM_FLAG('a', "Select all channels", true); PRINT_MODULE_USAGE_PARAM_FLAG('a', "Select all channels", true);
} }

View File

@ -139,14 +139,14 @@ $ pwm test -c 13 -p 1200
PRINT_MODULE_USAGE_PARAM_COMMENT("The commands 'failsafe', 'disarmed', 'min', 'max' and 'test' require a PWM value:"); PRINT_MODULE_USAGE_PARAM_COMMENT("The commands 'failsafe', 'disarmed', 'min', 'max' and 'test' require a PWM value:");
PRINT_MODULE_USAGE_PARAM_INT('p', 0, 0, 4000, "PWM value (eg. 1100)", false); PRINT_MODULE_USAGE_PARAM_INT('p', -1, 0, 4000, "PWM value (eg. 1100)", false);
PRINT_MODULE_USAGE_PARAM_COMMENT("The commands 'rate', 'oneshot', 'failsafe', 'disarmed', 'min', 'max', 'test' and 'steps' " PRINT_MODULE_USAGE_PARAM_COMMENT("The commands 'rate', 'oneshot', 'failsafe', 'disarmed', 'min', 'max', 'test' and 'steps' "
"additionally require to specify the channels with one of the following commands:"); "additionally require to specify the channels with one of the following commands:");
PRINT_MODULE_USAGE_PARAM_STRING('c', nullptr, nullptr, "select channels in the form: 1234 (1 digit per channel, 1=first)", PRINT_MODULE_USAGE_PARAM_STRING('c', nullptr, nullptr, "select channels in the form: 1234 (1 digit per channel, 1=first)",
true); true);
PRINT_MODULE_USAGE_PARAM_INT('m', 0, 0, 4096, "Select channels via bitmask (eg. 0xF, 3)", true); PRINT_MODULE_USAGE_PARAM_INT('m', -1, 0, 4096, "Select channels via bitmask (eg. 0xF, 3)", true);
PRINT_MODULE_USAGE_PARAM_INT('g', 0, 0, 10, "Select channels by group (eg. 0, 1, 2. use 'pwm info' to show groups)", PRINT_MODULE_USAGE_PARAM_INT('g', -1, 0, 10, "Select channels by group (eg. 0, 1, 2. use 'pwm info' to show groups)",
true); true);
PRINT_MODULE_USAGE_PARAM_FLAG('a', "Select all channels", true); PRINT_MODULE_USAGE_PARAM_FLAG('a', "Select all channels", true);

View File

@ -87,9 +87,9 @@ $ tune_control play -t 2
PRINT_MODULE_USAGE_NAME("tune_control", "system"); PRINT_MODULE_USAGE_NAME("tune_control", "system");
PRINT_MODULE_USAGE_COMMAND_DESCR("play","Play system tune, tone, or melody"); PRINT_MODULE_USAGE_COMMAND_DESCR("play","Play system tune, tone, or melody");
PRINT_MODULE_USAGE_PARAM_INT('t', 1, 1, 21, "Play predefined system tune", true); PRINT_MODULE_USAGE_PARAM_INT('t', 1, 1, 21, "Play predefined system tune", true);
PRINT_MODULE_USAGE_PARAM_INT('f', 0, 0, 22, "Frequency of tone in Hz (0-22kHz)", true); PRINT_MODULE_USAGE_PARAM_INT('f', -1, 0, 22, "Frequency of tone in Hz (0-22kHz)", true);
PRINT_MODULE_USAGE_PARAM_INT('d', 1, 1, 21, "Duration of tone in us", true); PRINT_MODULE_USAGE_PARAM_INT('d', -1, 1, 21, "Duration of tone in us", true);
PRINT_MODULE_USAGE_PARAM_INT('s', 40, 0, 100, "Strength of tone (0-100)", true); PRINT_MODULE_USAGE_PARAM_INT('s', 40, 0, 100, "Strength of tone (0-100)", true);
PRINT_MODULE_USAGE_PARAM_STRING('m', nullptr, R"(<string> - e.g. "MFT200e8a8a")", PRINT_MODULE_USAGE_PARAM_STRING('m', nullptr, R"(<string> - e.g. "MFT200e8a8a")",
"Melody in string form", true); "Melody in string form", true);