Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <string> |
| 3 | #include <algorithm> |
| 4 | #include "manager.hpp" |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 5 | namespace phosphor |
| 6 | { |
| 7 | namespace led |
| 8 | { |
| 9 | |
| 10 | // Assert -or- De-assert |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 11 | bool Manager::setGroupState(const std::string& path, bool assert, |
| 12 | group& ledsAssert, group& ledsDeAssert, |
| 13 | group& ledsUpdate) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 14 | { |
| 15 | if (assert) |
| 16 | { |
| 17 | assertedGroups.insert(&ledMap.at(path)); |
| 18 | } |
| 19 | else |
| 20 | { |
| 21 | auto search = assertedGroups.find(&ledMap.at(path)); |
| 22 | if (search != assertedGroups.end()) |
| 23 | { |
| 24 | assertedGroups.erase(&ledMap.at(path)); |
| 25 | } |
| 26 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 27 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 28 | // This will contain the union of what's already in the asserted group |
| 29 | group desiredState {}; |
| 30 | for(const auto& grp : assertedGroups) |
| 31 | { |
| 32 | desiredState.insert(grp->cbegin(), grp->cend()); |
| 33 | } |
| 34 | |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 35 | // Has the LEDs that are either to be turned off -or- want a new assertion |
| 36 | group transient {}; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 37 | std::set_difference(currentState.begin(), currentState.end(), |
| 38 | desiredState.begin(), desiredState.end(), |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 39 | std::inserter(transient, transient.begin())); |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 40 | if(transient.size()) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 41 | { |
| 42 | // We really do not want the Manager to know how a particular LED |
| 43 | // transitions from State-A --> State-B and all this must be handled by |
| 44 | // the physical LED controller implementation. |
| 45 | // So in this case, Manager really does not want to turn off the |
| 46 | // LEDs and then turning it back on and let the physical LED controller |
| 47 | // handle that. |
| 48 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 49 | // If we previously had a FRU in ON state , and then if there was a |
| 50 | // request to make it blink, the end state would now be blink. |
| 51 | // If we either turn off blink / fault, then we need to go back to its |
| 52 | // previous state. |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 53 | std::set_intersection(desiredState.begin(), desiredState.end(), |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 54 | transient.begin(), transient.end(), |
| 55 | std::inserter(ledsUpdate, ledsUpdate.begin()), |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 56 | ledComp); |
| 57 | |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 58 | // These LEDs are only to be De-Asserted. |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 59 | std::set_difference(transient.begin(), transient.end(), |
| 60 | ledsUpdate.begin(), ledsUpdate.end(), |
| 61 | std::inserter(ledsDeAssert, ledsDeAssert.begin()), |
| 62 | ledComp); |
| 63 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Turn on these |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 67 | std::set_difference(desiredState.begin(), desiredState.end(), |
| 68 | currentState.begin(), currentState.end(), |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 69 | std::inserter(ledsAssert, ledsAssert.begin())); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 70 | |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 71 | |
| 72 | // Done.. Save the latest and greatest. |
| 73 | currentState = std::move(desiredState); |
| 74 | |
| 75 | // If we survive, then set the state accordingly. |
| 76 | return assert; |
| 77 | } |
| 78 | |
| 79 | /** @brief Run through the map and apply action on the LEDs */ |
| 80 | void Manager::driveLEDs(group& ledsAssert, group& ledsDeAssert, |
| 81 | group& ledsUpdate) |
| 82 | { |
| 83 | // This order of LED operation is important. |
| 84 | if (ledsUpdate.size()) |
| 85 | { |
| 86 | std::cout << "Updating LED states between (On <--> Blink)" |
| 87 | << std::endl; |
| 88 | for (const auto& it: ledsUpdate) |
| 89 | { |
| 90 | std::cout << "\t{" << it.name << "::" << it.action << "}" |
| 91 | << std::endl; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (ledsDeAssert.size()) |
| 96 | { |
| 97 | std::cout << "De-Asserting LEDs" << std::endl; |
| 98 | for (const auto& it: ledsDeAssert) |
| 99 | { |
| 100 | std::cout << "\t{" << it.name << "::" << it.action << "}" |
| 101 | << std::endl; |
| 102 | } |
| 103 | } |
| 104 | |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 105 | if(ledsAssert.size()) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 106 | { |
| 107 | std::cout << "Asserting LEDs" << std::endl; |
Vishwanatha Subbanna | 447d0c8 | 2016-12-19 14:12:42 +0530 | [diff] [blame] | 108 | for (const auto& it: ledsAssert) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 109 | { |
| 110 | std::cout << "\t{" << it.name << "::" << it.action << "}" |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 111 | << std::endl; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 112 | } |
| 113 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 114 | return; |
| 115 | } |
| 116 | |
| 117 | } // namespace led |
| 118 | } // namespace phosphor |