GCC Code Coverage Report


Directory: ./
File: firmware/controllers/sensors/redundant_ford_tps.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 95.7% 22 0 23
Functions: 100.0% 3 0 3
Branches: 83.3% 15 0 18
Decisions: 87.5% 7 - 8

Line Branch Decision Exec Source
1 #include "pch.h"
2
3 #include "redundant_ford_tps.h"
4
5 10 RedundantFordTps::RedundantFordTps(SensorType outputType, SensorType first, SensorType second)
6 : Sensor(outputType)
7 10 , m_first(first)
8 10 , m_second(second)
9 {
10 10 }
11
12 11 void RedundantFordTps::configure(float maxDifference, float secondaryMaximum) {
13 11 m_maxDifference = maxDifference;
14 11 m_secondaryMaximum = secondaryMaximum;
15 11 }
16
17 9 SensorResult RedundantFordTps::get() const {
18 // Sensor 1 is "plain linear" and has the full range
19
1/1
✓ Branch 2 taken 9 times.
9 auto tps1 = Sensor::get(m_first);
20
21 // Sensor 2 is compressed in to 0 -> 50%
22
1/1
✓ Branch 2 taken 9 times.
9 auto tps2 = Sensor::get(m_second);
23
24 // If either result is invalid, return invalid.
25
6/6
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
2/2
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 6 times.
9 if (!tps1 || !tps2) {
26 3 return UnexpectedCode::Inconsistent;
27 }
28
29 // The "actual" position resolved by the second throttle - this tops out at m_secondaryMaximum instead of 100%
30 6 float tps2Actual = tps2.Value * m_secondaryMaximum / 100;
31
32 // Switch modes slightly below the maximum of the secondary, to avoid misbehavior near 100%
33 6 float avgThreshold = m_secondaryMaximum * 0.9f;
34
35 // Case 1: both sensors show low position, average result
36
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
2/2
✓ Decision 'true' taken 5 times.
✓ Decision 'false' taken 1 time.
6 if (tps1.Value < avgThreshold && tps2Actual < avgThreshold) {
37 // Check that the resolved positions are close
38 5 float delta = absF(tps1.Value - tps2Actual);
39
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 3 times.
5 if (delta > m_maxDifference) {
40 2 return UnexpectedCode::Inconsistent;
41 }
42
43 3 return (tps1.Value + tps2Actual) / 2;
44 }
45
46 // Case 2: both sensors show high position, return "full scale" sensor's position
47
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1/2
✓ Decision 'true' taken 1 time.
✗ Decision 'false' not taken.
1 if (tps1.Value > avgThreshold && tps2Actual > (avgThreshold - 3)) {
48 1 return tps1;
49 }
50
51 // Any other condition indicates an mismatch, and therefore an error
52 return UnexpectedCode::Inconsistent;
53 }
54