| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /* | |||
| 2 | * @file antilag_system.cpp | |||
| 3 | * | |||
| 4 | * @date 26. nov. 2022 | |||
| 5 | * Author: Turbo Marian | |||
| 6 | */ | |||
| 7 | ||||
| 8 | #include "pch.h" | |||
| 9 | ||||
| 10 | #if EFI_ANTILAG_SYSTEM | |||
| 11 | #include "antilag_system.h" | |||
| 12 | #include "engine_state.h" | |||
| 13 | #include "fuel_math.h" | |||
| 14 | ||||
| 15 | 2 | bool AntilagSystemBase::isInsideALSSwitchCondition() { | ||
| 16 | 2 | isALSSwitchActivated = engineConfiguration->antiLagActivationMode == SWITCH_INPUT_ANTILAG; | ||
| 17 | ||||
| 18 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 1 time.
|
2 | if (isALSSwitchActivated) { |
| 19 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
|
1 | if (isBrainPinValid(engineConfiguration->ALSActivatePin)) { |
| 20 | #if EFI_PROD_CODE | |||
| 21 | ALSActivatePinState = efiReadPin(engineConfiguration->ALSActivatePin, engineConfiguration->ALSActivatePinMode); | |||
| 22 | #else | |||
| 23 | ✗ | ALSActivatePinState = false; | ||
| 24 | #endif | |||
| 25 | } | |||
| 26 | 1 | return ALSActivatePinState; | ||
| 27 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
|
1 | } else if (engineConfiguration->antiLagActivationMode == LUA_ANTILAG) { |
| 28 | ✗ | return luaAntilagState; | ||
| 29 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 1 time.
✗ Decision 'false' not taken.
|
1 | } else if (engineConfiguration->antiLagActivationMode == ALWAYS_ON_ANTILAG) { |
| 30 | 1 | return true; | ||
| 31 | } else { | |||
| 32 | ✗ | criticalError("Unexpected antiLagActivationMode"); | ||
| 33 | ✗ | return false; | ||
| 34 | } | |||
| 35 | } | |||
| 36 | ||||
| 37 | 2 | bool AntilagSystemBase::isALSMinRPMCondition(float rpm) const { | ||
| 38 | 2 | return engineConfiguration->ALSMinRPM < rpm; | ||
| 39 | } | |||
| 40 | ||||
| 41 | 2 | bool AntilagSystemBase::isALSMaxRPMCondition(float rpm) const { | ||
| 42 | 2 | return engineConfiguration->ALSMaxRPM > rpm; | ||
| 43 | } | |||
| 44 | ||||
| 45 | 2 | bool AntilagSystemBase::isALSMinCLTCondition() const { | ||
| 46 | 2 | int clt = Sensor::getOrZero(SensorType::Clt); | ||
| 47 | ||||
| 48 | 2 | return engineConfiguration->ALSMinCLT < clt; | ||
| 49 | } | |||
| 50 | ||||
| 51 | 2 | bool AntilagSystemBase::isALSMaxCLTCondition() const { | ||
| 52 | 2 | int clt = Sensor::getOrZero(SensorType::Clt); | ||
| 53 | ||||
| 54 | 2 | return engineConfiguration->ALSMaxCLT > clt; | ||
| 55 | } | |||
| 56 | ||||
| 57 | 2 | bool AntilagSystemBase::isALSMaxThrottleIntentCondition() const { | ||
| 58 | 2 | int throttleIntent = Sensor::getOrZero(SensorType::DriverThrottleIntent); | ||
| 59 | ||||
| 60 | 2 | return engineConfiguration->ALSMaxTPS > throttleIntent; | ||
| 61 | } | |||
| 62 | ||||
| 63 | ✗ | bool AntilagSystemBase::isInsideALSTimerCondition() { | ||
| 64 | ✗ | auto ALStime = ALStimer.getElapsedSeconds(); | ||
| 65 | ||||
| 66 | ✗ | return ALStime < engineConfiguration->ALSMaxDuration; | ||
| 67 | } | |||
| 68 | ||||
| 69 | 2 | bool AntilagSystemBase::isAntilagConditionMet(float rpm) { | ||
| 70 | ||||
| 71 | ||||
| 72 | 2 | ALSMinRPMCondition = isALSMinRPMCondition(rpm); | ||
| 73 | 2 | ALSMaxRPMCondition = isALSMaxRPMCondition(rpm); | ||
| 74 | 2 | ALSMinCLTCondition = isALSMinCLTCondition(); | ||
| 75 | 2 | ALSMaxCLTCondition = isALSMaxCLTCondition(); | ||
| 76 | 2 | ALSMaxThrottleIntentCondition = isALSMaxThrottleIntentCondition(); | ||
| 77 | 2 | ALSSwitchCondition = isInsideALSSwitchCondition(); | ||
| 78 | 2 | ALSTimerCondition = true; | ||
| 79 | /* | |||
| 80 | todo: looking for a hero to figure out unit test part of this | |||
| 81 | ALSTimerCondition = isInsideALSTimerCondition(); | |||
| 82 | */ | |||
| 83 | ||||
| 84 | 4 | return ALSMinRPMCondition && | ||
| 85 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ALSMaxRPMCondition && | |
| 86 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ALSMinCLTCondition && | |
| 87 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ALSMaxCLTCondition && | |
| 88 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ALSMaxThrottleIntentCondition && | |
| 89 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
|
5 | ALSSwitchCondition && | |
| 90 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
3 | ALSTimerCondition; | |
| 91 | } | |||
| 92 | ||||
| 93 | 1101 | void AntilagSystemBase::update() { | ||
| 94 | 1101 | float rpm = Sensor::getOrZero(SensorType::Rpm); | ||
| 95 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1099 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
1101 | isAntilagCondition = engineConfiguration->antiLagEnabled && isAntilagConditionMet(rpm); | |
| 96 | ||||
| 97 |
2/2✓ Branch 0 taken 1099 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 1099 times.
✓ Decision 'false' taken 2 times.
|
1101 | if (!ALSMaxRPMCondition) { |
| 98 | 1099 | ALStimer.reset(); | ||
| 99 | } | |||
| 100 | ||||
| 101 | #if EFI_ANTILAG_SYSTEM | |||
| 102 | 1101 | fuelALSCorrection = getFuelALSCorrection(rpm); | ||
| 103 | #endif // EFI_ANTILAG_SYSTEM | |||
| 104 | 1101 | } | ||
| 105 | ||||
| 106 | #endif /* EFI_ANTILAG_SYSTEM */ | |||
| 107 |