PX4 Firmware
PX4 Autopilot Software http://px4.io
DataValidator Class Reference

#include <data_validator.h>

Collaboration diagram for DataValidator:

Public Member Functions

 DataValidator ()=default
 
 ~DataValidator ()=default
 
void put (uint64_t timestamp, float val, uint64_t error_count, int priority)
 Put an item into the validator. More...
 
void put (uint64_t timestamp, const float val[dimensions], uint64_t error_count, int priority)
 Put a 3D item into the validator. More...
 
DataValidatorsibling ()
 Get the next sibling in the group. More...
 
void setSibling (DataValidator *new_sibling)
 Set the sibling to the next node in the group. More...
 
float confidence (uint64_t timestamp)
 Get the confidence of this validator. More...
 
uint64_t error_count () const
 Get the error count of this validator. More...
 
float * value ()
 Get the values of this validator. More...
 
bool used () const
 Get the used status of this validator. More...
 
int priority () const
 Get the priority of this validator. More...
 
uint32_t state () const
 Get the error state of this validator. More...
 
void reset_state ()
 Reset the error state of this validator. More...
 
float * rms ()
 Get the RMS values of this validator. More...
 
float * vibration_offset ()
 Get the vibration offset. More...
 
void print ()
 Print the validator value. More...
 
void set_timeout (uint32_t timeout_interval_us)
 Set the timeout value. More...
 
void set_equal_value_threshold (uint32_t threshold)
 Set the equal count threshold. More...
 
uint32_t get_timeout () const
 Get the timeout value. More...
 

Static Public Attributes

static const unsigned dimensions = 3
 
static constexpr uint32_t ERROR_FLAG_NO_ERROR = (0x00000000U)
 Data validator error states. More...
 
static constexpr uint32_t ERROR_FLAG_NO_DATA = (0x00000001U)
 
static constexpr uint32_t ERROR_FLAG_STALE_DATA = (0x00000001U << 1)
 
static constexpr uint32_t ERROR_FLAG_TIMEOUT = (0x00000001U << 2)
 
static constexpr uint32_t ERROR_FLAG_HIGH_ERRCOUNT = (0x00000001U << 3)
 
static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4)
 

Private Member Functions

 DataValidator (const DataValidator &)=delete
 
DataValidator operator= (const DataValidator &)=delete
 

Private Attributes

uint32_t _error_mask {ERROR_FLAG_NO_ERROR}
 sensor error state More...
 
uint32_t _timeout_interval {20000}
 interval in which the datastream times out in us More...
 
uint64_t _time_last {0}
 last timestamp More...
 
uint64_t _event_count {0}
 total data counter More...
 
uint64_t _error_count {0}
 error count More...
 
int _error_density {0}
 ratio between successful reads and errors More...
 
int _priority {0}
 sensor nominal priority More...
 
float _mean [dimensions] {}
 mean of value More...
 
float _lp [dimensions] {}
 low pass value More...
 
float _M2 [dimensions] {}
 RMS component value. More...
 
float _rms [dimensions] {}
 root mean square error More...
 
float _value [dimensions] {}
 last value More...
 
float _vibe [dimensions] {}
 vibration level, in sensor unit More...
 
unsigned _value_equal_count {0}
 equal values in a row More...
 
unsigned _value_equal_count_threshold {VALUE_EQUAL_COUNT_DEFAULT}
 when to consider an equal count as a problem More...
 
DataValidator_sibling {nullptr}
 sibling in the group More...
 

Static Private Attributes

static const constexpr unsigned NORETURN_ERRCOUNT = 10000
 if the error count reaches this value, return sensor as invalid More...
 
static const constexpr float ERROR_DENSITY_WINDOW = 100.0f
 window in measurement counts for errors More...
 
static const constexpr unsigned VALUE_EQUAL_COUNT_DEFAULT = 100
 if the sensor value is the same (accumulated also between axes) this many times, flag it More...
 

Detailed Description

Definition at line 47 of file data_validator.h.

Constructor & Destructor Documentation

◆ DataValidator() [1/2]

DataValidator::DataValidator ( )
default

◆ ~DataValidator()

DataValidator::~DataValidator ( )
default

◆ DataValidator() [2/2]

DataValidator::DataValidator ( const DataValidator )
privatedelete

Member Function Documentation

◆ confidence()

float DataValidator::confidence ( uint64_t  timestamp)

Get the confidence of this validator.

Returns
the confidence between 0 and 1

Definition at line 103 of file data_validator.cpp.

References _error_count, _error_density, _error_mask, _time_last, _timeout_interval, _value_equal_count, _value_equal_count_threshold, ERROR_DENSITY_WINDOW, ERROR_FLAG_HIGH_ERRCOUNT, ERROR_FLAG_HIGH_ERRDENSITY, ERROR_FLAG_NO_DATA, ERROR_FLAG_NO_ERROR, ERROR_FLAG_STALE_DATA, ERROR_FLAG_TIMEOUT, f(), and NORETURN_ERRCOUNT.

Referenced by Sensors::diff_pres_poll(), DataValidatorGroup::get_best(), DataValidatorGroup::get_vibration_factor(), DataValidatorGroup::get_vibration_offset(), print(), setSibling(), test_error_tracking(), test_init(), test_put(), test_sensor_failure(), and test_stale_detector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error_count()

uint64_t DataValidator::error_count ( ) const
inline

Get the error count of this validator.

Returns
the error count

Definition at line 92 of file data_validator.h.

References _error_count.

Referenced by test_error_tracking(), test_init(), and test_simple_failover().

Here is the caller graph for this function:

◆ get_timeout()

uint32_t DataValidator::get_timeout ( ) const
inline

Get the timeout value.

Returns
The timeout interval in microseconds

Definition at line 160 of file data_validator.h.

References _timeout_interval.

Referenced by add_validator_to_group(), DataValidatorGroup::DataValidatorGroup(), and test_init().

Here is the caller graph for this function:

◆ operator=()

DataValidator DataValidator::operator= ( const DataValidator )
privatedelete

◆ print()

void DataValidator::print ( )

Print the validator value.

Definition at line 148 of file data_validator.cpp.

References _lp, _mean, _rms, _time_last, _value, confidence(), dimensions, ecl_absolute_time, and ECL_INFO.

Referenced by dump_validator_state(), DataValidatorGroup::print(), Sensors::print_status(), test_init(), and vibration_offset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priority()

int DataValidator::priority ( ) const
inline

Get the priority of this validator.

Returns
the stored priority

Definition at line 110 of file data_validator.h.

References _priority.

Referenced by DataValidatorGroup::get_best(), DataValidatorGroup::print(), and test_init().

Here is the caller graph for this function:

◆ put() [1/2]

void DataValidator::put ( uint64_t  timestamp,
float  val,
uint64_t  error_count,
int  priority 
)

Put an item into the validator.

Parameters
valItem to put

Definition at line 47 of file data_validator.cpp.

References data, and dimensions.

Referenced by Sensors::diff_pres_poll(), fill_validator_with_samples(), insert_values_around_mean(), DataValidatorGroup::put(), and test_error_tracking().

Here is the caller graph for this function:

◆ put() [2/2]

void DataValidator::put ( uint64_t  timestamp,
const float  val[dimensions],
uint64_t  error_count,
int  priority 
)

Put a 3D item into the validator.

Parameters
valItem to put

Definition at line 55 of file data_validator.cpp.

References _error_count, _error_density, _event_count, _lp, _M2, _mean, _priority, _rms, _time_last, _value, _value_equal_count, _vibe, dimensions, and f().

Here is the call graph for this function:

◆ reset_state()

void DataValidator::reset_state ( )
inline

Reset the error state of this validator.

Definition at line 121 of file data_validator.h.

References _error_mask, and ERROR_FLAG_NO_ERROR.

Referenced by DataValidatorGroup::get_best(), and test_error_tracking().

Here is the caller graph for this function:

◆ rms()

float* DataValidator::rms ( )
inline

Get the RMS values of this validator.

Returns
the stored RMS

Definition at line 127 of file data_validator.h.

References _rms.

Referenced by DataValidatorGroup::get_vibration_factor(), test_rms_calculation(), and test_vibration().

Here is the caller graph for this function:

◆ set_equal_value_threshold()

void DataValidator::set_equal_value_threshold ( uint32_t  threshold)
inline

Set the equal count threshold.

Parameters
thresholdThe number of equal values before considering the sensor stale

Definition at line 153 of file data_validator.h.

References _value_equal_count_threshold.

Referenced by add_validator_to_group(), fill_validator_with_samples(), Sensors::Sensors(), DataValidatorGroup::set_equal_value_threshold(), test_error_tracking(), and test_rms_calculation().

Here is the caller graph for this function:

◆ set_timeout()

void DataValidator::set_timeout ( uint32_t  timeout_interval_us)
inline

Set the timeout value.

Parameters
timeout_interval_usThe timeout interval in microseconds

Definition at line 146 of file data_validator.h.

References _timeout_interval.

Referenced by DataValidatorGroup::add_new_validator(), fill_validator_with_samples(), Sensors::Sensors(), DataValidatorGroup::set_timeout(), test_error_tracking(), and test_init().

Here is the caller graph for this function:

◆ setSibling()

void DataValidator::setSibling ( DataValidator new_sibling)
inline

Set the sibling to the next node in the group.

Definition at line 80 of file data_validator.h.

References _sibling, and confidence().

Referenced by DataValidatorGroup::add_new_validator(), DataValidatorGroup::DataValidatorGroup(), and test_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sibling()

DataValidator* DataValidator::sibling ( )
inline

Get the next sibling in the group.

Returns
the next sibling

Definition at line 74 of file data_validator.h.

References _sibling.

Referenced by DataValidatorGroup::failover_index(), DataValidatorGroup::failover_state(), DataValidatorGroup::get_best(), DataValidatorGroup::get_vibration_factor(), DataValidatorGroup::get_vibration_offset(), DataValidatorGroup::print(), DataValidatorGroup::put(), DataValidatorGroup::set_equal_value_threshold(), DataValidatorGroup::set_timeout(), test_init(), and DataValidatorGroup::~DataValidatorGroup().

Here is the caller graph for this function:

◆ state()

uint32_t DataValidator::state ( ) const
inline

Get the error state of this validator.

Returns
the bitmask with the error status

Definition at line 116 of file data_validator.h.

References _error_mask.

Referenced by dump_validator_state(), DataValidatorGroup::failover_index(), DataValidatorGroup::failover_state(), DataValidatorGroup::print(), test_error_tracking(), test_init(), test_put(), test_sensor_failure(), test_simple_failover(), and test_stale_detector().

Here is the caller graph for this function:

◆ used()

bool DataValidator::used ( ) const
inline

Get the used status of this validator.

Returns
true if this validator ever saw data

Definition at line 104 of file data_validator.h.

References _time_last.

Referenced by DataValidatorGroup::failover_index(), DataValidatorGroup::failover_state(), DataValidatorGroup::print(), test_error_tracking(), test_init(), and test_put().

Here is the caller graph for this function:

◆ value()

float* DataValidator::value ( )
inline

Get the values of this validator.

Returns
the stored value

Definition at line 98 of file data_validator.h.

References _value.

Referenced by DataValidatorGroup::get_best(), and test_put().

Here is the caller graph for this function:

◆ vibration_offset()

float* DataValidator::vibration_offset ( )
inline

Get the vibration offset.

Returns
the stored vibration offset

Definition at line 133 of file data_validator.h.

References _vibe, and print().

Referenced by DataValidatorGroup::get_vibration_offset(), test_init(), test_rms_calculation(), and test_vibration().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _error_count

uint64_t DataValidator::_error_count {0}
private

error count

Definition at line 179 of file data_validator.h.

Referenced by confidence(), error_count(), and put().

◆ _error_density

int DataValidator::_error_density {0}
private

ratio between successful reads and errors

Definition at line 181 of file data_validator.h.

Referenced by confidence(), and put().

◆ _error_mask

uint32_t DataValidator::_error_mask {ERROR_FLAG_NO_ERROR}
private

sensor error state

Definition at line 173 of file data_validator.h.

Referenced by confidence(), reset_state(), and state().

◆ _event_count

uint64_t DataValidator::_event_count {0}
private

total data counter

Definition at line 178 of file data_validator.h.

Referenced by put().

◆ _lp

float DataValidator::_lp[dimensions] {}
private

low pass value

Definition at line 186 of file data_validator.h.

Referenced by print(), and put().

◆ _M2

float DataValidator::_M2[dimensions] {}
private

RMS component value.

Definition at line 187 of file data_validator.h.

Referenced by put().

◆ _mean

float DataValidator::_mean[dimensions] {}
private

mean of value

Definition at line 185 of file data_validator.h.

Referenced by print(), and put().

◆ _priority

int DataValidator::_priority {0}
private

sensor nominal priority

Definition at line 183 of file data_validator.h.

Referenced by priority(), and put().

◆ _rms

float DataValidator::_rms[dimensions] {}
private

root mean square error

Definition at line 188 of file data_validator.h.

Referenced by print(), put(), and rms().

◆ _sibling

DataValidator* DataValidator::_sibling {nullptr}
private

sibling in the group

Definition at line 195 of file data_validator.h.

Referenced by setSibling(), and sibling().

◆ _time_last

uint64_t DataValidator::_time_last {0}
private

last timestamp

Definition at line 177 of file data_validator.h.

Referenced by confidence(), print(), put(), and used().

◆ _timeout_interval

uint32_t DataValidator::_timeout_interval {20000}
private

interval in which the datastream times out in us

Definition at line 175 of file data_validator.h.

Referenced by confidence(), get_timeout(), and set_timeout().

◆ _value

float DataValidator::_value[dimensions] {}
private

last value

Definition at line 189 of file data_validator.h.

Referenced by print(), put(), and value().

◆ _value_equal_count

unsigned DataValidator::_value_equal_count {0}
private

equal values in a row

Definition at line 192 of file data_validator.h.

Referenced by confidence(), and put().

◆ _value_equal_count_threshold

unsigned DataValidator::_value_equal_count_threshold {VALUE_EQUAL_COUNT_DEFAULT}
private

when to consider an equal count as a problem

Definition at line 193 of file data_validator.h.

Referenced by confidence(), and set_equal_value_threshold().

◆ _vibe

float DataValidator::_vibe[dimensions] {}
private

vibration level, in sensor unit

Definition at line 190 of file data_validator.h.

Referenced by put(), and vibration_offset().

◆ dimensions

const unsigned DataValidator::dimensions = 3
static

◆ ERROR_DENSITY_WINDOW

const constexpr float DataValidator::ERROR_DENSITY_WINDOW = 100.0f
staticprivate

window in measurement counts for errors

Definition at line 198 of file data_validator.h.

Referenced by confidence().

◆ ERROR_FLAG_HIGH_ERRCOUNT

constexpr uint32_t DataValidator::ERROR_FLAG_HIGH_ERRCOUNT = (0x00000001U << 3)
static

◆ ERROR_FLAG_HIGH_ERRDENSITY

constexpr uint32_t DataValidator::ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4)
static

◆ ERROR_FLAG_NO_DATA

constexpr uint32_t DataValidator::ERROR_FLAG_NO_DATA = (0x00000001U)
static

◆ ERROR_FLAG_NO_ERROR

constexpr uint32_t DataValidator::ERROR_FLAG_NO_ERROR = (0x00000000U)
static

◆ ERROR_FLAG_STALE_DATA

constexpr uint32_t DataValidator::ERROR_FLAG_STALE_DATA = (0x00000001U << 1)
static

◆ ERROR_FLAG_TIMEOUT

constexpr uint32_t DataValidator::ERROR_FLAG_TIMEOUT = (0x00000001U << 2)
static

◆ NORETURN_ERRCOUNT

const constexpr unsigned DataValidator::NORETURN_ERRCOUNT = 10000
staticprivate

if the error count reaches this value, return sensor as invalid

Definition at line 197 of file data_validator.h.

Referenced by confidence().

◆ VALUE_EQUAL_COUNT_DEFAULT

const constexpr unsigned DataValidator::VALUE_EQUAL_COUNT_DEFAULT = 100
staticprivate

if the sensor value is the same (accumulated also between axes) this many times, flag it

Definition at line 199 of file data_validator.h.


The documentation for this class was generated from the following files: