Skip to content

Commit

Permalink
param add status
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Jan 18, 2019
1 parent 3f69fac commit 05492cd
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/lib/parameters/param.h
Original file line number Diff line number Diff line change
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
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
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
7 changes: 7 additions & 0 deletions src/systemcmds/param/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit 05492cd

Please sign in to comment.