parameters lib convert to c++ (#10267)

This commit is contained in:
Daniel Agar
2018-09-04 09:18:28 -04:00
committed by GitHub
parent 0c08b7035b
commit 060463e8a7
20 changed files with 600 additions and 479 deletions
+2
View File
@@ -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}
+2 -3
View File
@@ -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;
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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;
}
+4 -3
View File
@@ -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;
}
+5 -5
View File
@@ -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 */
+4 -7
View File
@@ -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
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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.
+1 -1
View File
@@ -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;
}