From 584d8abe1e6e972b240397746e0148e18864ef59 Mon Sep 17 00:00:00 2001 From: Silvan Fuhrer Date: Mon, 5 Feb 2024 18:30:54 +0100 Subject: [PATCH] params: change return type of param_modify_on_import to enum Return early in param_import_callback() with 1 if we do a param_set in the param translation. Signed-off-by: Silvan Fuhrer --- src/lib/parameters/flashparams/flashparams.cpp | 4 +++- src/lib/parameters/param_translation.cpp | 8 ++++---- src/lib/parameters/param_translation.h | 8 +++++++- src/lib/parameters/param_translation_unit_tests.cpp | 4 ++-- src/lib/parameters/parameters.cpp | 5 ++++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/lib/parameters/flashparams/flashparams.cpp b/src/lib/parameters/flashparams/flashparams.cpp index f466fd805e..c37959a706 100644 --- a/src/lib/parameters/flashparams/flashparams.cpp +++ b/src/lib/parameters/flashparams/flashparams.cpp @@ -189,7 +189,9 @@ param_import_callback(bson_decoder_t decoder, bson_node_t node) return 0; } - param_modify_on_import(node); + if (param_modify_on_import(node) == param_modify_on_import_ret::PARAM_SKIP_IMPORT) { + return 1; + } /* * Find the parameter this node represents. If we don't know it, diff --git a/src/lib/parameters/param_translation.cpp b/src/lib/parameters/param_translation.cpp index 4f83be01aa..93cbddcdec 100644 --- a/src/lib/parameters/param_translation.cpp +++ b/src/lib/parameters/param_translation.cpp @@ -40,7 +40,7 @@ #include #include -bool param_modify_on_import(bson_node_t node) +param_modify_on_import_ret param_modify_on_import(bson_node_t node) { // 2023-12-06: translate and invert FW_ARSP_MODE-> FW_USE_AIRSPD { @@ -54,7 +54,7 @@ bool param_modify_on_import(bson_node_t node) strcpy(node->name, "FW_USE_AIRSPD"); PX4_INFO("copying and inverting %s -> %s", "FW_ARSP_MODE", "FW_USE_AIRSPD"); - return true; + return param_modify_on_import_ret::PARAM_MODIFIED; } } @@ -69,9 +69,9 @@ bool param_modify_on_import(bson_node_t node) } - return true; + return param_modify_on_import_ret::PARAM_MODIFIED; } } - return false; + return param_modify_on_import_ret::PARAM_NOT_MODIFIED; } diff --git a/src/lib/parameters/param_translation.h b/src/lib/parameters/param_translation.h index 1d001ce09e..2bbf401ac7 100644 --- a/src/lib/parameters/param_translation.h +++ b/src/lib/parameters/param_translation.h @@ -35,4 +35,10 @@ #include "tinybson/tinybson.h" -__EXPORT bool param_modify_on_import(bson_node_t node); +enum class param_modify_on_import_ret { + PARAM_SKIP_IMPORT = 0, + PARAM_NOT_MODIFIED = 1, + PARAM_MODIFIED = 2 +}; + +__EXPORT param_modify_on_import_ret param_modify_on_import(bson_node_t node); diff --git a/src/lib/parameters/param_translation_unit_tests.cpp b/src/lib/parameters/param_translation_unit_tests.cpp index 69709bf31a..b2e398effb 100644 --- a/src/lib/parameters/param_translation_unit_tests.cpp +++ b/src/lib/parameters/param_translation_unit_tests.cpp @@ -33,8 +33,8 @@ #include "param_translation.h" -bool param_modify_on_import(bson_node_t node) +param_modify_on_import_ret param_modify_on_import(bson_node_t node) { // don't modify params for unit tests - return false; + return param_modify_on_import_ret::PARAM_NOT_MODIFIED; } diff --git a/src/lib/parameters/parameters.cpp b/src/lib/parameters/parameters.cpp index ad35dca782..0b20bd0fe7 100644 --- a/src/lib/parameters/parameters.cpp +++ b/src/lib/parameters/parameters.cpp @@ -1078,7 +1078,10 @@ param_import_callback(bson_decoder_t decoder, bson_node_t node) return 0; } - param_modify_on_import(node); + // if we do param_set() directly in the translation, set PARAM_SKIP_IMPORT as return value and return here + if (param_modify_on_import(node) == param_modify_on_import_ret::PARAM_SKIP_IMPORT) { + return 1; + } // Find the parameter this node represents. If we don't know it, ignore the node. param_t param = param_find_no_notification(node->name);