George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 5 | #include "group.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 6 | #include "manager.hpp" |
| 7 | |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 8 | #include <nlohmann/json.hpp> |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 9 | #include <sdeventplus/utility/timer.hpp> |
| 10 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 11 | #include <queue> |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace led |
| 17 | { |
| 18 | |
| 19 | /** @class LampTest |
| 20 | * @brief Manager LampTest feature |
| 21 | */ |
| 22 | class LampTest |
| 23 | { |
| 24 | public: |
| 25 | LampTest() = delete; |
| 26 | ~LampTest() = default; |
| 27 | LampTest(const LampTest&) = delete; |
| 28 | LampTest& operator=(const LampTest&) = delete; |
| 29 | LampTest(LampTest&&) = default; |
| 30 | LampTest& operator=(LampTest&&) = default; |
| 31 | |
| 32 | /** @brief Constructs LED LampTest |
| 33 | * |
| 34 | * Constructs timer and when the timeout occurs, the stop method is called |
| 35 | * back to stop timer and also end the lamp test. |
| 36 | * |
| 37 | * @param[in] event - sd event handler |
| 38 | * @param[in] manager - reference to manager instance |
| 39 | */ |
| 40 | LampTest(const sdeventplus::Event& event, Manager& manager) : |
| 41 | timer(event, std::bind(std::mem_fn(&LampTest::timeOutHandler), this)), |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 42 | manager(manager), groupObj(NULL) |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 43 | { |
| 44 | // Get the force update and/or skipped physical LEDs names from the |
| 45 | // lamp-test-led-overrides.json file during lamp |
| 46 | getPhysicalLEDNamesFromJson(LAMP_TEST_LED_OVERRIDES_JSON); |
| 47 | } |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 48 | |
| 49 | /** @brief the lamp test request handler |
| 50 | * |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 51 | * @param[in] group - Pointer to Group object |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 52 | * @param[in] value - true: start lamptest |
| 53 | * false: stop lamptest |
| 54 | * @return |
| 55 | */ |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 56 | void requestHandler(Group* group, bool value); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 57 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 58 | /** @brief Update physical LEDs states during lamp test and the lamp test is |
| 59 | * running |
| 60 | * |
| 61 | * @param[in] ledsAssert - LEDs that are to be asserted newly or to a |
| 62 | * different state |
| 63 | * @param[in] ledsDeAssert - LEDs that are to be Deasserted |
| 64 | * |
| 65 | * @return Is running lamp test, true running |
| 66 | */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 67 | bool processLEDUpdates(const ActionSet& ledsAssert, |
| 68 | const ActionSet& ledsDeAssert); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 69 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 70 | private: |
| 71 | /** @brief Timer used for LEDs lamp test period */ |
| 72 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 73 | |
| 74 | /** @brief Reference to Manager object */ |
| 75 | Manager& manager; |
| 76 | |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 77 | /** DBusHandler class handles the D-Bus operations */ |
| 78 | DBusHandler dBusHandler; |
| 79 | |
| 80 | /** @brief Pointer to Group object */ |
| 81 | Group* groupObj; |
| 82 | |
| 83 | /** all the Physical paths */ |
| 84 | std::vector<std::string> physicalLEDPaths; |
| 85 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 86 | /** @brief Queue to save LED states during lamp test */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 87 | std::queue<std::pair<ActionSet, ActionSet>> updatedLEDsDuringLampTest; |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 88 | |
| 89 | /** @brief Get state of the lamp test operation */ |
| 90 | bool isLampTestRunning{false}; |
| 91 | |
| 92 | /** @brief Physical LED states prior to lamp test */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 93 | ActionSet physicalLEDStatesPriorToLampTest; |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 94 | |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 95 | /** @brief Vector of names of physical LEDs, whose changes will be forcibly |
| 96 | * updated even during lamp test. */ |
| 97 | std::vector<std::string> forceUpdateLEDs; |
| 98 | |
| 99 | /** @brief Vector of names of physical LEDs, that will be exempted from lamp |
| 100 | * test */ |
| 101 | std::vector<std::string> skipUpdateLEDs; |
| 102 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 103 | /** @brief Start and restart lamp test depending on what is the current |
| 104 | * state. */ |
| 105 | void start(); |
| 106 | |
| 107 | /** @brief Stop lamp test. */ |
| 108 | void stop(); |
| 109 | |
| 110 | /** @brief This method gets called when the lamp test procedure is done as |
| 111 | * part of timeout. */ |
| 112 | void timeOutHandler(); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 113 | |
| 114 | /** @brief Restore the physical LEDs states after the lamp test finishes */ |
| 115 | void restorePhysicalLedStates(); |
| 116 | |
| 117 | /** @brief Store the physical LEDs states before the lamp test start */ |
| 118 | void storePhysicalLEDsStates(); |
| 119 | |
| 120 | /** @brief Returns action enum based on string |
| 121 | * |
| 122 | * @param[in] str - Action string |
| 123 | * |
| 124 | * @return enumeration equivalent of the passed in string |
| 125 | */ |
| 126 | Layout::Action getActionFromString(const std::string& str); |
George Liu | ce4d1c5 | 2021-01-25 11:32:37 +0800 | [diff] [blame] | 127 | |
| 128 | /** @brief Notify PHYP to start / stop the lamp test |
| 129 | * |
| 130 | * @param[in] value - the Asserted property value |
| 131 | */ |
| 132 | void doHostLampTest(bool value); |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 133 | |
| 134 | /** @brief Get physical LED names from lamp test JSON config file |
| 135 | * |
| 136 | * @param[in] path - path of LED JSON file |
| 137 | * |
| 138 | * return |
| 139 | */ |
| 140 | void getPhysicalLEDNamesFromJson(const fs::path& path); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // namespace led |
| 144 | } // namespace phosphor |