GCC Code Coverage Report


Directory: ./
File: firmware/controllers/algo/antilag_system.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 86.0% 43 0 50
Functions: 88.9% 8 0 9
Branches: 67.9% 19 0 28
Decisions: 70.0% 7 - 10

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 1120 void AntilagSystemBase::update() {
94 1120 float rpm = Sensor::getOrZero(SensorType::Rpm);
95
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1118 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
1120 isAntilagCondition = engineConfiguration->antiLagEnabled && isAntilagConditionMet(rpm);
96
97
2/2
✓ Branch 0 taken 1118 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 1118 times.
✓ Decision 'false' taken 2 times.
1120 if (!ALSMaxRPMCondition) {
98 1118 ALStimer.reset();
99 }
100
101 #if EFI_ANTILAG_SYSTEM
102 1120 fuelALSCorrection = getFuelALSCorrection(rpm);
103 #endif // EFI_ANTILAG_SYSTEM
104 1120 }
105
106 #endif /* EFI_ANTILAG_SYSTEM */
107