Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | #include "pch.h" | |||
2 | ||||
3 | #include "redundant_sensor.h" | |||
4 | ||||
5 | 14 | RedundantSensor::RedundantSensor(SensorType outputType, SensorType first, SensorType second) | ||
6 | : Sensor(outputType) | |||
7 | 14 | , m_first(first) | ||
8 | 14 | , m_second(second) | ||
9 | { | |||
10 | 14 | } | ||
11 | ||||
12 | 29 | void RedundantSensor::configure(float /*split threshold*/maxDifference, bool ignoreSecondSensor) { | ||
13 | 29 | m_maxDifference = maxDifference; | ||
14 | 29 | m_ignoreSecond = ignoreSecondSensor; | ||
15 | 29 | } | ||
16 | ||||
17 | 222 | SensorResult RedundantSensor::get() const { | ||
18 |
1/1✓ Branch 2 taken 222 times.
|
222 | auto sensor1 = Sensor::get(m_first); | |
19 | ||||
20 | // If we're set to disable redundancy, just pass thru the first sensor | |||
21 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 214 times.
|
2/2✓ Decision 'true' taken 8 times.
✓ Decision 'false' taken 214 times.
|
222 | if (m_ignoreSecond) { |
22 | 8 | return sensor1; | ||
23 | } | |||
24 | ||||
25 |
1/1✓ Branch 1 taken 214 times.
|
214 | auto sensor2 = Sensor::get(m_second); | |
26 | ||||
27 | // If either result is invalid, return invalid. | |||
28 |
4/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 206 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
|
2/2✓ Decision 'true' taken 208 times.
✓ Decision 'false' taken 6 times.
|
214 | if (!sensor1.Valid || !sensor2.Valid) { |
29 | 208 | return UnexpectedCode::Inconsistent; | ||
30 | } | |||
31 | ||||
32 | // If both are valid, check that they're near one another | |||
33 | 6 | float delta = absF(sensor1.Value - sensor2.Value); | ||
34 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
2/2✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 4 times.
|
6 | if (delta > m_maxDifference) { |
35 | 2 | return UnexpectedCode::Inconsistent; | ||
36 | } | |||
37 | ||||
38 | // Both sensors are valid, and their readings are close. All is well. | |||
39 | // Return the average | |||
40 | 4 | return (sensor1.Value + sensor2.Value) / 2; | ||
41 | } | |||
42 |