Add increase & decrease timer values in seconds

Support setting the increase delay time(in seconds) for each zone from
the zone yaml file. Speed increases use a delay type timer where the
amount of time given delays additional increase requests from happening
until the fans within the zone reach the highest net increase in speeds.

Support setting the decrease interval time(in seconds) for each zone
from the zone yaml file. Since decreasing is done on an interval, a
decrease interval time of zero disables the decrease interval timer
causing no decreases in speed to occur. Speed decreases use an interval
type timer to decrease the fan speeds within the zone when no speed
increase requests exist on the given time interval.

Change-Id: I88334a313b6e2820b768fa7e3f1cb65887f29258
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
index adef86a..177bfe0 100755
--- a/control/gen-fan-zone-defs.py
+++ b/control/gen-fan-zone-defs.py
@@ -50,6 +50,8 @@
                 ${zone['num']},
                 ${zone['full_speed']},
                 ${zone['default_floor']},
+                ${zone['increase_delay']},
+                ${zone['decrease_interval']},
                 std::vector<FanDefinition>{
                 %for fan in zone['fans']:
                     FanDefinition{
@@ -311,6 +313,14 @@
 
             zone['default_floor'] = z['default_floor']
 
+            # 'increase_delay' is optional (use 0 by default)
+            key = 'increase_delay'
+            zone[key] = z.setdefault(key, 0)
+
+            # 'decrease_interval' is optional (use 0 by default)
+            key = 'decrease_interval'
+            zone[key] = z.setdefault(key, 0)
+
             # 'cooling_profiles' is optional (use 'all' instead)
             if ('cooling_profiles' not in z) or \
                     (z['cooling_profiles'] is None):
diff --git a/control/types.hpp b/control/types.hpp
index 6e99950..b6a031f 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -59,11 +59,15 @@
 constexpr auto zoneNumPos = 0;
 constexpr auto fullSpeedPos = 1;
 constexpr auto floorSpeedPos = 2;
-constexpr auto fanListPos = 3;
-constexpr auto setSpeedEventsPos = 4;
+constexpr auto incDelayPos = 3;
+constexpr auto decIntervalPos = 4;
+constexpr auto fanListPos = 5;
+constexpr auto setSpeedEventsPos = 6;
 using ZoneDefinition = std::tuple<size_t,
                                   uint64_t,
                                   uint64_t,
+                                  size_t,
+                                  size_t,
                                   std::vector<FanDefinition>,
                                   std::vector<SetSpeedEvent>>;
 
diff --git a/control/zone.cpp b/control/zone.cpp
index 8f11393..93a616a 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -42,6 +42,8 @@
     _zoneNum(std::get<zoneNumPos>(def)),
     _defFloorSpeed(std::get<floorSpeedPos>(def)),
     _defCeilingSpeed(std::get<fullSpeedPos>(def)),
+    _incDelay(std::get<incDelayPos>(def)),
+    _decInterval(std::get<decIntervalPos>(def)),
     _incTimer(events, [this](){ this->incTimerExpired(); }),
     _decTimer(events, [this](){ this->decTimerExpired(); })
 {
@@ -57,10 +59,9 @@
     {
         initEvents(def);
         // Start timer for fan speed decreases
-        if (!_decTimer.running())
+        if (!_decTimer.running() && _decInterval != seconds::zero())
         {
-            //TODO Update time value to what's given in zones yaml
-            _decTimer.start(seconds(30),
+            _decTimer.start(_decInterval,
                             phosphor::fan::util::Timer::TimerType::repeating);
         }
     }
@@ -123,8 +124,7 @@
         }
         setSpeed(_targetSpeed);
         // Start timer countdown for fan speed increase
-        //TODO Update time value to what's given in zones yaml
-        _incTimer.start(seconds(5),
+        _incTimer.start(_incDelay,
                         phosphor::fan::util::Timer::TimerType::oneshot);
     }
 }
diff --git a/control/zone.hpp b/control/zone.hpp
index 9786db4..706d9c2 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -1,4 +1,5 @@
 #pragma once
+#include <chrono>
 #include <vector>
 #include <algorithm>
 #include <sdbusplus/bus.hpp>
@@ -280,6 +281,16 @@
         uint64_t _decSpeedDelta = 0;
 
         /**
+         * Speed increase delay in seconds
+         */
+        std::chrono::seconds _incDelay;
+
+        /**
+         * Speed decrease interval in seconds
+         */
+        std::chrono::seconds _decInterval;
+
+        /**
          * The increase timer object
          */
         phosphor::fan::util::Timer _incTimer;