rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
RedundantSensor Class Referencefinal

#include <redundant_sensor.h>

Inheritance diagram for RedundantSensor:
Inheritance graph
[legend]
Collaboration diagram for RedundantSensor:
Collaboration graph
[legend]

Public Member Functions

 RedundantSensor (SensorType outputType, SensorType firstSensor, SensorType secondSensor)
 
void configure (float maxDifference, bool ignoreSecondSensor)
 
SensorResult get () const override
 
bool isRedundant () const override
 
void showInfo (const char *sensorName) const override
 
- Public Member Functions inherited from Sensor
bool Register ()
 
const chargetSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
void unregister ()
 
SensorType type () const
 

Private Attributes

const SensorType m_first
 
const SensorType m_second
 
float m_maxDifference = 0
 
bool m_ignoreSecond = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Sensor
static void showAllSensorInfo ()
 
static void showInfo (SensorType type)
 
static void resetRegistry ()
 
static const SensorgetSensorOfType (SensorType type)
 
static SensorResult get (SensorType type)
 
static float getOrZero (SensorType type)
 
static float getRaw (SensorType type)
 
static bool isRedundant (SensorType type)
 
static bool hasSensor (SensorType type)
 
static void setMockValue (SensorType type, float value, bool mockRedundant=false)
 
static void setInvalidMockValue (SensorType type)
 
static void resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const chargetSensorName (SensorType type)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

Definition at line 5 of file redundant_sensor.h.

Constructor & Destructor Documentation

◆ RedundantSensor()

RedundantSensor::RedundantSensor ( SensorType  outputType,
SensorType  firstSensor,
SensorType  secondSensor 
)

Definition at line 5 of file redundant_sensor.cpp.

6 : Sensor(outputType)
7 , m_first(first)
8 , m_second(second)
9{
10}
const SensorType m_first
const SensorType m_second

Member Function Documentation

◆ configure()

void RedundantSensor::configure ( float  maxDifference,
bool  ignoreSecondSensor 
)

Definition at line 12 of file redundant_sensor.cpp.

12 {
13 m_maxDifference = maxDifference;
14 m_ignoreSecond = ignoreSecondSensor;
15}

◆ get()

SensorResult RedundantSensor::get ( ) const
overridevirtual

Implements Sensor.

Definition at line 17 of file redundant_sensor.cpp.

17 {
18 auto sensor1 = Sensor::get(m_first);
19
20 // If we're set to disable redundancy, just pass thru the first sensor
21 if (m_ignoreSecond) {
22 return sensor1;
23 }
24
25 auto sensor2 = Sensor::get(m_second);
26
27 // If either result is invalid, return invalid.
28 if (!sensor1.Valid || !sensor2.Valid) {
29 return UnexpectedCode::Inconsistent;
30 }
31
32 // If both are valid, check that they're near one another
33 float delta = absF(sensor1.Value - sensor2.Value);
34 if (delta > m_maxDifference) {
35 return UnexpectedCode::Inconsistent;
36 }
37
38 // Both sensors are valid, and their readings are close. All is well.
39 // Return the average
40 return (sensor1.Value + sensor2.Value) / 2;
41}
virtual SensorResult get() const =0
Here is the call graph for this function:

◆ isRedundant()

bool RedundantSensor::isRedundant ( ) const
inlineoverridevirtual

Reimplemented from Sensor.

Definition at line 18 of file redundant_sensor.h.

18 {
19 // This sensor is redundant when not ignoring the second channel
20 return !m_ignoreSecond;
21 }

◆ showInfo()

void RedundantSensor::showInfo ( const char sensorName) const
overridevirtual

Implements Sensor.

Definition at line 50 of file sensor_info_printing.cpp.

50 {
51 efiPrintf("Sensor \"%s\" is redundant combining \"%s\" and \"%s\"", sensorName, getSensorName(m_first), getSensorName(m_second));
52}
const char * getSensorName() const
Definition sensor.h:130
Here is the call graph for this function:

Field Documentation

◆ m_first

const SensorType RedundantSensor::m_first
private

Definition at line 27 of file redundant_sensor.h.

Referenced by get(), and showInfo().

◆ m_ignoreSecond

bool RedundantSensor::m_ignoreSecond = false
private

Definition at line 34 of file redundant_sensor.h.

Referenced by configure(), get(), and isRedundant().

◆ m_maxDifference

float RedundantSensor::m_maxDifference = 0
private

Definition at line 31 of file redundant_sensor.h.

Referenced by configure(), and get().

◆ m_second

const SensorType RedundantSensor::m_second
private

Definition at line 28 of file redundant_sensor.h.

Referenced by get(), and showInfo().


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