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 | 8526 | 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 | 8526 | 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 8526 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 8526 times.
|
8526 | 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 8526 times.
|
2/2✓ Decision 'true' taken 267 times.
✓ Decision 'false' taken 8526 times.
|
8793 | while (m_consumedRemainder >= 1) { |
29 | 267 | m_consumedRemainder--; | ||
30 | 267 | m_consumedGrams++; | ||
31 | } | |||
32 | ||||
33 | 8526 | 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 265 times.
✓ Branch 1 taken 8261 times.
|
2/2✓ Decision 'true' taken 265 times.
✓ Decision 'false' taken 8261 times.
|
8526 | if (elapsedSecond > 0.2f) { |
37 | 265 | m_rate = 0; | ||
38 | } else { | |||
39 | 8261 | m_rate = grams / elapsedSecond; | ||
40 | } | |||
41 | #endif // EFI_PROD_CODE || EFI_UNIT_TEST | |||
42 | } | |||
43 | ||||
44 | 522962 | uint32_t TripOdometer::getConsumedGrams() const { | ||
45 | 522962 | return m_consumedGrams; | ||
46 | } | |||
47 | ||||
48 | 522954 | float TripOdometer::getConsumptionGramPerSecond() const { | ||
49 | 522954 | return m_rate; | ||
50 | } | |||
51 | ||||
52 | 1085 | void TripOdometer::onSlowCallback() { | ||
53 | 1085 | float meterPerSecond = Sensor::getOrZero(SensorType::VehicleSpeed) / 3.6f; | ||
54 | 1085 | float metersThisTick = meterPerSecond * (SLOW_CALLBACK_PERIOD_MS / 1000.0f); | ||
55 | ||||
56 | 1085 | m_distanceRemainder += metersThisTick; | ||
57 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1085 times.
|
2/2✓ Decision 'true' taken 41 times.
✓ Decision 'false' taken 1085 times.
|
1126 | while (m_distanceRemainder > 1.0f) { |
58 | 41 | m_distanceMeters++; | ||
59 | 41 | m_distanceRemainder--; | ||
60 | } | |||
61 | ||||
62 | 1085 | constexpr float slowCallbackPerSecond = 1000 / SLOW_CALLBACK_PERIOD_MS; | ||
63 | 1085 | m_slowCallbackCounter++; | ||
64 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1077 times.
|
2/2✓ Decision 'true' taken 8 times.
✓ Decision 'false' taken 1077 times.
|
1085 | 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 | 1085 | } | ||
76 | ||||
77 | 522954 | uint32_t TripOdometer::getDistanceMeters() const { | ||
78 | 522954 | return m_distanceMeters; | ||
79 | } | |||
80 | ||||
81 | 522954 | uint32_t TripOdometer::getIgnitionOnTime() const { | ||
82 | 522954 | return m_ignitionOnSeconds; | ||
83 | } | |||
84 | ||||
85 | 522954 | uint32_t TripOdometer::getEngineRunTime() const { | ||
86 | 522954 | return m_engineRunningSeconds; | ||
87 | } | |||
88 |