test AEM X-Series wideband protocol (#4002)

* break out acceptFrame, test CanListener

* test AEM xseries protocol

* tweaks

* tweaks

* maybe everyone compiles happily now
This commit is contained in:
Matthew Kennedy 2022-03-15 12:52:50 -07:00 committed by GitHub
parent cd2d93bc39
commit 4e57daf6d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 6 deletions

View File

@ -7,11 +7,10 @@
#pragma once
#if ! EFI_PROD_CODE
#if !EFI_PROD_CODE || !EFI_CAN_SUPPORT
#include "can_mocks.h"
#endif // EFI_PROD_CODE
#if !EFI_UNIT_TEST
#include "hal.h"
#endif // EFI_UNIT_TEST

View File

@ -3,7 +3,6 @@
#if EFI_CAN_SUPPORT
#include "rusefi_lua.h"
#include "can.h"
static constexpr size_t maxFilterCount = 48;

View File

@ -53,6 +53,9 @@ void testLuaExecString(const char* script);
#endif
#if EFI_CAN_SUPPORT
#include "can.h"
// Lua CAN rx feature
void initLuaCanRx();
// Called when the user script is unloaded, resets any CAN rx filters

View File

@ -1,6 +1,6 @@
#include "pch.h"
#if EFI_CAN_SUPPORT
#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
#include "AemXSeriesLambda.h"
AemXSeriesWideband::AemXSeriesWideband(uint8_t sensorIndex, SensorType type)

View File

@ -9,7 +9,6 @@
#include "stored_value_sensor.h"
#include "scaled_channel.h"
#include "hal.h"
#include "can_msg_tx.h"
#include "obd2.h"
#include "can.h"
@ -54,6 +53,8 @@ private:
const uint8_t m_offset;
};
#if EFI_PROD_CODE
template <int Size, int Offset>
class ObdCanSensor: public CanSensorBase {
public:
@ -95,3 +96,5 @@ public:
int PID;
float Scale;
};
#endif // EFI_PROD_CODE

View File

@ -24,7 +24,7 @@ void FunctionalSensor::showInfo(const char* sensorName) const {
}
}
#if EFI_CAN_SUPPORT
#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
#include "can_sensor.h"
void CanSensorBase::showInfo(const char* sensorName) const {

View File

@ -0,0 +1,57 @@
#include "pch.h"
#include "AemXSeriesLambda.h"
using ::testing::StrictMock;
using ::testing::_;
TEST(CanWideband, DecodeValid) {
Sensor::resetRegistry();
AemXSeriesWideband dut(0, SensorType::Lambda1);
dut.Register();
// check not set
EXPECT_FLOAT_EQ(-1, Sensor::get(SensorType::Lambda1).value_or(-1));
CANRxFrame frame;
frame.SID = 0x180;
frame.IDE = false;
frame.DLC = 8;
frame.data8[0] = 0x1F; // 8000, lambda 0.8
frame.data8[1] = 0x40;
frame.data8[2] = 0;
frame.data8[3] = 0;
frame.data8[4] = 0;
frame.data8[5] = 0;
frame.data8[6] =
1 << 1 | // LSU 4.9 detected
1 << 7; // Data valid
frame.data8[7] = 0;
// check that lambda updates
dut.processFrame(frame, getTimeNowNt());
EXPECT_FLOAT_EQ(0.8f, Sensor::get(SensorType::Lambda1).value_or(-1));
// Now check invalid data
frame.data8[6] =
1 << 1 | // LSU 4.9 detected
0 << 7; // Data INVALID
dut.processFrame(frame, getTimeNowNt());
EXPECT_FLOAT_EQ(-1, Sensor::get(SensorType::Lambda1).value_or(-1));
// Now check sensor fault
frame.data8[6] =
1 << 1 | // LSU 4.9 detected
1 << 7; // Data valid
frame.data8[7] = 1 << 6; // Sensor fault!
dut.processFrame(frame, getTimeNowNt());
EXPECT_FLOAT_EQ(-1, Sensor::get(SensorType::Lambda1).value_or(-1));
}

View File

@ -86,6 +86,7 @@ TESTS_SRC_CPP = \
tests/trigger/test_all_triggers.cpp \
tests/test_can_rx.cpp \
tests/test_can_serial.cpp \
tests/test_can_wideband.cpp \
tests/test_hellen_board_id.cpp \
tests/sensor/test_frequency_sensor.cpp \
tests/sensor/test_turbocharger_speed_converter.cpp \