Livello Serbatoio v0.13
This project realizes a simple device to monitor the water level in a tank.
Loading...
Searching...
No Matches
ReadingsAnalyzer Class Reference

Analyzes the readings from distance sensor to determine if the water level is increasing, decreasing or stationary. Permits also to detect sensor failure if the readings appear to be random. More...

Public Member Functions

 ReadingsAnalyzer (void)
 Default constructor.
 
void begin (void)
 Initializes this instance.
 
void addReading (const float64_t reading)
 Adds a measurement to the statistic.
 
uint8_t getAnalysis (void)
 Checks the measurements and gives a response.
 
void get_debug_values (uint16_t &dec, uint16_t &inc)
 Get current counters values for debug purpose.
 

Static Public Attributes

static const uint8_t UNKNOWN = 0U
 Unknown analysis result (initialization value).
 
static const uint8_t STATIONARY = 1U
 Water level is stationary.
 
static const uint8_t DECREASING = 2U
 Water level is decreasing.
 
static const uint8_t INCREASING = 3U
 Water level is increasing.
 
static const uint8_t NOISY = 4U
 Water level is not stable (possible sensor fault).
 

Static Private Member Functions

static uint16_t increase (const uint16_t val, const uint16_t by=1U)
 Increase the value val by by and returns it.
 
static uint16_t decrease (const uint16_t val, const uint16_t by=1U)
 Decrease the value val by by and returns it.
 

Private Attributes

float64_t last_reading
 Last water measurement.
 
uint16_t n_decreasing_readings
 Number of "decreasing" readings.
 
uint16_t n_increasing_readings
 Number of "increasing" readings.
 
bool is_noisy
 Noisy readings flag.
 
const float64_t NOISY_THRESHOLD = 5.0
 Difference in cm between readings to detect the noisy condition.
 
const float64_t READING_STEP = 0.2
 The minimum step in cm to detect an increasing or decreasing water tank level.
 

Static Private Attributes

static const int32_t INCREASING_COUNTER_THRESHOLD = 2
 Difference between increasing and decreasing counter to detect an "increasing" water tank level.
 
static const int32_t DECREASING_COUNTER_THRESHOLD = -2
 Difference between increasing and decreasing counter to detect a "decreasing" water tank level.
 

Detailed Description

Analyzes the readings from distance sensor to determine if the water level is increasing, decreasing or stationary. Permits also to detect sensor failure if the readings appear to be random.

Constructor & Destructor Documentation

◆ ReadingsAnalyzer()

ReadingsAnalyzer::ReadingsAnalyzer ( void )
inline

Default constructor.

Creates and instance of this class.

Member Function Documentation

◆ addReading()

void ReadingsAnalyzer::addReading ( const float64_t reading)
inline

Adds a measurement to the statistic.

Parameters
[in]readingThe distance measurement.

◆ begin()

void ReadingsAnalyzer::begin ( void )
inline

Initializes this instance.

◆ decrease()

static uint16_t ReadingsAnalyzer::decrease ( const uint16_t val,
const uint16_t by = 1U )
inlinestaticprivate

Decrease the value val by by and returns it.

Parameters
[in]valThe value to decrease.
[in]byThe value to sum.
Returns
The value of val - by or 0 if by >= val.

◆ get_debug_values()

void ReadingsAnalyzer::get_debug_values ( uint16_t & dec,
uint16_t & inc )
inline

Get current counters values for debug purpose.

Parameters
[out]decThe decreasing readings counter.
[out]incThe increasing readings counter.

◆ getAnalysis()

uint8_t ReadingsAnalyzer::getAnalysis ( void )
inline

Checks the measurements and gives a response.

Checks which events occurred more times.

Returns
The analysis result which can be any of the following: UNKNOWN, STATIONARY, DECREASING, INCREASING, NOISY.

◆ increase()

static uint16_t ReadingsAnalyzer::increase ( const uint16_t val,
const uint16_t by = 1U )
inlinestaticprivate

Increase the value val by by and returns it.

Parameters
[in]valThe value to increase.
[in]byThe value to sum.
Returns
The value of val + by or UINT16_MAX in case of overflow.

Member Data Documentation

◆ DECREASING

const uint8_t ReadingsAnalyzer::DECREASING = 2U
static

Water level is decreasing.

◆ DECREASING_COUNTER_THRESHOLD

const int32_t ReadingsAnalyzer::DECREASING_COUNTER_THRESHOLD = -2
staticprivate

Difference between increasing and decreasing counter to detect a "decreasing" water tank level.

◆ INCREASING

const uint8_t ReadingsAnalyzer::INCREASING = 3U
static

Water level is increasing.

◆ INCREASING_COUNTER_THRESHOLD

const int32_t ReadingsAnalyzer::INCREASING_COUNTER_THRESHOLD = 2
staticprivate

Difference between increasing and decreasing counter to detect an "increasing" water tank level.

◆ is_noisy

bool ReadingsAnalyzer::is_noisy
private

Noisy readings flag.

◆ last_reading

float64_t ReadingsAnalyzer::last_reading
private

Last water measurement.

◆ n_decreasing_readings

uint16_t ReadingsAnalyzer::n_decreasing_readings
private

Number of "decreasing" readings.

◆ n_increasing_readings

uint16_t ReadingsAnalyzer::n_increasing_readings
private

Number of "increasing" readings.

◆ NOISY

const uint8_t ReadingsAnalyzer::NOISY = 4U
static

Water level is not stable (possible sensor fault).

◆ NOISY_THRESHOLD

const float64_t ReadingsAnalyzer::NOISY_THRESHOLD = 5.0
private

Difference in cm between readings to detect the noisy condition.

◆ READING_STEP

const float64_t ReadingsAnalyzer::READING_STEP = 0.2
private

The minimum step in cm to detect an increasing or decreasing water tank level.

◆ STATIONARY

const uint8_t ReadingsAnalyzer::STATIONARY = 1U
static

Water level is stationary.

◆ UNKNOWN

const uint8_t ReadingsAnalyzer::UNKNOWN = 0U
static

Unknown analysis result (initialization value).


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