45 #include <px4_platform_common/defines.h> 46 #include <px4_platform_common/posix.h> 47 #include <px4_platform_common/shutdown.h> 62 # define debug(fmt, args...) do { warnx(fmt, ##args); } while(0) 64 # define debug(fmt, args...) do { } while(0) 103 if (only_unsaved && !s->
unsaved) {
146 debug(
"unrecognized parameter type");
165 int shutdown_lock_ret = px4_shutdown_lock();
167 if (shutdown_lock_ret) {
168 PX4_ERR(
"px4_shutdown_lock() failed (%i)", shutdown_lock_ret);
186 bool commit = was_result <
OK || was_buf_size != buf_size || 0 != memcmp(was_buffer, enc_buff, was_buf_size);
190 memcpy(buffer, enc_buff, buf_size);
192 result = result == buf_size ?
OK : -EFBIG;
200 if (shutdown_lock_ret == 0) {
201 px4_shutdown_unlock();
218 void *v, *tmp =
nullptr;
227 debug(
"end of parameters");
238 debug(
"ignoring unrecognised parameter '%s'", node->
name);
246 switch (node->
type) {
249 PX4_WARN(
"unexpected type for %s", node->
name);
260 PX4_WARN(
"unexpected type for %s", node->
name);
271 PX4_WARN(
"unexpected type for %s", node->
name);
277 PX4_WARN(
"bad size for '%s'", node->
name);
285 if (tmp ==
nullptr) {
286 debug(
"failed allocating for '%s'", node->
name);
291 debug(
"failed copying data for '%s'", node->
name);
299 debug(
"unrecognised node type");
305 debug(
"error setting value for '%s'", node->
name);
309 if (tmp !=
nullptr) {
319 if (tmp !=
nullptr) {
338 debug(
"decoder init failed");
347 }
while (result > 0);
352 debug(
"BSON error decoding parameters");
__EXPORT param_t param_find_no_notification(const char *name)
Look up a parameter by name.
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
__EXPORT size_t param_size(param_t param)
Determine the size of a parameter.
int flash_param_save(bool only_unsaved)
void * bson_encoder_buf_data(bson_encoder_t encoder)
Get a pointer to the encoded object buffer.
int bson_decoder_next(bson_decoder_t decoder)
Process the next node from the stream and invoke the callback.
#define PARAM_TYPE_INT32
Parameter types.
int bson_encoder_append_binary(bson_encoder_t encoder, const char *name, bson_binary_subtype_t subtype, size_t size, const void *data)
Append a binary blob to the encoded stream.
__BEGIN_DECLS __EXPORT UT_array * param_values
flexible array holding modified parameter values
#define PARAM_TYPE_STRUCT
Storage for modified parameters.
bson_binary_subtype_t subtype
__EXPORT int param_set_external(param_t param, const void *val, bool mark_saved, bool notify_changes)
__EXPORT const flash_file_token_t parameters_token
__EXPORT const void * param_get_value_ptr_external(param_t param)
int bson_decoder_copy_data(bson_decoder_t decoder, void *buf)
Copy node data.
static int param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
Node structure passed to the callback.
__EXPORT void parameter_flashfs_free(void)
A simple subset SAX-style BSON parser and generator.
Global flash based parameter store.
int bson_encoder_append_double(bson_encoder_t encoder, const char *name, double value)
Append a double to the encoded stream.
__EXPORT const char * param_name(param_t param)
Obtain the name of a parameter.
static int param_import_internal(bool mark_saved)
int bson_decoder_init_buf(bson_decoder_t decoder, void *buf, unsigned bufsize, bson_decoder_callback callback, void *priv)
Initialise the decoder to read from a buffer in memory.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
size_t bson_decoder_data_pending(bson_decoder_t decoder)
Report copyable data size.
#define PARAM_TYPE_STRUCT_MAX
__EXPORT param_type_t param_type(param_t param)
Obtain the type of a parameter.
#define utarray_next(a, e)
__EXPORT int parameter_flashfs_alloc(flash_file_token_t ft, uint8_t **buffer, size_t *buf_size)
#define debug(fmt, args...)
int bson_encoder_fini(bson_encoder_t encoder)
Finalise the encoded stream.
__EXPORT int parameter_flashfs_read(flash_file_token_t ft, uint8_t **buffer, size_t *buf_size)
int bson_encoder_buf_size(bson_encoder_t encoder)
Fetch the size of the encoded object; only valid for buffer operations.
__EXPORT int parameter_flashfs_write(flash_file_token_t ft, uint8_t *buffer, size_t buf_size)
int bson_encoder_init_buf(bson_encoder_t encoder, void *buf, unsigned bufsize)
Initialze the encoder for writing to a buffer.
__EXPORT void param_reset_all(void)
Reset all parameters to their default values.
static int param_export_internal(bool only_unsaved)
int bson_encoder_append_int(bson_encoder_t encoder, const char *name, int64_t value)
Append an integer to the encoded stream.
uint32_t param_t
Parameter handle.