mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
i2c drivers: add '-k' flag for keep_running directly to BusCLIArguments
This commit is contained in:
@@ -151,6 +151,12 @@ class ModuleDocumentation(object):
|
|||||||
self._handle_usage_param_int(['\'a\'', args[0], '0', '0xff', "\"I2C address\"", 'true'])
|
self._handle_usage_param_int(['\'a\'', args[0], '0', '0xff', "\"I2C address\"", 'true'])
|
||||||
self._paring_implicit_options = False
|
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):
|
def _handle_usage_param_flag(self, args):
|
||||||
assert(len(args) == 3) # option_char, description, is_optional
|
assert(len(args) == 3) # option_char, description, is_optional
|
||||||
option_char = self._get_option_char(args[0])
|
option_char = self._get_option_char(args[0])
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
board_adc start
|
board_adc start
|
||||||
|
|
||||||
# Start Digital power monitors
|
# 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
|
voxlpm -X -b 3 -T P5VDC start
|
||||||
|
|
||||||
# Internal SPI bus ICM-20602
|
# Internal SPI bus ICM-20602
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
|
|||||||
*(p++) = 'm'; *(p++) = ':'; // spi mode
|
*(p++) = 'm'; *(p++) = ':'; // spi mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (support_keep_running) {
|
||||||
|
*(p++) = 'k';
|
||||||
|
}
|
||||||
|
|
||||||
*(p++) = 'b'; *(p++) = ':'; // bus
|
*(p++) = 'b'; *(p++) = ':'; // bus
|
||||||
*(p++) = 'f'; *(p++) = ':'; // frequency
|
*(p++) = 'f'; *(p++) = ':'; // frequency
|
||||||
*(p++) = 'q'; // quiet flag
|
*(p++) = 'q'; // quiet flag
|
||||||
@@ -163,6 +167,14 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
|
|||||||
quiet_start = true;
|
quiet_start = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'k':
|
||||||
|
if (!support_keep_running) {
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_running = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (ch == '?') {
|
if (ch == '?') {
|
||||||
// abort further parsing on unknown arguments
|
// abort further parsing on unknown arguments
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ public:
|
|||||||
spi_mode_e spi_mode{SPIDEV_MODE3};
|
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
|
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 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_*
|
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_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]
|
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:
|
private:
|
||||||
bool validateConfiguration();
|
bool validateConfiguration();
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
__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(). */
|
/** @note Each of the PRINT_MODULE_USAGE_PARAM_* methods apply to the previous PRINT_MODULE_USAGE_COMMAND_DESCR(). */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
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,
|
void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val,
|
||||||
const char *description, bool is_optional)
|
const char *description, bool is_optional)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ LPS33HW::print_usage()
|
|||||||
PRINT_MODULE_USAGE_COMMAND("start");
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, true);
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, true);
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x5D);
|
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();
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst
|
|||||||
return nullptr;
|
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) {
|
if (dev == nullptr) {
|
||||||
delete interface;
|
delete interface;
|
||||||
@@ -96,22 +96,14 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst
|
|||||||
|
|
||||||
extern "C" int lps33hw_main(int argc, char *argv[])
|
extern "C" int lps33hw_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch;
|
|
||||||
using ThisDriver = LPS33HW;
|
using ThisDriver = LPS33HW;
|
||||||
BusCLIArguments cli{true, true};
|
BusCLIArguments cli{true, true};
|
||||||
cli.i2c_address = 0x5D;
|
cli.i2c_address = 0x5D;
|
||||||
cli.default_i2c_frequency = 400000;
|
cli.default_i2c_frequency = 400000;
|
||||||
cli.default_spi_frequency = 10 * 1000 * 1000;
|
cli.default_spi_frequency = 10 * 1000 * 1000;
|
||||||
|
cli.support_keep_running = true;
|
||||||
|
|
||||||
while ((ch = cli.getopt(argc, argv, "k")) != EOF) {
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
switch (ch) {
|
|
||||||
case 'k': // keep retrying
|
|
||||||
cli.custom1 = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *verb = cli.optarg();
|
|
||||||
|
|
||||||
if (!verb) {
|
if (!verb) {
|
||||||
ThisDriver::print_usage();
|
ThisDriver::print_usage();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ I2CSPIDriverBase *SDP3X::instantiate(const BusCLIArguments &cli, const BusInstan
|
|||||||
int runtime_instance)
|
int runtime_instance)
|
||||||
{
|
{
|
||||||
SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address,
|
SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address,
|
||||||
cli.custom1 == 1);
|
cli.keep_running);
|
||||||
|
|
||||||
if (instance == nullptr) {
|
if (instance == nullptr) {
|
||||||
PX4_ERR("alloc failed");
|
PX4_ERR("alloc failed");
|
||||||
@@ -64,28 +64,20 @@ SDP3X::print_usage()
|
|||||||
PRINT_MODULE_USAGE_COMMAND("start");
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x21);
|
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();
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sdp3x_airspeed_main(int argc, char *argv[])
|
sdp3x_airspeed_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch;
|
|
||||||
using ThisDriver = SDP3X;
|
using ThisDriver = SDP3X;
|
||||||
BusCLIArguments cli{true, false};
|
BusCLIArguments cli{true, false};
|
||||||
cli.default_i2c_frequency = 100000;
|
cli.default_i2c_frequency = 100000;
|
||||||
cli.i2c_address = I2C_ADDRESS_1_SDP3X;
|
cli.i2c_address = I2C_ADDRESS_1_SDP3X;
|
||||||
|
cli.support_keep_running = true;
|
||||||
|
|
||||||
while ((ch = cli.getopt(argc, argv, "k")) != EOF) {
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
switch (ch) {
|
|
||||||
case 'k': // keep retrying
|
|
||||||
cli.custom1 = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *verb = cli.optarg();
|
|
||||||
|
|
||||||
if (!verb) {
|
if (!verb) {
|
||||||
ThisDriver::print_usage();
|
ThisDriver::print_usage();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ I2CSPIDriverBase *INA226::instantiate(const BusCLIArguments &cli, const BusInsta
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cli.custom1 == 1) {
|
if (cli.keep_running) {
|
||||||
if (instance->force_init() != PX4_OK) {
|
if (instance->force_init() != PX4_OK) {
|
||||||
PX4_INFO("Failed to init INA226 on bus %d, but will try again periodically.", iterator.bus());
|
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_COMMAND("start");
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x41);
|
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_PARAM_INT('t', 1, 1, 2, "battery index for calibration values (1 or 2)", true);
|
||||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
}
|
||||||
@@ -65,14 +65,11 @@ ina226_main(int argc, char *argv[])
|
|||||||
BusCLIArguments cli{true, false};
|
BusCLIArguments cli{true, false};
|
||||||
cli.i2c_address = INA226_BASEADDR;
|
cli.i2c_address = INA226_BASEADDR;
|
||||||
cli.default_i2c_frequency = 100000;
|
cli.default_i2c_frequency = 100000;
|
||||||
|
cli.support_keep_running = true;
|
||||||
cli.custom2 = 1;
|
cli.custom2 = 1;
|
||||||
|
|
||||||
while ((ch = cli.getopt(argc, argv, "kt:")) != EOF) {
|
while ((ch = cli.getopt(argc, argv, "t:")) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'k': // keep retrying
|
|
||||||
cli.custom1 = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't': // battery index
|
case 't': // battery index
|
||||||
cli.custom2 = (int)strtol(cli.optarg(), NULL, 0);
|
cli.custom2 = (int)strtol(cli.optarg(), NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ I2CSPIDriverBase *VOXLPM::instantiate(const BusCLIArguments &cli, const BusInsta
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cli.custom1 == 1) {
|
if (cli.keep_running) {
|
||||||
if (OK != instance->force_init()) {
|
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,
|
PX4_INFO("Failed to init voxlpm type: %d on bus: %d, but will try again periodically.", (VOXLPM_CH_TYPE)cli.type,
|
||||||
iterator.bus());
|
iterator.bus());
|
||||||
@@ -69,7 +69,7 @@ VOXLPM::print_usage()
|
|||||||
PRINT_MODULE_USAGE_COMMAND("start");
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
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_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();
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +81,9 @@ voxlpm_main(int argc, char *argv[])
|
|||||||
BusCLIArguments cli{true, false};
|
BusCLIArguments cli{true, false};
|
||||||
cli.default_i2c_frequency = 400000;
|
cli.default_i2c_frequency = 400000;
|
||||||
cli.type = VOXLPM_CH_TYPE_VBATT;
|
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) {
|
switch (ch) {
|
||||||
case 'T':
|
case 'T':
|
||||||
if (strcmp(cli.optarg(), "VBATT") == 0) {
|
if (strcmp(cli.optarg(), "VBATT") == 0) {
|
||||||
@@ -100,10 +101,6 @@ voxlpm_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'K': // keep retrying
|
|
||||||
cli.custom1 = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user