mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-12 01:27:35 +08:00
validation initialize all members
- fixes Coverity CID 260331
This commit is contained in:
@@ -40,29 +40,9 @@
|
||||
*/
|
||||
|
||||
#include "data_validator.h"
|
||||
|
||||
#include <ecl.h>
|
||||
|
||||
DataValidator::DataValidator() :
|
||||
_error_mask(ERROR_FLAG_NO_ERROR),
|
||||
_timeout_interval(20000),
|
||||
_time_last(0),
|
||||
_event_count(0),
|
||||
_error_count(0),
|
||||
_error_density(0),
|
||||
_priority(0),
|
||||
_mean{0.0f},
|
||||
_lp{0.0f},
|
||||
_M2{0.0f},
|
||||
_rms{0.0f},
|
||||
_value{0.0f},
|
||||
_vibe{0.0f},
|
||||
_value_equal_count(0),
|
||||
_value_equal_count_threshold(VALUE_EQUAL_COUNT_DEFAULT),
|
||||
_sibling(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
DataValidator::put(uint64_t timestamp, float val, uint64_t error_count_in, int priority_in)
|
||||
{
|
||||
@@ -72,7 +52,7 @@ DataValidator::put(uint64_t timestamp, float val, uint64_t error_count_in, int p
|
||||
}
|
||||
|
||||
void
|
||||
DataValidator::put(uint64_t timestamp, float val[dimensions], uint64_t error_count_in, int priority_in)
|
||||
DataValidator::put(uint64_t timestamp, const float val[dimensions], uint64_t error_count_in, int priority_in)
|
||||
{
|
||||
_event_count++;
|
||||
|
||||
|
||||
+29
-24
@@ -49,8 +49,8 @@ class DataValidator
|
||||
public:
|
||||
static const unsigned dimensions = 3;
|
||||
|
||||
DataValidator();
|
||||
virtual ~DataValidator() = default;
|
||||
DataValidator() = default;
|
||||
~DataValidator() = default;
|
||||
|
||||
/**
|
||||
* Put an item into the validator.
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
*
|
||||
* @param val Item to put
|
||||
*/
|
||||
void put(uint64_t timestamp, float val[dimensions], uint64_t error_count, int priority);
|
||||
void put(uint64_t timestamp, const float val[dimensions], uint64_t error_count, int priority);
|
||||
|
||||
/**
|
||||
* Get the next sibling in the group
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
* Get the error count of this validator
|
||||
* @return the error count
|
||||
*/
|
||||
uint64_t error_count() { return _error_count; }
|
||||
uint64_t error_count() const { return _error_count; }
|
||||
|
||||
/**
|
||||
* Get the values of this validator
|
||||
@@ -101,19 +101,19 @@ public:
|
||||
* Get the used status of this validator
|
||||
* @return true if this validator ever saw data
|
||||
*/
|
||||
bool used() { return (_time_last > 0); }
|
||||
bool used() const { return (_time_last > 0); }
|
||||
|
||||
/**
|
||||
* Get the priority of this validator
|
||||
* @return the stored priority
|
||||
*/
|
||||
int priority() { return (_priority); }
|
||||
int priority() const { return _priority; }
|
||||
|
||||
/**
|
||||
* Get the error state of this validator
|
||||
* @return the bitmask with the error status
|
||||
*/
|
||||
uint32_t state() { return _error_mask; }
|
||||
uint32_t state() const { return _error_mask; }
|
||||
|
||||
/**
|
||||
* Reset the error state of this validator
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
*
|
||||
* @return The timeout interval in microseconds
|
||||
*/
|
||||
uint32_t get_timeout() const { return _timeout_interval; }
|
||||
uint32_t get_timeout() const { return _timeout_interval; }
|
||||
|
||||
/**
|
||||
* Data validator error states
|
||||
@@ -170,24 +170,29 @@ public:
|
||||
static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4);
|
||||
|
||||
private:
|
||||
uint32_t _error_mask; /**< sensor error state */
|
||||
uint32_t _timeout_interval; /**< interval in which the datastream times out in us */
|
||||
uint64_t _time_last; /**< last timestamp */
|
||||
uint64_t _event_count; /**< total data counter */
|
||||
uint64_t _error_count; /**< error count */
|
||||
int _error_density; /**< ratio between successful reads and errors */
|
||||
int _priority; /**< sensor nominal priority */
|
||||
float _mean[dimensions]; /**< mean of value */
|
||||
float _lp[dimensions]; /**< low pass value */
|
||||
float _M2[dimensions]; /**< RMS component value */
|
||||
float _rms[dimensions]; /**< root mean square error */
|
||||
float _value[dimensions]; /**< last value */
|
||||
float _vibe[dimensions]; /**< vibration level, in sensor unit */
|
||||
uint32_t _error_mask{ERROR_FLAG_NO_ERROR}; /**< sensor error state */
|
||||
|
||||
unsigned _value_equal_count; /**< equal values in a row */
|
||||
unsigned _value_equal_count_threshold; /**< when to consider an equal count as a problem */
|
||||
uint32_t _timeout_interval{20000}; /**< interval in which the datastream times out in us */
|
||||
|
||||
DataValidator *_sibling; /**< sibling in the group */
|
||||
uint64_t _time_last{0}; /**< last timestamp */
|
||||
uint64_t _event_count{0}; /**< total data counter */
|
||||
uint64_t _error_count{0}; /**< error count */
|
||||
|
||||
int _error_density{0}; /**< ratio between successful reads and errors */
|
||||
|
||||
int _priority{0}; /**< sensor nominal priority */
|
||||
|
||||
float _mean[dimensions] {}; /**< mean of value */
|
||||
float _lp[dimensions] {}; /**< low pass value */
|
||||
float _M2[dimensions] {}; /**< RMS component value */
|
||||
float _rms[dimensions] {}; /**< root mean square error */
|
||||
float _value[dimensions] {}; /**< last value */
|
||||
float _vibe[dimensions] {}; /**< vibration level, in sensor unit */
|
||||
|
||||
unsigned _value_equal_count{0}; /**< equal values in a row */
|
||||
unsigned _value_equal_count_threshold{VALUE_EQUAL_COUNT_DEFAULT}; /**< when to consider an equal count as a problem */
|
||||
|
||||
DataValidator *_sibling{nullptr}; /**< sibling in the group */
|
||||
|
||||
static const constexpr unsigned NORETURN_ERRCOUNT = 10000; /**< if the error count reaches this value, return sensor as invalid */
|
||||
static const constexpr float ERROR_DENSITY_WINDOW = 100.0f; /**< window in measurement counts for errors */
|
||||
|
||||
@@ -43,13 +43,7 @@
|
||||
#include <ecl.h>
|
||||
#include <cfloat>
|
||||
|
||||
DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
||||
_first(nullptr),
|
||||
_last(nullptr),
|
||||
_curr_best(-1),
|
||||
_prev_best(-1),
|
||||
_first_failover_time(0),
|
||||
_toggle_count(0)
|
||||
DataValidatorGroup::DataValidatorGroup(unsigned siblings)
|
||||
{
|
||||
DataValidator *next = nullptr;
|
||||
DataValidator *prev = nullptr;
|
||||
@@ -123,7 +117,7 @@ DataValidatorGroup::set_equal_value_threshold(uint32_t threshold)
|
||||
|
||||
|
||||
void
|
||||
DataValidatorGroup::put(unsigned index, uint64_t timestamp, float val[3], uint64_t error_count, int priority)
|
||||
DataValidatorGroup::put(unsigned index, uint64_t timestamp, const float val[3], uint64_t error_count, int priority)
|
||||
{
|
||||
DataValidator *next = _first;
|
||||
unsigned i = 0;
|
||||
@@ -305,12 +299,6 @@ DataValidatorGroup::print()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
DataValidatorGroup::failover_count()
|
||||
{
|
||||
return _toggle_count;
|
||||
}
|
||||
|
||||
int
|
||||
DataValidatorGroup::failover_index()
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
* @param siblings initial number of DataValidator's. Must be > 0.
|
||||
*/
|
||||
DataValidatorGroup(unsigned siblings);
|
||||
virtual ~DataValidatorGroup();
|
||||
~DataValidatorGroup();
|
||||
|
||||
/**
|
||||
* Create a new Validator (with index equal to the number of currently existing validators)
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
* @param error_count The current error count of the sensor
|
||||
* @param priority The priority of the sensor
|
||||
*/
|
||||
void put(unsigned index, uint64_t timestamp, float val[3], uint64_t error_count, int priority);
|
||||
void put(unsigned index, uint64_t timestamp, const float val[3], uint64_t error_count, int priority);
|
||||
|
||||
/**
|
||||
* Get the best data triplet of the group
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
*
|
||||
* @return the number of failovers
|
||||
*/
|
||||
unsigned failover_count();
|
||||
unsigned failover_count() const { return _toggle_count; }
|
||||
|
||||
/**
|
||||
* Get the index of the failed sensor in the group
|
||||
@@ -133,13 +133,18 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
DataValidator *_first; /**< first node in the group */
|
||||
DataValidator *_last; /**< last node in the group */
|
||||
uint32_t _timeout_interval_us; /**< currently set timeout */
|
||||
int _curr_best; /**< currently best index */
|
||||
int _prev_best; /**< the previous best index */
|
||||
uint64_t _first_failover_time; /**< timestamp where the first failover occured or zero if none occured */
|
||||
unsigned _toggle_count; /**< number of back and forth switches between two sensors */
|
||||
DataValidator *_first{nullptr}; /**< first node in the group */
|
||||
DataValidator *_last{nullptr}; /**< last node in the group */
|
||||
|
||||
uint32_t _timeout_interval_us{0}; /**< currently set timeout */
|
||||
|
||||
int _curr_best{-1}; /**< currently best index */
|
||||
int _prev_best{-1}; /**< the previous best index */
|
||||
|
||||
uint64_t _first_failover_time{0}; /**< timestamp where the first failover occured or zero if none occured */
|
||||
|
||||
unsigned _toggle_count{0}; /**< number of back and forth switches between two sensors */
|
||||
|
||||
static constexpr float MIN_REGULAR_CONFIDENCE = 0.9f;
|
||||
|
||||
/* we don't want this class to be copied */
|
||||
|
||||
Reference in New Issue
Block a user