2017-04-27 12:00:03 -03:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 PX4 Development Team. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file module.cpp
|
|
|
|
* Implementation of the API declared in px4_module.h.
|
|
|
|
*/
|
|
|
|
|
2019-01-30 11:54:53 -04:00
|
|
|
#ifndef MODULE_NAME
|
|
|
|
#define MODULE_NAME "module"
|
|
|
|
#endif
|
|
|
|
|
2019-10-25 05:56:32 -03:00
|
|
|
#include <px4_platform_common/module.h>
|
|
|
|
#include <px4_platform_common/defines.h>
|
|
|
|
#include <px4_platform_common/log.h>
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
pthread_mutex_t px4_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
#ifndef __PX4_NUTTX
|
|
|
|
|
|
|
|
void PRINT_MODULE_DESCRIPTION(const char *description)
|
|
|
|
{
|
2017-05-02 11:06:58 -03:00
|
|
|
// TODO: the output could be improved by:
|
|
|
|
// - mark titles in bold (lines starting with ##)
|
|
|
|
// - highlight commands (lines starting with $, or `cmd`)
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("%s\n\n", description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __PX4_NUTTX */
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_NAME(const char *executable_name, const char *category)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("Usage: %s <command> [arguments...]\n", executable_name);
|
|
|
|
PX4_INFO_RAW(" Commands:\n");
|
2021-07-14 18:49:37 -03:00
|
|
|
#else
|
|
|
|
PX4_INFO_RAW("Usage: %s See:" CONSTRAINED_FLASH_NO_HELP "\n", executable_name);
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
2019-01-31 02:18:58 -04:00
|
|
|
void PRINT_MODULE_USAGE_SUBCATEGORY(const char *subcategory)
|
|
|
|
{
|
|
|
|
(void)subcategory;
|
|
|
|
}
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
void PRINT_MODULE_USAGE_NAME_SIMPLE(const char *executable_name, const char *category)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("Usage: %s [arguments...]\n", executable_name);
|
2021-07-14 18:49:37 -03:00
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_COMMAND_DESCR(const char *name, const char *description)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (description) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("\n %-13s %s\n", name, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("\n %s\n", name);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_PARAM_COMMENT(const char *comment)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW("\n %s\n", comment);
|
2021-07-14 18:49:37 -03:00
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
2020-02-29 04:43:11 -04:00
|
|
|
void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool spi_support)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2020-02-29 04:43:11 -04:00
|
|
|
// Note: this must be kept in sync with Tools/px4moduledoc/srcparser.py
|
|
|
|
if (i2c_support) {
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('I', "Internal I2C bus(es)", true);
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('X', "External I2C bus(es)", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spi_support) {
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('s', "Internal SPI bus(es)", true);
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('S', "External SPI bus", true);
|
|
|
|
}
|
|
|
|
|
2020-09-03 08:19:54 -03:00
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('b', -1, 0, 16, "board-specific bus (default=all) (external SPI: n-th bus (default=1))",
|
2020-02-29 04:43:11 -04:00
|
|
|
true);
|
|
|
|
|
|
|
|
if (spi_support) {
|
2021-11-15 07:09:35 -04:00
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('c', -1, 0, 31, "chip-select pin (for internal SPI) or index (for external SPI)", true);
|
2020-02-29 04:43:11 -04:00
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('m', -1, 0, 3, "SPI mode", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('f', -1, 0, 100000, "bus frequency in kHz", true);
|
2020-08-26 03:46:35 -03:00
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('q', "quiet startup (no message if no device found)", true);
|
2021-07-14 18:49:37 -03:00
|
|
|
#endif
|
2020-02-29 04:43:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
2020-02-29 04:43:11 -04:00
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('a', default_address, 0, 0xff, "I2C address", true);
|
2021-07-14 18:49:37 -03:00
|
|
|
#endif
|
2020-02-29 04:43:11 -04:00
|
|
|
}
|
|
|
|
|
2020-09-18 05:18:40 -03:00
|
|
|
void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG()
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
2020-09-18 05:18:40 -03:00
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true);
|
2021-07-14 18:49:37 -03:00
|
|
|
#endif
|
2020-09-18 05:18:40 -03:00
|
|
|
}
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val,
|
|
|
|
const char *description, bool is_optional)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (is_optional) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description);
|
2019-01-31 02:17:45 -04:00
|
|
|
|
|
|
|
if (default_val != -1) {
|
|
|
|
PX4_INFO_RAW(" default: %i\n", default_val);
|
|
|
|
}
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" -%c <val> %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_PARAM_FLOAT(char option_char, float default_val, float min_val, float max_val,
|
|
|
|
const char *description, bool is_optional)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (is_optional) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description);
|
2019-01-31 02:17:45 -04:00
|
|
|
|
|
|
|
if (PX4_ISFINITE(default_val)) {
|
|
|
|
PX4_INFO_RAW(" default: %.1f\n", (double)default_val);
|
|
|
|
}
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" -%c <val> %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_PARAM_FLAG(char option_char, const char *description, bool is_optional)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (is_optional) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" [-%c] %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" -%c %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_PARAM_STRING(char option_char, const char *default_val, const char *values,
|
|
|
|
const char *description, bool is_optional)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (is_optional) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" [-%c <val>] %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" -%c <val> %s\n", option_char, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (values) {
|
|
|
|
if (default_val) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" values: %s, default: %s\n", values, default_val);
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" values: %s\n", values);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (default_val) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" default: %s\n", default_val);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PRINT_MODULE_USAGE_ARG(const char *values, const char *description, bool is_optional)
|
|
|
|
{
|
2021-07-14 18:49:37 -03:00
|
|
|
#ifndef CONSTRAINED_FLASH_NO_HELP
|
|
|
|
|
2017-04-27 12:00:03 -03:00
|
|
|
if (is_optional) {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" [%-9s] %s\n", values, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
|
|
|
|
} else {
|
2018-08-06 03:12:50 -03:00
|
|
|
PX4_INFO_RAW(" %-11s %s\n", values, description);
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
2021-07-14 18:49:37 -03:00
|
|
|
|
|
|
|
#endif
|
2017-04-27 12:00:03 -03:00
|
|
|
}
|
|
|
|
|