All sensors should return a target speed value
All tach sensors associated with a fan should return a target speed
sensor from its getTarget function. In the case where a target speed
sensor does not exist for the tach sensor, it retrieves and returns the
target speed value from the fan where the fan finds the target speed
value from a tach sensor the fan contains that provides it.
Resolves openbmc/openbmc#2784
Change-Id: Iea5561b0aad6942be52af262c7255c60e5e75c7a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index a6af74a..f24312d 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -134,34 +134,32 @@
}
-uint64_t Fan::getTargetSpeed(const TachSensor& sensor)
+uint64_t Fan::findTargetSpeed()
{
uint64_t target = 0;
+ //The sensor doesn't support a target,
+ //so get it from another sensor.
+ auto s = std::find_if(_sensors.begin(), _sensors.end(),
+ [](const auto& s)
+ {
+ return s->hasTarget();
+ });
- if (sensor.hasTarget())
+ if (s != _sensors.end())
{
- target = sensor.getTarget();
- }
- else
- {
- //The sensor doesn't support a target,
- //so get it from another sensor.
- auto s = std::find_if(_sensors.begin(), _sensors.end(),
- [](const auto& s)
- {
- return s->hasTarget();
- });
-
- if (s != _sensors.end())
- {
- target = (*s)->getTarget();
- }
+ target = (*s)->getTarget();
}
return target;
}
+uint64_t Fan::getTargetSpeed(const TachSensor& sensor)
+{
+ return sensor.getTarget();
+}
+
+
bool Fan::tooManySensorsNonfunctional()
{
size_t numFailed = std::count_if(_sensors.begin(), _sensors.end(),