From 8e3517fae04d29375ff32f2440a2fa3a08a80dd9 Mon Sep 17 00:00:00 2001 From: bresch Date: Mon, 5 Dec 2022 14:13:09 +0100 Subject: [PATCH] DataValidator: fix unexpected failover Instead of always starting with instance 0 (potentially an internal mag), first take the current sensor as reference to compare the other ones against it. The issue is that otherwise we can end up in a situation where a switch occurs because the currently used sensor isn't much better than a sensor with a lower index: because the selected one isn't much better, we cannot "fail-over" to it and get stuck on another sensor, triggering a fail-over. --- .../data_validator/DataValidatorGroup.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/modules/sensors/data_validator/DataValidatorGroup.cpp b/src/modules/sensors/data_validator/DataValidatorGroup.cpp index c58574307c..a7ded78d26 100644 --- a/src/modules/sensors/data_validator/DataValidatorGroup.cpp +++ b/src/modules/sensors/data_validator/DataValidatorGroup.cpp @@ -153,14 +153,32 @@ float *DataValidatorGroup::get_best(uint64_t timestamp, int *index) int i = 0; + // First find the current selected sensor + while (next != nullptr) { + if (i == pre_check_best) { + const int prio = next->priority(); + const float confidence = next->confidence(timestamp); + + pre_check_prio = prio; + pre_check_confidence = confidence; + + max_index = i; + max_confidence = confidence; + max_priority = prio; + best = next; + break; + } + + next = next->sibling(); + i++; + } + + i = 0; + next = _first; + while (next != nullptr) { float confidence = next->confidence(timestamp); - if (i == pre_check_best) { - pre_check_prio = next->priority(); - pre_check_confidence = confidence; - } - /* * Switch if: * 1) the confidence is higher and priority is equal or higher