rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
sensor_checker.cpp File Reference

Functions

static ObdCode getCode (SensorType type, UnexpectedCode code)
 
const chardescribeUnexpected (UnexpectedCode code)
 
static void check (SensorType type)
 
static ObdCode getCodeForInjector (int idx, brain_pin_diag_e diag)
 
static ObdCode getCodeForIgnition (int idx, brain_pin_diag_e diag)
 
static uint8_t getTSErrorCode (brain_pin_diag_e diag)
 
PUBLIC_API_WEAK void boardSensorChecker ()
 

Function Documentation

◆ boardSensorChecker()

PUBLIC_API_WEAK void boardSensorChecker ( )

Definition at line 167 of file sensor_checker.cpp.

167 {
168}

Referenced by SensorChecker::onSlowCallback().

Here is the caller graph for this function:

◆ check()

static void check ( SensorType  type)
static

Definition at line 104 of file sensor_checker.cpp.

104 {
105 // Don't check sensors we don't have
106 if (!Sensor::hasSensor(type)) {
107 return;
108 }
109
110 auto result = Sensor::get(type);
111
112 // If the sensor is OK, nothing to check.
113 if (result) {
114 return;
115 }
116
117 ObdCode code = getCode(type, result.Code);
118
119 if (code != ObdCode::None) {
120 warning(code, "Sensor fault: %s %s", Sensor::getSensorName(type), describeUnexpected(result.Code));
121 }
122}
uint8_t code
Definition bluetooth.cpp:40
virtual bool hasSensor() const
Definition sensor.h:141
virtual SensorResult get() const =0
const char * getSensorName() const
Definition sensor.h:130
bool warning(ObdCode code, const char *fmt,...)
ObdCode
static ObdCode getCode(SensorType type, UnexpectedCode code)
const char * describeUnexpected(UnexpectedCode code)

Referenced by SensorChecker::onSlowCallback().

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

◆ describeUnexpected()

const char * describeUnexpected ( UnexpectedCode  code)
inline

Definition at line 91 of file sensor_checker.cpp.

91 {
92 switch (code) {
93 case UnexpectedCode::Timeout: return "has timed out";
94 case UnexpectedCode::High: return "input too high";
95 case UnexpectedCode::Low: return "input too low";
96 case UnexpectedCode::Inconsistent: return "is inconsistent";
97 case UnexpectedCode::Configuration: return "is misconfigured";
98 case UnexpectedCode::Unknown:
99 default:
100 return "unknown";
101 }
102}

Referenced by check().

Here is the caller graph for this function:

◆ getCode()

static ObdCode getCode ( SensorType  type,
UnexpectedCode  code 
)
static

Definition at line 4 of file sensor_checker.cpp.

4 {
5 switch (type) {
8 switch (code) {
9 case UnexpectedCode::Timeout: return ObdCode::OBD_TPS1_Primary_Timeout;
10 case UnexpectedCode::Low: return ObdCode::OBD_TPS1_Primary_Low;
11 case UnexpectedCode::High: return ObdCode::OBD_TPS1_Primary_High;
12 case UnexpectedCode::Inconsistent: return ObdCode::OBD_TPS1_Correlation;
13 default: break;
14 } break;
16 switch (code) {
17 case UnexpectedCode::Timeout: return ObdCode::OBD_TPS1_Secondary_Timeout;
18 case UnexpectedCode::Low: return ObdCode::OBD_TPS1_Secondary_Low;
19 case UnexpectedCode::High: return ObdCode::OBD_TPS1_Secondary_High;
20 default: break;
21 } break;
24 switch (code) {
25 case UnexpectedCode::Timeout: return ObdCode::OBD_TPS2_Primary_Timeout;
26 case UnexpectedCode::Low: return ObdCode::OBD_TPS2_Primary_Low;
27 case UnexpectedCode::High: return ObdCode::OBD_TPS2_Primary_High;
28 case UnexpectedCode::Inconsistent: return ObdCode::OBD_TPS2_Correlation;
29 default: break;
30 } break;
32 switch (code) {
33 case UnexpectedCode::Timeout: return ObdCode::OBD_TPS2_Secondary_Timeout;
34 case UnexpectedCode::Low: return ObdCode::OBD_TPS2_Secondary_Low;
35 case UnexpectedCode::High: return ObdCode::OBD_TPS2_Secondary_High;
36 default: break;
37 } break;
38
41 switch (code) {
42 case UnexpectedCode::Timeout: return ObdCode::OBD_PPS_Primary_Timeout;
43 case UnexpectedCode::Low: return ObdCode::OBD_PPS_Primary_Low;
44 case UnexpectedCode::High: return ObdCode::OBD_PPS_Primary_High;
45 case UnexpectedCode::Inconsistent: return ObdCode::OBD_PPS_Correlation;
46 default: break;
47 } break;
49 switch (code) {
50 case UnexpectedCode::Timeout: return ObdCode::OBD_PPS_Secondary_Timeout;
51 case UnexpectedCode::Low: return ObdCode::OBD_PPS_Secondary_Low;
52 case UnexpectedCode::High: return ObdCode::OBD_PPS_Secondary_High;
53 default: break;
54 } break;
55
56 case SensorType::Map:
57 switch (code) {
58 case UnexpectedCode::Timeout: return ObdCode::OBD_Map_Timeout;
59 case UnexpectedCode::Low: return ObdCode::OBD_Map_Low;
60 case UnexpectedCode::High: return ObdCode::OBD_Map_High;
61 default: break;
62 } break;
63 case SensorType::Clt:
64 switch (code) {
65 case UnexpectedCode::Timeout: return ObdCode::OBD_Clt_Timeout;
66 case UnexpectedCode::Low: return ObdCode::OBD_Clt_Low;
67 case UnexpectedCode::High: return ObdCode::OBD_Clt_High;
68 default: break;
69 } break;
70 case SensorType::Iat:
71 switch (code) {
72 case UnexpectedCode::Timeout: return ObdCode::OBD_Iat_Timeout;
73 case UnexpectedCode::Low: return ObdCode::OBD_Iat_Low;
74 case UnexpectedCode::High: return ObdCode::OBD_Iat_High;
75 default: break;
76 } break;
78 switch (code) {
79 case UnexpectedCode::Timeout: return ObdCode::OBD_FlexSensor_Timeout;
80 case UnexpectedCode::Low: return ObdCode::OBD_FlexSensor_Low;
81 case UnexpectedCode::High: return ObdCode::OBD_FlexSensor_High;
82 default: break;
83 } break;
84 default:
85 break;
86 }
87
88 return ObdCode::None;
89}
@ OBD_Clt_Timeout
@ OBD_Map_High
@ OBD_Iat_High
@ OBD_TPS1_Secondary_High
@ OBD_TPS1_Primary_Low
@ OBD_TPS2_Secondary_Low
@ OBD_PPS_Primary_Timeout
@ OBD_TPS1_Primary_High
@ OBD_PPS_Primary_High
@ OBD_TPS2_Secondary_High
@ OBD_TPS2_Primary_Low
@ OBD_TPS1_Correlation
@ OBD_PPS_Secondary_High
@ OBD_FlexSensor_High
@ OBD_TPS2_Primary_Timeout
@ OBD_TPS1_Secondary_Timeout
@ OBD_Clt_High
@ OBD_TPS2_Primary_High
@ OBD_TPS2_Correlation
@ OBD_PPS_Correlation
@ OBD_TPS1_Primary_Timeout
@ OBD_Map_Timeout
@ OBD_PPS_Secondary_Low
@ OBD_PPS_Secondary_Timeout
@ OBD_PPS_Primary_Low
@ OBD_FlexSensor_Low
@ OBD_TPS1_Secondary_Low
@ OBD_TPS2_Secondary_Timeout
@ OBD_FlexSensor_Timeout
@ OBD_Iat_Timeout
@ FuelEthanolPercent
@ AcceleratorPedalPrimary
@ AcceleratorPedalSecondary

Referenced by check().

Here is the caller graph for this function:

◆ getCodeForIgnition()

static ObdCode getCodeForIgnition ( int  idx,
brain_pin_diag_e  diag 
)
static

Definition at line 142 of file sensor_checker.cpp.

142 {
143 if (idx < 0 || idx >= MAX_CYLINDER_COUNT) {
144 return ObdCode::None;
145 }
146
147 // TODO: do something more intelligent with `diag`?
148 UNUSED(diag);
149
150 return (ObdCode)((int)ObdCode::OBD_Ignition_Circuit_1 + idx);
151}
UNUSED(samplingTimeSeconds)
@ OBD_Ignition_Circuit_1

Referenced by SensorChecker::onSlowCallback().

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

◆ getCodeForInjector()

static ObdCode getCodeForInjector ( int  idx,
brain_pin_diag_e  diag 
)
static

Definition at line 126 of file sensor_checker.cpp.

126 {
127 if (idx < 0 || idx >= MAX_CYLINDER_COUNT) {
128 return ObdCode::None;
129 }
130
131 if ((diag & PIN_OPEN) || (diag & PIN_SHORT_TO_GND)) {
132 return (ObdCode)((int)ObdCode::OBD_Injector_Circuit_1_Low + (idx * 3));
133 } else if ((diag & PIN_SHORT_TO_BAT) || (diag & PIN_OVERLOAD)) {
134 return (ObdCode)((int)ObdCode::OBD_Injector_Circuit_1_High + (idx * 3));
135 }
136
137 /* else common error code */
138 return (ObdCode)((int)ObdCode::OBD_Injector_Circuit_1 + idx);
139}
@ OBD_Injector_Circuit_1
@ OBD_Injector_Circuit_1_High
@ OBD_Injector_Circuit_1_Low

Referenced by SensorChecker::onSlowCallback().

Here is the caller graph for this function:

◆ getTSErrorCode()

static uint8_t getTSErrorCode ( brain_pin_diag_e  diag)
static

Definition at line 153 of file sensor_checker.cpp.

153 {
154 /* Error codes reported to TS:
155 * 0 - output is not used
156 * 1 - ok status/no diagnostic available (TODO: separate codes)
157 * >1 - see brain_pin_diag_e, first least significant 1-bit position + 1 *
158 * Keep in sync with outputDiagErrorList in tunerstudio.template.ini
159 * Note:
160 * diag can be combination of few errors,
161 * while we report only one error to simplify handling on TS side
162 * find position of least significant 1-bit */
163 return __builtin_ffs(diag) + TS_ENUM_OFFSET;
164}

Referenced by SensorChecker::onSlowCallback().

Here is the caller graph for this function:

Go to the source code of this file.