control: Add zone setTarget required functions
Copy over the setTarget required functions to the JSON based zone
object. This enables JSON based zone objects to set fan targets based on
actions.
Change-Id: I5be4ad2a6bc85c6a1333d8319fdad0c206b23bb0
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/zone.cpp b/control/json/zone.cpp
index c0ecfe4..5596d09 100644
--- a/control/json/zone.cpp
+++ b/control/json/zone.cpp
@@ -51,7 +51,8 @@
Zone::Zone(sdbusplus::bus::bus& bus, const json& jsonObj) :
ConfigBase(jsonObj),
ThermalObject(bus, (fs::path{CONTROL_OBJPATH} /= getName()).c_str(), true),
- _incDelay(0), _floor(0), _target(0), _incDelta(0), _requestTargetBase(0)
+ _incDelay(0), _floor(0), _target(0), _incDelta(0), _requestTargetBase(0),
+ _isActive(true)
{
if (jsonObj.contains("profiles"))
{
@@ -80,10 +81,37 @@
_fans.emplace_back(std::move(fan));
}
+void Zone::setTarget(uint64_t target)
+{
+ if (_isActive)
+ {
+ _target = target;
+ for (auto& fan : _fans)
+ {
+ fan->setTarget(_target);
+ }
+ }
+}
+
+void Zone::setActiveAllow(const std::string& ident, bool isActiveAllow)
+{
+ _active[ident] = isActiveAllow;
+ if (!isActiveAllow)
+ {
+ _isActive = false;
+ }
+ else
+ {
+ // Check all entries are set to allow active fan control
+ auto actPred = [](const auto& entry) { return entry.second; };
+ _isActive = std::all_of(_active.begin(), _active.end(), actPred);
+ }
+}
+
void Zone::setFloor(uint64_t target)
{
// Check all entries are set to allow floor to be set
- auto pred = [](auto const& entry) { return entry.second; };
+ auto pred = [](const auto& entry) { return entry.second; };
if (std::all_of(_floorChange.begin(), _floorChange.end(), pred))
{
_floor = target;
@@ -109,9 +137,8 @@
{
requestTarget = _ceiling;
}
- // TODO Set target and handle increase timer
- // setTarget(requestTarget);
- // // Restart timer countdown for fan speed increase
+ setTarget(requestTarget);
+ // TODO // Restart timer countdown for fan speed increase
// _incTimer.restartOnce(_incDelay);
}
}
diff --git a/control/json/zone.hpp b/control/json/zone.hpp
index 45dea20..56fb855 100644
--- a/control/json/zone.hpp
+++ b/control/json/zone.hpp
@@ -147,6 +147,21 @@
void addFan(std::unique_ptr<Fan> fan);
/**
+ * Sets all fans in the zone to the target given when the zone is active
+ *
+ * @param[in] target - Target for fans
+ */
+ void setTarget(uint64_t target);
+
+ /**
+ * @brief Sets the automatic fan control allowed active state
+ *
+ * @param[in] ident - An identifier that affects the active state
+ * @param[in] isActiveAllow - Active state according to group
+ */
+ void setActiveAllow(const std::string& ident, bool isActiveAllow);
+
+ /**
* @brief Set the floor to the given target and increase target to the floor
* when the target is below the floor value when floor changes are allowed.
*
@@ -276,6 +291,12 @@
/* Map of interfaces to persisted properties the zone hosts*/
std::map<std::string, std::vector<std::string>> _propsPersisted;
+ /* Automatic fan control active state */
+ bool _isActive;
+
+ /* Map of active fan control allowed by a string identifier */
+ std::map<std::string, bool> _active;
+
/* Interface to property mapping of their associated set property handler
* function */
static const std::map<