mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 10:30:34 +08:00
parameters: support for an optional remote parameter database (#22836)
The voxl2 has a split architecture. PX4 runs on a posix platform and a Qurt platform. The two communicate uorb topics back and forth with the muorb module. But each has it's own parameters database and they need to stay in sync with each other. This PR adds support to keep the 2 parameter databases in sync. The main parameters database running on Linux has file system support while the Qurt one does not. The Linux side is considered the primary and the Qurt side is considered the remote.
This commit is contained in:
@@ -105,8 +105,10 @@ static DynamicSparseLayer runtime_defaults{&firmware_defaults};
|
||||
DynamicSparseLayer user_config{&runtime_defaults};
|
||||
|
||||
/** parameter update topic handle */
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
static orb_advert_t param_topic = nullptr;
|
||||
static unsigned int param_instance = 0;
|
||||
#endif
|
||||
|
||||
static perf_counter_t param_export_perf;
|
||||
static perf_counter_t param_find_perf;
|
||||
@@ -116,6 +118,14 @@ static perf_counter_t param_set_perf;
|
||||
static pthread_mutex_t file_mutex =
|
||||
PTHREAD_MUTEX_INITIALIZER; ///< this protects against concurrent param saves (file or flash access).
|
||||
|
||||
// Support for remote parameter node
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
# include "parameters_primary.h"
|
||||
#endif // CONFIG_PARAM_PRIMARY
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
# include "parameters_remote.h"
|
||||
#endif // CONFIG_PARAM_REMOTE
|
||||
|
||||
void
|
||||
param_init()
|
||||
{
|
||||
@@ -128,14 +138,27 @@ param_init()
|
||||
px4_register_boardct_ioctl(_PARAMIOCBASE, param_ioctl);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_init();
|
||||
#endif // CONFIG_PARAM_PRIMARY
|
||||
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
param_remote_init();
|
||||
#endif // CONFIG_PARAM_REMOTE
|
||||
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
autosave_instance = new ParamAutosave();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
param_notify_changes()
|
||||
{
|
||||
parameter_update_s pup{};
|
||||
// Don't send if this is a remote node. Only the primary
|
||||
// sends out update notices
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
parameter_update_s pup {};
|
||||
pup.instance = param_instance++;
|
||||
pup.get_count = perf_event_count(param_get_perf);
|
||||
pup.set_count = perf_event_count(param_set_perf);
|
||||
@@ -152,6 +175,8 @@ param_notify_changes()
|
||||
} else {
|
||||
orb_publish(ORB_ID(parameter_update), param_topic, &pup);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static param_t param_find_internal(const char *name, bool notification)
|
||||
@@ -372,7 +397,7 @@ param_control_autosave(bool enable)
|
||||
}
|
||||
|
||||
static int
|
||||
param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes)
|
||||
param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes, bool update_remote = true)
|
||||
{
|
||||
if (!handle_in_range(param)) {
|
||||
PX4_ERR("set invalid param %d", param);
|
||||
@@ -421,6 +446,24 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_
|
||||
param_autosave();
|
||||
}
|
||||
|
||||
// If this is the parameter server, make sure that the remote is updated
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
|
||||
if (param_changed && update_remote) {
|
||||
param_primary_set_value(param, val);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// If this is the parameter remote, make sure that the primary is updated
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
|
||||
if (param_changed && update_remote) {
|
||||
param_remote_set_value(param, val);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
perf_end(param_set_perf);
|
||||
|
||||
/*
|
||||
@@ -456,6 +499,11 @@ int param_set_no_notification(param_t param, const void *val)
|
||||
return param_set_internal(param, val, false, false);
|
||||
}
|
||||
|
||||
int param_set_no_remote_update(param_t param, const void *val, bool notify)
|
||||
{
|
||||
return param_set_internal(param, val, false, notify, false);
|
||||
}
|
||||
|
||||
bool param_used(param_t param)
|
||||
{
|
||||
if (handle_in_range(param)) {
|
||||
@@ -468,6 +516,14 @@ bool param_used(param_t param)
|
||||
void param_set_used(param_t param)
|
||||
{
|
||||
if (handle_in_range(param)) {
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
|
||||
if (!param_used(param)) {
|
||||
param_remote_set_used(param);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
params_active.set(param, true);
|
||||
}
|
||||
}
|
||||
@@ -544,6 +600,11 @@ int param_set_default_value(param_t param, const void *val)
|
||||
|
||||
static int param_reset_internal(param_t param, bool notify = true, bool autosave = true)
|
||||
{
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
// Remote doesn't support reset
|
||||
return false;
|
||||
#endif
|
||||
|
||||
bool param_found = user_config.contains(param);
|
||||
|
||||
if (handle_in_range(param)) {
|
||||
@@ -558,6 +619,10 @@ static int param_reset_internal(param_t param, bool notify = true, bool autosave
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_reset(param);
|
||||
#endif
|
||||
|
||||
return param_found;
|
||||
}
|
||||
|
||||
@@ -567,6 +632,11 @@ int param_reset_no_notification(param_t param) { return param_reset_internal(par
|
||||
static void
|
||||
param_reset_all_internal(bool auto_save)
|
||||
{
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
// Remote doesn't support reset
|
||||
return;
|
||||
#endif
|
||||
|
||||
for (param_t param = 0; handle_in_range(param); param++) {
|
||||
param_reset_internal(param, false, false);
|
||||
}
|
||||
@@ -575,6 +645,10 @@ param_reset_all_internal(bool auto_save)
|
||||
param_autosave();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_reset_all();
|
||||
#endif
|
||||
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
@@ -1280,4 +1354,27 @@ void param_print_status()
|
||||
perf_print_counter(param_find_perf);
|
||||
perf_print_counter(param_get_perf);
|
||||
perf_print_counter(param_set_perf);
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
struct param_primary_counters counts;
|
||||
param_primary_get_counters(&counts);
|
||||
PX4_INFO("set value requests received: %" PRIu32 ", set value responses sent: %" PRIu32,
|
||||
counts.set_value_request_received, counts.set_value_response_sent);
|
||||
PX4_INFO("set value requests sent: %" PRIu32 ", set value responses received: %" PRIu32,
|
||||
counts.set_value_request_sent, counts.set_value_response_received);
|
||||
PX4_INFO("resets sent: %" PRIu32 ", set used requests received: %" PRIu32,
|
||||
counts.reset_sent, counts.set_used_received);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
struct param_remote_counters counts;
|
||||
param_remote_get_counters(&counts);
|
||||
PX4_INFO("set value requests received: %" PRIu32 ", set value responses sent: %" PRIu32,
|
||||
counts.set_value_request_received, counts.set_value_response_sent);
|
||||
PX4_INFO("set value requests sent: %" PRIu32 ", set value responses received: %" PRIu32,
|
||||
counts.set_value_request_sent, counts.set_value_response_received);
|
||||
PX4_INFO("resets received: %" PRIu32 ", set used requests sent: %" PRIu32,
|
||||
counts.reset_received, counts.set_used_sent);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user