Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 5 second delay before changing floors due to nonfunctional sensors #32

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions control/config_files/p10bmc/ibm,everest/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@
"name": "count_state_floor",
"count": 1,
"state": false,
"delay": 5,
"floor": 11300
}
]
Expand Down
1 change: 1 addition & 0 deletions control/config_files/p10bmc/ibm,rainier-1s4u/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"name": "count_state_floor",
"count": 1,
"state": false,
"delay": 5,
"floor": 10400
}
]
Expand Down
1 change: 1 addition & 0 deletions control/config_files/p10bmc/ibm,rainier-2u/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@
"name": "count_state_floor",
"count": 1,
"state": false,
"delay": 5,
"floor": 18000
}
]
Expand Down
1 change: 1 addition & 0 deletions control/config_files/p10bmc/ibm,rainier-4u/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
"name": "count_state_floor",
"count": 1,
"state": false,
"delay": 5,
"floor": 10400
}
]
Expand Down
76 changes: 66 additions & 10 deletions control/json/actions/count_state_floor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../zone.hpp"
#include "action.hpp"
#include "group.hpp"
#include "sdeventplus.hpp"

namespace phosphor::fan::control::json
{
Expand All @@ -30,11 +31,63 @@ CountStateFloor::CountStateFloor(const json& jsonObj,
setCount(jsonObj);
setState(jsonObj);
setFloor(jsonObj);
setDelayTime(jsonObj);
}

void CountStateFloor::run(Zone& zone)
{
auto countReached = doCount();

if (_delayTime == std::chrono::seconds::zero())
{
// If no delay time configured, can immediately update the hold.
zone.setFloorHold(getUniqueName(), _floor, countReached);
return;
}

if (!countReached)
{
if (_timer && _timer->isEnabled())
{
record("Stopping delay timer");
_timer->setEnabled(false);
}

zone.setFloorHold(getUniqueName(), _floor, countReached);
return;
}

// The count has been reached and a delay is configured, so either:
// 1. This hold has already been set, so don't need to do anything else.
// 2. The timer hasn't been started yet, so start it (May need to create
// it first).
// 3. The timer is already running, don't need to do anything else.
// When the timer expires, then count again and set the hold.

if (zone.hasFloorHold(getUniqueName()))
{
return;
}

if (!_timer)
{
_timer = std::make_unique<Timer>(util::SDEventPlus::getEvent(),
[&zone, this](Timer&) {
zone.setFloorHold(getUniqueName(), _floor, doCount());
});
}

if (!_timer->isEnabled())
{
record("Starting delay timer");
_timer->restartOnce(_delayTime);
}
}

bool CountStateFloor::doCount()
{
size_t numAtState = 0;

for (const auto& group : _groups)
{
for (const auto& member : group.getMembers())
Expand All @@ -45,25 +98,20 @@ void CountStateFloor::run(Zone& zone)
group.getProperty()) == _state)
{
numAtState++;
if (numAtState >= _count)
{
return true;
}
}
}
catch (const std::out_of_range& oore)
{
// Default to property not equal when not found
}
if (numAtState >= _count)
{
break;
}
}
if (numAtState >= _count)
{
break;
}
}

// Update zone's floor hold based on action results
zone.setFloorHold(getUniqueName(), _floor, (numAtState >= _count));
return false;
}

void CountStateFloor::setCount(const json& jsonObj)
Expand Down Expand Up @@ -96,4 +144,12 @@ void CountStateFloor::setFloor(const json& jsonObj)
_floor = jsonObj["floor"].get<uint64_t>();
}

void CountStateFloor::setDelayTime(const json& jsonObj)
{
if (jsonObj.contains("delay"))
{
_delayTime = std::chrono::seconds(jsonObj["delay"].get<size_t>());
}
}

} // namespace phosphor::fan::control::json
23 changes: 23 additions & 0 deletions control/json/actions/count_state_floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ using json = nlohmann::json;
* "state": false,
* "floor": 5000
* }
*
* There is an optional 'delay' field that that prevents the floor from
* being changed until the count has been met for that amount of time.
*/
class CountStateFloor :
public ActionBase,
Expand Down Expand Up @@ -104,6 +107,20 @@ class CountStateFloor :
*/
void setFloor(const json& jsonObj);

/**
* @brief Parse and set the delay
*
* @param[in] jsonObj - JSON object for the action
*/
void setDelayTime(const json& jsonObj);

/**
* @brief Counts the number of members that are equal to the state.
*
* @return bool - If the count is reached or not.
*/
bool doCount();

/* Number of group members */
size_t _count;

Expand All @@ -112,6 +129,12 @@ class CountStateFloor :

/* Floor for this action */
uint64_t _floor;

/* Amount of time the count has to be met */
std::chrono::seconds _delayTime{0};

/* Timer used for checking the delay */
std::unique_ptr<Timer> _timer;
};

} // namespace phosphor::fan::control::json
9 changes: 5 additions & 4 deletions docs/control/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,15 @@ below the configured count, the floor hold is released.
"name": "count_state_floor",
"count": 2,
"state": false,
"floor": 18000
"floor": 18000,
"delay": 3
}
```

The above config reads the configured D-Bus property on each group member
configured for the action. If two or more members have a property value of
false, a floor hold will be requested with a value of 18000. Otherwise, the
floor hold will be released (if it was previously requested).
configured for the action. If two or more members have a property value of false
for 3 seconds, a floor hold will be requested with a value of 18000. Otherwise,
the floor hold will be released (if it was previously requested).

### count_state_before_target

Expand Down