move AEM xseries lambda to new sensor (#1764)
* lambda sens * fix init * new sensor aem * comment * g * format * x * guard * fix init for tests * fix * put back * put back * fix * fix init * why is this different Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
f2edf843e5
commit
df551d77fb
|
@ -27,7 +27,6 @@ static void printPacket(const CANRxFrame& rx, Logging* logger) {
|
|||
}
|
||||
}
|
||||
|
||||
volatile float aemXSeriesLambda = 0;
|
||||
volatile float canMap = 0;
|
||||
|
||||
CanSensorBase* cansensors_head = nullptr;
|
||||
|
@ -56,18 +55,13 @@ void processCanRxMessage(const CANRxFrame& frame, Logging* logger, efitick_t now
|
|||
//Vss is configurable, should we handle it here:
|
||||
processCanRxVss(frame, nowNt);
|
||||
|
||||
// TODO: if/when we support multiple lambda sensors, sensor N
|
||||
// has address 0x0180 + N where N = [0, 15]
|
||||
if (frame.SID == 0x0180) {
|
||||
// AEM x-series lambda sensor reports in 0.0001 lambda per bit
|
||||
uint16_t lambdaInt = SWAP_UINT16(frame.data16[0]);
|
||||
aemXSeriesLambda = 0.0001f * lambdaInt;
|
||||
#if EFI_CANBUS_SLAVE
|
||||
} else if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) {
|
||||
if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) {
|
||||
int16_t mapScaled = *reinterpret_cast<const int16_t*>(&frame.data8[0]);
|
||||
canMap = mapScaled / (1.0 * PACK_MULT_PRESSURE);
|
||||
} else
|
||||
#endif
|
||||
} else {
|
||||
{
|
||||
obdOnCanPacketRx(frame);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#include "global.h"
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
#include "AemXSeriesLambda.h"
|
||||
#include "efilib.h"
|
||||
|
||||
AemXSeriesWideband::AemXSeriesWideband(uint8_t sensorIndex, SensorType type)
|
||||
: CanSensorBase(
|
||||
0x180 + sensorIndex, // 0th sensor is 0x180, others sequential above that
|
||||
type,
|
||||
MS2NT(21) // sensor transmits at 100hz, allow a frame to be missed
|
||||
)
|
||||
{}
|
||||
|
||||
void AemXSeriesWideband::decodeFrame(const CANRxFrame& frame, efitick_t nowNt) {
|
||||
if (frame.DLC != 8) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
// bit 6 indicates sensor fault
|
||||
bool sensorFault = frame.data8[7] & 0x40;
|
||||
if (sensorFault) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
// bit 7 indicates valid
|
||||
bool valid = frame.data8[6] & 0x80;
|
||||
if (!valid) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
// reports in 0.0001 lambda per LSB
|
||||
uint16_t lambdaInt = SWAP_UINT16(frame.data16[0]);
|
||||
setValidValue(0.0001f * lambdaInt, nowNt);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "can_sensor.h"
|
||||
|
||||
class AemXSeriesWideband final : public CanSensorBase {
|
||||
public:
|
||||
AemXSeriesWideband(uint8_t sensorIndex, SensorType type);
|
||||
|
||||
protected:
|
||||
void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) override;
|
||||
};
|
|
@ -121,4 +121,3 @@ public:
|
|||
int PID;
|
||||
float Scale;
|
||||
};
|
||||
|
||||
|
|
|
@ -108,16 +108,9 @@ bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
return engineConfiguration->afr.hwChannel != EFI_ADC_NONE;
|
||||
}
|
||||
|
||||
extern float aemXSeriesLambda;
|
||||
extern float InnovateLC2AFR;
|
||||
|
||||
float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
#if EFI_CAN_SUPPORT
|
||||
if (CONFIG(enableAemXSeries)) {
|
||||
return aemXSeriesLambda * 14.7f;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EFI_AUX_SERIAL
|
||||
if (CONFIG(enableInnovateLC2))
|
||||
return InnovateLC2AFR;
|
||||
|
|
|
@ -13,6 +13,7 @@ CONTROLLERS_SENSORS_SRC_CPP = $(PROJECT_DIR)/controllers/sensors/thermistors.cp
|
|||
$(PROJECT_DIR)/controllers/sensors/sensor_info_printing.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/functional_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/redundant_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/AemXSeriesLambda.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/software_knock.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/linear_func.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/resistance_func.cpp \
|
||||
|
|
|
@ -23,9 +23,22 @@ static FunctionPointerSensor lambdaSensor(SensorType::Lambda,
|
|||
return afrWrapper.getLambda();
|
||||
});
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
#include "AemXSeriesLambda.h"
|
||||
static AemXSeriesWideband aem(0, SensorType::Lambda);
|
||||
#endif
|
||||
|
||||
void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
INJECT_ENGINE_REFERENCE(&afrWrapper);
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
if (CONFIG(enableAemXSeries)) {
|
||||
registerCanSensor(aem);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!lambdaSensor.Register()) {
|
||||
warning(OBD_PCM_Processor_Fault, "Duplicate lambda sensor registration, ignoring");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue