* Add vehicle_speed_converter.h with realization. * Add test_vehicle_speed_converter.cpp with realization. * Add test_vehicle_speed_converter.cpp to Makefile * Edit "VehicleSpeedSensor" from function pointer sensor to frequency sensor * Fix "VehicleSpeedSensor" init function args * Remove "VehicleSpeedConverter" empty constructor * Edit vehicle_speed_converter.h code style * Fix args and engine injection in "VehicleSpeedSensor" initialization procedure * Remove old "Vehicle Speed" module initialization * Revert "Remove old "Vehicle Speed" module initialization" This reverts commit 100b7caa8c615c20eed3d0c23a49824b4e556148. * Remove old "Vehicle Speed" module initialization pieces * Revert "Revert "Remove old "Vehicle Speed" module initialization"" This reverts commit f559a726f1f7f5a7acacd1b6517e571743e84327. * Debug changes * Revert "Debug changes" This reverts commit f7e2be1a8a46c6f3f93f14f002b2f2db539da8e2. * Another debug changes * More debug changes * And more debug changes. * Revert "Another debug changes" This reverts commit 914fbb1df42c37e4b5ecbb119bb45e7cffdf4064. * Revert "More debug changes" This reverts commit 0b2d96d461c3cd9b0f1ae97ed110b8effe6b0cc6. * Revert "And more debug changes." This reverts commit 06ae8daded0e6e1c025e4e5058b47283f4adfe92. * Add "Vehicle Speed" sensor reconfiguration * Revert "Add "Vehicle Speed" sensor reconfiguration" This reverts commit a089a6d563dd710004ce1a7da1744b0b4b90c3b1. * Revert "Revert "Add "Vehicle Speed" sensor reconfiguration"" This reverts commit 7b2bb8af4b3caa547236ca59e4c4bdb3ac1200cc. * Debug changes * Another debug changes * Fix another debug changes * Another debug changes 2 * Revert "Another debug changes 2" This reverts commit cfad55141eec125b2f1d35fb95d9f46b54f666b6. * Revert "Fix another debug changes" This reverts commit 9bc2c74a3be6fd896827ff48cf4580e7657529c0. * Revert "Another debug changes" This reverts commit 4337ed8cad8dff508d093944eb3f75e9a69e4a77. * Edit class FrequencySensor, make it more RAII * Debug changes * Debug changes 2 * Debug changes 3 * Revert "Debug changes 3" This reverts commit 52a7054c122b5157540fe45a055a84b57478d722. * Revert "Debug changes 2" This reverts commit dec79fb913344ccb4b8614910ad62e6c129a243e. * Revert "Debug changes" This reverts commit eb08d7a529b55ba397a7dd2c154b76eab42f212b. * Revert "Edit class FrequencySensor, make it more RAII" This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Citroen Berlingo" engine config. This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Dodge Neon" engine config Co-authored-by: alxrMironov <330OMcorporative>
This commit is contained in:
parent
9be0985079
commit
f926d2ccba
|
@ -167,7 +167,7 @@ void setCitroenBerlingoTU3JPConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
/**
|
||||
* Speed Sensor
|
||||
*/
|
||||
engineConfiguration->vehicleSpeedSensorInputPin = GPIOA_8;
|
||||
//engineConfiguration->vehicleSpeedSensorInputPin = GPIOA_8;
|
||||
/**
|
||||
* Other
|
||||
*/
|
||||
|
|
|
@ -359,7 +359,7 @@ void setDodgeNeonNGCEngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
engineConfiguration->auxPid[0].iFactor = 0.1;
|
||||
engineConfiguration->auxPid[0].dFactor = 0.1;
|
||||
|
||||
engineConfiguration->vehicleSpeedSensorInputPin = GPIOA_8;
|
||||
// engineConfiguration->vehicleSpeedSensorInputPin = GPIOA_8;
|
||||
|
||||
engineConfiguration->fanOnTemperature = 92;
|
||||
engineConfiguration->fanOffTemperature = 89;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include "pch.h"
|
||||
#include "sensor_converter_func.h"
|
||||
|
||||
class VehicleSpeedConverter : public SensorConverter {
|
||||
public:
|
||||
DECLARE_ENGINE_PTR;
|
||||
|
||||
SensorResult convert(float frequency) const override {
|
||||
auto speed = frequency * engineConfiguration->vehicleSpeedCoef;
|
||||
return speed;
|
||||
}
|
||||
};
|
|
@ -14,12 +14,12 @@ static void freqSensorExtiCallback(void* arg) {
|
|||
inst->onEdge(getTimeNowNt());
|
||||
}
|
||||
|
||||
void FrequencySensor::init(brain_pin_e pin) {
|
||||
void FrequencySensor::init(brain_pin_e pin, const char* const msg) {
|
||||
m_pin = pin;
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
// todo: refactor https://github.com/rusefi/rusefi/issues/2123
|
||||
efiExtiEnablePin("flex", pin,
|
||||
efiExtiEnablePin(msg, pin,
|
||||
PAL_EVENT_MODE_FALLING_EDGE,
|
||||
freqSensorExtiCallback, reinterpret_cast<void*>(this));
|
||||
#endif // EFI_PROD_CODE
|
||||
|
|
|
@ -6,7 +6,7 @@ public:
|
|||
FrequencySensor(SensorType type, efitick_t timeoutPeriod)
|
||||
: FunctionalSensor(type, timeoutPeriod) { }
|
||||
|
||||
void init(brain_pin_e pin);
|
||||
void init(brain_pin_e pin, const char* const msg);
|
||||
void deInit();
|
||||
|
||||
void onEdge(efitick_t nowNt);
|
||||
|
|
|
@ -390,9 +390,9 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if EFI_VEHICLE_SPEED && ! EFI_UNIT_TEST
|
||||
/* #if EFI_VEHICLE_SPEED && ! EFI_UNIT_TEST
|
||||
startVSSPins();
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
#endif EFI_VEHICLE_SPEED */
|
||||
|
||||
#if EFI_BOOST_CONTROL
|
||||
startBoostPin();
|
||||
|
@ -474,9 +474,9 @@ void stopHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
stopSmartCsPins();
|
||||
#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
|
||||
|
||||
#if EFI_VEHICLE_SPEED
|
||||
/* #if EFI_VEHICLE_SPEED
|
||||
stopVSSPins();
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
#endif EFI_VEHICLE_SPEED */
|
||||
|
||||
#if EFI_LOGIC_ANALYZER
|
||||
stopLogicAnalyzerPins();
|
||||
|
@ -596,9 +596,9 @@ void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
initAuxSerial();
|
||||
#endif /* EFI_AUX_SERIAL */
|
||||
|
||||
#if EFI_VEHICLE_SPEED
|
||||
/*#if EFI_VEHICLE_SPEED
|
||||
initVehicleSpeed();
|
||||
#endif // EFI_VEHICLE_SPEED
|
||||
#endif // EFI_VEHICLE_SPEED*/
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
initCanVssSupport();
|
||||
|
|
|
@ -37,3 +37,4 @@ void reconfigureTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
|||
void reconfigureThermistors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void reconfigureOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void deInitFlexSensor();
|
||||
void deInitVehicleSpeedSensor();
|
||||
|
|
|
@ -18,7 +18,7 @@ void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
flexSensor.setFunction(converter);
|
||||
flexSensor.init(pin);
|
||||
flexSensor.init(pin, "flex");
|
||||
flexSensor.Register();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,13 @@ void initNewSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
deInitFlexSensor();
|
||||
deInitVehicleSpeedSensor();
|
||||
reconfigureVbatt(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureTps(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initFlexSensor(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
// Mocking/testing helpers
|
||||
|
|
|
@ -2,25 +2,28 @@
|
|||
|
||||
#include "init.h"
|
||||
#include "vehicle_speed.h"
|
||||
#include "function_pointer_sensor.h"
|
||||
#include "frequency_sensor.h"
|
||||
#include "vehicle_speed_converter.h"
|
||||
|
||||
struct GetVehicleSpeedWrapper {
|
||||
DECLARE_ENGINE_PTR;
|
||||
static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500));
|
||||
static VehicleSpeedConverter vehicleSpeedConverter;
|
||||
|
||||
float getVehicleSpeed() {
|
||||
return ::getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
};
|
||||
|
||||
static GetVehicleSpeedWrapper vehicleSpeedWrapper;
|
||||
|
||||
static FunctionPointerSensor vehicleSpeedSensor(SensorType::VehicleSpeed,
|
||||
[]() {
|
||||
return vehicleSpeedWrapper.getVehicleSpeed();
|
||||
});
|
||||
|
||||
void initVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
INJECT_ENGINE_REFERENCE(&vehicleSpeedWrapper);
|
||||
INJECT_ENGINE_REFERENCE(&vehicleSpeedConverter);
|
||||
|
||||
auto pin = CONFIG(vehicleSpeedSensorInputPin);
|
||||
|
||||
// Nothing to do if no sensor configured
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vehicleSpeedSensor.setFunction(vehicleSpeedConverter);
|
||||
vehicleSpeedSensor.init(pin, "vss");
|
||||
vehicleSpeedSensor.Register();
|
||||
}
|
||||
|
||||
void deInitVehicleSpeedSensor() {
|
||||
vehicleSpeedSensor.deInit();
|
||||
}
|
|
@ -22,7 +22,7 @@ public:
|
|||
void SetUp() override {
|
||||
// If somehow prodcode will be unwrapped for test it MAYBE! will fire with error.
|
||||
// At least we must init FlexSensor somehow
|
||||
dut.init(GPIO_INVALID);
|
||||
dut.init(GPIO_INVALID, "Test");
|
||||
dut.setFunction(identityFunc);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
#include "pch.h"
|
||||
#include "vehicle_speed_converter.h"
|
||||
|
||||
static constexpr engine_type_e ENGINE_TEST_HELPER = TEST_ENGINE;
|
||||
|
||||
class VehicleSpeedConverterTest : public ::testing::Test {
|
||||
|
||||
public:
|
||||
VehicleSpeedConverter dut;
|
||||
|
||||
VehicleSpeedConverterTest(){
|
||||
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
WITH_ENGINE_TEST_HELPER(ENGINE_TEST_HELPER);
|
||||
INJECT_ENGINE_REFERENCE(&dut);
|
||||
}
|
||||
|
||||
void SetCoef(float new_coef) {
|
||||
dut.engineConfiguration->vehicleSpeedCoef = new_coef;
|
||||
}
|
||||
|
||||
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
|
||||
return (speed / coef);
|
||||
}
|
||||
|
||||
void TestForSpeedWithCoef(float expectedSpeed, float coef)
|
||||
{
|
||||
SetCoef(coef);
|
||||
auto inputFreq = GetFrequencyBySpeedAndCoef(expectedSpeed, coef);
|
||||
auto result = dut.convert(inputFreq);
|
||||
ASSERT_TRUE(result.Valid);
|
||||
ASSERT_NEAR(expectedSpeed, result.Value, 0.01f);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Converter must return valid and expected result for setted coef
|
||||
*/
|
||||
TEST_F(VehicleSpeedConverterTest, returnExpectedResultForSettedCoef) {
|
||||
|
||||
TestForSpeedWithCoef(0.0f, 0.5f);
|
||||
TestForSpeedWithCoef(0.5f, 0.5f);
|
||||
TestForSpeedWithCoef(10.0f, 0.5f);
|
||||
TestForSpeedWithCoef(0.0f, 10.0f);
|
||||
TestForSpeedWithCoef(0.5f, 10.0f);
|
||||
TestForSpeedWithCoef(10.0f, 10.0f);
|
||||
}
|
||||
|
||||
/*
|
||||
* Converter must always return strong float zero if coef == 0.0f
|
||||
*/
|
||||
TEST_F(VehicleSpeedConverterTest, zeroCoefReturnsZeroSpeedOnAnyInput) {
|
||||
|
||||
SetCoef(0.0f);
|
||||
|
||||
{
|
||||
auto result = dut.convert(0.0f);
|
||||
ASSERT_TRUE(result.Valid);
|
||||
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||
}
|
||||
|
||||
{
|
||||
auto result = dut.convert(0.5f);
|
||||
ASSERT_TRUE(result.Valid);
|
||||
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||
}
|
||||
|
||||
{
|
||||
auto result = dut.convert(10.0f);
|
||||
ASSERT_TRUE(result.Valid);
|
||||
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||
}
|
||||
}
|
|
@ -87,4 +87,6 @@ TESTS_SRC_CPP = \
|
|||
tests/test_stepper.cpp \
|
||||
tests/sensor/test_frequency_sensor.cpp \
|
||||
tests/sensor/test_vehicle_speed.cpp \
|
||||
tests/sensor/test_vehicle_speed_converter.cpp
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue