mirror of https://github.com/rusefi/rusefi-1.git
unit test for vehicle_speed.cpp #3081
This commit is contained in:
parent
b692ba02e7
commit
511b5c22dd
|
@ -478,7 +478,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
|
||||||
float crankingTaper = getCrankingTaperFraction();
|
float crankingTaper = getCrankingTaperFraction();
|
||||||
|
|
||||||
// Determine what operation phase we're in - idling or not
|
// Determine what operation phase we're in - idling or not
|
||||||
auto phase = determinePhase(rpm, targetRpm, tps, getVehicleSpeed(), crankingTaper);
|
auto phase = determinePhase(rpm, targetRpm, tps, getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE), crankingTaper);
|
||||||
m_lastPhase = phase;
|
m_lastPhase = phase;
|
||||||
|
|
||||||
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
||||||
|
|
|
@ -18,7 +18,7 @@ void DynoView::update(vssSrc src) {
|
||||||
efitimeus_t timeNow, deltaTime = 0.0;
|
efitimeus_t timeNow, deltaTime = 0.0;
|
||||||
float speed,deltaSpeed = 0.0;
|
float speed,deltaSpeed = 0.0;
|
||||||
timeNow = getTimeNowUs();
|
timeNow = getTimeNowUs();
|
||||||
speed = getVehicleSpeed();
|
speed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
if (src == ICU) {
|
if (src == ICU) {
|
||||||
speed = efiRound(speed,1.0);
|
speed = efiRound(speed,1.0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,7 +55,7 @@ bool LaunchControlBase::isInsideSwitchCondition() const {
|
||||||
* then we have to return true, and trust that we would disable by other condition!
|
* then we have to return true, and trust that we would disable by other condition!
|
||||||
*/
|
*/
|
||||||
bool LaunchControlBase::isInsideSpeedCondition() const {
|
bool LaunchControlBase::isInsideSpeedCondition() const {
|
||||||
int speed = getVehicleSpeed();
|
int speed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
return (CONFIG(launchSpeedTreshold) > speed) || (!(CONFIG(launchActivationMode) == ALWAYS_ACTIVE_LAUNCH));
|
return (CONFIG(launchSpeedTreshold) > speed) || (!(CONFIG(launchActivationMode) == ALWAYS_ACTIVE_LAUNCH));
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,7 +395,7 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if EFI_VEHICLE_SPEED
|
#if EFI_VEHICLE_SPEED && ! EFI_UNIT_TEST
|
||||||
startVSSPins();
|
startVSSPins();
|
||||||
#endif /* EFI_VEHICLE_SPEED */
|
#endif /* EFI_VEHICLE_SPEED */
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#include "vehicle_speed.h"
|
#include "vehicle_speed.h"
|
||||||
|
|
||||||
|
#define DEFAULT_MOCK_SPEED -1
|
||||||
|
|
||||||
|
static float mockVehicleSpeed = DEFAULT_MOCK_SPEED; // in kilometers per hour
|
||||||
|
|
||||||
#if EFI_VEHICLE_SPEED
|
#if EFI_VEHICLE_SPEED
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
@ -15,20 +19,16 @@
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
#include "can_vss.h"
|
#include "can_vss.h"
|
||||||
|
|
||||||
|
|
||||||
|
// todo: move from static into Engine GOD object in order for tests reset
|
||||||
static efitick_t lastSignalTimeNt = 0;
|
static efitick_t lastSignalTimeNt = 0;
|
||||||
static efitick_t vssDiff = 0;
|
static efitick_t vssDiff = 0;
|
||||||
|
|
||||||
#define DEFAULT_MOCK_SPEED -1
|
|
||||||
static float mockVehicleSpeed = DEFAULT_MOCK_SPEED; // in kilometers per hour
|
|
||||||
|
|
||||||
void setMockVehicleSpeed(float speedKPH) {
|
|
||||||
mockVehicleSpeed = speedKPH;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return vehicle speed, in kilometers per hour
|
* @return vehicle speed, in kilometers per hour
|
||||||
*/
|
*/
|
||||||
float getVehicleSpeed(void) {
|
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (mockVehicleSpeed != DEFAULT_MOCK_SPEED)
|
if (mockVehicleSpeed != DEFAULT_MOCK_SPEED)
|
||||||
return mockVehicleSpeed;
|
return mockVehicleSpeed;
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
|
@ -36,7 +36,7 @@ float getVehicleSpeed(void) {
|
||||||
return getVehicleCanSpeed();
|
return getVehicleCanSpeed();
|
||||||
}
|
}
|
||||||
#endif /* EFI_CAN_SUPPORT */
|
#endif /* EFI_CAN_SUPPORT */
|
||||||
if (!hasVehicleSpeedSensor())
|
if (!hasVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE))
|
||||||
return 0;
|
return 0;
|
||||||
efitick_t nowNt = getTimeNowNt();
|
efitick_t nowNt = getTimeNowNt();
|
||||||
if (nowNt - lastSignalTimeNt > NT_PER_SECOND)
|
if (nowNt - lastSignalTimeNt > NT_PER_SECOND)
|
||||||
|
@ -45,13 +45,20 @@ float getVehicleSpeed(void) {
|
||||||
return engineConfiguration->vehicleSpeedCoef * NT_PER_SECOND / vssDiff;
|
return engineConfiguration->vehicleSpeedCoef * NT_PER_SECOND / vssDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vsAnaWidthCallback(void) {
|
// todo: make this method public and invoke this method from test
|
||||||
|
void vsCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
engine->engineState.vssEventCounter++;
|
engine->engineState.vssEventCounter++;
|
||||||
efitick_t nowNt = getTimeNowNt();
|
efitick_t nowNt = getTimeNowNt();
|
||||||
vssDiff = nowNt - lastSignalTimeNt;
|
vssDiff = nowNt - lastSignalTimeNt;
|
||||||
lastSignalTimeNt = nowNt;
|
lastSignalTimeNt = nowNt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ! EFI_UNIT_TEST
|
||||||
|
|
||||||
|
static void vsAnaWidthCallback() {
|
||||||
|
vsCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
}
|
||||||
|
|
||||||
static void speedInfo(void) {
|
static void speedInfo(void) {
|
||||||
efiPrintf("VSS input at %s",
|
efiPrintf("VSS input at %s",
|
||||||
hwPortname(CONFIG(vehicleSpeedSensorInputPin)));
|
hwPortname(CONFIG(vehicleSpeedSensorInputPin)));
|
||||||
|
@ -59,17 +66,18 @@ static void speedInfo(void) {
|
||||||
efiPrintf("c=%.2f eventCounter=%d speed=%.2f",
|
efiPrintf("c=%.2f eventCounter=%d speed=%.2f",
|
||||||
engineConfiguration->vehicleSpeedCoef,
|
engineConfiguration->vehicleSpeedCoef,
|
||||||
engine->engineState.vssEventCounter,
|
engine->engineState.vssEventCounter,
|
||||||
getVehicleSpeed());
|
getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||||
efiPrintf("vss diff %d", vssDiff);
|
efiPrintf("vss diff %d", vssDiff);
|
||||||
}
|
}
|
||||||
|
#endif // EFI_UNIT_TEST
|
||||||
|
|
||||||
bool hasVehicleSpeedSensor() {
|
bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin)));
|
return (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAL_VSS_USE_PAL
|
#if HAL_VSS_USE_PAL
|
||||||
static void vsExtiCallback(void *) {
|
static void vsExtiCallback(void *) {
|
||||||
vsAnaWidthCallback();
|
vsAnaWidthCallback(engine);
|
||||||
}
|
}
|
||||||
#endif /* HAL_VSS_USE_PAL */
|
#endif /* HAL_VSS_USE_PAL */
|
||||||
|
|
||||||
|
@ -81,6 +89,8 @@ void stopVSSPins(void) {
|
||||||
#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */
|
#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ! EFI_UNIT_TEST
|
||||||
|
|
||||||
void startVSSPins(void) {
|
void startVSSPins(void) {
|
||||||
if (!hasVehicleSpeedSensor()) {
|
if (!hasVehicleSpeedSensor()) {
|
||||||
return;
|
return;
|
||||||
|
@ -92,34 +102,41 @@ void startVSSPins(void) {
|
||||||
#elif HAL_USE_ICU
|
#elif HAL_USE_ICU
|
||||||
digital_input_s* vehicleSpeedInput = startDigitalCapture("VSS", CONFIG(vehicleSpeedSensorInputPin));
|
digital_input_s* vehicleSpeedInput = startDigitalCapture("VSS", CONFIG(vehicleSpeedSensorInputPin));
|
||||||
|
|
||||||
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
|
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, nullptr);
|
||||||
#else
|
#else
|
||||||
#error "HAL_USE_ICU or HAL_VSS_USE_PAL should be enabled to use EFI_VEHICLE_SPEED"
|
#error "HAL_USE_ICU or HAL_VSS_USE_PAL should be enabled to use EFI_VEHICLE_SPEED"
|
||||||
#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */
|
#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void initVehicleSpeed() {
|
void initVehicleSpeed() {
|
||||||
|
#if ! EFI_UNIT_TEST
|
||||||
addConsoleAction("speedinfo", speedInfo);
|
addConsoleAction("speedinfo", speedInfo);
|
||||||
startVSSPins();
|
startVSSPins();
|
||||||
|
#endif // EFI_UNIT_TEST
|
||||||
}
|
}
|
||||||
#else /* EFI_VEHICLE_SPEED */
|
#else /* EFI_VEHICLE_SPEED */
|
||||||
|
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
static float mockVehicleSpeed = 0.0; // in kilometers per hour
|
|
||||||
|
|
||||||
void setMockVehicleSpeed(float speedKPH) {
|
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
mockVehicleSpeed = speedKPH;
|
|
||||||
}
|
|
||||||
float getVehicleSpeed(void) {
|
|
||||||
|
|
||||||
// Mock return to be used in unit tests
|
// Mock return to be used in unit tests
|
||||||
return mockVehicleSpeed;
|
return mockVehicleSpeed;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
float getVehicleSpeed(void) {
|
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
||||||
// no VSS support
|
// no VSS support
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* EFI_UNIT_TEST */
|
#endif /* EFI_UNIT_TEST */
|
||||||
#endif /* EFI_VEHICLE_SPEED */
|
#endif /* EFI_VEHICLE_SPEED */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setMockVehicleSpeed(float speedKPH) {
|
||||||
|
mockVehicleSpeed = speedKPH;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
/**
|
/**
|
||||||
* @return vehicle speed, in kilometers per hour
|
* @return vehicle speed, in kilometers per hour
|
||||||
*/
|
*/
|
||||||
float getVehicleSpeed(void);
|
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void initVehicleSpeed();
|
void initVehicleSpeed();
|
||||||
void setMockVehicleSpeed(float speedKPH);
|
void setMockVehicleSpeed(float speedKPH);
|
||||||
bool hasVehicleSpeedSensor();
|
bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void stopVSSPins(void);
|
void stopVSSPins(void);
|
||||||
void startVSSPins(void);
|
void startVSSPins(void);
|
||||||
|
|
Loading…
Reference in New Issue