mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-06 11:58:53 +08:00
Make the distinction between "parameter import" which merges parameters, and "parameter load" which blows away any current changes.
This commit is contained in:
@@ -216,7 +216,7 @@ eeprom_load(const char *name)
|
||||
if (fd < 0)
|
||||
err(1, "open '%s'", name);
|
||||
|
||||
int result = param_import(fd);
|
||||
int result = param_load(fd);
|
||||
close(fd);
|
||||
|
||||
if (result < 0)
|
||||
|
||||
@@ -178,6 +178,22 @@ param_find_changed(param_t param) {
|
||||
return s;
|
||||
}
|
||||
|
||||
static void
|
||||
param_notify_changes(void)
|
||||
{
|
||||
struct parameter_update_s pup = { .timestamp = hrt_absolute_time() };
|
||||
|
||||
/*
|
||||
* If we don't have a handle to our topic, create one now; otherwise
|
||||
* just publish.
|
||||
*/
|
||||
if (param_topic == -1) {
|
||||
param_topic = orb_advertise(ORB_ID(parameter_update), &pup);
|
||||
} else {
|
||||
orb_publish(ORB_ID(parameter_update), param_topic, &pup);
|
||||
}
|
||||
}
|
||||
|
||||
param_t
|
||||
param_find(const char *name)
|
||||
{
|
||||
@@ -390,24 +406,50 @@ out:
|
||||
* If we set something, now that we have unlocked, go ahead and advertise that
|
||||
* a thing has been set.
|
||||
*/
|
||||
if (params_changed) {
|
||||
struct parameter_update_s pup = { .timestamp = hrt_absolute_time() };
|
||||
|
||||
/*
|
||||
* If we don't have a handle to our topic, create one now; otherwise
|
||||
* just publish.
|
||||
*/
|
||||
if (param_topic == -1) {
|
||||
param_topic = orb_advertise(ORB_ID(parameter_update), &pup);
|
||||
} else {
|
||||
orb_publish(ORB_ID(parameter_update), param_topic, &pup);
|
||||
}
|
||||
|
||||
}
|
||||
if (params_changed)
|
||||
param_notify_changes();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
param_reset(param_t param)
|
||||
{
|
||||
struct param_wbuf_s *s = NULL;
|
||||
|
||||
param_lock();
|
||||
|
||||
if (handle_in_range(param)) {
|
||||
|
||||
/* look for a saved value */
|
||||
s = param_find_changed(param);
|
||||
|
||||
/* if we found one, erase it */
|
||||
if (s != NULL) {
|
||||
int pos = utarry_eltidx(param_values, s);
|
||||
utarray_erase(param_values, pos, 1);
|
||||
}
|
||||
}
|
||||
param_unlock();
|
||||
|
||||
if (s != NULL)
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
void
|
||||
param_reset_all(void)
|
||||
{
|
||||
param_lock();
|
||||
|
||||
if (param_values != NULL) {
|
||||
utarray_free(param_values);
|
||||
}
|
||||
|
||||
param_unlock();
|
||||
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
int
|
||||
param_export(int fd, bool only_unsaved)
|
||||
{
|
||||
@@ -619,9 +661,17 @@ param_import(int fd)
|
||||
out:
|
||||
if (result < 0)
|
||||
debug("BSON error decoding parameters");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
param_load(int fd)
|
||||
{
|
||||
param_reset_all();
|
||||
return param_import(fd);
|
||||
}
|
||||
|
||||
void
|
||||
param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed)
|
||||
{
|
||||
|
||||
@@ -148,15 +148,31 @@ __EXPORT size_t param_size(param_t param) __attribute__((const));
|
||||
__EXPORT int param_get(param_t param, void *val);
|
||||
|
||||
/**
|
||||
* Set the scalar value of a parameter.
|
||||
* Set the value of a parameter.
|
||||
*
|
||||
* @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 copy of the structure.
|
||||
* 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(param_t param, const void *val);
|
||||
|
||||
/**
|
||||
* Reset a parameter to its default value.
|
||||
*
|
||||
* This function frees any storage used by struct parameters, but scalar parameters
|
||||
*
|
||||
* @param param A handle returned by param_find or passed by param_foreach.
|
||||
*/
|
||||
__EXPORT void param_reset(param_t param);
|
||||
|
||||
/**
|
||||
* Reset all parameters to their default values.
|
||||
*
|
||||
* This function also releases the storage used by struct parameters.
|
||||
*/
|
||||
__EXPORT void param_reset_all(void);
|
||||
|
||||
/**
|
||||
* Export changed parameters to a file.
|
||||
*
|
||||
@@ -169,12 +185,26 @@ __EXPORT int param_export(int fd, bool only_unsaved);
|
||||
/**
|
||||
* Import parameters from a file, discarding any unrecognized parameters.
|
||||
*
|
||||
* This function merges the imported parameters with the current parameter set.
|
||||
*
|
||||
* @param fd File descriptor to import from. (Currently expected to be a file.)
|
||||
* @return Zero on success, nonzero if an error occurred during import.
|
||||
* Note that in the failure case, parameters may be inconsistent.
|
||||
*/
|
||||
__EXPORT int param_import(int fd);
|
||||
|
||||
/**
|
||||
* Load parameters from a file.
|
||||
*
|
||||
* This function resets all parameters to their default values, then loads new
|
||||
* values from a file.
|
||||
*
|
||||
* @param fd File descriptor to import from. (Currently expected to be a file.)
|
||||
* @return Zero on success, nonzero if an error occurred during import.
|
||||
* Note that in the failure case, parameters may be inconsistent.
|
||||
*/
|
||||
__EXPORT int param_load(int fd);
|
||||
|
||||
/**
|
||||
* Apply a function to each parameter.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user