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 <msbarth@us.ibm.com>
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 @@
}
}
- 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 @@
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<level::INFO>("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 @@
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<level::INFO>("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<level::ERR>("Setting a fan to nonfunctional",