From 246235237c92bd6a55487bdd9fdc6b4b11466a7e Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 21 Jun 2017 14:09:57 -0500 Subject: Add zone net increase set speed action The net increase speed action provides the ability to determine what the net delta the zone's fan speeds should be updated by from their current target speed. Change-Id: Ib463e5ed4836bebf906cea27ea5788d826ec9c38 Signed-off-by: Matthew Barth --- control/actions.hpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ control/zone.hpp | 15 +++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/control/actions.hpp b/control/actions.hpp index 4393c4d..60b5484 100644 --- a/control/actions.hpp +++ b/control/actions.hpp @@ -209,6 +209,51 @@ auto set_ceiling_from_average_sensor_value( }; } +/** + * @brief An action to set the speed increase delta and request speed change + * @details Provides the ability to determine what the net increase delta the + * zone's fan speeds should be updated by from their current target speed and + * request that new target speed. + * + * @param[in] state - State to compare the group's property value to + * @param[in] speedDelta - Speed delta of the group + * + * @return Lambda function + * A lambda function that determines the net increase delta and requests + * a new target speed with that increase for the zone. + */ +template +auto set_net_increase_speed(T&& state, uint64_t speedDelta) +{ + return [speedDelta, + state = std::forward(state)](auto& zone, auto& group) + { + auto netDelta = zone.getIncSpeedDelta(); + std::for_each( + group.begin(), + group.end(), + [&zone, &state, &speedDelta, &netDelta](auto const& entry) + { + T value = zone.template getPropertyValue( + entry.first, + std::get(entry.second), + std::get(entry.second)); + // TODO openbmc/phosphor-fan-presence#7 - Support possible + // state types for comparison + if (value >= state) + { + // Increase by at least a single delta + // to attempt bringing under 'state' + auto delta = std::max((value - state), 1); + // Increase is the difference times the given speed delta + netDelta = std::max(netDelta, delta * speedDelta); + } + } + ); + // TODO Do a request speed change for target speed update + }; +} + } // namespace action } // namespace control } // namespace fan diff --git a/control/zone.hpp b/control/zone.hpp index fef3734..20b9ac9 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -168,6 +168,16 @@ class Zone return keyValue; }; + /** + * @brief Get the increase speed delta + * + * @return - The current increase speed delta + */ + inline auto& getIncSpeedDelta() const + { + return _incSpeedDelta; + }; + private: /** @@ -215,6 +225,11 @@ class Zone */ bool _isActive = true; + /** + * Speed increase delta + */ + uint64_t _incSpeedDelta = 0; + /** * The vector of fans in this zone */ -- cgit v1.2.1