forked from Archive/PX4-Autopilot
parameters lib convert to c++ (#10267)
This commit is contained in:
parent
0c08b7035b
commit
060463e8a7
|
@ -38,6 +38,8 @@ if (("${BOARD}" STREQUAL "eagle") OR ("${BOARD}" STREQUAL "excelsior"))
|
|||
apps.cpp
|
||||
LINK_LIBS
|
||||
-Wl,--start-group
|
||||
px4_layer
|
||||
parameters
|
||||
${module_libraries}
|
||||
${df_driver_libs}
|
||||
${FASTRPC_ARM_LIBS}
|
||||
|
|
|
@ -38,10 +38,9 @@ if("${CONFIG_SHMEM}" STREQUAL "1")
|
|||
include_directories(${HEXAGON_SDK_INCLUDES})
|
||||
include_directories(${PX4_BINARY_DIR}/platforms/posix)
|
||||
list(APPEND SHMEM_SRCS
|
||||
shmem_posix.c
|
||||
shmem_posix.cpp
|
||||
)
|
||||
# TODO: This didn't seem to be tracked correctly from posix_eagle_release.cmake
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCONFIG_SHMEM")
|
||||
add_definitions(-DCONFIG_SHMEM=1)
|
||||
set(EXTRA_DEPENDS generate_px4muorb_stubs)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -58,10 +58,6 @@ __BEGIN_DECLS
|
|||
|
||||
long PX4_TICKS_PER_SEC = sysconf(_SC_CLK_TCK);
|
||||
|
||||
#ifdef CONFIG_SHMEM
|
||||
extern void init_params(void);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
namespace px4
|
||||
|
@ -77,11 +73,6 @@ void init_once()
|
|||
hrt_work_queue_init();
|
||||
hrt_init();
|
||||
param_init();
|
||||
|
||||
#ifdef CONFIG_SHMEM
|
||||
PX4_DEBUG("Syncing params to shared memory\n");
|
||||
init_params();
|
||||
#endif
|
||||
}
|
||||
|
||||
void init(int argc, char *argv[], const char *app_name)
|
||||
|
|
|
@ -69,8 +69,7 @@ struct param_wbuf_s {
|
|||
/*update value and param's change bit in shared memory*/
|
||||
void update_to_shmem(param_t param, union param_value_u value)
|
||||
{
|
||||
if (px4muorb_param_update_to_shmem(param, (unsigned char *) &value,
|
||||
sizeof(value))) {
|
||||
if (px4muorb_param_update_to_shmem(param, (unsigned char *) &value, sizeof(value))) {
|
||||
PX4_ERR("krait update param %u failed", param);
|
||||
}
|
||||
}
|
||||
|
@ -82,14 +81,12 @@ void update_index_from_shmem(void)
|
|||
return;
|
||||
}
|
||||
|
||||
px4muorb_param_update_index_from_shmem(adsp_changed_index,
|
||||
PARAM_BUFFER_SIZE);
|
||||
px4muorb_param_update_index_from_shmem(adsp_changed_index, PARAM_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
static void update_value_from_shmem(param_t param, union param_value_u *value)
|
||||
{
|
||||
if (px4muorb_param_update_value_from_shmem(param, (unsigned char *) value,
|
||||
sizeof(union param_value_u))) {
|
||||
if (px4muorb_param_update_value_from_shmem(param, (unsigned char *) value, sizeof(union param_value_u))) {
|
||||
PX4_ERR("%s get param failed", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
@ -128,4 +125,3 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
|||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -43,10 +43,10 @@ else()
|
|||
SOURCES
|
||||
${PX4_BINARY_DIR}/apps.cpp
|
||||
LINK_LIBS
|
||||
modules__muorb__adsp
|
||||
${module_libraries}
|
||||
${df_driver_libs}
|
||||
m
|
||||
modules__muorb__adsp
|
||||
)
|
||||
|
||||
add_custom_target(upload
|
||||
|
|
|
@ -43,7 +43,7 @@ set(QURT_LAYER_SRCS
|
|||
../../../posix/src/px4_layer/drv_hrt.c
|
||||
qurt_stubs.c
|
||||
main.cpp
|
||||
shmem_qurt.c
|
||||
shmem_qurt.cpp
|
||||
)
|
||||
|
||||
if ("${QURT_ENABLE_STUBS}" STREQUAL "1")
|
||||
|
|
|
@ -71,7 +71,6 @@ unsigned int sleep(unsigned int sec)
|
|||
}
|
||||
|
||||
extern void hrt_init(void);
|
||||
extern void init_params();
|
||||
|
||||
#if 0
|
||||
void qurt_log(const char *fmt, ...)
|
||||
|
@ -108,9 +107,6 @@ void init_once(void)
|
|||
hrt_work_queue_init();
|
||||
hrt_init();
|
||||
param_init();
|
||||
|
||||
/* Shared memory param sync*/
|
||||
init_params();
|
||||
}
|
||||
|
||||
void init(int argc, char *argv[], const char *app_name)
|
||||
|
|
|
@ -56,11 +56,11 @@ unsigned char *map_base, *virt_addr;
|
|||
struct shmem_info *shmem_info_p;
|
||||
int get_shmem_lock(const char *caller_file_name, int caller_line_number);
|
||||
void release_shmem_lock(const char *caller_file_name, int caller_line_number);
|
||||
void init_shared_memory(void);
|
||||
void copy_params_to_shmem(struct param_info_s *);
|
||||
void init_shared_memory();
|
||||
void copy_params_to_shmem(param_info_s *);
|
||||
void update_to_shmem(param_t param, union param_value_u value);
|
||||
int update_from_shmem(param_t param, union param_value_u *value);
|
||||
void update_index_from_shmem(void);
|
||||
void update_index_from_shmem();
|
||||
uint64_t update_from_shmem_prev_time = 0, update_from_shmem_current_time = 0;
|
||||
static unsigned char krait_changed_index[MAX_SHMEM_PARAMS / 8 + 1];
|
||||
|
||||
|
@ -136,7 +136,7 @@ void init_shared_memory(void)
|
|||
}
|
||||
|
||||
//virt_addr = map_memory(MAP_ADDRESS);
|
||||
map_base = calloc(MAP_SIZE, 1); //16KB
|
||||
map_base = (unsigned char *)calloc(MAP_SIZE, 1); //16KB
|
||||
|
||||
if (map_base == NULL) {
|
||||
PX4_INFO("adsp memory malloc failed\n");
|
||||
|
@ -153,10 +153,9 @@ void init_shared_memory(void)
|
|||
}
|
||||
|
||||
PX4_INFO("adsp memory mapped\n");
|
||||
|
||||
}
|
||||
|
||||
void copy_params_to_shmem(struct param_info_s *param_info_base)
|
||||
void copy_params_to_shmem(const param_info_s *param_info_base)
|
||||
{
|
||||
param_t param;
|
||||
unsigned int i;
|
||||
|
@ -350,4 +349,3 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
|||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -105,9 +105,10 @@ add_custom_command(OUTPUT px4_parameters.c px4_parameters.h px4_parameters_publi
|
|||
set(SRCS)
|
||||
if ("${CONFIG_SHMEM}" STREQUAL "1")
|
||||
message(STATUS "parameters shared memory enabled")
|
||||
list(APPEND SRCS param_shmem.c)
|
||||
add_definitions(-DCONFIG_SHMEM=1)
|
||||
list(APPEND SRCS parameters_shmem.cpp)
|
||||
else()
|
||||
list(APPEND SRCS param.c)
|
||||
list(APPEND SRCS parameters.cpp)
|
||||
endif()
|
||||
|
||||
if(${OS} STREQUAL "nuttx")
|
||||
|
@ -136,5 +137,5 @@ endif()
|
|||
add_dependencies(parameters prebuild_targets)
|
||||
|
||||
if(${OS} STREQUAL "nuttx")
|
||||
target_link_libraries(parameters PRIVATE flashparams)
|
||||
target_link_libraries(parameters PRIVATE flashparams tinybson)
|
||||
endif()
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
add_library(flashparams
|
||||
flashfs.c
|
||||
flashparams.c
|
||||
flashparams.cpp
|
||||
)
|
||||
add_dependencies(flashparams prebuild_targets)
|
||||
target_compile_definitions(flashparams PRIVATE -DMODULE_NAME="flashparams")
|
||||
|
|
|
@ -75,21 +75,21 @@ struct param_wbuf_s {
|
|||
static int
|
||||
param_export_internal(bool only_unsaved)
|
||||
{
|
||||
struct param_wbuf_s *s = NULL;
|
||||
struct param_wbuf_s *s = nullptr;
|
||||
struct bson_encoder_s encoder;
|
||||
int result = -1;
|
||||
|
||||
/* Use realloc */
|
||||
|
||||
bson_encoder_init_buf(&encoder, NULL, 0);
|
||||
bson_encoder_init_buf(&encoder, nullptr, 0);
|
||||
|
||||
/* no modified parameters -> we are done */
|
||||
if (param_values == NULL) {
|
||||
if (param_values == nullptr) {
|
||||
result = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != NULL) {
|
||||
while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != nullptr) {
|
||||
|
||||
int32_t i;
|
||||
float f;
|
||||
|
@ -209,13 +209,13 @@ struct param_import_state {
|
|||
};
|
||||
|
||||
static int
|
||||
param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
||||
{
|
||||
float f;
|
||||
int32_t i;
|
||||
void *v, *tmp = NULL;
|
||||
void *v, *tmp = nullptr;
|
||||
int result = -1;
|
||||
struct param_import_state *state = (struct param_import_state *)private;
|
||||
struct param_import_state *state = (struct param_import_state *)priv;
|
||||
|
||||
/*
|
||||
* EOO means the end of the parameter object. (Currently not supporting
|
||||
|
@ -280,7 +280,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
/* XXX check actual file data size? */
|
||||
tmp = malloc(param_size(param));
|
||||
|
||||
if (tmp == NULL) {
|
||||
if (tmp == nullptr) {
|
||||
debug("failed allocating for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
@ -304,9 +304,9 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (tmp != NULL) {
|
||||
if (tmp != nullptr) {
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
tmp = nullptr;
|
||||
}
|
||||
|
||||
/* don't return zero, that means EOF */
|
||||
|
@ -314,7 +314,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
|
||||
out:
|
||||
|
||||
if (tmp != NULL) {
|
||||
if (tmp != nullptr) {
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
|
@ -353,18 +353,18 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
int flash_param_save(void)
|
||||
int flash_param_save()
|
||||
{
|
||||
return param_export_internal(false);
|
||||
}
|
||||
|
||||
int flash_param_load(void)
|
||||
int flash_param_load()
|
||||
{
|
||||
param_reset_all();
|
||||
return param_import_internal(true);
|
||||
}
|
||||
|
||||
int flash_param_import(void)
|
||||
int flash_param_import()
|
||||
{
|
||||
return -1;
|
||||
}
|
|
@ -58,15 +58,15 @@ __BEGIN_DECLS
|
|||
* the param_values and 2 functions to be global
|
||||
*/
|
||||
|
||||
#define FLASH_PARAMS_EXPOSE __EXPORT
|
||||
|
||||
__EXPORT extern UT_array *param_values;
|
||||
__EXPORT int param_set_external(param_t param, const void *val, bool mark_saved, bool notify_changes);
|
||||
__EXPORT const void *param_get_value_ptr_external(param_t param);
|
||||
|
||||
/* The interface hooks to the Flash based storage. The caller is responsible for locking */
|
||||
__EXPORT int flash_param_save(void);
|
||||
__EXPORT int flash_param_load(void);
|
||||
__EXPORT int flash_param_import(void);
|
||||
__EXPORT int flash_param_save();
|
||||
__EXPORT int flash_param_load();
|
||||
__EXPORT int flash_param_import();
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _SYSTEMLIB_FLASHPARAMS_FLASHPARAMS_H */
|
||||
|
|
|
@ -482,21 +482,18 @@ __END_DECLS
|
|||
// param is a C-interface. This means there is no overloading, and thus no type-safety for param_get().
|
||||
// So for C++ code we redefine param_get() to inlined overloaded versions, which gives us type-safety
|
||||
// w/o having to use a different interface
|
||||
static inline int param_get_cplusplus(param_t param, float *val)
|
||||
static inline int param_get(param_t param, float *val)
|
||||
{
|
||||
CHECK_PARAM_TYPE(param, PARAM_TYPE_FLOAT);
|
||||
return param_get(param, val);
|
||||
return param_get(param, (void *)val);
|
||||
}
|
||||
static inline int param_get_cplusplus(param_t param, int32_t *val)
|
||||
static inline int param_get(param_t param, int32_t *val)
|
||||
{
|
||||
CHECK_PARAM_TYPE(param, PARAM_TYPE_INT32);
|
||||
return param_get(param, val);
|
||||
return param_get(param, (void *)val);
|
||||
}
|
||||
#undef CHECK_PARAM_TYPE
|
||||
|
||||
#define param_get(param, val) param_get_cplusplus(param, val)
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -67,20 +67,12 @@
|
|||
# include "uORB/topics/parameter_update.h"
|
||||
#endif
|
||||
|
||||
#if !defined(FLASH_BASED_PARAMS)
|
||||
# define FLASH_PARAMS_EXPOSE
|
||||
#else
|
||||
# include "flashparams/flashparams.h"
|
||||
#if defined(FLASH_BASED_PARAMS)
|
||||
#include "flashparams/flashparams.h"
|
||||
#endif
|
||||
|
||||
static const char *param_default_file = PX4_ROOTFSDIR"/eeprom/parameters";
|
||||
static char *param_user_file = NULL;
|
||||
|
||||
#if 0
|
||||
# define debug(fmt, args...) do { PX4_INFO(fmt, ##args); } while(0)
|
||||
#else
|
||||
# define debug(fmt, args...) do { } while(0)
|
||||
#endif
|
||||
static char *param_user_file = nullptr;
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
#define PARAM_OPEN px4_open
|
||||
|
@ -102,7 +94,7 @@ static bool autosave_disabled = false;
|
|||
/**
|
||||
* Array of static parameter info.
|
||||
*/
|
||||
static const struct param_info_s *param_info_base = (const struct param_info_s *) &px4_parameters;
|
||||
static const param_info_s *param_info_base = (const param_info_s *) &px4_parameters;
|
||||
#define param_info_count px4_parameters.param_count
|
||||
|
||||
/**
|
||||
|
@ -115,24 +107,24 @@ struct param_wbuf_s {
|
|||
};
|
||||
|
||||
|
||||
uint8_t *param_changed_storage = NULL;
|
||||
uint8_t *param_changed_storage = nullptr;
|
||||
int size_param_changed_storage_bytes = 0;
|
||||
const int bits_per_allocation_unit = (sizeof(*param_changed_storage) * 8);
|
||||
|
||||
|
||||
static unsigned
|
||||
get_param_info_count(void)
|
||||
get_param_info_count()
|
||||
{
|
||||
/* Singleton creation of and array of bits to track changed values */
|
||||
if (!param_changed_storage) {
|
||||
/* Note that we have a (highly unlikely) race condition here: in the worst case the allocation is done twice */
|
||||
size_param_changed_storage_bytes = (param_info_count / bits_per_allocation_unit) + 1;
|
||||
param_changed_storage = calloc(size_param_changed_storage_bytes, 1);
|
||||
param_changed_storage = (uint8_t *)calloc(size_param_changed_storage_bytes, 1);
|
||||
|
||||
/* If the allocation fails we need to indicate failure in the
|
||||
* API by returning PARAM_INVALID
|
||||
*/
|
||||
if (param_changed_storage == NULL) {
|
||||
if (param_changed_storage == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -141,14 +133,14 @@ get_param_info_count(void)
|
|||
}
|
||||
|
||||
/** flexible array holding modified parameter values */
|
||||
FLASH_PARAMS_EXPOSE UT_array *param_values;
|
||||
UT_array *param_values{nullptr};
|
||||
|
||||
/** array info for the modified parameters array */
|
||||
FLASH_PARAMS_EXPOSE const UT_icd param_icd = {sizeof(struct param_wbuf_s), NULL, NULL, NULL};
|
||||
const UT_icd param_icd = {sizeof(param_wbuf_s), nullptr, nullptr, nullptr};
|
||||
|
||||
#if !defined(PARAM_NO_ORB)
|
||||
/** parameter update topic handle */
|
||||
static orb_advert_t param_topic = NULL;
|
||||
static orb_advert_t param_topic = nullptr;
|
||||
static unsigned int param_instance = 0;
|
||||
#endif
|
||||
|
||||
|
@ -175,7 +167,7 @@ static px4_sem_t param_sem_save; ///< this protects against concurrent param sav
|
|||
|
||||
/** lock the parameter store for read access */
|
||||
static void
|
||||
param_lock_reader(void)
|
||||
param_lock_reader()
|
||||
{
|
||||
do {} while (px4_sem_wait(&reader_lock_holders_lock) != 0);
|
||||
|
||||
|
@ -191,14 +183,14 @@ param_lock_reader(void)
|
|||
|
||||
/** lock the parameter store for write access */
|
||||
static void
|
||||
param_lock_writer(void)
|
||||
param_lock_writer()
|
||||
{
|
||||
do {} while (px4_sem_wait(¶m_sem) != 0);
|
||||
}
|
||||
|
||||
/** unlock the parameter store */
|
||||
static void
|
||||
param_unlock_reader(void)
|
||||
param_unlock_reader()
|
||||
{
|
||||
do {} while (px4_sem_wait(&reader_lock_holders_lock) != 0);
|
||||
|
||||
|
@ -214,20 +206,20 @@ param_unlock_reader(void)
|
|||
|
||||
/** unlock the parameter store */
|
||||
static void
|
||||
param_unlock_writer(void)
|
||||
param_unlock_writer()
|
||||
{
|
||||
px4_sem_post(¶m_sem);
|
||||
}
|
||||
|
||||
/** assert that the parameter store is locked */
|
||||
static void
|
||||
param_assert_locked(void)
|
||||
param_assert_locked()
|
||||
{
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
void
|
||||
param_init(void)
|
||||
param_init()
|
||||
{
|
||||
px4_sem_init(¶m_sem, 0, 1);
|
||||
px4_sem_init(¶m_sem_save, 0, 1);
|
||||
|
@ -279,38 +271,37 @@ param_compare_values(const void *a, const void *b)
|
|||
*
|
||||
* @param param The parameter being searched.
|
||||
* @return The structure holding the modified value, or
|
||||
* NULL if the parameter has not been modified.
|
||||
* nullptr if the parameter has not been modified.
|
||||
*/
|
||||
static struct param_wbuf_s *
|
||||
static param_wbuf_s *
|
||||
param_find_changed(param_t param)
|
||||
{
|
||||
struct param_wbuf_s *s = NULL;
|
||||
param_wbuf_s *s = nullptr;
|
||||
|
||||
param_assert_locked();
|
||||
|
||||
if (param_values != NULL) {
|
||||
struct param_wbuf_s key;
|
||||
if (param_values != nullptr) {
|
||||
param_wbuf_s key{};
|
||||
key.param = param;
|
||||
s = utarray_find(param_values, &key, param_compare_values);
|
||||
s = (param_wbuf_s *)utarray_find(param_values, &key, param_compare_values);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static void
|
||||
_param_notify_changes(void)
|
||||
_param_notify_changes()
|
||||
{
|
||||
#if !defined(PARAM_NO_ORB)
|
||||
struct parameter_update_s pup = {
|
||||
.timestamp = hrt_absolute_time(),
|
||||
.instance = param_instance++,
|
||||
};
|
||||
parameter_update_s pup = {};
|
||||
pup.timestamp = hrt_absolute_time();
|
||||
pup.instance = param_instance++;
|
||||
|
||||
/*
|
||||
* If we don't have a handle to our topic, create one now; otherwise
|
||||
* just publish.
|
||||
*/
|
||||
if (param_topic == NULL) {
|
||||
if (param_topic == nullptr) {
|
||||
param_topic = orb_advertise(ORB_ID(parameter_update), &pup);
|
||||
|
||||
} else {
|
||||
|
@ -321,7 +312,7 @@ _param_notify_changes(void)
|
|||
}
|
||||
|
||||
void
|
||||
param_notify_changes(void)
|
||||
param_notify_changes()
|
||||
{
|
||||
_param_notify_changes();
|
||||
}
|
||||
|
@ -380,13 +371,13 @@ param_find_no_notification(const char *name)
|
|||
}
|
||||
|
||||
unsigned
|
||||
param_count(void)
|
||||
param_count()
|
||||
{
|
||||
return get_param_info_count();
|
||||
}
|
||||
|
||||
unsigned
|
||||
param_count_used(void)
|
||||
param_count_used()
|
||||
{
|
||||
unsigned count = 0;
|
||||
|
||||
|
@ -486,7 +477,7 @@ param_get_used_index(param_t param)
|
|||
const char *
|
||||
param_name(param_t param)
|
||||
{
|
||||
return handle_in_range(param) ? param_info_base[param].name : NULL;
|
||||
return handle_in_range(param) ? param_info_base[param].name : nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -549,13 +540,13 @@ param_size(param_t param)
|
|||
* Obtain a pointer to the storage allocated for a parameter.
|
||||
*
|
||||
* @param param The parameter whose storage is sought.
|
||||
* @return A pointer to the parameter value, or NULL
|
||||
* @return A pointer to the parameter value, or nullptr
|
||||
* if the parameter does not exist.
|
||||
*/
|
||||
static const void *
|
||||
param_get_value_ptr(param_t param)
|
||||
{
|
||||
const void *result = NULL;
|
||||
const void *result = nullptr;
|
||||
|
||||
param_assert_locked();
|
||||
|
||||
|
@ -566,7 +557,7 @@ param_get_value_ptr(param_t param)
|
|||
/* work out whether we're fetching the default or a written value */
|
||||
struct param_wbuf_s *s = param_find_changed(param);
|
||||
|
||||
if (s != NULL) {
|
||||
if (s != nullptr) {
|
||||
v = &s->val;
|
||||
|
||||
} else {
|
||||
|
@ -607,7 +598,6 @@ param_get(param_t param, void *val)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
#ifndef PARAM_NO_AUTOSAVE
|
||||
/**
|
||||
* worker callback method to save the parameters
|
||||
|
@ -644,7 +634,7 @@ autosave_worker(void *arg)
|
|||
* needs to be the same lock as autosave_worker() and param_control_autosave() use).
|
||||
*/
|
||||
static void
|
||||
param_autosave(void)
|
||||
param_autosave()
|
||||
{
|
||||
#ifndef PARAM_NO_AUTOSAVE
|
||||
|
||||
|
@ -666,7 +656,7 @@ param_autosave(void)
|
|||
}
|
||||
|
||||
autosave_scheduled = true;
|
||||
work_queue(LPWORK, &autosave_work, (worker_t)&autosave_worker, NULL, USEC2TICK(delay));
|
||||
work_queue(LPWORK, &autosave_work, (worker_t)&autosave_worker, nullptr, USEC2TICK(delay));
|
||||
#endif /* PARAM_NO_AUTOSAVE */
|
||||
}
|
||||
|
||||
|
@ -695,27 +685,25 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_
|
|||
param_lock_writer();
|
||||
perf_begin(param_set_perf);
|
||||
|
||||
if (param_values == NULL) {
|
||||
if (param_values == nullptr) {
|
||||
utarray_new(param_values, ¶m_icd);
|
||||
}
|
||||
|
||||
if (param_values == NULL) {
|
||||
if (param_values == nullptr) {
|
||||
PX4_ERR("failed to allocate modified values array");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (handle_in_range(param)) {
|
||||
|
||||
struct param_wbuf_s *s = param_find_changed(param);
|
||||
param_wbuf_s *s = param_find_changed(param);
|
||||
|
||||
if (s == NULL) {
|
||||
if (s == nullptr) {
|
||||
|
||||
/* construct a new parameter */
|
||||
struct param_wbuf_s buf = {
|
||||
.param = param,
|
||||
.val.p = NULL,
|
||||
.unsaved = false
|
||||
};
|
||||
param_wbuf_s buf = {};
|
||||
buf.param = param;
|
||||
|
||||
params_changed = true;
|
||||
|
||||
/* add it to the array and sort */
|
||||
|
@ -740,17 +728,17 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_
|
|||
break;
|
||||
|
||||
case PARAM_TYPE_STRUCT ... PARAM_TYPE_STRUCT_MAX:
|
||||
if (s->val.p == NULL) {
|
||||
if (s->val.p == nullptr) {
|
||||
size_t psize = param_size(param);
|
||||
|
||||
if (psize > 0) {
|
||||
s->val.p = malloc(psize);
|
||||
|
||||
} else {
|
||||
s->val.p = NULL;
|
||||
s->val.p = nullptr;
|
||||
}
|
||||
|
||||
if (s->val.p == NULL) {
|
||||
if (s->val.p == nullptr) {
|
||||
PX4_ERR("failed to allocate parameter storage");
|
||||
goto out;
|
||||
}
|
||||
|
@ -845,7 +833,7 @@ void param_set_used_internal(param_t param)
|
|||
int
|
||||
param_reset(param_t param)
|
||||
{
|
||||
struct param_wbuf_s *s = NULL;
|
||||
param_wbuf_s *s = nullptr;
|
||||
bool param_found = false;
|
||||
|
||||
param_lock_writer();
|
||||
|
@ -856,7 +844,7 @@ param_reset(param_t param)
|
|||
s = param_find_changed(param);
|
||||
|
||||
/* if we found one, erase it */
|
||||
if (s != NULL) {
|
||||
if (s != nullptr) {
|
||||
int pos = utarray_eltidx(param_values, s);
|
||||
utarray_erase(param_values, pos, 1);
|
||||
}
|
||||
|
@ -868,7 +856,7 @@ param_reset(param_t param)
|
|||
|
||||
param_unlock_writer();
|
||||
|
||||
if (s != NULL) {
|
||||
if (s != nullptr) {
|
||||
_param_notify_changes();
|
||||
}
|
||||
|
||||
|
@ -879,12 +867,12 @@ param_reset_all_internal(bool auto_save)
|
|||
{
|
||||
param_lock_writer();
|
||||
|
||||
if (param_values != NULL) {
|
||||
if (param_values != nullptr) {
|
||||
utarray_free(param_values);
|
||||
}
|
||||
|
||||
/* mark as reset / deleted */
|
||||
param_values = NULL;
|
||||
param_values = nullptr;
|
||||
|
||||
if (auto_save) {
|
||||
param_autosave();
|
||||
|
@ -896,7 +884,7 @@ param_reset_all_internal(bool auto_save)
|
|||
}
|
||||
|
||||
void
|
||||
param_reset_all(void)
|
||||
param_reset_all()
|
||||
{
|
||||
param_reset_all_internal(true);
|
||||
}
|
||||
|
@ -933,10 +921,10 @@ param_reset_excludes(const char *excludes[], int num_excludes)
|
|||
int
|
||||
param_set_default_file(const char *filename)
|
||||
{
|
||||
if (param_user_file != NULL) {
|
||||
if (param_user_file != nullptr) {
|
||||
// we assume this is not in use by some other thread
|
||||
free(param_user_file);
|
||||
param_user_file = NULL;
|
||||
param_user_file = nullptr;
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
|
@ -947,13 +935,13 @@ param_set_default_file(const char *filename)
|
|||
}
|
||||
|
||||
const char *
|
||||
param_get_default_file(void)
|
||||
param_get_default_file()
|
||||
{
|
||||
return (param_user_file != NULL) ? param_user_file : param_default_file;
|
||||
return (param_user_file != nullptr) ? param_user_file : param_default_file;
|
||||
}
|
||||
|
||||
int
|
||||
param_save_default(void)
|
||||
param_save_default()
|
||||
{
|
||||
int res = PX4_ERROR;
|
||||
#if !defined(FLASH_BASED_PARAMS)
|
||||
|
@ -998,7 +986,7 @@ param_save_default(void)
|
|||
* @return 0 on success, 1 if all params have not yet been stored, -1 if device open failed, -2 if writing parameters failed
|
||||
*/
|
||||
int
|
||||
param_load_default(void)
|
||||
param_load_default()
|
||||
{
|
||||
int res = 0;
|
||||
#if !defined(FLASH_BASED_PARAMS)
|
||||
|
@ -1034,7 +1022,7 @@ param_export(int fd, bool only_unsaved)
|
|||
{
|
||||
perf_begin(param_export_perf);
|
||||
|
||||
struct param_wbuf_s *s = NULL;
|
||||
param_wbuf_s *s = nullptr;
|
||||
int result = -1;
|
||||
|
||||
struct bson_encoder_s encoder;
|
||||
|
@ -1054,12 +1042,12 @@ param_export(int fd, bool only_unsaved)
|
|||
bson_encoder_init_buf_file(&encoder, fd, &bson_buffer, sizeof(bson_buffer));
|
||||
|
||||
/* no modified parameters -> we are done */
|
||||
if (param_values == NULL) {
|
||||
if (param_values == nullptr) {
|
||||
result = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != NULL) {
|
||||
while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != nullptr) {
|
||||
/*
|
||||
* If we are only saving values changed since last save, and this
|
||||
* one hasn't, then skip it
|
||||
|
@ -1079,7 +1067,7 @@ param_export(int fd, bool only_unsaved)
|
|||
case PARAM_TYPE_INT32: {
|
||||
const int32_t i = s->val.i;
|
||||
|
||||
debug("exporting: %s (%d) size: %d val: %d", name, s->param, size, i);
|
||||
PX4_DEBUG("exporting: %s (%d) size: %d val: %d", name, s->param, size, i);
|
||||
|
||||
if (bson_encoder_append_int(&encoder, name, i)) {
|
||||
PX4_ERR("BSON append failed for '%s'", name);
|
||||
|
@ -1091,7 +1079,7 @@ param_export(int fd, bool only_unsaved)
|
|||
case PARAM_TYPE_FLOAT: {
|
||||
const double f = (double)s->val.f;
|
||||
|
||||
debug("exporting: %s (%d) size: %d val: %.3f", name, s->param, size, (double)f);
|
||||
PX4_DEBUG("exporting: %s (%d) size: %d val: %.3f", name, s->param, size, (double)f);
|
||||
|
||||
if (bson_encoder_append_double(&encoder, name, f)) {
|
||||
PX4_ERR("BSON append failed for '%s'", name);
|
||||
|
@ -1150,20 +1138,21 @@ struct param_import_state {
|
|||
};
|
||||
|
||||
static int
|
||||
param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
||||
{
|
||||
float f;
|
||||
int32_t i;
|
||||
void *v, *tmp = NULL;
|
||||
float f = 0.0f;
|
||||
int32_t i = 0;
|
||||
void *tmp = nullptr;
|
||||
void *v = nullptr;
|
||||
int result = -1;
|
||||
struct param_import_state *state = (struct param_import_state *)private;
|
||||
param_import_state *state = (param_import_state *)priv;
|
||||
|
||||
/*
|
||||
* EOO means the end of the parameter object. (Currently not supporting
|
||||
* nested BSON objects).
|
||||
*/
|
||||
if (node->type == BSON_EOO) {
|
||||
debug("end of parameters");
|
||||
PX4_DEBUG("end of parameters");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1174,7 +1163,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
param_t param = param_find_no_notification(node->name);
|
||||
|
||||
if (param == PARAM_INVALID) {
|
||||
debug("ignoring unrecognised parameter '%s'", node->name);
|
||||
PX4_ERR("ignoring unrecognised parameter '%s'", node->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1183,81 +1172,84 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
*/
|
||||
|
||||
switch (node->type) {
|
||||
case BSON_INT32:
|
||||
if (param_type(param) != PARAM_TYPE_INT32) {
|
||||
PX4_WARN("unexpected type for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
case BSON_INT32: {
|
||||
if (param_type(param) != PARAM_TYPE_INT32) {
|
||||
PX4_WARN("unexpected type for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
}
|
||||
|
||||
i = node->i;
|
||||
v = &i;
|
||||
|
||||
PX4_DEBUG("Imported %s with value %d", param_name(param), i);
|
||||
}
|
||||
|
||||
i = node->i;
|
||||
v = &i;
|
||||
|
||||
debug("importing: %s (%d) = %d", node->name, param, i);
|
||||
break;
|
||||
|
||||
case BSON_DOUBLE:
|
||||
if (param_type(param) != PARAM_TYPE_FLOAT) {
|
||||
PX4_WARN("unexpected type for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
case BSON_DOUBLE: {
|
||||
if (param_type(param) != PARAM_TYPE_FLOAT) {
|
||||
PX4_WARN("unexpected type for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
}
|
||||
|
||||
f = node->d;
|
||||
v = &f;
|
||||
|
||||
PX4_DEBUG("Imported %s with value %f", param_name(param), (double)f);
|
||||
}
|
||||
|
||||
f = node->d;
|
||||
v = &f;
|
||||
|
||||
debug("importing: %s (%d) = %.3f", node->name, param, (double)f);
|
||||
break;
|
||||
|
||||
case BSON_BINDATA:
|
||||
if (node->subtype != BSON_BIN_BINARY) {
|
||||
PX4_WARN("unexpected subtype for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
case BSON_BINDATA: {
|
||||
if (node->subtype != BSON_BIN_BINARY) {
|
||||
PX4_WARN("unexpected subtype for %s", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (bson_decoder_data_pending(decoder) != param_size(param)) {
|
||||
PX4_WARN("bad size for '%s'", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* XXX check actual file data size? */
|
||||
size_t psize = param_size(param);
|
||||
|
||||
if (psize > 0) {
|
||||
tmp = malloc(psize);
|
||||
|
||||
} else {
|
||||
tmp = nullptr;
|
||||
}
|
||||
|
||||
if (tmp == nullptr) {
|
||||
PX4_ERR("failed allocating for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (bson_decoder_copy_data(decoder, tmp)) {
|
||||
PX4_ERR("failed copying data for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
v = tmp;
|
||||
}
|
||||
|
||||
if (bson_decoder_data_pending(decoder) != param_size(param)) {
|
||||
PX4_WARN("bad size for '%s'", node->name);
|
||||
result = 1; // just skip this entry
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* XXX check actual file data size? */
|
||||
size_t psize = param_size(param);
|
||||
|
||||
if (psize > 0) {
|
||||
tmp = malloc(psize);
|
||||
|
||||
} else {
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (tmp == NULL) {
|
||||
PX4_ERR("failed allocating for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (bson_decoder_copy_data(decoder, tmp)) {
|
||||
PX4_ERR("failed copying data for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
v = tmp;
|
||||
break;
|
||||
|
||||
default:
|
||||
debug("unrecognised node type");
|
||||
PX4_DEBUG("unrecognised node type");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (param_set_internal(param, v, state->mark_saved, true)) {
|
||||
debug("error setting value for '%s'", node->name);
|
||||
PX4_DEBUG("error setting value for '%s'", node->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (tmp != NULL) {
|
||||
if (tmp != nullptr) {
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
tmp = nullptr;
|
||||
}
|
||||
|
||||
/* don't return zero, that means EOF */
|
||||
|
@ -1265,7 +1257,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
|
||||
out:
|
||||
|
||||
if (tmp != NULL) {
|
||||
if (tmp != nullptr) {
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
|
@ -1275,13 +1267,13 @@ out:
|
|||
static int
|
||||
param_import_internal(int fd, bool mark_saved)
|
||||
{
|
||||
struct bson_decoder_s decoder;
|
||||
struct param_import_state state;
|
||||
bson_decoder_s decoder;
|
||||
param_import_state state;
|
||||
int result = -1;
|
||||
|
||||
if (bson_decoder_init_file(&decoder, fd, param_import_callback, &state)) {
|
||||
PX4_ERR("decoder init failed");
|
||||
return -ENODATA;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
state.mark_saved = mark_saved;
|
||||
|
@ -1322,7 +1314,7 @@ param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_chang
|
|||
for (param = 0; handle_in_range(param); param++) {
|
||||
|
||||
/* if requested, skip unchanged values */
|
||||
if (only_changed && (param_find_changed(param) == NULL)) {
|
||||
if (only_changed && (param_find_changed(param) == nullptr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1334,7 +1326,7 @@ param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_chang
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t param_hash_check(void)
|
||||
uint32_t param_hash_check()
|
||||
{
|
||||
uint32_t param_hash = 0;
|
||||
|
||||
|
@ -1349,7 +1341,7 @@ uint32_t param_hash_check(void)
|
|||
const char *name = param_name(param);
|
||||
const void *val = param_get_value_ptr(param);
|
||||
param_hash = crc32part((const uint8_t *)name, strlen(name), param_hash);
|
||||
param_hash = crc32part(val, param_size(param), param_hash);
|
||||
param_hash = crc32part((const uint8_t *)val, param_size(param), param_hash);
|
||||
}
|
||||
|
||||
param_unlock_reader();
|
File diff suppressed because it is too large
Load Diff
|
@ -31,7 +31,7 @@
|
|||
#
|
||||
############################################################################
|
||||
|
||||
add_library(tinybson tinybson.c)
|
||||
add_library(tinybson tinybson.cpp)
|
||||
target_compile_definitions(tinybson PRIVATE -DMODULE_NAME="tinybson")
|
||||
target_compile_options(tinybson PRIVATE -Wno-sign-compare) # TODO: fix this
|
||||
add_dependencies(tinybson prebuild_targets)
|
||||
|
|
|
@ -67,7 +67,7 @@ read_x(bson_decoder_t decoder, void *p, size_t s)
|
|||
return (BSON_READ(decoder->fd, p, s) == s) ? 0 : -1;
|
||||
}
|
||||
|
||||
if (decoder->buf != NULL) {
|
||||
if (decoder->buf != nullptr) {
|
||||
/* staged operations to avoid integer overflow for corrupt data */
|
||||
if (s >= decoder->bufsize) {
|
||||
CODER_KILL(decoder, "buffer too small for read");
|
||||
|
@ -116,7 +116,7 @@ bson_decoder_init_file(bson_decoder_t decoder, int fd, bson_decoder_callback cal
|
|||
int32_t junk;
|
||||
|
||||
decoder->fd = fd;
|
||||
decoder->buf = NULL;
|
||||
decoder->buf = nullptr;
|
||||
decoder->dead = false;
|
||||
decoder->callback = callback;
|
||||
decoder->priv = priv;
|
||||
|
@ -140,7 +140,7 @@ bson_decoder_init_buf(bson_decoder_t decoder, void *buf, unsigned bufsize, bson_
|
|||
int32_t len;
|
||||
|
||||
/* argument sanity */
|
||||
if ((buf == NULL) || (callback == NULL)) {
|
||||
if ((buf == nullptr) || (callback == nullptr)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ bson_decoder_next(bson_decoder_t decoder)
|
|||
CODER_KILL(decoder, "read error on type byte");
|
||||
}
|
||||
|
||||
decoder->node.type = tbyte;
|
||||
decoder->node.type = (bson_type_t)tbyte;
|
||||
decoder->pending = 0;
|
||||
|
||||
debug("got type byte 0x%02x", decoder->node.type);
|
||||
|
@ -295,7 +295,7 @@ bson_decoder_next(bson_decoder_t decoder)
|
|||
CODER_KILL(decoder, "read error on BSON_BINDATA subtype");
|
||||
}
|
||||
|
||||
decoder->node.subtype = tbyte;
|
||||
decoder->node.subtype = (bson_binary_subtype_t)tbyte;
|
||||
break;
|
||||
|
||||
/* XXX currently not supporting other types */
|
||||
|
@ -339,7 +339,7 @@ write_x(bson_encoder_t encoder, const void *p, size_t s)
|
|||
CODER_CHECK(encoder);
|
||||
|
||||
/* bson file encoder (non-buffered) */
|
||||
if (encoder->fd > -1 && encoder->buf == NULL) {
|
||||
if (encoder->fd > -1 && encoder->buf == nullptr) {
|
||||
return (BSON_WRITE(encoder->fd, p, s) == (int)s) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
@ -371,9 +371,9 @@ write_x(bson_encoder_t encoder, const void *p, size_t s)
|
|||
CODER_KILL(encoder, "fixed-size buffer overflow");
|
||||
}
|
||||
|
||||
uint8_t *newbuf = realloc(encoder->buf, encoder->bufsize + BSON_BUF_INCREMENT);
|
||||
uint8_t *newbuf = (uint8_t *)realloc(encoder->buf, encoder->bufsize + BSON_BUF_INCREMENT);
|
||||
|
||||
if (newbuf == NULL) {
|
||||
if (newbuf == nullptr) {
|
||||
CODER_KILL(encoder, "could not grow buffer");
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,7 @@ int
|
|||
bson_encoder_init_file(bson_encoder_t encoder, int fd)
|
||||
{
|
||||
encoder->fd = fd;
|
||||
encoder->buf = NULL;
|
||||
encoder->buf = nullptr;
|
||||
encoder->dead = false;
|
||||
|
||||
if (write_int32(encoder, 0)) {
|
||||
|
@ -464,7 +464,7 @@ bson_encoder_init_buf(bson_encoder_t encoder, void *buf, unsigned bufsize)
|
|||
encoder->bufpos = 0;
|
||||
encoder->dead = false;
|
||||
|
||||
if (encoder->buf == NULL) {
|
||||
if (encoder->buf == nullptr) {
|
||||
encoder->bufsize = 0;
|
||||
encoder->realloc_ok = true;
|
||||
|
||||
|
@ -489,7 +489,7 @@ bson_encoder_fini(bson_encoder_t encoder)
|
|||
CODER_KILL(encoder, "write error on document terminator");
|
||||
}
|
||||
|
||||
if (encoder->fd > -1 && encoder->buf != NULL) {
|
||||
if (encoder->fd > -1 && encoder->buf != nullptr) {
|
||||
/* write final buffer to disk */
|
||||
int ret = BSON_WRITE(encoder->fd, encoder->buf, encoder->bufpos);
|
||||
|
||||
|
@ -497,7 +497,7 @@ bson_encoder_fini(bson_encoder_t encoder)
|
|||
CODER_KILL(encoder, "write error");
|
||||
}
|
||||
|
||||
} else if (encoder->buf != NULL) {
|
||||
} else if (encoder->buf != nullptr) {
|
||||
/* update buffer length */
|
||||
int32_t len = bson_encoder_buf_size(encoder);
|
||||
memcpy(encoder->buf, &len, sizeof(len));
|
||||
|
@ -529,7 +529,7 @@ bson_encoder_buf_data(bson_encoder_t encoder)
|
|||
/* note, no CODER_CHECK here as the caller has to clean up dead buffers */
|
||||
|
||||
if (encoder->fd > -1) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return encoder->buf;
|
|
@ -58,7 +58,7 @@ typedef enum {
|
|||
BSON_UNDEFINED = 6,
|
||||
BSON_BOOL = 8,
|
||||
BSON_DATE = 9,
|
||||
BSON_NULL = 10,
|
||||
BSON_nullptr = 10,
|
||||
BSON_INT32 = 16,
|
||||
BSON_INT64 = 18
|
||||
} bson_type_t;
|
||||
|
@ -198,7 +198,7 @@ __EXPORT int bson_encoder_init_file(bson_encoder_t encoder, int fd);
|
|||
*
|
||||
* @param encoder Encoder state structure to be initialised.
|
||||
* @param fd File to write to.
|
||||
* @param buf Buffer pointer to use, can't be NULL
|
||||
* @param buf Buffer pointer to use, can't be nullptr
|
||||
* @param bufsize Supplied buffer size
|
||||
* @return Zero on success.
|
||||
*/
|
||||
|
@ -208,7 +208,7 @@ __EXPORT int bson_encoder_init_buf_file(bson_encoder_t encoder, int fd, void *bu
|
|||
* Initialze the encoder for writing to a buffer.
|
||||
*
|
||||
* @param encoder Encoder state structure to be initialised.
|
||||
* @param buf Buffer pointer to use, or NULL if the buffer
|
||||
* @param buf Buffer pointer to use, or nullptr if the buffer
|
||||
* should be allocated by the encoder.
|
||||
* @param bufsize Maximum buffer size, or zero for no limit. If
|
||||
* the buffer is supplied, the size of the supplied buffer.
|
||||
|
|
|
@ -35,7 +35,7 @@ set(srcs
|
|||
test_adc.c
|
||||
test_autodeclination.cpp
|
||||
test_bezierQuad.cpp
|
||||
test_bson.c
|
||||
test_bson.cpp
|
||||
test_conv.cpp
|
||||
test_dataman.c
|
||||
test_file.c
|
||||
|
|
|
@ -98,7 +98,7 @@ encode(bson_encoder_t encoder)
|
|||
}
|
||||
|
||||
static int
|
||||
decode_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
||||
decode_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
||||
{
|
||||
unsigned len;
|
||||
|
||||
|
@ -194,7 +194,7 @@ decode_callback(bson_decoder_t decoder, void *private, bson_node_t node)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(sbuf, sample_string)) {
|
||||
if (strcmp(sbuf, sample_string) != 0) {
|
||||
PX4_ERR("FAIL: decoder: string1 value '%s', expected '%s'", sbuf, sample_string);
|
||||
return 1;
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ test_bson(int argc, char *argv[])
|
|||
int len;
|
||||
|
||||
/* encode data to a memory buffer */
|
||||
if (bson_encoder_init_buf(&encoder, NULL, 0)) {
|
||||
if (bson_encoder_init_buf(&encoder, nullptr, 0)) {
|
||||
PX4_ERR("FAIL: bson_encoder_init_buf");
|
||||
return 1;
|
||||
}
|
||||
|
@ -283,13 +283,13 @@ test_bson(int argc, char *argv[])
|
|||
|
||||
buf = bson_encoder_buf_data(&encoder);
|
||||
|
||||
if (buf == NULL) {
|
||||
if (buf == nullptr) {
|
||||
PX4_ERR("FAIL: bson_encoder_buf_data");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* now test-decode it */
|
||||
if (bson_decoder_init_buf(&decoder, buf, len, decode_callback, NULL)) {
|
||||
if (bson_decoder_init_buf(&decoder, buf, len, decode_callback, nullptr)) {
|
||||
PX4_ERR("FAIL: bson_decoder_init_buf");
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue