mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-06 06:43:21 +08:00
Merge branch 'master' of https://github.com/PX4/Firmware
This commit is contained in:
@@ -106,7 +106,9 @@ bson_decoder_next(bson_decoder_t decoder)
|
||||
|
||||
/* if the nesting level is now zero, the top-level document is done */
|
||||
if (decoder->nesting == 0) {
|
||||
CODER_KILL(decoder, "nesting is zero, document is done");
|
||||
/* like kill but not an error */
|
||||
debug("nesting is zero, document is done");
|
||||
decoder->fd = -1;
|
||||
|
||||
/* return end-of-file to the caller */
|
||||
return 0;
|
||||
|
||||
@@ -242,6 +242,25 @@ param_name(param_t param)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
param_value_is_default(param_t param)
|
||||
{
|
||||
return param_find_changed(param) ? false : true;
|
||||
}
|
||||
|
||||
bool
|
||||
param_value_unsaved(param_t param)
|
||||
{
|
||||
static struct param_wbuf_s *s;
|
||||
|
||||
s = param_find_changed(param);
|
||||
|
||||
if (s && s->unsaved)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
enum param_type_e
|
||||
param_type(param_t param)
|
||||
{
|
||||
@@ -330,8 +349,8 @@ param_get(param_t param, void *val)
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
param_set(param_t param, const void *val)
|
||||
static int
|
||||
param_set_internal(param_t param, const void *val, bool mark_saved)
|
||||
{
|
||||
int result = -1;
|
||||
bool params_changed = false;
|
||||
@@ -394,7 +413,7 @@ param_set(param_t param, const void *val)
|
||||
goto out;
|
||||
}
|
||||
|
||||
s->unsaved = true;
|
||||
s->unsaved = !mark_saved;
|
||||
params_changed = true;
|
||||
result = 0;
|
||||
}
|
||||
@@ -412,6 +431,12 @@ out:
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
param_set(param_t param, const void *val)
|
||||
{
|
||||
return param_set_internal(param, val, false);
|
||||
}
|
||||
|
||||
void
|
||||
param_reset(param_t param)
|
||||
{
|
||||
@@ -535,6 +560,11 @@ out:
|
||||
return result;
|
||||
}
|
||||
|
||||
struct param_import_state
|
||||
{
|
||||
bool mark_saved;
|
||||
};
|
||||
|
||||
static int
|
||||
param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
{
|
||||
@@ -542,13 +572,13 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
int32_t i;
|
||||
void *v, *tmp = NULL;
|
||||
int result = -1;
|
||||
struct param_import_state *state = (struct param_import_state *)private;
|
||||
|
||||
/*
|
||||
* EOO means the end of the parameter object. (Currently not supporting
|
||||
* nested BSON objects).
|
||||
*/
|
||||
if (node->type == BSON_EOO) {
|
||||
*(bool *)private = true;
|
||||
debug("end of parameters");
|
||||
return 0;
|
||||
}
|
||||
@@ -621,7 +651,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (param_set(param, v)) {
|
||||
if (param_set_internal(param, v, state->mark_saved)) {
|
||||
debug("error setting value for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
@@ -642,19 +672,19 @@ out:
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
param_import(int fd)
|
||||
static int
|
||||
param_import_internal(int fd, bool mark_saved)
|
||||
{
|
||||
bool done;
|
||||
struct bson_decoder_s decoder;
|
||||
int result = -1;
|
||||
struct param_import_state state;
|
||||
|
||||
if (bson_decoder_init(&decoder, fd, param_import_callback, &done)) {
|
||||
if (bson_decoder_init(&decoder, fd, param_import_callback, &state)) {
|
||||
debug("decoder init failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
done = false;
|
||||
state.mark_saved = mark_saved;
|
||||
|
||||
do {
|
||||
result = bson_decoder_next(&decoder);
|
||||
@@ -668,11 +698,17 @@ out:
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
param_import(int fd)
|
||||
{
|
||||
return param_import_internal(fd, false);
|
||||
}
|
||||
|
||||
int
|
||||
param_load(int fd)
|
||||
{
|
||||
param_reset_all();
|
||||
return param_import(fd);
|
||||
return param_import_internal(fd, true);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -121,6 +121,20 @@ __EXPORT int param_get_index(param_t param);
|
||||
*/
|
||||
__EXPORT const char *param_name(param_t param);
|
||||
|
||||
/**
|
||||
* Test whether a parameter's value has changed from the default.
|
||||
*
|
||||
* @return If true, the parameter's value has not been changed from the default.
|
||||
*/
|
||||
__EXPORT bool param_value_is_default(param_t param);
|
||||
|
||||
/**
|
||||
* Test whether a parameter's value has been changed but not saved.
|
||||
*
|
||||
* @return If true, the parameter's value has not been saved.
|
||||
*/
|
||||
__EXPORT bool param_value_unsaved(param_t param);
|
||||
|
||||
/**
|
||||
* Obtain the type of a parameter.
|
||||
*
|
||||
@@ -160,7 +174,8 @@ __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
|
||||
* This function frees any storage used by struct parameters, and returns the parameter
|
||||
* to its default value.
|
||||
*
|
||||
* @param param A handle returned by param_find or passed by param_foreach.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user