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; |
George Liu | 8f538d9 | 2024-08-22 15:41:22 +0800 | [diff] [blame] | 29 | LampTest(LampTest&&) = delete; |
| 30 | LampTest& operator=(LampTest&&) = delete; |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 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) : |
George Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 41 | timer(event, [this](auto&) { timeOutHandler(); }), manager(manager), |
George Liu | aaa667f | 2024-08-22 17:37:51 +0800 | [diff] [blame] | 42 | groupObj(nullptr) |
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 | * |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 51 | * If lamp test is running (Asserted=true) and if user requests to stop lamp |
| 52 | * test (Asserted input=false), Stop operation will not take place and set |
| 53 | * the Asserted to true itself. LampTest Asserted is/can be set to false |
| 54 | * only when the lamptest timer expires. |
| 55 | * |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 56 | * @param[in] group - Pointer to Group object |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 57 | * @param[in] value - true: start lamptest |
| 58 | * false: stop lamptest |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 59 | * |
| 60 | * @return Whether lamp test request is handled successfully or not. |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 61 | */ |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 62 | bool requestHandler(Group* group, bool value); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 63 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 64 | /** @brief Update physical LEDs states during lamp test and the lamp test is |
| 65 | * running |
| 66 | * |
| 67 | * @param[in] ledsAssert - LEDs that are to be asserted newly or to a |
| 68 | * different state |
| 69 | * @param[in] ledsDeAssert - LEDs that are to be Deasserted |
| 70 | * |
| 71 | * @return Is running lamp test, true running |
| 72 | */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 73 | bool processLEDUpdates(const ActionSet& ledsAssert, |
| 74 | const ActionSet& ledsDeAssert); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 75 | |
Manojkiran Eda | 94e894c | 2024-06-17 11:44:39 +0530 | [diff] [blame] | 76 | /** @brief Clear LEDs triggered by lamptest |
| 77 | * When system reboots during lamptest, leds triggered by lamptest needs to |
Sunny Srivastava | e3515c7 | 2022-10-15 12:45:40 -0500 | [diff] [blame] | 78 | * be cleared in the upcoming boot. This method clears all the leds along |
| 79 | * with the persisted lamp test indicator file so that there is no sign of |
| 80 | * lamptest. |
| 81 | */ |
| 82 | void clearLamps(); |
| 83 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 84 | private: |
| 85 | /** @brief Timer used for LEDs lamp test period */ |
| 86 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 87 | |
| 88 | /** @brief Reference to Manager object */ |
| 89 | Manager& manager; |
| 90 | |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 91 | /** DBusHandler class handles the D-Bus operations */ |
| 92 | DBusHandler dBusHandler; |
| 93 | |
| 94 | /** @brief Pointer to Group object */ |
| 95 | Group* groupObj; |
| 96 | |
| 97 | /** all the Physical paths */ |
| 98 | std::vector<std::string> physicalLEDPaths; |
| 99 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 100 | /** @brief Queue to save LED states during lamp test */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 101 | std::queue<std::pair<ActionSet, ActionSet>> updatedLEDsDuringLampTest; |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 102 | |
| 103 | /** @brief Get state of the lamp test operation */ |
| 104 | bool isLampTestRunning{false}; |
| 105 | |
| 106 | /** @brief Physical LED states prior to lamp test */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 107 | ActionSet physicalLEDStatesPriorToLampTest; |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 108 | |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 109 | /** @brief Vector of names of physical LEDs, whose changes will be forcibly |
| 110 | * updated even during lamp test. */ |
| 111 | std::vector<std::string> forceUpdateLEDs; |
| 112 | |
| 113 | /** @brief Vector of names of physical LEDs, that will be exempted from lamp |
| 114 | * test */ |
| 115 | std::vector<std::string> skipUpdateLEDs; |
| 116 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 117 | /** @brief Start and restart lamp test depending on what is the current |
| 118 | * state. */ |
| 119 | void start(); |
| 120 | |
| 121 | /** @brief Stop lamp test. */ |
| 122 | void stop(); |
| 123 | |
| 124 | /** @brief This method gets called when the lamp test procedure is done as |
| 125 | * part of timeout. */ |
| 126 | void timeOutHandler(); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 127 | |
| 128 | /** @brief Restore the physical LEDs states after the lamp test finishes */ |
| 129 | void restorePhysicalLedStates(); |
| 130 | |
| 131 | /** @brief Store the physical LEDs states before the lamp test start */ |
| 132 | void storePhysicalLEDsStates(); |
| 133 | |
| 134 | /** @brief Returns action enum based on string |
| 135 | * |
| 136 | * @param[in] str - Action string |
| 137 | * |
| 138 | * @return enumeration equivalent of the passed in string |
| 139 | */ |
| 140 | Layout::Action getActionFromString(const std::string& str); |
George Liu | ce4d1c5 | 2021-01-25 11:32:37 +0800 | [diff] [blame] | 141 | |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 142 | /** @brief Notify host to start / stop the lamp test |
George Liu | ce4d1c5 | 2021-01-25 11:32:37 +0800 | [diff] [blame] | 143 | * |
| 144 | * @param[in] value - the Asserted property value |
| 145 | */ |
| 146 | void doHostLampTest(bool value); |
George Liu | 8215032 | 2021-03-03 17:13:13 +0800 | [diff] [blame] | 147 | |
| 148 | /** @brief Get physical LED names from lamp test JSON config file |
| 149 | * |
| 150 | * @param[in] path - path of LED JSON file |
| 151 | * |
| 152 | * return |
| 153 | */ |
| 154 | void getPhysicalLEDNamesFromJson(const fs::path& path); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | } // namespace led |
| 158 | } // namespace phosphor |