From 3a43038583c1b863fd85b3043afbc6208406bf3a Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 22 Jan 2016 11:35:56 +0100 Subject: [PATCH] Params: Provide set and save API --- src/modules/systemlib/param/param.c | 29 +++++++++++++++++++---------- src/modules/systemlib/param/param.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index f606f20702..dd5c30b667 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -235,9 +235,9 @@ param_find_changed(param_t param) } static void -param_notify_changes(void) +param_notify_changes(bool is_saved) { - struct parameter_update_s pup = { .timestamp = hrt_absolute_time() }; + struct parameter_update_s pup = { .timestamp = hrt_absolute_time(), .saved = is_saved}; /* * If we don't have a handle to our topic, create one now; otherwise @@ -497,7 +497,7 @@ param_get(param_t param, void *val) } static int -param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes) +param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes, bool autosave) { int result = -1; bool params_changed = false; @@ -575,7 +575,7 @@ out: * a thing has been set. */ if (params_changed && notify_changes) { - param_notify_changes(); + param_notify_changes(autosave); } return result; @@ -584,13 +584,19 @@ out: int param_set(param_t param, const void *val) { - return param_set_internal(param, val, false, true); + return param_set_internal(param, val, false, true, false); +} + +int +param_set_no_autosave(param_t param, const void *val) +{ + return param_set_internal(param, val, false, true, true); } int param_set_no_notification(param_t param, const void *val) { - return param_set_internal(param, val, false, false); + return param_set_internal(param, val, false, false, false); } bool @@ -643,7 +649,7 @@ param_reset(param_t param) param_unlock(); if (s != NULL) { - param_notify_changes(); + param_notify_changes(false); } return (!param_found); @@ -663,7 +669,7 @@ param_reset_all(void) param_unlock(); - param_notify_changes(); + param_notify_changes(false); } void @@ -695,7 +701,7 @@ param_reset_excludes(const char *excludes[], int num_excludes) param_unlock(); - param_notify_changes(); + param_notify_changes(false); } static const char *param_default_file = PX4_ROOTFSDIR"/eeprom/parameters"; @@ -851,6 +857,9 @@ param_export(int fd, bool only_unsaved) debug("unrecognized parameter type"); goto out; } + + /* allow this process to be interrupted by another process / thread */ + usleep(5); } result = 0; @@ -955,7 +964,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) goto out; } - if (param_set_internal(param, v, state->mark_saved, true)) { + if (param_set_internal(param, v, state->mark_saved, true, false)) { debug("error setting value for '%s'", node->name); goto out; } diff --git a/src/modules/systemlib/param/param.h b/src/modules/systemlib/param/param.h index f8334361f1..8c49a0b01c 100644 --- a/src/modules/systemlib/param/param.h +++ b/src/modules/systemlib/param/param.h @@ -211,6 +211,16 @@ __EXPORT int param_get(param_t param, void *val); */ __EXPORT int param_set(param_t param, const void *val); +/** + * Set the value of a parameter, but do not trigger an auto-save + * + * @param param A handle returned by param_find or passed by param_foreach. + * @param val The value to set; assumed to point to a variable of the parameter type. + * For structures, the pointer is assumed to point to a structure to be copied. + * @return Zero if the parameter's value could be set from a scalar, nonzero otherwise. + */ +__EXPORT int param_set_no_autosave(param_t param, const void *val); + /** * Set the value of a parameter, but do not notify the system about the change. *