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();
|
||||
|
||||
// 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;
|
||||
|
||||
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
||||
|
|
|
@ -18,7 +18,7 @@ void DynoView::update(vssSrc src) {
|
|||
efitimeus_t timeNow, deltaTime = 0.0;
|
||||
float speed,deltaSpeed = 0.0;
|
||||
timeNow = getTimeNowUs();
|
||||
speed = getVehicleSpeed();
|
||||
speed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
if (src == ICU) {
|
||||
speed = efiRound(speed,1.0);
|
||||
} else {
|
||||
|
@ -163,4 +163,4 @@ void updateDynoViewCan(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
dynoInstance.update(CAN);
|
||||
}
|
||||
|
||||
#endif /* EFI_DYNO_VIEW */
|
||||
#endif /* EFI_DYNO_VIEW */
|
||||
|
|
|
@ -55,7 +55,7 @@ bool LaunchControlBase::isInsideSwitchCondition() const {
|
|||
* then we have to return true, and trust that we would disable by other condition!
|
||||
*/
|
||||
bool LaunchControlBase::isInsideSpeedCondition() const {
|
||||
int speed = getVehicleSpeed();
|
||||
int speed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
return (CONFIG(launchSpeedTreshold) > speed) || (!(CONFIG(launchActivationMode) == ALWAYS_ACTIVE_LAUNCH));
|
||||
}
|
||||
|
|
|
@ -395,7 +395,7 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if EFI_VEHICLE_SPEED
|
||||
#if EFI_VEHICLE_SPEED && ! EFI_UNIT_TEST
|
||||
startVSSPins();
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
#include "vehicle_speed.h"
|
||||
|
||||
#define DEFAULT_MOCK_SPEED -1
|
||||
|
||||
static float mockVehicleSpeed = DEFAULT_MOCK_SPEED; // in kilometers per hour
|
||||
|
||||
#if EFI_VEHICLE_SPEED
|
||||
|
||||
#include "engine.h"
|
||||
|
@ -15,20 +19,16 @@
|
|||
#include "pin_repository.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 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
|
||||
*/
|
||||
float getVehicleSpeed(void) {
|
||||
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (mockVehicleSpeed != DEFAULT_MOCK_SPEED)
|
||||
return mockVehicleSpeed;
|
||||
#if EFI_CAN_SUPPORT
|
||||
|
@ -36,7 +36,7 @@ float getVehicleSpeed(void) {
|
|||
return getVehicleCanSpeed();
|
||||
}
|
||||
#endif /* EFI_CAN_SUPPORT */
|
||||
if (!hasVehicleSpeedSensor())
|
||||
if (!hasVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE))
|
||||
return 0;
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
if (nowNt - lastSignalTimeNt > NT_PER_SECOND)
|
||||
|
@ -45,13 +45,20 @@ float getVehicleSpeed(void) {
|
|||
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++;
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
vssDiff = nowNt - lastSignalTimeNt;
|
||||
lastSignalTimeNt = nowNt;
|
||||
}
|
||||
|
||||
#if ! EFI_UNIT_TEST
|
||||
|
||||
static void vsAnaWidthCallback() {
|
||||
vsCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
static void speedInfo(void) {
|
||||
efiPrintf("VSS input at %s",
|
||||
hwPortname(CONFIG(vehicleSpeedSensorInputPin)));
|
||||
|
@ -59,17 +66,18 @@ static void speedInfo(void) {
|
|||
efiPrintf("c=%.2f eventCounter=%d speed=%.2f",
|
||||
engineConfiguration->vehicleSpeedCoef,
|
||||
engine->engineState.vssEventCounter,
|
||||
getVehicleSpeed());
|
||||
getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
efiPrintf("vss diff %d", vssDiff);
|
||||
}
|
||||
#endif // EFI_UNIT_TEST
|
||||
|
||||
bool hasVehicleSpeedSensor() {
|
||||
bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin)));
|
||||
}
|
||||
|
||||
#if HAL_VSS_USE_PAL
|
||||
static void vsExtiCallback(void *) {
|
||||
vsAnaWidthCallback();
|
||||
vsAnaWidthCallback(engine);
|
||||
}
|
||||
#endif /* HAL_VSS_USE_PAL */
|
||||
|
||||
|
@ -81,6 +89,8 @@ void stopVSSPins(void) {
|
|||
#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */
|
||||
}
|
||||
|
||||
#if ! EFI_UNIT_TEST
|
||||
|
||||
void startVSSPins(void) {
|
||||
if (!hasVehicleSpeedSensor()) {
|
||||
return;
|
||||
|
@ -92,34 +102,41 @@ void startVSSPins(void) {
|
|||
#elif HAL_USE_ICU
|
||||
digital_input_s* vehicleSpeedInput = startDigitalCapture("VSS", CONFIG(vehicleSpeedSensorInputPin));
|
||||
|
||||
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
|
||||
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, nullptr);
|
||||
#else
|
||||
#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
|
||||
|
||||
void initVehicleSpeed() {
|
||||
#if ! EFI_UNIT_TEST
|
||||
addConsoleAction("speedinfo", speedInfo);
|
||||
startVSSPins();
|
||||
#endif // EFI_UNIT_TEST
|
||||
}
|
||||
#else /* EFI_VEHICLE_SPEED */
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
static float mockVehicleSpeed = 0.0; // in kilometers per hour
|
||||
|
||||
void setMockVehicleSpeed(float speedKPH) {
|
||||
mockVehicleSpeed = speedKPH;
|
||||
}
|
||||
float getVehicleSpeed(void) {
|
||||
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
|
||||
// Mock return to be used in unit tests
|
||||
return mockVehicleSpeed;
|
||||
}
|
||||
#else
|
||||
float getVehicleSpeed(void) {
|
||||
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
|
||||
// no VSS support
|
||||
return 0;
|
||||
}
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
|
||||
|
||||
|
||||
|
||||
void setMockVehicleSpeed(float speedKPH) {
|
||||
mockVehicleSpeed = speedKPH;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
/**
|
||||
* @return vehicle speed, in kilometers per hour
|
||||
*/
|
||||
float getVehicleSpeed(void);
|
||||
float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initVehicleSpeed();
|
||||
void setMockVehicleSpeed(float speedKPH);
|
||||
bool hasVehicleSpeedSensor();
|
||||
bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void stopVSSPins(void);
|
||||
void startVSSPins(void);
|
||||
|
|
Loading…
Reference in New Issue