rusEFI
The most advanced open source ECU
Public Member Functions | Private Attributes
StoredValueSensor Class Reference

Base class for sensors that compute a value on one thread, and want to make it available to consumers asynchronously. More...

#include <stored_value_sensor.h>

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

Public Member Functions

SensorResult get () const final override
 
 StoredValueSensor (SensorType type, efidur_t timeoutNt)
 
void invalidate ()
 
void invalidate (UnexpectedCode why)
 
void setValidValue (float value, efitick_t timestamp)
 
void showInfo (const char *sensorName) const override
 
virtual void setTimeout (int timeoutMs)
 
- Public Member Functions inherited from Sensor
bool Register ()
 
const char * getSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 

Private Attributes

SensorResult m_result
 
efidur_t m_timeoutPeriod
 
efitick_t m_lastUpdate = 0
 

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 setMockValue (int type, float value)
 
static void resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const char * getSensorName (SensorType type)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

Base class for sensors that compute a value on one thread, and want to make it available to consumers asynchronously.

Common examples include sensors that have to do heavy lifting to produce a reading, and don't want to perform that conversion at the time of consumption.

To use this class, create a class for your sensor that inherits StoredValueSensor, and call Invalidate() and SetValidValue(float) as appropriate when readings are available (or known to be invalid) for your sensor.

Consumers will retrieve the last set (or invalidated) value.

Definition at line 30 of file stored_value_sensor.h.

Constructor & Destructor Documentation

◆ StoredValueSensor()

StoredValueSensor::StoredValueSensor ( SensorType  type,
efidur_t  timeoutNt 
)
inline

Definition at line 54 of file stored_value_sensor.h.

55  : Sensor(type)
56  , m_result(unexpected)
57  , m_timeoutPeriod(timeoutNt)
58  {
59  }
Sensor(SensorType type)
Definition: sensor.h:182
SensorType type() const
Definition: sensor.h:176

Member Function Documentation

◆ get()

SensorResult StoredValueSensor::get ( ) const
inlinefinaloverridevirtual

Implements Sensor.

Definition at line 32 of file stored_value_sensor.h.

32  {
33  auto result = m_result;
34 
35  // Timeouts are disabled, return last value
37  return result;
38  }
39 
40  // Result is already failed, return that so that we get the real error code instead of a timeout
41  if (!result) {
42  return result;
43  }
44 
45  if (m_timeoutPeriod != 0) { // zero m_timeoutPeriod means value lasts forever
47  return UnexpectedCode::Timeout;
48  }
49  }
50 
51  return result;
52  }
static bool s_inhibitSensorTimeouts
Definition: sensor.h:185
efitick_t getTimeNowNt()
Definition: efitime.cpp:19

Referenced by MapAverager::showInfo(), RpmCalculator::showInfo(), CanSensorBase::showInfo(), FunctionalSensor::showInfo(), showInfo(), and Lps25Sensor::showInfo().

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

◆ invalidate() [1/2]

void StoredValueSensor::invalidate ( )
inline

Definition at line 62 of file stored_value_sensor.h.

62  {
63  m_result = unexpected;
64  }

Referenced by AemXSeriesWideband::decodeAemXSeries(), AemXSeriesWideband::decodeRusefiStandard(), flexCallback(), HellaOilLevelSensor::onEdge(), FunctionalSensor::postRawValue(), and Lps25Sensor::update().

Here is the caller graph for this function:

◆ invalidate() [2/2]

void StoredValueSensor::invalidate ( UnexpectedCode  why)
inline

Definition at line 67 of file stored_value_sensor.h.

67  {
68  m_result = why;
69  }

◆ setTimeout()

virtual void StoredValueSensor::setTimeout ( int  timeoutMs)
inlinevirtual

Definition at line 80 of file stored_value_sensor.h.

80  {
81  m_timeoutPeriod = MS2NT(timeoutMs);
82  }

◆ setValidValue()

void StoredValueSensor::setValidValue ( float  value,
efitick_t  timestamp 
)
inline

◆ showInfo()

void StoredValueSensor::showInfo ( const char *  sensorName) const
overridevirtual

Implements Sensor.

Reimplemented in Lps25Sensor, and FrequencySensor.

Definition at line 16 of file sensor_info_printing.cpp.

16  {
17  const auto value = get();
18  efiPrintf("StoredValue Sensor \"%s\": valid: %s, value: %.2f", sensorName, boolToString(value.Valid), value.Value);
19 }
SensorResult get() const final override
const char * boolToString(bool value)
Definition: efilib.cpp:18
Here is the call graph for this function:

Field Documentation

◆ m_lastUpdate

efitick_t StoredValueSensor::m_lastUpdate = 0
private

Definition at line 88 of file stored_value_sensor.h.

Referenced by get(), and setValidValue().

◆ m_result

SensorResult StoredValueSensor::m_result
private

Definition at line 85 of file stored_value_sensor.h.

Referenced by get(), invalidate(), and setValidValue().

◆ m_timeoutPeriod

efidur_t StoredValueSensor::m_timeoutPeriod
private

Definition at line 87 of file stored_value_sensor.h.

Referenced by get(), and setTimeout().


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