From a4c8f1f5143573c267dd9b0391daa47345276632 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Thu, 27 Apr 2017 14:38:38 -0500 Subject: Add timer start/stop support In Fan's tachChanged handler, start up the timer for a sensor if it is running too slow. If it is within spec, stop the timer if running and make the sensor functional again if necessary. Change-Id: Ib18de2b69942d334da0cb8cd4cc4de8a2784efab Signed-off-by: Matt Spinler --- monitor/fan.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'monitor/fan.cpp') diff --git a/monitor/fan.cpp b/monitor/fan.cpp index 7d657a0..d1101b9 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -26,6 +26,7 @@ namespace monitor { using namespace phosphor::logging; +using TimerType = phosphor::fan::util::Timer::TimerType; Fan::Fan(sdbusplus::bus::bus& bus, std::shared_ptr& events, @@ -47,6 +48,10 @@ Fan::Fan(sdbusplus::bus::bus& bus, std::get(def), events)); } + + //The TachSensors will now have already read the input + //and target values, so check them. + tachChanged(); } @@ -61,7 +66,44 @@ void Fan::tachChanged() void Fan::tachChanged(TachSensor& sensor) { - //TODO + auto& timer = sensor.getTimer(); + auto running = timer.running(); + + //If this sensor is out of range at this moment, start + //its timer, at the end of which the inventory + //for the fan may get updated to not functional. + + //If this sensor is OK, put everything back into a good state. + + if (outOfRange(sensor)) + { + if (sensor.functional() && !running) + { + timer.start(sensor.getTimeout(), TimerType::oneshot); + } + } + else + { + if (!sensor.functional()) + { + sensor.setFunctional(true); + } + + if (running) + { + timer.stop(); + } + + //If the fan was nonfunctional and enough sensors are now OK, + //the fan can go back to functional + if (!_functional && !tooManySensorsNonfunctional()) + { + log("Setting a fan back to functional", + entry("FAN=%s", _name.c_str())); + + //TODO: actually update inventory + } + } } -- cgit v1.2.1