Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file VvlController.cpp | |||
3 | * | |||
4 | * @date: ago 25, 2025 | |||
5 | * @author FDSoftware | |||
6 | */ | |||
7 | ||||
8 | #include "pch.h" | |||
9 | #include "vvl_controller.h" | |||
10 | ||||
11 | 1163 | void VvlController::onSlowCallback() { | ||
12 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 1117 times.
|
2/2✓ Decision 'true' taken 46 times.
✓ Decision 'false' taken 1117 times.
|
1163 | if (engineConfiguration->vvlControlEnabled) { |
13 | 46 | updateTpsConditionSatisfied(); | ||
14 | 46 | updateCltConditionSatisfied(); | ||
15 | 46 | updateMapConditionSatisfied(); | ||
16 | 46 | updateAfrConditionSatisfied(); | ||
17 | 46 | updateRpmConditionSatisfied(); | ||
18 | 46 | isVvlCondition = ( | ||
19 |
10/10✓ Branch 0 taken 43 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 39 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 38 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 33 times.
|
46 | isVvlTpsCondition && isVvlCltCondition && isVvlMapCondition && isVvlAfrCondition && isVvlRpmCondition | |
20 | ); | |||
21 | } else { | |||
22 | 1117 | isVvlCondition = false; | ||
23 | } | |||
24 | 1163 | enginePins.vvlRelay.setValue(isVvlCondition); | ||
25 | 1163 | } | ||
26 | ||||
27 | 986 | float VvlController::getFuelCoefficient() const { | ||
28 | 986 | float result = 1.0f; | ||
29 |
3/4✓ Branch 0 taken 1 time.
✓ Branch 1 taken 985 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 986 times.
|
986 | if (engineConfiguration->vvlControlEnabled && isVvlCondition) { |
30 | ✗ | result += engineConfiguration->vvlController.fuelAdderPercent / 100.0f; | ||
31 | } | |||
32 | 986 | return result; | ||
33 | } | |||
34 | ||||
35 | 1070 | float VvlController::getTimingModifier() const { | ||
36 |
3/4✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1069 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1070 times.
|
1070 | if (engineConfiguration->vvlControlEnabled && isVvlCondition) { |
37 | // note the "-" here to remove timing! | |||
38 | ✗ | return -engineConfiguration->vvlController.ignitionRetard; | ||
39 | } | |||
40 | 1070 | return 0.0f; | ||
41 | } | |||
42 | ||||
43 | 46 | void VvlController::updateTpsConditionSatisfied() { | ||
44 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 41 times.
|
2/2✓ Decision 'true' taken 5 times.
✓ Decision 'false' taken 41 times.
|
46 | if (engineConfiguration->vvlController.minimumTps != 0) { |
45 | 5 | const expected<float> tps = Sensor::get(SensorType::DriverThrottleIntent); | ||
46 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
|
5 | isVvlTpsCondition = tps.Valid && (engineConfiguration->vvlController.minimumTps <= tps.Value); | |
47 | } else { | |||
48 | 41 | isVvlTpsCondition = true; | ||
49 | } | |||
50 | 46 | } | ||
51 | ||||
52 | 46 | void VvlController::updateCltConditionSatisfied() { | ||
53 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 41 times.
|
2/2✓ Decision 'true' taken 5 times.
✓ Decision 'false' taken 41 times.
|
46 | if (engineConfiguration->vvlController.minimumClt != 0) { |
54 | 5 | const expected<float> clt = Sensor::get(SensorType::Clt); | ||
55 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
|
5 | isVvlCltCondition = clt.Valid && (engineConfiguration->vvlController.minimumClt <= clt.Value); | |
56 | } else { | |||
57 | 41 | isVvlCltCondition = true; | ||
58 | } | |||
59 | 46 | } | ||
60 | ||||
61 | 46 | void VvlController::updateMapConditionSatisfied() { | ||
62 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 42 times.
|
2/2✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 42 times.
|
46 | if (engineConfiguration->vvlController.maximumMap != 0) { |
63 | 4 | const expected<float> map = Sensor::get(SensorType::Map); | ||
64 |
3/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
|
4 | isVvlMapCondition = map.Valid && (map.Value <= engineConfiguration->vvlController.maximumMap); | |
65 | } else { | |||
66 | 42 | isVvlMapCondition = true; | ||
67 | } | |||
68 | 46 | } | ||
69 | ||||
70 | 46 | void VvlController::updateAfrConditionSatisfied() { | ||
71 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 42 times.
|
2/2✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 42 times.
|
46 | if (static_cast<float>(engineConfiguration->vvlController.maximumAfr) != 0.0f) { |
72 | 4 | const expected<float> lambda1 = Sensor::get(SensorType::Lambda1); | ||
73 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 4 times.
✗ Decision 'false' not taken.
|
4 | if (lambda1.Valid) { |
74 | 4 | const float afr = lambda1.Value * STOICH_RATIO; | ||
75 | 4 | isVvlAfrCondition = (afr <= static_cast<float>(engineConfiguration->vvlController.maximumAfr)); | ||
76 | } else { | |||
77 | ✗ | isVvlAfrCondition = false; | ||
78 | } | |||
79 | } else { | |||
80 | 42 | isVvlAfrCondition = true; | ||
81 | } | |||
82 | 46 | } | ||
83 | ||||
84 | namespace { | |||
85 | MaxLimitWithHysteresis<UnstrictChecker> rpmHysteresis; | |||
86 | } | |||
87 | ||||
88 | 46 | void VvlController::updateRpmConditionSatisfied() { | ||
89 | 46 | const expected<float> rpmSensorReading = Sensor::get(SensorType::Rpm); | ||
90 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 46 times.
✗ Decision 'false' not taken.
|
46 | if (rpmSensorReading.Valid) { |
91 | 46 | const float rpm = rpmSensorReading.Value; | ||
92 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 7 times.
|
46 | if (rpmHysteresis.checkIfLimitIsExceeded( | |
93 | rpm, | |||
94 | 46 | engineConfiguration->vvlController.deactivationRpm, | ||
95 | 46 | engineConfiguration->vvlController.deactivationRpmWindow | ||
96 | )) { | |||
97 | 39 | isVvlRpmCondition = false; | ||
98 | } else { | |||
99 | 7 | isVvlRpmCondition = (engineConfiguration->vvlController.activationRpm <= rpm); | ||
100 | } | |||
101 | } else { | |||
102 | ✗ | isVvlRpmCondition = false; | ||
103 | } | |||
104 | 46 | } | ||
105 |