mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-21 23:50:36 +08:00
Reverse the linked list of data_validator_group and maintain a first node
for search from index 0 Fixes issue PX4/Firmware#8644
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
#include "data_validator.h"
|
#include "data_validator.h"
|
||||||
#include <ecl/ecl.h>
|
#include <ecl/ecl.h>
|
||||||
|
|
||||||
DataValidator::DataValidator(DataValidator *prev_sibling) :
|
DataValidator::DataValidator() :
|
||||||
_error_mask(ERROR_FLAG_NO_ERROR),
|
_error_mask(ERROR_FLAG_NO_ERROR),
|
||||||
_timeout_interval(20000),
|
_timeout_interval(20000),
|
||||||
_time_last(0),
|
_time_last(0),
|
||||||
@@ -58,7 +58,7 @@ DataValidator::DataValidator(DataValidator *prev_sibling) :
|
|||||||
_vibe{0.0f},
|
_vibe{0.0f},
|
||||||
_value_equal_count(0),
|
_value_equal_count(0),
|
||||||
_value_equal_count_threshold(VALUE_EQUAL_COUNT_DEFAULT),
|
_value_equal_count_threshold(VALUE_EQUAL_COUNT_DEFAULT),
|
||||||
_sibling(prev_sibling)
|
_sibling(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class __EXPORT DataValidator {
|
|||||||
public:
|
public:
|
||||||
static const unsigned dimensions = 3;
|
static const unsigned dimensions = 3;
|
||||||
|
|
||||||
DataValidator(DataValidator *prev_sibling = nullptr);
|
DataValidator();
|
||||||
virtual ~DataValidator() = default;
|
virtual ~DataValidator() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +72,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
DataValidator* sibling() { return _sibling; }
|
DataValidator* sibling() { return _sibling; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the sibling to the next node in the group
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sibling(DataValidator* sibling) { _sibling = sibling; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the confidence of this validator
|
* Get the confidence of this validator
|
||||||
* @return the confidence between 0 and 1
|
* @return the confidence between 0 and 1
|
||||||
|
|||||||
@@ -45,19 +45,31 @@
|
|||||||
|
|
||||||
DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
||||||
_first(nullptr),
|
_first(nullptr),
|
||||||
|
_last(nullptr),
|
||||||
_curr_best(-1),
|
_curr_best(-1),
|
||||||
_prev_best(-1),
|
_prev_best(-1),
|
||||||
_first_failover_time(0),
|
_first_failover_time(0),
|
||||||
_toggle_count(0)
|
_toggle_count(0)
|
||||||
{
|
{
|
||||||
DataValidator *next = _first;
|
DataValidator *next = nullptr;
|
||||||
|
DataValidator *prev = nullptr;
|
||||||
|
|
||||||
for (unsigned i = 0; i < siblings; i++) {
|
for (unsigned i = 0; i < siblings; i++) {
|
||||||
next = new DataValidator(next);
|
next = new DataValidator();
|
||||||
|
if(i == 0) {
|
||||||
|
_first = next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev->sibling(next);
|
||||||
|
}
|
||||||
|
prev = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
_first = next;
|
_last = next;
|
||||||
_timeout_interval_us = _first->get_timeout();
|
|
||||||
|
if(_first) {
|
||||||
|
_timeout_interval_us = _first->get_timeout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataValidatorGroup::~DataValidatorGroup()
|
DataValidatorGroup::~DataValidatorGroup()
|
||||||
@@ -71,13 +83,14 @@ DataValidatorGroup::~DataValidatorGroup()
|
|||||||
|
|
||||||
DataValidator *DataValidatorGroup::add_new_validator()
|
DataValidator *DataValidatorGroup::add_new_validator()
|
||||||
{
|
{
|
||||||
DataValidator *validator = new DataValidator(_first);
|
DataValidator *validator = new DataValidator();
|
||||||
if (!validator) {
|
if (!validator) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
_first = validator;
|
_last->sibling(validator);
|
||||||
_first->set_timeout(_timeout_interval_us);
|
_last = validator;
|
||||||
return _first;
|
_last->set_timeout(_timeout_interval_us);
|
||||||
|
return _last;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -133,7 +133,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataValidator *_first; /**< sibling in the group */
|
DataValidator *_first; /**< first node in the group */
|
||||||
|
DataValidator *_last; /**< last node in the group */
|
||||||
uint32_t _timeout_interval_us; /**< currently set timeout */
|
uint32_t _timeout_interval_us; /**< currently set timeout */
|
||||||
int _curr_best; /**< currently best index */
|
int _curr_best; /**< currently best index */
|
||||||
int _prev_best; /**< the previous best index */
|
int _prev_best; /**< the previous best index */
|
||||||
|
|||||||
Reference in New Issue
Block a user