rusEFI
The most advanced open source ECU
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
Sensor Class Referenceabstract

#include <sensor.h>

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

Public Member Functions

bool Register ()
 
virtual void showInfo (const char *sensorName) const =0
 
const char * getSensorName () const
 
virtual SensorResult get () const =0
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 

Static Public Member Functions

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

 Sensor (SensorType type)
 

Static Protected Attributes

static bool s_inhibitSensorTimeouts = false
 

Private Member Functions

constexpr size_t getIndex ()
 

Static Private Member Functions

static constexpr size_t getIndex (SensorType type)
 
static SensorRegistryEntry * getEntryForType (SensorType type)
 

Private Attributes

const SensorType m_type
 

Detailed Description

Definition at line 60 of file sensor.h.

Constructor & Destructor Documentation

◆ Sensor()

Sensor::Sensor ( SensorType  type)
inlineexplicitprotected

Definition at line 182 of file sensor.h.

183  : m_type(type) {}
const SensorType m_type
Definition: sensor.h:188
SensorType type() const
Definition: sensor.h:176

Member Function Documentation

◆ get() [1/2]

virtual SensorResult Sensor::get ( ) const
pure virtual

Implemented in RedundantSensor, RedundantFordTps, ProxySensor, FallbackSensor, GearDetector, StoredValueSensor, LuaOverrideSensor, and FunctionPointerSensor.

Referenced by HpfpQuantity::calcPI(), canDashboardHaltech(), canMazdaRX8(), check(), EtbController::checkStatus(), WallFuelController::computeBeta(), WallFuelController::computeTau(), ThrottleModelBase::estimateThrottleFlow(), SensorReader< TSensorType >::get(), LuaOverrideSensor::get(), FallbackSensor::get(), ProxySensor::get(), RedundantFordTps::get(), RedundantSensor::get(), AcController::getAcState(), getAdvanceCorrections(), AlphaNAirmass::getAirmass(), getBaroCorrection(), getCltFuelCorrection(), getCltTimingCorrection(), getCrankingFuel3(), InjectorModelWithConfig::getDeadtime(), InjectorModelWithConfig::getFuelDifferentialPressure(), getIatFuelCorrection(), IdleController::getIdlePosition(), ClosedLoopFuelCellImpl::getLambdaError(), IFuelComputer::getLoadOverride(), MafAirmass::getMaf(), SpeedDensityAirmass::getMap(), BoostController::getOpenLoop(), getOrZero(), PrimeController::getPrimeDuration(), getRunningAdvance(), getSensor(), BoostController::getSetpoint(), EtbController::getSetpointEtb(), DfcoController::getState(), FanController::getState(), FuelComputer::getStoichiometricRatio(), IFuelComputer::getTCharge(), AirmassVeModelBase::getVe(), initMapDecoder(), LambdaMonitorBase::isCurrentlyGood(), Engine::isInShutdownMode(), LaunchControlBase::isInsideTpsCondition(), isPedalError(), TransmissionControllerBase::isShiftCompleted(), isTps1Error(), isTps2Error(), kLineThread(), AlternatorController::observePlant(), BoostController::observePlant(), EtbController::observePlant(), HpfpController::onFastCallback(), EngineState::periodicFastCallback(), Engine::periodicSlowCallback(), populateFrame(), TransmissionControllerBase::postState(), printMAPInfo(), printTPSInfo(), printTpsSenser(), readGppwmChannel(), recalculateAuxValveTiming(), TwoPinDcMotor::set(), Gm4l6xTransmissionController::set32State(), Generic4TransmissionController::setTccState(), shouldCorrect(), AutomaticGearController::update(), LimpManager::updateState(), updateTempSensors(), updateThrottles(), and updateTunerStudioState().

◆ get() [2/2]

SensorResult Sensor::get ( SensorType  type)
static
Returns
NotNull: sensor result or UnexpectedCode::Configuration if sensor is not registered

Definition at line 166 of file sensor.cpp.

166  {
167  const auto entry = getEntryForType(type);
168 
169  // Check if this is a valid sensor entry
170  if (!entry) {
171  return UnexpectedCode::Configuration;
172  }
173 
174  return entry->get();
175 }
static SensorRegistryEntry * getEntryForType(SensorType type)
Definition: sensor.cpp:148
Here is the call graph for this function:

◆ getEntryForType()

SensorRegistryEntry * Sensor::getEntryForType ( SensorType  type)
staticprivate

Definition at line 148 of file sensor.cpp.

148  {
149  size_t index = getIndex(type);
150  // Check that we didn't get garbage
151  if (index >= getIndex(SensorType::PlaceholderLast)) {
152  return nullptr;
153  }
154 
155  return &s_sensorRegistry[index];
156 }
constexpr size_t getIndex()
Definition: sensor.h:191
static SensorRegistryEntry s_sensorRegistry[static_cast< size_t >(SensorType::PlaceholderLast)]
Definition: sensor.cpp:129

Referenced by get(), getRaw(), getSensorOfType(), hasSensor(), isRedundant(), resetMockValue(), setInvalidMockValue(), setMockValue(), and showInfo().

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

◆ getIndex() [1/2]

constexpr size_t Sensor::getIndex ( )
inlineconstexprprivate

Definition at line 191 of file sensor.h.

191  {
192  return getIndex(m_type);
193  }

Referenced by getEntryForType(), Register(), and unregister().

Here is the caller graph for this function:

◆ getIndex() [2/2]

static constexpr size_t Sensor::getIndex ( SensorType  type)
inlinestaticconstexprprivate

Definition at line 196 of file sensor.h.

196  {
197  return static_cast<size_t>(type);
198  }
Here is the call graph for this function:

◆ getOrZero()

static float Sensor::getOrZero ( SensorType  type)
inlinestatic

Definition at line 92 of file sensor.h.

92  {
93  return Sensor::get(type).value_or(0);
94  }
virtual SensorResult get() const =0

Referenced by adjustCrankPhase(), canDashboardBmwE46(), canDashboardBmwE90(), canDashboardFiat(), canDashboardGenesisCoupe(), canDashboardHaltech(), canDashboardNissanVQ(), canDashboardVAG(), canDashboardVagMqb(), canDashboardW202(), canMazdaRX8(), EtbController::checkStatus(), GearDetector::computeGearboxRatio(), configureRusefiLuaHooks(), TriggerCentral::decodeMapCam(), TriggerDecoderBase::decodeTriggerEvent(), fuelClosedLoopCorrection(), AcController::getAcState(), getBaroCorrection(), BoostController::getClosedLoopImpl(), GearDetector::getDriveshaftRpm(), getFuelALSCorrection(), IdleController::getIdlePosition(), KnockController::getKnockThreshold(), getLoad(), SpeedDensityAirmass::getMap(), getMaxAirflowAtMap(), KnockController::getMaximumRetard(), BoostController::getOpenLoop(), getRunningAdvance(), AlternatorController::getSetpoint(), BoostController::getSetpoint(), VvtController::getSetpoint(), EtbController::getSetpointEtb(), IgnitionState::getSparkDwell(), DfcoController::getState(), TpsAccelEnrichment::getTpsEnrichment(), getVeLoadAxis(), handleGetDataRequest(), hipThread(), initElectronicThrottle(), initNewSensors(), AntilagSystemBase::isALSMaxCLTCondition(), AntilagSystemBase::isALSMaxThrottleIntentCondition(), AntilagSystemBase::isALSMinCLTCondition(), LambdaMonitorBase::isCurrentlyGood(), isIgnVoltage(), LaunchControlBase::isInsideSpeedCondition(), LaunchControlBase::isLaunchRpmRetardCondition(), isPrimeInjectionPulseSkipped(), TriggerCentral::isToothExpectedNow(), lua_getAirmass(), mapAveragingTriggerCallback(), HpfpController::onFastCallback(), BoostController::onFastCallback(), WallFuelController::onFastCallback(), LimpManager::onFastCallback(), MainRelayController::onSlowCallback(), TripOdometer::onSlowCallback(), ThrottleModelBase::onSlowCallback(), onTdcCallback(), InjectionEvent::onTriggerTooth(), EngineState::periodicFastCallback(), Engine::periodicSlowCallback(), populateFrame(), printMAPInfo(), refreshMapAveragingPreCalc(), reportWave(), LambdaMonitorBase::restoreConditionsMet(), sendWidebandInfo(), StepperMotorBase::setInitialPosition(), shouldUpdateCorrection(), showAltInfo(), speedoUpdate(), startDwellByTurningSparkPinHigh(), tachUpdate(), tdcMarkCallback(), AntilagSystemBase::update(), LaunchControlBase::update(), GenericGearController::update(), DynoView::update(), updateEgtSensors(), updateFuelSensors(), DynoView::updateHP(), updateLambda(), updateMiscSensors(), updatePressures(), updateRawSensors(), LimpManager::updateRevLimit(), Engine::updateSlowSensors(), LimpManager::updateState(), updateThrottles(), updateTunerStudioState(), updateVehicleSpeed(), and updateVrThresholdPwm().

Here is the call graph for this function:

◆ getRaw() [1/2]

virtual float Sensor::getRaw ( ) const
inlinevirtual

Reimplemented in FunctionalSensor.

Definition at line 162 of file sensor.h.

162  {
163  return 0;
164  }

Referenced by grabPedalIsUp(), grabPedalIsWideOpen(), grabTPSIsClosed(), grabTPSIsWideOpen(), lua_getSensorRaw(), Engine::periodicSlowCallback(), printTpsSenser(), sendQcBenchRawAnalogValues(), updateRawSensors(), and updateThrottles().

Here is the caller graph for this function:

◆ getRaw() [2/2]

float Sensor::getRaw ( SensorType  type)
static

Definition at line 177 of file sensor.cpp.

177  {
178  const auto entry = getEntryForType(type);
179 
180  return entry ? entry->getRaw() : 0;
181 }
Here is the call graph for this function:

◆ getSensorName() [1/2]

const char* Sensor::getSensorName ( ) const
inline

Definition at line 144 of file sensor.h.

144 { return getSensorName(m_type); }
const char * getSensorName() const
Definition: sensor.h:144

Referenced by check(), getSensorName(), HellaOilLevelSensor::init(), EtbController::init(), FrequencySensor::initIfValid(), AdcSubscription::PrintInfo(), FallbackSensor::showInfo(), ProxySensor::showInfo(), RedundantFordTps::showInfo(), RedundantSensor::showInfo(), and showInfo().

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

◆ getSensorName() [2/2]

const char * Sensor::getSensorName ( SensorType  type)
static

Definition at line 235 of file sensor.cpp.

235  {
236  return getSensorType(type);
237 }
const char * getSensorType(SensorType value)
Here is the call graph for this function:

◆ getSensorOfType()

const Sensor * Sensor::getSensorOfType ( SensorType  type)
static

Definition at line 158 of file sensor.cpp.

158  {
159  auto entry = getEntryForType(type);
160  return entry ? entry->getSensor() : nullptr;
161 }

Referenced by ProxySensor::isRedundant().

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

◆ hasSensor() [1/2]

virtual bool Sensor::hasSensor ( ) const
inlinevirtual

◆ hasSensor() [2/2]

bool Sensor::hasSensor ( SensorType  type)
static

Definition at line 189 of file sensor.cpp.

189  {
190  const auto entry = getEntryForType(type);
191 
192  return entry ? entry->hasSensor() : false;
193 }
Here is the call graph for this function:

◆ inhibitTimeouts()

void Sensor::inhibitTimeouts ( bool  inhibit)
static

Definition at line 241 of file sensor.cpp.

241  {
243 }
static bool s_inhibitSensorTimeouts
Definition: sensor.h:185

Referenced by writeToFlashIfPending().

Here is the caller graph for this function:

◆ isRedundant() [1/2]

virtual bool Sensor::isRedundant ( ) const
inlinevirtual

Reimplemented in SentTps, RedundantSensor, RedundantFordTps, and ProxySensor.

Definition at line 169 of file sensor.h.

169  {
170  // By default sensors are not redundant
171  return false;
172  }

Referenced by EtbController::init().

Here is the caller graph for this function:

◆ isRedundant() [2/2]

bool Sensor::isRedundant ( SensorType  type)
static

Definition at line 183 of file sensor.cpp.

183  {
184  const auto entry = getEntryForType(type);
185 
186  return entry ? entry->isRedundant() : false;
187 }

Referenced by ProxySensor::isRedundant().

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

◆ Register()

bool Sensor::Register ( )

◆ resetAllMocks()

void Sensor::resetAllMocks ( )
static

Definition at line 228 of file sensor.cpp.

228  {
229  // Reset all mocks
230  for (size_t i = 0; i < efi::size(s_sensorRegistry); i++) {
231  s_sensorRegistry[i].resetMock();
232  }
233 }
composite packet size

Referenced by initSensorCli().

Here is the caller graph for this function:

◆ resetMockValue()

void Sensor::resetMockValue ( SensorType  type)
static

Definition at line 220 of file sensor.cpp.

220  {
221  auto entry = getEntryForType(type);
222 
223  if (entry) {
224  entry->resetMock();
225  }
226 }
Here is the call graph for this function:

◆ resetRegistry()

void Sensor::resetRegistry ( )
static

Definition at line 139 of file sensor.cpp.

139  {
140  // Clear all entries
141  for (size_t i = 0; i < efi::size(s_sensorRegistry); i++) {
142  auto &entry = s_sensorRegistry[i];
143 
144  entry.reset();
145  }
146 }

◆ setInvalidMockValue()

void Sensor::setInvalidMockValue ( SensorType  type)
static

Definition at line 195 of file sensor.cpp.

195  {
196  auto entry = getEntryForType(type);
197 
198  if (entry) {
199  entry->setInvalidMockValue();
200  }
201 }
Here is the call graph for this function:

◆ setMockValue() [1/2]

void Sensor::setMockValue ( int  type,
float  value 
)
static

Definition at line 211 of file sensor.cpp.

211  {
212  // bounds check
213  if (type <= 0 || type >= static_cast<int>(SensorType::PlaceholderLast)) {
214  return;
215  }
216 
217  setMockValue(static_cast<SensorType>(type), value);
218 }
static void setMockValue(SensorType type, float value, bool mockRedundant=false)
Definition: sensor.cpp:203
SensorType
Definition: sensor_type.h:18
Here is the call graph for this function:

◆ setMockValue() [2/2]

void Sensor::setMockValue ( SensorType  type,
float  value,
bool  mockRedundant = false 
)
static

Definition at line 203 of file sensor.cpp.

203  {
204  auto entry = getEntryForType(type);
205 
206  if (entry) {
207  entry->setMockValue(value, mockRedundant);
208  }
209 }

Referenced by initMapDecoder(), initNewSensors(), initSensorCli(), and setMockValue().

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

◆ showAllSensorInfo()

void Sensor::showAllSensorInfo ( )
static

Definition at line 246 of file sensor.cpp.

246  {
247  for (size_t i = 1; i < efi::size(s_sensorRegistry); i++) {
248  auto& entry = s_sensorRegistry[i];
249  const char* name = getSensorType((SensorType)i);
250 
251  entry.showInfo(name);
252  }
253 }

Referenced by initSensorCli(), and printSensorInfo().

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

◆ showInfo() [1/2]

virtual void Sensor::showInfo ( const char *  sensorName) const
pure virtual

◆ showInfo() [2/2]

void Sensor::showInfo ( SensorType  type)
static

Definition at line 256 of file sensor.cpp.

256  {
257  auto entry = getEntryForType(type);
258 
259  if (entry) {
260  entry->showInfo(getSensorName(type));
261  }
262 }
Here is the call graph for this function:

◆ type()

SensorType Sensor::type ( ) const
inline

Definition at line 176 of file sensor.h.

176  {
177  return m_type;
178  }

Referenced by get(), getEntryForType(), getIndex(), getOrZero(), getRaw(), getSensorName(), getSensorOfType(), hasSensor(), isRedundant(), resetMockValue(), setInvalidMockValue(), setMockValue(), and showInfo().

Here is the caller graph for this function:

◆ unregister()

void Sensor::unregister ( )

Definition at line 135 of file sensor.cpp.

135  {
136  s_sensorRegistry[getIndex()].unregister();
137 }

Referenced by deinitAuxSensors(), deInitFlexSensor(), deinitTps(), onEcuStartDoSomethingTriggerInputPins(), and GearDetector::~GearDetector().

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

Field Documentation

◆ m_type

const SensorType Sensor::m_type
private

Definition at line 188 of file sensor.h.

Referenced by getIndex(), getSensorName(), and type().

◆ s_inhibitSensorTimeouts

bool Sensor::s_inhibitSensorTimeouts = false
staticprotected

Definition at line 185 of file sensor.h.

Referenced by StoredValueSensor::get(), and inhibitTimeouts().


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