diff options
author | Matt Spinler <spinler@us.ibm.com> | 2017-04-27 14:38:38 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2017-05-11 13:52:50 -0500 |
commit | a4c8f1f5143573c267dd9b0391daa47345276632 (patch) | |
tree | 7399a2ecd87aa30a59172bdd56fee882d709d9f8 /monitor/fan.cpp | |
parent | c36168a1a58a26eaade4ca53d68c49cc98303904 (diff) | |
download | phosphor-fan-presence-a4c8f1f5143573c267dd9b0391daa47345276632.tar.gz phosphor-fan-presence-a4c8f1f5143573c267dd9b0391daa47345276632.zip |
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 <spinler@us.ibm.com>
Diffstat (limited to 'monitor/fan.cpp')
-rw-r--r-- | monitor/fan.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
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<sd_event>& events, @@ -47,6 +48,10 @@ Fan::Fan(sdbusplus::bus::bus& bus, std::get<timeoutField>(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<level::INFO>("Setting a fan back to functional", + entry("FAN=%s", _name.c_str())); + + //TODO: actually update inventory + } + } } |