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
107
108
109
110
111
112
|
#include <iostream>
#include <string>
#include <algorithm>
#include "manager.hpp"
#include "led-gen.hpp"
namespace phosphor
{
namespace led
{
// Assert -or- De-assert
bool Manager::setGroupState(const std::string& path, bool assert)
{
if (assert)
{
assertedGroups.insert(&ledMap.at(path));
}
else
{
auto search = assertedGroups.find(&ledMap.at(path));
if (search != assertedGroups.end())
{
assertedGroups.erase(&ledMap.at(path));
}
}
// If something does not go right here, then there should be an sdbusplus
// exception thrown.
driveLEDs();
// If we survive, then set the state accordingly.
return assert;
}
/** @brief Run through the map and apply action on the LEDs */
void Manager::driveLEDs()
{
// This will contain the union of what's already in the asserted group
group desiredState {};
for(const auto& grp : assertedGroups)
{
desiredState.insert(grp->cbegin(), grp->cend());
}
// Always Do execute Turn Off and then Turn on since we have the Blink
// taking priority over -on-
group ledsToDeAssert {};
std::set_difference(currentState.begin(), currentState.end(),
desiredState.begin(), desiredState.end(),
std::inserter(ledsToDeAssert, ledsToDeAssert.begin()));
if(ledsToDeAssert.size())
{
// We really do not want the Manager to know how a particular LED
// transitions from State-A --> State-B and all this must be handled by
// the physical LED controller implementation.
// So in this case, Manager really does not want to turn off the
// LEDs and then turning it back on and let the physical LED controller
// handle that.
// I am still experimenting on the algo..
std::cout << "De asserting the LEDs" << std::endl;
for (const auto& it: ledsToDeAssert)
{
std::cout << "\t{" << it.name << "::" << it.action << "}"
<< std::endl;
}
// If we previously had a FRU in ON state , and then if there was a
// request to make it blink, the end state would now be blink.
// If we either turn off blink / fault, then we need to go back to its
// previous state.
group ledsToReAssert {};
std::set_intersection(desiredState.begin(), desiredState.end(),
ledsToDeAssert.begin(), ledsToDeAssert.end(),
std::inserter(ledsToReAssert, ledsToReAssert.begin()),
ledComp);
if (ledsToReAssert.size())
{
std::cout << "Asserting LEDs again" << std::endl;
for (const auto& it: ledsToReAssert)
{
std::cout << "\t{" << it.name << "::" << it.action << "}"
<< std::endl;
}
}
}
// Turn on these
group ledsToAssert {};
std::set_difference(desiredState.begin(), desiredState.end(),
currentState.begin(), currentState.end(),
std::inserter(ledsToAssert, ledsToAssert.begin()));
if(ledsToAssert.size())
{
std::cout << "Asserting LEDs" << std::endl;
for (const auto& it: ledsToAssert)
{
std::cout << "\t{" << it.name << "::" << it.action << "}"
<< std::endl;
}
}
// Done.. Save the latest and greatest.
currentState = std::move(desiredState);
return;
}
} // namespace led
} // namespace phosphor
|