mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 20:28:37 +08:00
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:
@@ -128,7 +128,7 @@ if ("${CONFIG_SHMEM}" STREQUAL "1")
|
|||||||
list(APPEND SRCS parameters_shmem.cpp)
|
list(APPEND SRCS parameters_shmem.cpp)
|
||||||
else()
|
else()
|
||||||
list(APPEND SRCS parameters.cpp)
|
list(APPEND SRCS parameters.cpp)
|
||||||
if(PX4_TESTING)
|
if(BUILD_TESTING)
|
||||||
list(APPEND SRCS param_translation_unit_tests.cpp)
|
list(APPEND SRCS param_translation_unit_tests.cpp)
|
||||||
else()
|
else()
|
||||||
list(APPEND SRCS param_translation.cpp)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
param_modify_on_import(node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the parameter this node represents. If we don't know it,
|
* Find the parameter this node represents. If we don't know it,
|
||||||
* ignore the node.
|
* ignore the node.
|
||||||
@@ -301,8 +303,6 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
param_modify_on_import(node->name, node->type, v);
|
|
||||||
|
|
||||||
if (param_set_external(param, v, state->mark_saved, true)) {
|
if (param_set_external(param, v, state->mark_saved, true)) {
|
||||||
|
|
||||||
debug("error setting value for '%s'", node->name);
|
debug("error setting value for '%s'", node->name);
|
||||||
|
|||||||
@@ -39,34 +39,26 @@
|
|||||||
#include <drivers/drv_sensor.h>
|
#include <drivers/drv_sensor.h>
|
||||||
#include <lib/parameters/param.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)
|
// 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 (node->type == BSON_DOUBLE) {
|
||||||
if (strcmp("MC_DTERM_CUTOFF", name) == 0) {
|
if (strcmp("MC_DTERM_CUTOFF", node->name) == 0) {
|
||||||
param_t h = param_find("IMU_DGYRO_CUTOFF");
|
strcpy(node->name, "IMU_DGYRO_CUTOFF");
|
||||||
|
PX4_INFO("param migrating MC_DTERM_CUTOFF (removed) -> IMU_DGYRO_CUTOFF: value=%.3f", node->d);
|
||||||
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// translate (SPI) calibration ID parameters. This can be removed after the next release (current release=1.10)
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t *ivalue = (int32_t *)value;
|
int64_t *ivalue = &node->i;
|
||||||
|
|
||||||
const char *cal_id_params[] = {
|
const char *cal_id_params[] = {
|
||||||
"CAL_ACC0_ID",
|
"CAL_ACC0_ID",
|
||||||
@@ -94,7 +86,7 @@ bool param_modify_on_import(const char *name, bson_type_t type, void *value)
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(cal_id_params) / sizeof(cal_id_params[0]); ++i) {
|
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;
|
found = true;
|
||||||
break;
|
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;
|
int32_t new_value = (int32_t)device_id.devid;
|
||||||
|
|
||||||
if (new_value != *ivalue) {
|
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;
|
*ivalue = new_value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,5 @@
|
|||||||
|
|
||||||
#include "tinybson/tinybson.h"
|
#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"
|
#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
|
// don't modify params for unit tests
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1177,6 +1177,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
param_modify_on_import(node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the parameter this node represents. If we don't know it,
|
* Find the parameter this node represents. If we don't know it,
|
||||||
* ignore the node.
|
* ignore the node.
|
||||||
@@ -1263,8 +1265,6 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
param_modify_on_import(node->name, node->type, v);
|
|
||||||
|
|
||||||
if (param_set_internal(param, v, state->mark_saved, true)) {
|
if (param_set_internal(param, v, state->mark_saved, true)) {
|
||||||
PX4_DEBUG("error setting value for '%s'", node->name);
|
PX4_DEBUG("error setting value for '%s'", node->name);
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
Reference in New Issue
Block a user