1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#pragma once
#include <algorithm>
#include <numeric>
namespace phosphor
{
namespace fan
{
namespace control
{
namespace action
{
/**
* @brief An action to set the speed on a zone
* @details The zone is held at the given speed when a defined number of
* properties in the group are set to the given state
*
* @param[in] count - Number of properties
* @param[in] state - Value the property(s) needed to be set at
* @param[in] speed - Speed to set the zone to
*
* @return Lambda function
* A lambda function to set the zone speed when the number of properties
* within the group are at a certain value
*/
template <typename T>
auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
{
return [count,
speed,
state = std::forward<T>(state)](auto& zone, auto& group)
{
size_t numAtState = std::count_if(
group.begin(),
group.end(),
[&zone, &state](auto const& entry)
{
return zone.template getPropertyValue<T>(
entry.first,
std::get<intfPos>(entry.second),
std::get<propPos>(entry.second)) == state;
});
// Update group's fan control active allowed based on action results
zone.setActiveAllow(&group, !(numAtState >= count));
if (numAtState >= count)
{
zone.setSpeed(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
} // namespace phosphor
|