Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

param command updates (change show default and add status) #11200

Merged
merged 2 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/lib/parameters/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ __EXPORT int param_load(int fd);
* @param arg Argument passed to the function.
* @param only_changed If true, the function is only called for parameters whose values have
* been changed from the default.
* @param only_changed If true, the function is only called for parameters which have been
* @param only_used If true, the function is only called for parameters which have been
* used in one of the running applications.
*/
__EXPORT void param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed, bool only_used);
Expand Down Expand Up @@ -397,6 +397,11 @@ __EXPORT int param_load_default(void);
*/
__EXPORT uint32_t param_hash_check(void);

/**
* Print the status of the param system
*
*/
__EXPORT void param_print_status(void);

/**
* Enable/disable the param autosaving.
Expand Down
50 changes: 42 additions & 8 deletions src/lib/parameters/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@
#include <math.h>

#include <drivers/drv_hrt.h>
#include <lib/perf/perf_counter.h>
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_posix.h>
#include <px4_sem.h>
#include <px4_shutdown.h>

#include <perf/perf_counter.h>
#include <systemlib/uthash/utarray.h>

using namespace time_literals;

//#define PARAM_NO_ORB ///< if defined, avoid uorb dependency. This disables publication of parameter_update on param change
//#define PARAM_NO_AUTOSAVE ///< if defined, do not autosave (avoids LP work queue dependency)

Expand Down Expand Up @@ -91,8 +92,8 @@ static char *param_user_file = nullptr;
#include <px4_workqueue.h>
/* autosaving variables */
static hrt_abstime last_autosave_timestamp = 0;
static struct work_s autosave_work;
static bool autosave_scheduled = false;
static struct work_s autosave_work {};
static volatile bool autosave_scheduled = false;
static bool autosave_disabled = false;
#endif /* PARAM_NO_AUTOSAVE */

Expand Down Expand Up @@ -627,7 +628,7 @@ autosave_worker(void *arg)
int ret = param_save_default();

if (ret != 0) {
PX4_ERR("param save failed (%i)", ret);
PX4_ERR("param auto save failed (%i)", ret);
}
}
#endif /* PARAM_NO_AUTOSAVE */
Expand All @@ -651,10 +652,10 @@ param_autosave()
// - tasks often call param_set() for multiple params, so this avoids unnecessary save calls
// - the logger stores changed params. He gets notified on a param change via uORB and then
// looks at all unsaved params.
hrt_abstime delay = 300 * 1000;
hrt_abstime delay = 300_ms;

const hrt_abstime rate_limit = 2000 * 1000; // rate-limit saving to 2 seconds
hrt_abstime last_save_elapsed = hrt_elapsed_time(&last_autosave_timestamp);
static constexpr const hrt_abstime rate_limit = 2_s; // rate-limit saving to 2 seconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static constexpr const is a bit too much here, no? Does it actually make a difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, in this case it almost certainly not, but I guess the point would be that it's never going to be worse to make something a compile time constant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I was just thinking that it hurts readability a bit.

const hrt_abstime last_save_elapsed = hrt_elapsed_time(&last_autosave_timestamp);

if (last_save_elapsed < rate_limit && rate_limit > last_save_elapsed + delay) {
delay = rate_limit - last_save_elapsed;
Expand Down Expand Up @@ -1371,3 +1372,36 @@ uint32_t param_hash_check()

return param_hash;
}

void param_print_status()
{
PX4_INFO("summary: %d/%d (used/total)", param_count_used(), param_count());

#ifndef FLASH_BASED_PARAMS
dagar marked this conversation as resolved.
Show resolved Hide resolved
const char *filename = param_get_default_file();

if (filename != nullptr) {
PX4_INFO("file: %s", param_get_default_file());
}

#endif /* FLASH_BASED_PARAMS */

if (param_values != nullptr) {
PX4_INFO("storage array: %d/%d elements (%zu bytes total)",
utarray_len(param_values), param_values->n, param_values->n * sizeof(UT_icd));
}

#ifndef PARAM_NO_AUTOSAVE
PX4_INFO("auto save: %s", autosave_disabled ? "off" : "on");

if (!autosave_disabled && (last_autosave_timestamp > 0)) {
PX4_INFO("last auto save: %.3f seconds ago", hrt_elapsed_time(&last_autosave_timestamp) * 1e-6);
}

#endif /* PARAM_NO_AUTOSAVE */

perf_print_counter(param_export_perf);
perf_print_counter(param_find_perf);
perf_print_counter(param_get_perf);
perf_print_counter(param_set_perf);
}
33 changes: 33 additions & 0 deletions src/lib/parameters/parameters_shmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,39 @@ uint32_t param_hash_check()
return param_hash;
}

void param_print_status()
{
PX4_INFO("summary: %d/%d (used/total)", param_count_used(), param_count());

#ifndef FLASH_BASED_PARAMS
const char *filename = param_get_default_file();

if (filename != nullptr) {
PX4_INFO("file: %s", param_get_default_file());
}

#endif /* FLASH_BASED_PARAMS */

if (param_values != nullptr) {
PX4_INFO("storage array: %d/%d elements (%zu bytes total)",
utarray_len(param_values), param_values->n, param_values->n * sizeof(UT_icd));
}

#ifndef PARAM_NO_AUTOSAVE
PX4_INFO("auto save: %s", autosave_disabled ? "off" : "on");

if (!autosave_disabled && (last_autosave_timestamp > 0)) {
PX4_INFO("last auto save: %.3f seconds ago", hrt_elapsed_time(&last_autosave_timestamp) * 1e-6);
}

#endif /* PARAM_NO_AUTOSAVE */

perf_print_counter(param_export_perf);
perf_print_counter(param_find_perf);
perf_print_counter(param_get_perf);
perf_print_counter(param_set_perf);
}

void init_params()
{
#ifdef __PX4_QURT
Expand Down
27 changes: 25 additions & 2 deletions src/systemcmds/param/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static int do_save_default();
static int do_load(const char *param_file_name);
static int do_import(const char *param_file_name);
static int do_show(const char *search_string, bool only_changed);
static int do_show_all();
static int do_show_quiet(const char *param_name);
static int do_show_index(const char *index, bool used_index);
static void do_show_print(void *arg, param_t param);
Expand Down Expand Up @@ -130,10 +131,13 @@ Change the airframe and make sure the airframe's default parameters are loaded:
PRINT_MODULE_USAGE_ARG("<file>", "File name (use <root>/eeprom/parameters if not given)", true);

PRINT_MODULE_USAGE_COMMAND_DESCR("show", "Show parameter values");
PRINT_MODULE_USAGE_PARAM_FLAG('c', "Show only changed params", true);
PRINT_MODULE_USAGE_PARAM_FLAG('a', "Show all parameters (not just used)", true);
PRINT_MODULE_USAGE_PARAM_FLAG('c', "Show only changed and used params", true);
PRINT_MODULE_USAGE_PARAM_FLAG('q', "quiet mode, print only param value (name needs to be exact)", true);
PRINT_MODULE_USAGE_ARG("<filter>", "Filter by param name (wildcard at end allowed, eg. sys_*)", true);

PRINT_MODULE_USAGE_COMMAND_DESCR("status", "Print status of parameter system");

PRINT_MODULE_USAGE_COMMAND_DESCR("set", "Set parameter to a value");
PRINT_MODULE_USAGE_ARG("<param_name> <value>", "Parameter name and value to set", false);
PRINT_MODULE_USAGE_ARG("fail", "If provided, let the command fail if param is not found", true);
Expand Down Expand Up @@ -227,6 +231,9 @@ param_main(int argc, char *argv[])
return do_show(nullptr, true);
}

} else if (!strcmp(argv[2], "-a")) {
return do_show_all();

} else if (!strcmp(argv[2], "-q")) {
if (argc >= 4) {
return do_show_quiet(argv[3]);
Expand All @@ -240,6 +247,11 @@ param_main(int argc, char *argv[])
}
}

if (!strcmp(argv[1], "status")) {
param_print_status();
return PX4_OK;
}

if (!strcmp(argv[1], "set")) {
if (argc >= 5) {

Expand Down Expand Up @@ -426,11 +438,22 @@ static int
do_show(const char *search_string, bool only_changed)
{
PARAM_PRINT("Symbols: x = used, + = saved, * = unsaved\n");
param_foreach(do_show_print, (char *)search_string, only_changed, false);
param_foreach(do_show_print, (char *)search_string, only_changed, true);
PARAM_PRINT("\n %u/%u parameters used.\n", param_count_used(), param_count());

return 0;
}

static int
do_show_all()
{
PARAM_PRINT("Symbols: x = used, + = saved, * = unsaved\n");
param_foreach(do_show_print, nullptr, false, false);
PARAM_PRINT("\n %u parameters total, %u used.\n", param_count(), param_count_used());

return 0;
}

static int
do_show_quiet(const char *param_name)
{
Expand Down