From 98726c4585d6743c0948ed0140835e438de1df79 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 17 Oct 2017 10:35:20 -0500 Subject: Set floor to default on missing owner action An action to set the fan floor speed to the defined default fan floor speed when any services associated to a given group of sensors have terminated. Once those services are functional and providing the sensors, the fan floor is allowed to be set normally again. i.e.) For fan floor speeds based on an ambient sensor, if the service providing the ambient temperature value from the sensor terminates, the default floor for the zone is used as the fan floor speed. Change-Id: I2d58cc9b31051e6b8e5e798c0a736f58f5efe5b1 Signed-off-by: Matthew Barth --- control/actions.cpp | 18 ++++++++++++++++++ control/actions.hpp | 12 ++++++++++++ control/zone.cpp | 16 ++++++++++++---- control/zone.hpp | 19 ++++++++++++++++++- 4 files changed, 60 insertions(+), 5 deletions(-) (limited to 'control') diff --git a/control/actions.cpp b/control/actions.cpp index b1eb9be..6eda2a6 100644 --- a/control/actions.cpp +++ b/control/actions.cpp @@ -81,6 +81,24 @@ Action call_actions_based_on_timer(Timer&& tConf, std::vector&& actions) }; } +void default_floor_on_missing_owner(Zone& zone, const Group& group) +{ + auto services = zone.getGroupServices(&group); + auto defFloor = std::any_of( + services.begin(), + services.end(), + [](const auto& s) + { + return !std::get(s); + }); + if (defFloor) + { + zone.setFloor(zone.getDefFloor()); + } + // Update fan control floor change allowed + zone.setFloorChangeAllow(&group, !defFloor); +} + void set_request_speed_base_with_max(control::Zone& zone, const Group& group) { diff --git a/control/actions.hpp b/control/actions.hpp index fff8250..4d2c5c3 100644 --- a/control/actions.hpp +++ b/control/actions.hpp @@ -29,6 +29,18 @@ Action call_actions_based_on_timer( Timer&& tConf, std::vector&& actions); +/** + * @brief An action that sets the floor to the default fan floor speed + * @details Sets the fan floor to the defined default fan floor speed when a + * service associated to the given group has terminated. Once all services + * are functional and providing the sensors again, the fan floor is allowed + * to be set normally. + * + * @param[in] zone - Zone containing fans + * @param[in] group - Group of sensors to determine services' states + */ +void default_floor_on_missing_owner(Zone& zone, const Group& group); + /** * @brief An action to set the request speed base * @details A new target speed is determined using a speed delta being added diff --git a/control/zone.cpp b/control/zone.cpp index 018f594..418b3ba 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -147,11 +147,19 @@ void Zone::setServiceOwner(const Group* group, void Zone::setFloor(uint64_t speed) { - _floorSpeed = speed; - // Floor speed above target, update target to floor speed - if (_targetSpeed < _floorSpeed) + // Check all entries are set to allow floor to be set + auto pred = [](auto const& entry) {return entry.second;}; + auto setFloor = std::all_of(_floorChange.begin(), + _floorChange.end(), + pred); + if (setFloor) { - requestSpeedIncrease(_floorSpeed - _targetSpeed); + _floorSpeed = speed; + // Floor speed above target, update target to floor speed + if (_targetSpeed < _floorSpeed) + { + requestSpeedIncrease(_floorSpeed - _targetSpeed); + } } } diff --git a/control/zone.hpp b/control/zone.hpp index 1fdeaf2..fa3ed82 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -77,6 +77,17 @@ class Zone */ void setActiveAllow(const Group* group, bool isActiveAllow); + /** + * @brief Sets the floor change allowed state + * + * @param[in] group - A group that affects floor changes + * @param[in] isAllow - Allow state according to group + */ + inline void setFloorChangeAllow(const Group* group, bool isAllow) + { + _floorChange[*(group)] = isAllow; + } + /** * @brief Sets a given object's property value * @@ -231,7 +242,8 @@ class Zone /** * @brief Set the floor speed to the given speed and increase target - * speed to the floor when target is below floor. + * speed to the floor when target is below floor where floor changes + * are allowed. * * @param[in] speed - Speed to set the floor to */ @@ -453,6 +465,11 @@ class Zone */ std::map _active; + /** + * @brief Map of floor change allowed by groups + */ + std::map _floorChange; + /** * @brief Map of group service names */ -- cgit v1.2.1