diff --git a/Tools/px4moduledoc/srcparser.py b/Tools/px4moduledoc/srcparser.py index f962e3da3b..1f42123b4c 100644 --- a/Tools/px4moduledoc/srcparser.py +++ b/Tools/px4moduledoc/srcparser.py @@ -151,6 +151,12 @@ class ModuleDocumentation(object): self._handle_usage_param_int(['\'a\'', args[0], '0', '0xff', "\"I2C address\"", 'true']) self._paring_implicit_options = False + def _handle_usage_params_i2c_keep_running_flag(self, args): + assert(len(args) == 0) + self._paring_implicit_options = True + self._handle_usage_param_flag(['\'k\'', "\"if initialization (probing) fails, keep retrying periodically\"", 'true']) + self._paring_implicit_options = False + def _handle_usage_param_flag(self, args): assert(len(args) == 3) # option_char, description, is_optional option_char = self._get_option_char(args[0]) diff --git a/boards/modalai/fc-v1/init/rc.board_sensors b/boards/modalai/fc-v1/init/rc.board_sensors index d99330afd7..8261c9b5c2 100644 --- a/boards/modalai/fc-v1/init/rc.board_sensors +++ b/boards/modalai/fc-v1/init/rc.board_sensors @@ -6,7 +6,7 @@ board_adc start # Start Digital power monitors -voxlpm -X -b 3 -K -T VBATT start +voxlpm -X -b 3 -k -T VBATT start voxlpm -X -b 3 -T P5VDC start # Internal SPI bus ICM-20602 diff --git a/platforms/common/i2c_spi_buses.cpp b/platforms/common/i2c_spi_buses.cpp index 6b887d6c2b..c738b068fb 100644 --- a/platforms/common/i2c_spi_buses.cpp +++ b/platforms/common/i2c_spi_buses.cpp @@ -84,6 +84,10 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options) *(p++) = 'm'; *(p++) = ':'; // spi mode } + if (support_keep_running) { + *(p++) = 'k'; + } + *(p++) = 'b'; *(p++) = ':'; // bus *(p++) = 'f'; *(p++) = ':'; // frequency *(p++) = 'q'; // quiet flag @@ -163,6 +167,14 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options) quiet_start = true; break; + case 'k': + if (!support_keep_running) { + return ch; + } + + keep_running = true; + break; + default: if (ch == '?') { // abort further parsing on unknown arguments diff --git a/platforms/common/include/px4_platform_common/i2c_spi_buses.h b/platforms/common/include/px4_platform_common/i2c_spi_buses.h index d492e0b0a9..b3a6f7c72e 100644 --- a/platforms/common/include/px4_platform_common/i2c_spi_buses.h +++ b/platforms/common/include/px4_platform_common/i2c_spi_buses.h @@ -110,6 +110,7 @@ public: spi_mode_e spi_mode{SPIDEV_MODE3}; uint8_t i2c_address{0}; ///< optional I2C address: a driver can set this to allow configuring the I2C address bool quiet_start{false}; ///< do not print a message when startup fails + bool keep_running{false}; ///< keep driver running even if no device is detected on startup uint8_t orientation{0}; ///< distance_sensor_s::ROTATION_* @@ -121,6 +122,8 @@ public: int default_spi_frequency{-1}; ///< default spi bus frequency (driver needs to set this) [Hz] int default_i2c_frequency{-1}; ///< default i2c bus frequency (driver needs to set this) [Hz] + bool support_keep_running{false}; ///< true if keep_running (see above) is supported + private: bool validateConfiguration(); diff --git a/platforms/common/include/px4_platform_common/module.h b/platforms/common/include/px4_platform_common/module.h index e55795dc5d..d9e9061365 100644 --- a/platforms/common/include/px4_platform_common/module.h +++ b/platforms/common/include/px4_platform_common/module.h @@ -513,6 +513,11 @@ __EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool sp */ __EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address); +/** + * -k flag + */ +__EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(void); + /** @note Each of the PRINT_MODULE_USAGE_PARAM_* methods apply to the previous PRINT_MODULE_USAGE_COMMAND_DESCR(). */ /** diff --git a/platforms/common/module.cpp b/platforms/common/module.cpp index f4e489542c..3ca0b6a748 100644 --- a/platforms/common/module.cpp +++ b/platforms/common/module.cpp @@ -119,6 +119,11 @@ void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address) PRINT_MODULE_USAGE_PARAM_INT('a', default_address, 0, 0xff, "I2C address", true); } +void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG() +{ + PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true); +} + void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val, const char *description, bool is_optional) { diff --git a/src/drivers/barometer/lps33hw/lps33hw_main.cpp b/src/drivers/barometer/lps33hw/lps33hw_main.cpp index 3f81ed4bef..168b0562f3 100644 --- a/src/drivers/barometer/lps33hw/lps33hw_main.cpp +++ b/src/drivers/barometer/lps33hw/lps33hw_main.cpp @@ -52,7 +52,7 @@ LPS33HW::print_usage() PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, true); PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x5D); - PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true); + PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } @@ -79,7 +79,7 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst return nullptr; } - LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.custom1 == 1); + LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.keep_running); if (dev == nullptr) { delete interface; @@ -96,22 +96,14 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst extern "C" int lps33hw_main(int argc, char *argv[]) { - int ch; using ThisDriver = LPS33HW; BusCLIArguments cli{true, true}; cli.i2c_address = 0x5D; cli.default_i2c_frequency = 400000; cli.default_spi_frequency = 10 * 1000 * 1000; + cli.support_keep_running = true; - while ((ch = cli.getopt(argc, argv, "k")) != EOF) { - switch (ch) { - case 'k': // keep retrying - cli.custom1 = 1; - break; - } - } - - const char *verb = cli.optarg(); + const char *verb = cli.parseDefaultArguments(argc, argv); if (!verb) { ThisDriver::print_usage(); diff --git a/src/drivers/differential_pressure/sdp3x/SDP3X_main.cpp b/src/drivers/differential_pressure/sdp3x/SDP3X_main.cpp index 73fc521368..c24e5b6bd2 100644 --- a/src/drivers/differential_pressure/sdp3x/SDP3X_main.cpp +++ b/src/drivers/differential_pressure/sdp3x/SDP3X_main.cpp @@ -39,7 +39,7 @@ I2CSPIDriverBase *SDP3X::instantiate(const BusCLIArguments &cli, const BusInstan int runtime_instance) { SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address, - cli.custom1 == 1); + cli.keep_running); if (instance == nullptr) { PX4_ERR("alloc failed"); @@ -64,28 +64,20 @@ SDP3X::print_usage() PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x21); - PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true); + PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } int sdp3x_airspeed_main(int argc, char *argv[]) { - int ch; using ThisDriver = SDP3X; BusCLIArguments cli{true, false}; cli.default_i2c_frequency = 100000; cli.i2c_address = I2C_ADDRESS_1_SDP3X; + cli.support_keep_running = true; - while ((ch = cli.getopt(argc, argv, "k")) != EOF) { - switch (ch) { - case 'k': // keep retrying - cli.custom1 = 1; - break; - } - } - - const char *verb = cli.optarg(); + const char *verb = cli.parseDefaultArguments(argc, argv); if (!verb) { ThisDriver::print_usage(); diff --git a/src/drivers/power_monitor/ina226/ina226_main.cpp b/src/drivers/power_monitor/ina226/ina226_main.cpp index c2471ce484..045a2568f5 100644 --- a/src/drivers/power_monitor/ina226/ina226_main.cpp +++ b/src/drivers/power_monitor/ina226/ina226_main.cpp @@ -15,7 +15,7 @@ I2CSPIDriverBase *INA226::instantiate(const BusCLIArguments &cli, const BusInsta return nullptr; } - if (cli.custom1 == 1) { + if (cli.keep_running) { if (instance->force_init() != PX4_OK) { PX4_INFO("Failed to init INA226 on bus %d, but will try again periodically.", iterator.bus()); } @@ -52,7 +52,7 @@ this flag set, the battery must be plugged in before starting the driver. PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x41); - PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true); + PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(); PRINT_MODULE_USAGE_PARAM_INT('t', 1, 1, 2, "battery index for calibration values (1 or 2)", true); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } @@ -65,14 +65,11 @@ ina226_main(int argc, char *argv[]) BusCLIArguments cli{true, false}; cli.i2c_address = INA226_BASEADDR; cli.default_i2c_frequency = 100000; + cli.support_keep_running = true; cli.custom2 = 1; - while ((ch = cli.getopt(argc, argv, "kt:")) != EOF) { + while ((ch = cli.getopt(argc, argv, "t:")) != EOF) { switch (ch) { - case 'k': // keep retrying - cli.custom1 = 1; - break; - case 't': // battery index cli.custom2 = (int)strtol(cli.optarg(), NULL, 0); break; diff --git a/src/drivers/power_monitor/voxlpm/voxlpm_main.cpp b/src/drivers/power_monitor/voxlpm/voxlpm_main.cpp index 14d81375a0..1d26cc2e62 100644 --- a/src/drivers/power_monitor/voxlpm/voxlpm_main.cpp +++ b/src/drivers/power_monitor/voxlpm/voxlpm_main.cpp @@ -47,7 +47,7 @@ I2CSPIDriverBase *VOXLPM::instantiate(const BusCLIArguments &cli, const BusInsta return nullptr; } - if (cli.custom1 == 1) { + if (cli.keep_running) { if (OK != instance->force_init()) { PX4_INFO("Failed to init voxlpm type: %d on bus: %d, but will try again periodically.", (VOXLPM_CH_TYPE)cli.type, iterator.bus()); @@ -69,7 +69,7 @@ VOXLPM::print_usage() PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); PRINT_MODULE_USAGE_PARAM_STRING('T', "VBATT", "VBATT|P5VDC|P12VDC", "Type", true); - PRINT_MODULE_USAGE_PARAM_FLAG('K', "if initialization (probing) fails, keep retrying periodically", true); + PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } @@ -81,8 +81,9 @@ voxlpm_main(int argc, char *argv[]) BusCLIArguments cli{true, false}; cli.default_i2c_frequency = 400000; cli.type = VOXLPM_CH_TYPE_VBATT; + cli.support_keep_running = true; - while ((ch = cli.getopt(argc, argv, "KT:")) != EOF) { + while ((ch = cli.getopt(argc, argv, "T:")) != EOF) { switch (ch) { case 'T': if (strcmp(cli.optarg(), "VBATT") == 0) { @@ -100,10 +101,6 @@ voxlpm_main(int argc, char *argv[]) } break; - - case 'K': // keep retrying - cli.custom1 = 1; - break; } }