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

This commit is contained in:
Daniel Agar
2022-12-19 17:09:23 -05:00
parent f5524fa605
commit f2cd7667dc
61 changed files with 286 additions and 194 deletions
+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)
{