| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "fan_control.h" | |||
| 4 | ||||
| 5 | #include "bench_test.h" | |||
| 6 | ||||
| 7 | 2086 | PUBLIC_API_WEAK bool fansDisabledByBoardStatus() { | ||
| 8 | 2086 | return false; | ||
| 9 | } | |||
| 10 | ||||
| 11 | 2186 | PUBLIC_API_WEAK bool fansEnabledByBoardStatus() { | ||
| 12 | 2186 | return false; | ||
| 13 | } | |||
| 14 | ||||
| 15 | 2186 | bool FanController::getState(bool acActive, bool lastState) { | ||
| 16 |
1/1✓ Branch 2 taken 2186 times.
|
2186 | auto clt = Sensor::get(SensorType::Clt); | |
| 17 |
1/1✓ Branch 1 taken 2186 times.
|
2186 | auto vss = Sensor::get(SensorType::VehicleSpeed); | |
| 18 | ||||
| 19 | #if EFI_SHAFT_POSITION_INPUT | |||
| 20 |
1/1✓ Branch 1 taken 2186 times.
|
2186 | cranking = engine->rpmCalculator.isCranking(); | |
| 21 |
1/1✓ Branch 1 taken 2186 times.
|
2186 | notRunning = !engine->rpmCalculator.isRunning(); | |
| 22 | #else | |||
| 23 | cranking = false; | |||
| 24 | notRunning = true; | |||
| 25 | #endif | |||
| 26 | ||||
| 27 |
2/8✓ Branch 1 taken 2186 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2186 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2186 | disabledBySpeed = disableAtSpeed() > 0 && vss.Valid && vss.Value > disableAtSpeed(); | |
| 28 |
5/5✓ Branch 0 taken 2137 times.
✓ Branch 1 taken 49 times.
✓ Branch 3 taken 2137 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 2136 times.
|
2186 | disabledWhileEngineStopped = notRunning && disableWhenStopped(); | |
| 29 | 2186 | brokenClt = !clt; | ||
| 30 |
5/5✓ Branch 1 taken 2186 times.
✓ Branch 3 taken 195 times.
✓ Branch 4 taken 1991 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 194 times.
|
2186 | enabledForAc = enableWithAc() && acActive; | |
| 31 |
1/1✓ Branch 2 taken 2186 times.
|
2186 | hot = clt.value_or(0) > getFanOnTemp(); | |
| 32 |
1/1✓ Branch 2 taken 2186 times.
|
2186 | cold = clt.value_or(0) < getFanOffTemp(); | |
| 33 | ||||
| 34 |
2/3✓ Branch 1 taken 2186 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2186 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 2186 times.
|
2186 | if (fansEnabledByBoardStatus()) { |
| 35 | ✗ | radiatorFanStatus = (int)RadiatorFanState::BoardForcedOn; | ||
| 36 | ✗ | return true; | ||
| 37 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 2087 times.
|
2/2✓ Decision 'true' taken 99 times.
✓ Decision 'false' taken 2087 times.
|
2186 | } else if (cranking) { |
| 38 | // Inhibit while cranking | |||
| 39 | 99 | radiatorFanStatus = (int)RadiatorFanState::Cranking; | ||
| 40 | 99 | return false; | ||
| 41 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2086 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 2086 times.
|
2087 | } else if (disabledWhileEngineStopped) { |
| 42 | // Inhibit while not running (if so configured) | |||
| 43 | 1 | radiatorFanStatus = (int)RadiatorFanState::EngineStopped; | ||
| 44 | 1 | return false; | ||
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2086 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 2086 times.
|
2086 | } else if (disabledBySpeed) { |
| 46 | // Inhibit while driving fast | |||
| 47 | ✗ | radiatorFanStatus = (int)RadiatorFanState::VehicleIsTooFast; | ||
| 48 | ✗ | return false; | ||
| 49 |
2/3✓ Branch 1 taken 2086 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2086 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 2086 times.
|
2086 | } else if (fansDisabledByBoardStatus()) { |
| 50 | ✗ | radiatorFanStatus = (int)RadiatorFanState::BoardStatus; | ||
| 51 | ✗ | return false; | ||
| 52 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2075 times.
|
2/2✓ Decision 'true' taken 11 times.
✓ Decision 'false' taken 2075 times.
|
2086 | } else if (brokenClt) { |
| 53 | // If CLT is broken, turn the fan on | |||
| 54 | 11 | radiatorFanStatus = (int)RadiatorFanState::CltBroken; | ||
| 55 | 11 | return true; | ||
| 56 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2074 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 2074 times.
|
2075 | } else if (enabledForAc) { |
| 57 | 1 | radiatorFanStatus = (int)RadiatorFanState::AC; | ||
| 58 | 1 | return true; | ||
| 59 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2070 times.
|
2/2✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 2070 times.
|
2074 | } else if (hot) { |
| 60 | 4 | radiatorFanStatus = (int)RadiatorFanState::Hot; | ||
| 61 | 4 | return true; | ||
| 62 |
2/2✓ Branch 0 taken 2068 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 2068 times.
✓ Decision 'false' taken 2 times.
|
2070 | } else if (cold) { |
| 63 | 2068 | radiatorFanStatus = (int)RadiatorFanState::Cold; | ||
| 64 | 2068 | return false; | ||
| 65 | } else { | |||
| 66 | 2 | radiatorFanStatus = (int)RadiatorFanState::Previous; | ||
| 67 | // no condition met, maintain previous state | |||
| 68 | 2 | return lastState; | ||
| 69 | } | |||
| 70 | } | |||
| 71 | ||||
| 72 | 2186 | void FanController::onSlowCallback() { | ||
| 73 | #if EFI_PROD_CODE | |||
| 74 | if (isRunningBenchTest()) { | |||
| 75 | radiatorFanStatus = (int)RadiatorFanState::Bench; | |||
| 76 | return; // let's not mess with bench testing | |||
| 77 | } | |||
| 78 | #endif | |||
| 79 | ||||
| 80 | 2186 | bool acActive = engine->module<AcController>()->isAcEnabled(); | ||
| 81 | ||||
| 82 | 2186 | auto& pin = getPin(); | ||
| 83 | ||||
| 84 | 2186 | bool result = getState(acActive, pin.getLogicValue()); | ||
| 85 | ||||
| 86 | 2186 | m_state = result; | ||
| 87 | ||||
| 88 | 2186 | pin.setValue(result); | ||
| 89 | 2186 | } | ||
| 90 | ||||
| 91 | 1174 | void FanController::setDefaultConfiguration() { | ||
| 92 | 1174 | engineConfiguration->fanOnTemperature = 92; | ||
| 93 | 1174 | engineConfiguration->fanOffTemperature = 88; | ||
| 94 | 1174 | engineConfiguration->fan2OnTemperature = 95; | ||
| 95 | 1174 | engineConfiguration->fan2OffTemperature = 91; | ||
| 96 | 1174 | } | ||
| 97 |