| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | ✗ | void TripOdometer::reset() { | ||
| 4 | ✗ | m_consumedGrams = 0; | ||
| 5 | ✗ | m_consumedRemainder = 0; | ||
| 6 | ||||
| 7 | ✗ | m_distanceMeters = 0; | ||
| 8 | ✗ | m_distanceRemainder = 0; | ||
| 9 | ||||
| 10 | ✗ | m_slowCallbackCounter = 0; | ||
| 11 | ✗ | m_engineRunningSeconds = 0; | ||
| 12 | ✗ | m_ignitionOnSeconds = 0; | ||
| 13 | ✗ | } | ||
| 14 | ||||
| 15 | 9304 | void TripOdometer::consumeFuel(float grams, efitick_t nowNt) { | ||
| 16 | // we have some drama with simulator busy loop in reality :( | |||
| 17 | #if EFI_PROD_CODE || EFI_UNIT_TEST | |||
| 18 | 9304 | m_consumedRemainder += grams; | ||
| 19 | ||||
| 20 | // 1000grams of fuel between invocations of TripOdometer logic means something very wrong, we do not control cruise ship engines yet! | |||
| 21 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9304 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 9304 times.
|
9304 | if (m_consumedRemainder > 1000) { |
| 22 | ✗ | firmwareError(ObdCode::OBD_PCM_Processor_Fault, "m_consumedRemainder busy loop %f %f", m_consumedRemainder, grams); | ||
| 23 | ✗ | return; | ||
| 24 | } | |||
| 25 | // A racecar with a very large fuel tank might consume 60kg of fuel on a single run of the ECU | |||
| 26 | // we use integers to gain dynamic range of about 10^9 which is more than float would give us | |||
| 27 | // optimized for lots of small pulses | |||
| 28 |
2/2✓ Branch 0 taken 267 times.
✓ Branch 1 taken 9304 times.
|
2/2✓ Decision 'true' taken 267 times.
✓ Decision 'false' taken 9304 times.
|
9571 | while (m_consumedRemainder >= 1) { |
| 29 | 267 | m_consumedRemainder--; | ||
| 30 | 267 | m_consumedGrams++; | ||
| 31 | } | |||
| 32 | ||||
| 33 | 9304 | float elapsedSecond = m_timer.getElapsedSecondsAndReset(nowNt); | ||
| 34 | ||||
| 35 | // If it's been a long time since last injection, ignore this pulse | |||
| 36 |
2/2✓ Branch 0 taken 266 times.
✓ Branch 1 taken 9038 times.
|
2/2✓ Decision 'true' taken 266 times.
✓ Decision 'false' taken 9038 times.
|
9304 | if (elapsedSecond > 0.2f) { |
| 37 | 266 | m_rate = 0; | ||
| 38 | } else { | |||
| 39 | 9038 | m_rate = grams / elapsedSecond; | ||
| 40 | } | |||
| 41 | #endif // EFI_PROD_CODE || EFI_UNIT_TEST | |||
| 42 | } | |||
| 43 | ||||
| 44 | 531086 | uint32_t TripOdometer::getConsumedGrams() const { | ||
| 45 | 531086 | return m_consumedGrams; | ||
| 46 | } | |||
| 47 | ||||
| 48 | 531078 | float TripOdometer::getConsumptionGramPerSecond() const { | ||
| 49 | 531078 | return m_rate; | ||
| 50 | } | |||
| 51 | ||||
| 52 | 1086 | void TripOdometer::onSlowCallback() { | ||
| 53 | 1086 | float meterPerSecond = Sensor::getOrZero(SensorType::VehicleSpeed) / 3.6f; | ||
| 54 | 1086 | float metersThisTick = meterPerSecond * (SLOW_CALLBACK_PERIOD_MS / 1000.0f); | ||
| 55 | ||||
| 56 | 1086 | m_distanceRemainder += metersThisTick; | ||
| 57 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1086 times.
|
2/2✓ Decision 'true' taken 41 times.
✓ Decision 'false' taken 1086 times.
|
1127 | while (m_distanceRemainder > 1.0f) { |
| 58 | 41 | m_distanceMeters++; | ||
| 59 | 41 | m_distanceRemainder--; | ||
| 60 | } | |||
| 61 | ||||
| 62 | 1086 | constexpr float slowCallbackPerSecond = 1000 / SLOW_CALLBACK_PERIOD_MS; | ||
| 63 | 1086 | m_slowCallbackCounter++; | ||
| 64 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1078 times.
|
2/2✓ Decision 'true' taken 8 times.
✓ Decision 'false' taken 1078 times.
|
1086 | if (m_slowCallbackCounter == slowCallbackPerSecond) { |
| 65 | 8 | m_slowCallbackCounter = 0; | ||
| 66 | ||||
| 67 | 8 | m_ignitionOnSeconds++; | ||
| 68 | ||||
| 69 | #if EFI_SHAFT_POSITION_INPUT | |||
| 70 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 7 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 7 times.
|
8 | if (engine->rpmCalculator.isRunning()) { |
| 71 | 1 | m_engineRunningSeconds++; | ||
| 72 | } | |||
| 73 | #endif // EFI_SHAFT_POSITION_INPUT | |||
| 74 | } | |||
| 75 | 1086 | } | ||
| 76 | ||||
| 77 | 531078 | uint32_t TripOdometer::getDistanceMeters() const { | ||
| 78 | 531078 | return m_distanceMeters; | ||
| 79 | } | |||
| 80 | ||||
| 81 | 531078 | uint32_t TripOdometer::getIgnitionOnTime() const { | ||
| 82 | 531078 | return m_ignitionOnSeconds; | ||
| 83 | } | |||
| 84 | ||||
| 85 | 531078 | uint32_t TripOdometer::getEngineRunTime() const { | ||
| 86 | 531078 | return m_engineRunningSeconds; | ||
| 87 | } | |||
| 88 |