summaryrefslogtreecommitdiffstats
path: root/control/actions.hpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-06-12 13:39:31 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-06-26 22:23:13 +0000
commit4af419cd334fa1fc182fe0ba608f984d043df5d9 (patch)
treee6be15c48ff0487013344607850c1aa518bb95a4 /control/actions.hpp
parent28c1a09042a5088069ab3fb69f5886554e1f891e (diff)
downloadphosphor-fan-presence-4af419cd334fa1fc182fe0ba608f984d043df5d9.tar.gz
phosphor-fan-presence-4af419cd334fa1fc182fe0ba608f984d043df5d9.zip
Allow floor speed changes based on sensor values
Given a group of sensor values, the average of those sensor values will be used in selecting the floor speed for the zone. Each time the speed is set/updated, any speed requested lower than the current floor will be overwritten with the floor speed to not allow speeds below the floor. Change-Id: I4c8e8a2cd66892b9fdc2bc5643e907adddff51f8 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control/actions.hpp')
-rw-r--r--control/actions.hpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/control/actions.hpp b/control/actions.hpp
index 8a2675b..a99fa97 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
+#include <numeric>
namespace phosphor
{
@@ -50,6 +51,55 @@ auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
};
}
+/**
+ * @brief An action to set the floor speed on a zone
+ * @details Based on the average of the defined sensor group values, the floor
+ * speed is selected from the first map key entry that the average sensor value
+ * is less than.
+ *
+ * @param[in] val_to_speed - Ordered map of sensor value-to-speed
+ *
+ * @return Lambda function
+ * A lambda function to set the zone's floor speed when the average of
+ * property values within the group is below the lowest sensor value given
+ */
+auto set_floor_from_average_sensor_value(
+ std::map<int64_t, uint64_t>&& val_to_speed)
+{
+ return [val_to_speed = std::move(val_to_speed)](auto& zone, auto& group)
+ {
+ auto speed = zone.getDefFloor();
+ if (group.size() != 0)
+ {
+ auto sumValue = std::accumulate(
+ group.begin(),
+ group.end(),
+ 0,
+ [&zone](int64_t sum, auto const& entry)
+ {
+ return sum + zone.template getPropertyValue<int64_t>(
+ entry.first,
+ std::get<intfPos>(entry.second),
+ std::get<propPos>(entry.second));
+ });
+ auto avgValue= sumValue / group.size();
+ auto it = std::find_if(
+ val_to_speed.begin(),
+ val_to_speed.end(),
+ [&avgValue](auto const& entry)
+ {
+ return avgValue < entry.first;
+ }
+ );
+ if (it != std::end(val_to_speed))
+ {
+ speed = (*it).second;
+ }
+ }
+ zone.setFloor(speed);
+ };
+}
+
} // namespace action
} // namespace control
} // namespace fan
OpenPOWER on IntegriCloud