From e11cbc605e79bbf6b2651c30ef8f64a9ae4167b0 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 20 Feb 2018 12:11:07 -0600 Subject: Handle timer expiration on state changes Update to start all tach sensor functional state change timers on a fan where the corresponding state and inventory is updated when the timer expires. Only start the timer in nonfunctional mode when a tach sensor is out of range and is currently functional and start the functional mode timer when its in range and currently nonfunctional. Tested: Tach sensors are marked nonfunctional as normal. Tach sensors are updated to functional after 5sec(yaml test value) Nonfunctional timer is cancelled if fan returns within spec Functional timer is cancelled if fan returns out of spec Change-Id: I88622d07d8713f88e8070940a4bd96046a053fb5 Signed-off-by: Matthew Barth --- monitor/fan.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/monitor/fan.cpp b/monitor/fan.cpp index 96db76c..39b32bb 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -100,8 +100,6 @@ void Fan::tachChanged(TachSensor& sensor) } } - auto running = sensor.timerRunning(); - //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. @@ -110,31 +108,22 @@ void Fan::tachChanged(TachSensor& sensor) if (outOfRange(sensor)) { - if (sensor.functional() && !running) + if (sensor.functional()) { + // Start nonfunctional timer if not already running sensor.startTimer(TimerMode::nonfunc); } } else { - if (!sensor.functional()) - { - sensor.setFunctional(true); - } - - if (running) + if (sensor.functional()) { sensor.stopTimer(); } - - //If the fan was nonfunctional and enough sensors are now OK, - //the fan can go back to functional - if (!_functional && !tooManySensorsNonfunctional()) + else { - log("Setting a fan back to functional", - entry("FAN=%s", _name.c_str())); - - updateInventory(true); + // Start functional timer if not already running + sensor.startTimer(TimerMode::func); } } } @@ -198,12 +187,21 @@ bool Fan::outOfRange(const TachSensor& sensor) void Fan::timerExpired(TachSensor& sensor) { - sensor.setFunctional(false); + sensor.setFunctional(!sensor.functional()); + + //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())); + + updateInventory(true); + } //If the fan is currently functional, but too many //contained sensors are now nonfunctional, update //the whole fan nonfunctional. - if (_functional && tooManySensorsNonfunctional()) { log("Setting a fan to nonfunctional", -- cgit v1.2.1