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
Changes from 1 commit
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
Prev Previous commit
param add status
dagar committed Jan 18, 2019
commit 05492cd37cced6e8ad1dd9034e1c2b62518ddcec
5 changes: 5 additions & 0 deletions src/lib/parameters/param.h
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 42 additions & 8 deletions src/lib/parameters/parameters.cpp
Original file line number Diff line number Diff line change
@@ -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)

@@ -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 */

@@ -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 */
@@ -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;
@@ -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
@@ -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
7 changes: 7 additions & 0 deletions src/systemcmds/param/param.cpp
Original file line number Diff line number Diff line change
@@ -136,6 +136,8 @@ Change the airframe and make sure the airframe's default parameters are loaded:
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);
@@ -245,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) {