systemcmds/bsondump: new command line utility (extracted from parameters)

This commit is contained in:
Daniel Agar
2022-12-21 10:14:00 -05:00
parent f5524fa605
commit f2cd7667dc
61 changed files with 286 additions and 194 deletions
+1
View File
@@ -68,6 +68,7 @@ add_subdirectory(system_identification EXCLUDE_FROM_ALL)
add_subdirectory(tecs EXCLUDE_FROM_ALL)
add_subdirectory(terrain_estimation EXCLUDE_FROM_ALL)
add_subdirectory(timesync EXCLUDE_FROM_ALL)
add_subdirectory(tinybson EXCLUDE_FROM_ALL)
add_subdirectory(tunes EXCLUDE_FROM_ALL)
add_subdirectory(version EXCLUDE_FROM_ALL)
add_subdirectory(weather_vane EXCLUDE_FROM_ALL)
-2
View File
@@ -33,8 +33,6 @@
add_compile_options(${MAX_CUSTOM_OPT_LEVEL})
add_subdirectory(tinybson)
if (NOT PARAM_DEFAULT_OVERRIDES)
set(PARAM_DEFAULT_OVERRIDES "{}")
endif()
@@ -55,7 +55,7 @@
#include <parameters/param.h>
#include "../uthash/utarray.h"
#include <parameters/tinybson/tinybson.h>
#include <lib/tinybson/tinybson.h>
#include "flashparams.h"
#include "flashfs.h"
#include "../param_translation.h"
-11
View File
@@ -347,17 +347,6 @@ __EXPORT int param_import(int fd);
*/
__EXPORT int param_load(int fd);
/**
* Read saved parameters from file and dump to console.
*
* This function reads the file and dumps all contents to console
* values from a file.
*
* @param fd File descriptor to read from.
* @return Zero on success, nonzero if an error occurred during import.
*/
__EXPORT int param_dump(int fd);
/**
* Apply a function to each parameter.
*
+1 -69
View File
@@ -45,7 +45,7 @@
#include "param.h"
#include "param_translation.h"
#include <parameters/px4_parameters.hpp>
#include "tinybson/tinybson.h"
#include <lib/tinybson/tinybson.h>
#include <crc32.h>
#include <float.h>
@@ -1521,38 +1521,6 @@ param_import_callback(bson_decoder_t decoder, bson_node_t node)
return 1;
}
static int
param_dump_callback(bson_decoder_t decoder, bson_node_t node)
{
switch (node->type) {
case BSON_EOO:
PX4_INFO_RAW("BSON_EOO\n");
return 0;
case BSON_DOUBLE:
PX4_INFO_RAW("BSON_DOUBLE: %s = %.6f\n", node->name, node->d);
return 1;
case BSON_BOOL:
PX4_INFO_RAW("BSON_BOOL: %s = %d\n", node->name, node->b);
return 1;
case BSON_INT32:
PX4_INFO_RAW("BSON_INT32: %s = %" PRIi32 "\n", node->name, node->i32);
return 1;
case BSON_INT64:
PX4_INFO_RAW("BSON_INT64: %s = %" PRIi64 "\n", node->name, node->i64);
return 1;
default:
PX4_INFO_RAW("ERROR %s unhandled bson type %d\n", node->name, node->type);
return 1; // just skip this entry
}
return -1;
}
static int
param_import_internal(int fd)
{
@@ -1630,42 +1598,6 @@ param_load(int fd)
return param_import_internal(fd);
}
int
param_dump(int fd)
{
bson_decoder_s decoder{};
if (bson_decoder_init_file(&decoder, fd, param_dump_callback) == 0) {
PX4_INFO_RAW("BSON document size %" PRId32 "\n", decoder.total_document_size);
int result = -1;
do {
result = bson_decoder_next(&decoder);
} while (result > 0);
if (result == 0) {
PX4_INFO_RAW("BSON decoded %" PRId32 " bytes (double:%" PRIu16 ", string:%" PRIu16 ", bin:%" PRIu16 ", bool:%" PRIu16
", int32:%" PRIu16 ", int64:%" PRIu16 ")\n",
decoder.total_decoded_size,
decoder.count_node_double, decoder.count_node_string, decoder.count_node_bindata, decoder.count_node_bool,
decoder.count_node_int32, decoder.count_node_int64);
return 0;
} else if (result == -ENODATA) {
PX4_WARN("BSON: no data");
return 0;
} else {
PX4_ERR("param dump failed (%d)", result);
}
}
return -1;
}
void
param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed, bool only_used)
{
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2018 PX4 Development Team. All rights reserved.
# Copyright (c) 2018-2022 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -31,7 +31,15 @@
#
############################################################################
add_library(tinybson tinybson.cpp)
add_library(tinybson
tinybson.cpp
tinybson.h
)
target_compile_definitions(tinybson PRIVATE -DMODULE_NAME="tinybson")
target_compile_options(tinybson PRIVATE -Wno-sign-compare) # TODO: fix this
target_compile_options(tinybson
PRIVATE
-Wno-sign-compare # TODO: fix this
${MAX_CUSTOM_OPT_LEVEL}
)
add_dependencies(tinybson prebuild_targets)