fix param import transition

* fix param import transition for MC_DTERM_CUTOFF

The previous implementation did not work, as there was a check for
param_find_no_notification() returning PARAM_INVALID for IMU_DGYRO_CUTOFF,
and therefore would not call param_modify_on_import().

This moves param_modify_on_import() before the check and makes it modify
the bson node directly.

* parameters: fix param import transition when testing is enabled

BUILD_TESTING is used for unit test builds, PX4_TESTING is used to enable additional test material within PX4

Co-authored-by: Daniel Agar <daniel@agar.ca>
This commit is contained in:
Beat Küng
2020-04-03 00:41:00 +02:00
committed by GitHub
parent 2baa5ca4d7
commit dfb5b5d7d9
6 changed files with 17 additions and 25 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ if ("${CONFIG_SHMEM}" STREQUAL "1")
list(APPEND SRCS parameters_shmem.cpp)
else()
list(APPEND SRCS parameters.cpp)
if(PX4_TESTING)
if(BUILD_TESTING)
list(APPEND SRCS param_translation_unit_tests.cpp)
else()
list(APPEND SRCS param_translation.cpp)
@@ -229,6 +229,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
return 0;
}
param_modify_on_import(node);
/*
* Find the parameter this node represents. If we don't know it,
* ignore the node.
@@ -301,8 +303,6 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
goto out;
}
param_modify_on_import(node->name, node->type, v);
if (param_set_external(param, v, state->mark_saved, true)) {
debug("error setting value for '%s'", node->name);
+10 -18
View File
@@ -39,34 +39,26 @@
#include <drivers/drv_sensor.h>
#include <lib/parameters/param.h>
bool param_modify_on_import(const char *name, bson_type_t type, void *value)
bool param_modify_on_import(bson_node_t node)
{
// migrate MC_DTERM_CUTOFF -> IMU_DGYRO_CUTOFF (2020-03-12). This can be removed after the next release (current release=1.10)
if (type == BSON_DOUBLE) {
if (strcmp("MC_DTERM_CUTOFF", name) == 0) {
param_t h = param_find("IMU_DGYRO_CUTOFF");
if (h == PX4_OK) {
float fvalue = *(float *)value;
PX4_INFO("param migrating MC_DTERM_CUTOFF (removed) -> IMU_DGYRO_CUTOFF: value=%.3f", (double)fvalue);
param_set_no_notification(h, value);
return true;
}
return false;
if (node->type == BSON_DOUBLE) {
if (strcmp("MC_DTERM_CUTOFF", node->name) == 0) {
strcpy(node->name, "IMU_DGYRO_CUTOFF");
PX4_INFO("param migrating MC_DTERM_CUTOFF (removed) -> IMU_DGYRO_CUTOFF: value=%.3f", node->d);
return true;
}
}
// translate (SPI) calibration ID parameters. This can be removed after the next release (current release=1.10)
if (type != BSON_INT32) {
if (node->type != BSON_INT32) {
return false;
}
int32_t *ivalue = (int32_t *)value;
int64_t *ivalue = &node->i;
const char *cal_id_params[] = {
"CAL_ACC0_ID",
@@ -94,7 +86,7 @@ bool param_modify_on_import(const char *name, bson_type_t type, void *value)
bool found = false;
for (int i = 0; i < sizeof(cal_id_params) / sizeof(cal_id_params[0]); ++i) {
if (strcmp(cal_id_params[i], name) == 0) {
if (strcmp(cal_id_params[i], node->name) == 0) {
found = true;
break;
}
@@ -145,7 +137,7 @@ bool param_modify_on_import(const char *name, bson_type_t type, void *value)
int32_t new_value = (int32_t)device_id.devid;
if (new_value != *ivalue) {
PX4_INFO("param modify: %s, value=0x%x (old=0x%x)", name, new_value, *ivalue);
PX4_INFO("param modify: %s, value=0x%x (old=0x%x)", node->name, new_value, (int32_t)*ivalue);
*ivalue = new_value;
return true;
}
+1 -1
View File
@@ -35,5 +35,5 @@
#include "tinybson/tinybson.h"
__EXPORT bool param_modify_on_import(const char *name, bson_type_t type, void *value);
__EXPORT bool param_modify_on_import(bson_node_t node);
@@ -33,7 +33,7 @@
#include "param_translation.h"
bool param_modify_on_import(const char *name, bson_type_t type, void *value)
bool param_modify_on_import(bson_node_t node)
{
// don't modify params for unit tests
return false;
+2 -2
View File
@@ -1177,6 +1177,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
return 0;
}
param_modify_on_import(node);
/*
* Find the parameter this node represents. If we don't know it,
* ignore the node.
@@ -1263,8 +1265,6 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
goto out;
}
param_modify_on_import(node->name, node->type, v);
if (param_set_internal(param, v, state->mark_saved, true)) {
PX4_DEBUG("error setting value for '%s'", node->name);
goto out;