Process speed increase requests

Speed increases are made providing a target speed delta. The increase is
made when the delta is higher than the current increase that may be
occurring. When no increase is currently happening, the increase delta
requested is accepted. All resulting target increases will not go above
a defined ceiling speed.

Change-Id: Ia19c71a023cf5b897d5ba92974ff98451f34d5a3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.hpp b/control/actions.hpp
index 60b5484..d4dedba 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -250,7 +250,8 @@
                 }
             }
         );
-        // TODO Do a request speed change for target speed update
+        // Request speed change for target speed update
+        zone.requestSpeedIncrease(netDelta);
     };
 }
 
diff --git a/control/zone.cpp b/control/zone.cpp
index d569aa8..5ed0c3a 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -110,11 +110,6 @@
         {
             speed = _floorSpeed;
         }
-        //TODO openbmc/openbmc#1626 Move to control algorithm function
-        if (speed > _ceilingSpeed)
-        {
-            speed = _ceilingSpeed;
-        }
         fan->setSpeed(speed);
     }
 }
@@ -136,6 +131,34 @@
     }
 }
 
+void Zone::requestSpeedIncrease(uint64_t targetDelta)
+{
+    // Only increase speed when delta is higher than
+    // the current increase delta for the zone and currently under ceiling
+    if (targetDelta > _incSpeedDelta &&
+        _targetSpeed < _ceilingSpeed)
+    {
+        _targetSpeed = (targetDelta - _incSpeedDelta) + _targetSpeed;
+        _incSpeedDelta = targetDelta;
+        //TODO openbmc/openbmc#1625 Cancel current timer countdown
+        //TODO Floor speed above target, update target to floor speed
+        if (_targetSpeed < _floorSpeed)
+        {
+            _targetSpeed = _floorSpeed;
+        }
+        // Target speed can not go above a defined ceiling speed
+        if (_targetSpeed > _ceilingSpeed)
+        {
+            _targetSpeed = _ceilingSpeed;
+        }
+
+        setSpeed(_targetSpeed);
+        //TODO openbmc/openbmc#1625 Start timer countdown for fan speed increase
+    }
+    //TODO openbmc/openbmc#1625 Clear increase delta when timer expires
+    _incSpeedDelta = 0;
+}
+
 void Zone::getProperty(sdbusplus::bus::bus& bus,
                        const std::string& path,
                        const std::string& iface,
diff --git a/control/zone.hpp b/control/zone.hpp
index 20b9ac9..cc05959 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -178,6 +178,14 @@
             return _incSpeedDelta;
         };
 
+        /**
+         * @brief Calculate the requested target speed from the given delta
+         * and increase the fan speeds, not going above the ceiling.
+         *
+         * @param[in] targetDelta - The delta to increase the target speed by
+         */
+        void requestSpeedIncrease(uint64_t targetDelta);
+
     private:
 
         /**
@@ -226,6 +234,11 @@
         bool _isActive = true;
 
         /**
+         * Target speed for this zone
+         */
+        uint64_t _targetSpeed = _fullSpeed;
+
+        /**
          * Speed increase delta
          */
         uint64_t _incSpeedDelta = 0;