rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
SensorChecker Struct Reference

#include <sensor_checker.h>

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

Public Member Functions

void onSlowCallback () override
 
void onIgnitionStateChanged (bool ignitionOn) override
 
bool analogSensorsShouldWork () const
 
- Public Member Functions inherited from EngineModule
virtual void initNoConfiguration ()
 
virtual void setDefaultConfiguration ()
 
virtual void onConfigurationChange (engine_configuration_s const *)
 
virtual void onFastCallback ()
 
virtual void onEngineStop ()
 
virtual bool needsDelayedShutoff ()
 
virtual void onEnginePhase (float, efitick_t, angle_t, angle_t)
 

Private Attributes

bool m_ignitionIsOn = false
 
Timer m_timeSinceIgnOff
 
bool m_analogSensorsShouldWork = false
 

Detailed Description

Definition at line 6 of file sensor_checker.h.

Member Function Documentation

◆ analogSensorsShouldWork()

bool SensorChecker::analogSensorsShouldWork ( ) const
inline

Definition at line 11 of file sensor_checker.h.

11 {
13 }
bool m_analogSensorsShouldWork

◆ onIgnitionStateChanged()

void SensorChecker::onIgnitionStateChanged ( bool  ignitionOn)
overridevirtual

Reimplemented from EngineModule.

Definition at line 266 of file sensor_checker.cpp.

266 {
267 m_ignitionIsOn = ignitionOn;
268
269 if (!ignitionOn) {
270 // timer keeps track of how long since the state was turned to on (ie, how long ago was it last off)
271 m_timeSinceIgnOff.reset();
272 }
273}
Timer m_timeSinceIgnOff

◆ onSlowCallback()

void SensorChecker::onSlowCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 170 of file sensor_checker.cpp.

170 {
171 // Don't check when the ignition is off, or when it was just turned on (let things stabilize)
172 // TODO: also inhibit checking if we just did a flash burn, since that blocks the ECU for a few seconds.
173 bool shouldCheck = m_ignitionIsOn && m_timeSinceIgnOff.hasElapsedSec(5);
174 m_analogSensorsShouldWork = shouldCheck;
175 if (!shouldCheck) {
176 return;
177 }
178
179 // Check sensors
186
190
193
196
198
199#if EFI_PROD_CODE
201 // only bother checking these if we have GPIO chips actually capable of reporting an error
202#if BOARD_EXT_GPIOCHIPS > 0
203#if EFI_ENGINE_CONTROL
204 // Check injectors
205 int unhappyInjector = 0;
206 for (size_t i = 0; i < efi::size(enginePins.injectors); i++) {
208
209 // Skip not-configured pins
210 if (!isBrainPinValid(pin.brainPin)) {
211 state->injectorDiagnostic[i] = 0;
212 continue;
213 }
214
215 auto diag = pin.getDiag();
216 if (diag != PIN_OK && diag != PIN_UNKNOWN) {
217 unhappyInjector = 1 + i;
218 auto code = getCodeForInjector(i, diag);
219
220 char description[32];
221 pinDiag2string(description, efi::size(description), diag);
222 warning(code, "Injector %d fault: %s", i + 1, description);
223 }
224 state->injectorDiagnostic[i] = getTSErrorCode(diag);
225 }
226 engine->fuelComputer.brokenInjector = unhappyInjector;
227 engine->fuelComputer.injectorHwIssue = (unhappyInjector != 0);
228#endif // EFI_ENGINE_CONTROL
229
230 // Check ignition
231 for (size_t i = 0; i < efi::size(enginePins.injectors); i++) {
233
234 // Skip not-configured pins
235 if (!isBrainPinValid(pin.brainPin)) {
236 state->ignitorDiagnostic[i] = 0;
237 continue;
238 }
239
240 auto diag = pin.getDiag();
241 if (diag != PIN_OK && diag != PIN_UNKNOWN) {
242 auto code = getCodeForIgnition(i, diag);
243
244 char description[32];
245 pinDiag2string(description, efi::size(description), diag);
246 warning(code, "Ignition %d fault: %s", i + 1, description);
247 }
248 state->ignitorDiagnostic[i] = getTSErrorCode(diag);
249 }
250#endif // BOARD_EXT_GPIOCHIPS > 0
251
252 // Check ADC(s) and analog inputs
253 auto code = analogGetDiagnostic();
254 if (code != ObdCode::None) {
255 /* TODO: map to more OBD codes? */
256 warning(code, "Analog subsystem fault");
257 state->isAnalogFailure = true;
258 } else {
259 state->isAnalogFailure = false;
260 }
261#endif // EFI_PROD_CODE
262
264}
ObdCode analogGetDiagnostic()
uint8_t code
Definition bluetooth.cpp:40
FuelComputer fuelComputer
Definition engine.h:139
InjectorOutputPin injectors[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:127
IgnitionOutputPin coils[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:129
brain_pin_diag_e getDiag() const
Definition efi_gpio.cpp:678
EnginePins enginePins
Definition efi_gpio.cpp:24
static EngineAccessor engine
Definition engine.h:413
bool warning(ObdCode code, const char *fmt,...)
void pinDiag2string(char *buffer, size_t size, brain_pin_diag_e pin_diag)
bool isBrainPinValid(brain_pin_e brainPin)
static ObdCode getCodeForIgnition(int idx, brain_pin_diag_e diag)
static ObdCode getCodeForInjector(int idx, brain_pin_diag_e diag)
static void check(SensorType type)
static uint8_t getTSErrorCode(brain_pin_diag_e diag)
PUBLIC_API_WEAK void boardSensorChecker()
@ FuelEthanolPercent
@ AcceleratorPedalPrimary
@ AcceleratorPedalSecondary
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1871, 1.0, -1.0, -1.0, "")
brain_pin_e pin
Definition stm32_adc.cpp:15
TunerStudioOutputChannels * getTunerStudioOutputChannels()
Definition engine.cpp:581
Here is the call graph for this function:

Field Documentation

◆ m_analogSensorsShouldWork

bool SensorChecker::m_analogSensorsShouldWork = false
private

Definition at line 19 of file sensor_checker.h.

Referenced by analogSensorsShouldWork(), and onSlowCallback().

◆ m_ignitionIsOn

bool SensorChecker::m_ignitionIsOn = false
private

Definition at line 16 of file sensor_checker.h.

Referenced by onIgnitionStateChanged(), and onSlowCallback().

◆ m_timeSinceIgnOff

Timer SensorChecker::m_timeSinceIgnOff
private

Definition at line 17 of file sensor_checker.h.

Referenced by onIgnitionStateChanged(), and onSlowCallback().


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