add isRedundant (#2031)
Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
70467a0117
commit
9ccda6bbe7
|
@ -15,6 +15,11 @@ public:
|
||||||
|
|
||||||
SensorResult get() const override;
|
SensorResult get() const override;
|
||||||
|
|
||||||
|
bool isRedundant() const override {
|
||||||
|
// This sensor is redundant when not ignoring the second channel
|
||||||
|
return !m_ignoreSecond;
|
||||||
|
}
|
||||||
|
|
||||||
void showInfo(Logging* logger, const char* sensorName) const override;
|
void showInfo(Logging* logger, const char* sensorName) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -118,14 +118,24 @@ public:
|
||||||
float getRaw() const {
|
float getRaw() const {
|
||||||
const auto sensor = m_sensor;
|
const auto sensor = m_sensor;
|
||||||
|
|
||||||
if (m_sensor) {
|
if (sensor) {
|
||||||
return m_sensor->getRaw();
|
return sensor->getRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We've exhausted all valid ways to return something - sensor not found.
|
// We've exhausted all valid ways to return something - sensor not found.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isRedundant() const {
|
||||||
|
const auto sensor = m_sensor;
|
||||||
|
|
||||||
|
if (sensor) {
|
||||||
|
return sensor->isRedundant();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_useMock = false;
|
bool m_useMock = false;
|
||||||
float m_mockValue;
|
float m_mockValue;
|
||||||
|
@ -181,6 +191,12 @@ bool Sensor::Register() {
|
||||||
return entry ? entry->getRaw() : 0;
|
return entry ? entry->getRaw() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ bool Sensor::isRedundant(SensorType type) {
|
||||||
|
const auto entry = getEntryForType(type);
|
||||||
|
|
||||||
|
return entry ? entry->isRedundant() : false;
|
||||||
|
}
|
||||||
|
|
||||||
/*static*/ bool Sensor::hasSensor(SensorType type) {
|
/*static*/ bool Sensor::hasSensor(SensorType type) {
|
||||||
const auto entry = getEntryForType(type);
|
const auto entry = getEntryForType(type);
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,11 @@ public:
|
||||||
*/
|
*/
|
||||||
static float getRaw(SensorType type);
|
static float getRaw(SensorType type);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get whether a sensor is redundant (a composite of multiple other sensors that can check consistency between them)
|
||||||
|
*/
|
||||||
|
static bool isRedundant(SensorType type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Query whether there is a sensor of a particular type currently registered.
|
* Query whether there is a sensor of a particular type currently registered.
|
||||||
*/
|
*/
|
||||||
|
@ -137,6 +142,14 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get whether this sensor is redundant (backed by multiple other sensors)
|
||||||
|
*/
|
||||||
|
virtual bool isRedundant() const {
|
||||||
|
// By default sensors are not redundant
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Protected constructor - only subclasses call this
|
// Protected constructor - only subclasses call this
|
||||||
explicit Sensor(SensorType type)
|
explicit Sensor(SensorType type)
|
||||||
|
|
|
@ -71,6 +71,8 @@ TEST_F(SensorRedundant, SetTwoSensors)
|
||||||
auto result = dut.get();
|
auto result = dut.get();
|
||||||
EXPECT_TRUE(result.Valid);
|
EXPECT_TRUE(result.Valid);
|
||||||
EXPECT_FLOAT_EQ(result.Value, 25.0f);
|
EXPECT_FLOAT_EQ(result.Value, 25.0f);
|
||||||
|
|
||||||
|
EXPECT_TRUE(dut.isRedundant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +178,8 @@ TEST_F(SensorRedundantIgnoreSecond, OnlyFirst)
|
||||||
auto result = dut.get();
|
auto result = dut.get();
|
||||||
EXPECT_TRUE(result.Valid);
|
EXPECT_TRUE(result.Valid);
|
||||||
EXPECT_FLOAT_EQ(result.Value, 44.0f);
|
EXPECT_FLOAT_EQ(result.Value, 44.0f);
|
||||||
|
|
||||||
|
EXPECT_FALSE(dut.isRedundant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue