Browse Source

param add status

sbg
Daniel Agar 6 years ago
parent
commit
658d734068
  1. 5
      src/lib/parameters/param.h
  2. 50
      src/lib/parameters/parameters.cpp
  3. 33
      src/lib/parameters/parameters_shmem.cpp
  4. 7
      src/systemcmds/param/param.cpp

5
src/lib/parameters/param.h

@ -397,6 +397,11 @@ __EXPORT int param_load_default(void);
*/ */
__EXPORT uint32_t param_hash_check(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. * Enable/disable the param autosaving.

50
src/lib/parameters/parameters.cpp

@ -50,15 +50,16 @@
#include <math.h> #include <math.h>
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <lib/perf/perf_counter.h>
#include <px4_config.h> #include <px4_config.h>
#include <px4_defines.h> #include <px4_defines.h>
#include <px4_posix.h> #include <px4_posix.h>
#include <px4_sem.h> #include <px4_sem.h>
#include <px4_shutdown.h> #include <px4_shutdown.h>
#include <perf/perf_counter.h>
#include <systemlib/uthash/utarray.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_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) //#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> #include <px4_workqueue.h>
/* autosaving variables */ /* autosaving variables */
static hrt_abstime last_autosave_timestamp = 0; static hrt_abstime last_autosave_timestamp = 0;
static struct work_s autosave_work; static struct work_s autosave_work {};
static bool autosave_scheduled = false; static volatile bool autosave_scheduled = false;
static bool autosave_disabled = false; static bool autosave_disabled = false;
#endif /* PARAM_NO_AUTOSAVE */ #endif /* PARAM_NO_AUTOSAVE */
@ -627,7 +628,7 @@ autosave_worker(void *arg)
int ret = param_save_default(); int ret = param_save_default();
if (ret != 0) { if (ret != 0) {
PX4_ERR("param save failed (%i)", ret); PX4_ERR("param auto save failed (%i)", ret);
} }
} }
#endif /* PARAM_NO_AUTOSAVE */ #endif /* PARAM_NO_AUTOSAVE */
@ -651,10 +652,10 @@ param_autosave()
// - tasks often call param_set() for multiple params, so this avoids unnecessary save calls // - 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 // - the logger stores changed params. He gets notified on a param change via uORB and then
// looks at all unsaved params. // 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 static constexpr const hrt_abstime rate_limit = 2_s; // rate-limit saving to 2 seconds
hrt_abstime last_save_elapsed = hrt_elapsed_time(&last_autosave_timestamp); const hrt_abstime last_save_elapsed = hrt_elapsed_time(&last_autosave_timestamp);
if (last_save_elapsed < rate_limit && rate_limit > last_save_elapsed + delay) { if (last_save_elapsed < rate_limit && rate_limit > last_save_elapsed + delay) {
delay = rate_limit - last_save_elapsed; delay = rate_limit - last_save_elapsed;
@ -1371,3 +1372,36 @@ uint32_t param_hash_check()
return param_hash; 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
src/lib/parameters/parameters_shmem.cpp

@ -1479,6 +1479,39 @@ uint32_t param_hash_check()
return param_hash; 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() void init_params()
{ {
#ifdef __PX4_QURT #ifdef __PX4_QURT

7
src/systemcmds/param/param.cpp

@ -136,6 +136,8 @@ $ reboot
PRINT_MODULE_USAGE_PARAM_FLAG('q', "quiet mode, print only param value (name needs to be exact)", 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_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_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("<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); 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 (!strcmp(argv[1], "set")) {
if (argc >= 5) { if (argc >= 5) {

Loading…
Cancel
Save