From 2b6ca2cf82e4b8a216758cd9f5835db3befaf231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 19 Feb 2018 15:09:07 +0100 Subject: [PATCH] uavcan_main: use parameter_update to check for param updates this avoids calling param_get() on every loop iteration. --- src/modules/uavcan/uavcan_main.cpp | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/modules/uavcan/uavcan_main.cpp b/src/modules/uavcan/uavcan_main.cpp index f42978d772..d9137b41c2 100644 --- a/src/modules/uavcan/uavcan_main.cpp +++ b/src/modules/uavcan/uavcan_main.cpp @@ -58,6 +58,7 @@ #include #include +#include #include #include @@ -419,16 +420,14 @@ int UavcanNode::get_param(int remote_node_id, const char *name) void UavcanNode::update_params() { - param_t param_handle; + // multicopter air-mode + param_t param_handle = param_find("MC_AIRMODE"); - // multicopter air-mode - param_handle = param_find("MC_AIRMODE"); - - if (param_handle != PARAM_INVALID) { - int val; - param_get(param_handle, &val); - _airmode = val > 0; - } + if (param_handle != PARAM_INVALID) { + int32_t val; + param_get(param_handle, &val); + _airmode = val > 0; + } } int UavcanNode::start_fw_server() @@ -828,9 +827,21 @@ int UavcanNode::run() _actuator_direct_poll_fd_num = add_poll_fd(_actuator_direct_sub); } + update_params(); + + int params_sub = orb_subscribe(ORB_ID(parameter_update)); + while (!_task_should_exit) { - update_params(); + /* check for parameter updates */ + bool param_updated = false; + orb_check(params_sub, ¶m_updated); + + if (param_updated) { + struct parameter_update_s update; + orb_copy(ORB_ID(parameter_update), params_sub, &update); + update_params(); + } switch (_fw_server_action) { case Start: @@ -991,6 +1002,8 @@ int UavcanNode::run() } } + orb_unsubscribe(params_sub); + (void)::close(busevent_fd); teardown();