rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
AemXSeriesWideband Class Reference

#include <AemXSeriesLambda.h>

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

Public Member Functions

 AemXSeriesWideband (uint8_t sensorIndex, SensorType type)
 
bool acceptFrame (const size_t busIndex, const CANRxFrame &frame) const override final
 
void refreshState (void)
 
void refreshSmoothedLambda (float lambda)
 
- Public Member Functions inherited from CanSensorBase
 CanSensorBase (uint32_t eid, SensorType type, efidur_t timeout)
 
void showInfo (const char *sensorName) const override
 
- Public Member Functions inherited from StoredValueSensor
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 chargetSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 
- Public Member Functions inherited from CanListener
 CanListener (uint32_t id)
 
CanListenerprocessFrame (const size_t busIndex, const CANRxFrame &frame, efitick_t nowNt)
 
uint32_t getId ()
 
void setNext (CanListener *next)
 
virtual CanListenerrequest ()
 
CanListenergetNext () const
 

Protected Member Functions

void decodeFrame (const CANRxFrame &frame, efitick_t nowNt) override
 
bool decodeAemXSeries (const CANRxFrame &frame, efitick_t nowNt)
 
bool decodeRusefiStandard (const CANRxFrame &frame, efitick_t nowNt)
 
void decodeRusefiDiag (const CANRxFrame &frame)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 

Private Member Functions

can_wbo_type_e sensorType () const
 
uint32_t getReCanId () const
 
uint32_t getAemCanId () const
 
bool isHeaterAllowed ()
 

Private Attributes

const uint8_t m_sensorIndex
 
uint8_t m_stateCode
 
bool m_afrIsValid
 
bool m_isFault
 
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 resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const chargetSensorName (SensorType type)
 
- Data Fields inherited from wideband_state_s
uint8_t stateCode = (uint8_t)0
 
uint8_t heaterDuty = (uint8_t)0
 
uint8_t pumpDuty = (uint8_t)0
 
uint8_t alignmentFill_at_3 [1] = {}
 
bool isValid: 1 {}
 
bool canSilent: 1 {}
 
bool allowed: 1 {}
 
bool fwUnsupported: 1 {}
 
bool fwOutdated: 1 {}
 
bool unusedBit_9_5: 1 {}
 
bool unusedBit_9_6: 1 {}
 
bool unusedBit_9_7: 1 {}
 
bool unusedBit_9_8: 1 {}
 
bool unusedBit_9_9: 1 {}
 
bool unusedBit_9_10: 1 {}
 
bool unusedBit_9_11: 1 {}
 
bool unusedBit_9_12: 1 {}
 
bool unusedBit_9_13: 1 {}
 
bool unusedBit_9_14: 1 {}
 
bool unusedBit_9_15: 1 {}
 
bool unusedBit_9_16: 1 {}
 
bool unusedBit_9_17: 1 {}
 
bool unusedBit_9_18: 1 {}
 
bool unusedBit_9_19: 1 {}
 
bool unusedBit_9_20: 1 {}
 
bool unusedBit_9_21: 1 {}
 
bool unusedBit_9_22: 1 {}
 
bool unusedBit_9_23: 1 {}
 
bool unusedBit_9_24: 1 {}
 
bool unusedBit_9_25: 1 {}
 
bool unusedBit_9_26: 1 {}
 
bool unusedBit_9_27: 1 {}
 
bool unusedBit_9_28: 1 {}
 
bool unusedBit_9_29: 1 {}
 
bool unusedBit_9_30: 1 {}
 
bool unusedBit_9_31: 1 {}
 
uint16_t tempC = (uint16_t)0
 
scaled_channel< uint16_t, 1000, 1 > nernstVoltage = (uint16_t)0
 
uint16_t esr = (uint16_t)0
 
uint8_t alignmentFill_at_14 [2] = {}
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

Definition at line 14 of file AemXSeriesLambda.h.

Constructor & Destructor Documentation

◆ AemXSeriesWideband()

AemXSeriesWideband::AemXSeriesWideband ( uint8_t  sensorIndex,
SensorType  type 
)

Definition at line 14 of file AemXSeriesLambda.cpp.

16 0, // ID passed here doesn't matter since we override acceptFrame
17 type,
19 )
20 , m_sensorIndex(sensorIndex)
21{
22 stateCode = m_stateCode = static_cast<uint8_t>(wbo::Status::CanSilent);// silent, initial state is "no one has spoken to us so far"
23 isValid = m_isFault = m_afrIsValid = false;
24 // wait for first rusEFI WBO standard frame with protocol version field
25 fwUnsupported = true;
26 // Do not light "FW: need update" indicator until we get some data from WBO
27 fwOutdated = false;
28}
static constexpr efidur_t sensor_timeout
const uint8_t m_sensorIndex
SensorType type() const
Definition sensor.h:162

Member Function Documentation

◆ acceptFrame()

bool AemXSeriesWideband::acceptFrame ( const size_t  busIndex,
const CANRxFrame frame 
) const
finaloverridevirtual

Reimplemented from CanListener.

Definition at line 44 of file AemXSeriesLambda.cpp.

44 {
45#if !EFI_UNIT_TEST
46 if (busIndex != getWidebandBus()) {
47 return false;
48 }
49#endif
50
51 if (frame.DLC != 8) {
52 return false;
53 }
54
56
57 if (type == DISABLED) {
58 return false;
59 }
60
61 // RusEFI wideband uses standard CAN IDs
62 if ((!CAN_ISX(frame)) && (type == RUSEFI)) {
63 // 0th sensor is 0x190 and 0x191, 1st sensor is 0x192 and 0x193
64 uint32_t rusefiBaseId = getReCanId();
65 return ((CAN_SID(frame) == rusefiBaseId) || (CAN_SID(frame) == rusefiBaseId + 1));
66 }
67
68 // AEM uses extended CAN ID
69 if ((CAN_ISX(frame)) && (type == AEM)) {
70 // 0th sensor is 0x00000180, 1st sensor is 0x00000181, etc
71 uint32_t aemXSeriesId = getAemCanId();
72 return (CAN_EID(frame) == aemXSeriesId);
73 }
74
75 return false;
76}
can_wbo_type_e sensorType() const
uint32_t getAemCanId() const
uint32_t getReCanId() const
can_wbo_type_e
size_t getWidebandBus()
uint8_t DLC
Data length.
Definition can_mocks.h:42
Here is the call graph for this function:

◆ decodeAemXSeries()

bool AemXSeriesWideband::decodeAemXSeries ( const CANRxFrame frame,
efitick_t  nowNt 
)
protected
Returns
true if valid, false if invalid

Definition at line 163 of file AemXSeriesLambda.cpp.

163 {
164 // we don't care
165 fwUnsupported = false;
166 fwOutdated = false;
167
168 // reports in 0.0001 lambda per LSB
169 uint16_t lambdaInt = SWAP_UINT16(frame.data16[0]);
170 float lambdaFloat = 0.0001f * lambdaInt;
171
172 // bit 6 indicates sensor fault
173 m_isFault = frame.data8[7] & 0x40;
174 // bit 7 indicates valid
175 m_afrIsValid = frame.data8[6] & 0x80;
176
177 if ((m_isFault) || (!m_afrIsValid)) {
178 invalidate();
179 return false;
180 }
181
182 setValidValue(lambdaFloat, nowNt);
183 refreshSmoothedLambda(lambdaFloat);
184 return true;
185}
void refreshSmoothedLambda(float lambda)
void setValidValue(float value, efitick_t timestamp)
uint16_t SWAP_UINT16(uint16_t x)
Definition efilib.h:22
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55
uint16_t data16[4]
Frame data.
Definition can_mocks.h:56

Referenced by decodeFrame().

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

◆ decodeFrame()

void AemXSeriesWideband::decodeFrame ( const CANRxFrame frame,
efitick_t  nowNt 
)
overrideprotectedvirtual

Implements CanListener.

Definition at line 133 of file AemXSeriesLambda.cpp.

133 {
134 bool accepted = false;
135 // accept frame has already guaranteed that this message belongs to us
136 // We just have to check if it's AEM or rusEFI
137 if (sensorType() == RUSEFI){
138 uint32_t id = CAN_ID(frame);
139
140 // rusEFI custom format
141 if ((id & 0x1) != 0) {
142 // low bit is set, this is the "diag" frame
143 decodeRusefiDiag(frame);
144 } else {
145 // low bit not set, this is standard frame
146 accepted = decodeRusefiStandard(frame, nowNt);
147 }
148 } else /* if (sensorType() == AEM) */ {
149 accepted = decodeAemXSeries(frame, nowNt);
150 }
151
152 if (accepted) {
153 m_lastUpdate = nowNt;
154 }
155
156 // Do refresh on each CAN packet
157 refreshState();
158}
void decodeRusefiDiag(const CANRxFrame &frame)
bool decodeRusefiStandard(const CANRxFrame &frame, efitick_t nowNt)
bool decodeAemXSeries(const CANRxFrame &frame, efitick_t nowNt)
Here is the call graph for this function:

◆ decodeRusefiDiag()

void AemXSeriesWideband::decodeRusefiDiag ( const CANRxFrame frame)
protected

Definition at line 240 of file AemXSeriesLambda.cpp.

240 {
241 if (fwUnsupported) {
242 return;
243 }
244
245 auto data = reinterpret_cast<const wbo::DiagData*>(&frame.data8[0]);
246
247 // convert to percent
248 heaterDuty = data->HeaterDuty / 2.55f;
249 pumpDuty = data->PumpDuty / 2.55f;
250
251 // convert to volts
252 nernstVoltage = data->NernstDc * 0.001f;
253
254 // no conversion, just ohms
255 esr = data->Esr;
256
257 // This state is handle in refreshState()
258 //if (!isHeaterAllowed()) {
259 // m_stateCode = HACK_CRANKING_VALUE;
260 // return;
261 //}
262
263 m_stateCode = static_cast<uint8_t>(data->status);
264
265 if ((isStatusError(static_cast<wbo::Status>(data->status))) && isHeaterAllowed()) {
267 warning(code, "Wideband #%d fault: %s", (m_sensorIndex + 1), wbo::describeStatus(data->status));
268 }
269}
uint8_t code
Definition bluetooth.cpp:40
bool warning(ObdCode code, const char *fmt,...)
@ Wideband_2_Fault
@ Wideband_1_Fault
scaled_channel< uint16_t, 1000, 1 > nernstVoltage

Referenced by decodeFrame().

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

◆ decodeRusefiStandard()

bool AemXSeriesWideband::decodeRusefiStandard ( const CANRxFrame frame,
efitick_t  nowNt 
)
protected

Definition at line 187 of file AemXSeriesLambda.cpp.

187 {
188 auto data = reinterpret_cast<const wbo::StandardData*>(&frame.data8[0]);
189
190 if (data->Version > RUSEFI_WIDEBAND_VERSION) {
191 firmwareError(ObdCode::OBD_WB_FW_Mismatch, "Wideband controller index %d has newer protocol version (0x%02x while 0x%02x supported), please update ECU FW!",
192 m_sensorIndex, data->Version, RUSEFI_WIDEBAND_VERSION);
193 fwUnsupported = true;
194 return false;
195 }
196
197 if (data->Version < RUSEFI_WIDEBAND_VERSION_MIN) {
198 firmwareError(ObdCode::OBD_WB_FW_Mismatch, "Wideband controller index %d has outdated protocol version (0x%02x while minimum 0x%02x expected), please update WBO!",
199 m_sensorIndex, data->Version, RUSEFI_WIDEBAND_VERSION_MIN);
200 fwUnsupported = true;
201 return false;
202 }
203
204 fwUnsupported = false;
205 // compatible, but not latest
206 fwOutdated = (data->Version != RUSEFI_WIDEBAND_VERSION);
207 // TODO: request and check builddate
208
209 tempC = data->TemperatureC;
210 float lambda = 0.0001f * data->Lambda;
211 m_afrIsValid = data->Valid & 0x01;
212
213 if (!m_afrIsValid) {
214 invalidate();
215 } else {
216 setValidValue(lambda, nowNt);
217 refreshSmoothedLambda(lambda);
218 }
219
220 return true;
221}
void firmwareError(ObdCode code, const char *fmt,...)
@ OBD_WB_FW_Mismatch

Referenced by decodeFrame().

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

◆ getAemCanId()

uint32_t AemXSeriesWideband::getAemCanId ( ) const
private

Definition at line 39 of file AemXSeriesLambda.cpp.

39 {
40 // 0th sensor is 0x00000180, 1st sensor is 0x00000181, etc
42}
static constexpr uint32_t aem_base
static constexpr engine_configuration_s * engineConfiguration

Referenced by acceptFrame().

Here is the caller graph for this function:

◆ getReCanId()

uint32_t AemXSeriesWideband::getReCanId ( ) const
private

Definition at line 34 of file AemXSeriesLambda.cpp.

34 {
35 // 0th sensor is 0x190 and 0x191, 1st sensor is 0x192 and 0x193
37}
static constexpr uint32_t rusefi_base

Referenced by acceptFrame().

Here is the caller graph for this function:

◆ isHeaterAllowed()

bool AemXSeriesWideband::isHeaterAllowed ( )
private

Definition at line 78 of file AemXSeriesLambda.cpp.

78 {
79 return ((sensorType() == AEM) || (engine->engineState.heaterControlEnabled));
80}
EngineState engineState
Definition engine.h:352
static EngineAccessor engine
Definition engine.h:421

Referenced by decodeRusefiDiag(), and refreshState().

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

◆ refreshSmoothedLambda()

void AemXSeriesWideband::refreshSmoothedLambda ( float  lambda)

Definition at line 223 of file AemXSeriesLambda.cpp.

223 {
224 switch (type()) {
225 case SensorType::Lambda1: {
228 break;
229 }
230 case SensorType::Lambda2: {
233 break;
234 }
235 default:
236 break;
237 }
238}
void setSmoothingFactor(float p_smoothingFactor)
Definition exp_average.h:26
float initOrAverage(float value)
Definition exp_average.h:9
efitick_t getTimeNowNt()
Definition efitime.cpp:19
StoredValueSensor smoothedLambda2Sensor(SensorType::SmoothedLambda2, MS2NT(500))
ExpAverage expAverageLambda2
Definition ego.cpp:13
StoredValueSensor smoothedLambda1Sensor(SensorType::SmoothedLambda1, MS2NT(500))
ExpAverage expAverageLambda1
Definition ego.cpp:12

Referenced by decodeAemXSeries(), and decodeRusefiStandard().

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

◆ refreshState()

void AemXSeriesWideband::refreshState ( void  )

Definition at line 82 of file AemXSeriesLambda.cpp.

82 {
84
85 // Report ECU to WBO allow state
88 canSilent = true;
89 isValid = false;
90 return;
91 }
92 canSilent = false;
93
94 if (type == RUSEFI) {
95 // This is RE WBO
97 // Report state code from WBO
99 return;
100 } else if (type == AEM) {
101 // This is AEM with two flags only and no debug fields
102 heaterDuty = 0;
103 pumpDuty = 0;
104 tempC = 0;
105 nernstVoltage = 0;
106
107 if (m_isFault) {
108 stateCode = HACK_INVALID_AEM;
109 isValid = false;
110 } else {
111 // TODO: better status code?
113 static_cast<uint8_t>(wbo::Status::RunningClosedLoop) :
114 static_cast<uint8_t>(wbo::Status::Warmup);
116 }
117 return;
118 } else {
119 // disabled or analog
120 // clear all livedata
121 heaterDuty = 0;
122 pumpDuty = 0;
123 tempC = 0;
124 nernstVoltage = 0;
125 isValid = false;
126 return;
127 }
128
129 // non configured
130 stateCode = static_cast<uint8_t>(wbo::Status::CanSilent);
131}

Referenced by decodeFrame(), and getLiveData().

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

◆ sensorType()

can_wbo_type_e AemXSeriesWideband::sensorType ( ) const
private

Definition at line 30 of file AemXSeriesLambda.cpp.

Referenced by acceptFrame(), decodeFrame(), isHeaterAllowed(), and refreshState().

Here is the caller graph for this function:

Field Documentation

◆ m_afrIsValid

bool AemXSeriesWideband::m_afrIsValid
private

◆ m_isFault

bool AemXSeriesWideband::m_isFault
private

Definition at line 47 of file AemXSeriesLambda.h.

Referenced by AemXSeriesWideband(), decodeAemXSeries(), and refreshState().

◆ m_lastUpdate

efitick_t AemXSeriesWideband::m_lastUpdate = 0
private

Definition at line 49 of file AemXSeriesLambda.h.

Referenced by decodeFrame(), and refreshState().

◆ m_sensorIndex

const uint8_t AemXSeriesWideband::m_sensorIndex
private

◆ m_stateCode

uint8_t AemXSeriesWideband::m_stateCode
private

Definition at line 43 of file AemXSeriesLambda.h.

Referenced by AemXSeriesWideband(), decodeRusefiDiag(), and refreshState().


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