blob: ce7bae1a855fa3048b28b312171f60eda38305c5 [file] [log] [blame]
George Liuc777bef2020-11-23 17:04:21 +08001#pragma once
2
George Liu82150322021-03-03 17:13:13 +08003#include "config.h"
4
George Liu87fd11c2020-11-23 16:40:14 +08005#include "group.hpp"
George Liuc777bef2020-11-23 17:04:21 +08006#include "manager.hpp"
7
George Liu82150322021-03-03 17:13:13 +08008#include <nlohmann/json.hpp>
George Liuc777bef2020-11-23 17:04:21 +08009#include <sdeventplus/utility/timer.hpp>
10
George Liub6151622020-11-23 18:16:18 +080011#include <queue>
George Liuc777bef2020-11-23 17:04:21 +080012#include <vector>
13
14namespace phosphor
15{
16namespace led
17{
18
19/** @class LampTest
20 * @brief Manager LampTest feature
21 */
22class LampTest
23{
24 public:
25 LampTest() = delete;
26 ~LampTest() = default;
27 LampTest(const LampTest&) = delete;
28 LampTest& operator=(const LampTest&) = delete;
George Liu8f538d92024-08-22 15:41:22 +080029 LampTest(LampTest&&) = delete;
30 LampTest& operator=(LampTest&&) = delete;
George Liuc777bef2020-11-23 17:04:21 +080031
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 Liu226059b2024-08-22 16:01:44 +080041 timer(event, [this](auto&) { timeOutHandler(); }), manager(manager),
George Liuaaa667f2024-08-22 17:37:51 +080042 groupObj(nullptr)
George Liu82150322021-03-03 17:13:13 +080043 {
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 Liuc777bef2020-11-23 17:04:21 +080048
49 /** @brief the lamp test request handler
50 *
PriyangaRamasamy180090c2022-10-10 10:50:52 +053051 * 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 Liu87fd11c2020-11-23 16:40:14 +080056 * @param[in] group - Pointer to Group object
George Liuc777bef2020-11-23 17:04:21 +080057 * @param[in] value - true: start lamptest
58 * false: stop lamptest
PriyangaRamasamy180090c2022-10-10 10:50:52 +053059 *
60 * @return Whether lamp test request is handled successfully or not.
George Liuc777bef2020-11-23 17:04:21 +080061 */
PriyangaRamasamy180090c2022-10-10 10:50:52 +053062 bool requestHandler(Group* group, bool value);
George Liuc777bef2020-11-23 17:04:21 +080063
George Liub6151622020-11-23 18:16:18 +080064 /** @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 Williams158b2c12022-03-17 05:57:44 -050073 bool processLEDUpdates(const ActionSet& ledsAssert,
74 const ActionSet& ledsDeAssert);
George Liub6151622020-11-23 18:16:18 +080075
Manojkiran Eda94e894c2024-06-17 11:44:39 +053076 /** @brief Clear LEDs triggered by lamptest
77 * When system reboots during lamptest, leds triggered by lamptest needs to
Sunny Srivastavae3515c72022-10-15 12:45:40 -050078 * 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 */
George Liuf0592552024-08-23 09:46:17 +080082 static void clearLamps();
Sunny Srivastavae3515c72022-10-15 12:45:40 -050083
George Liuc777bef2020-11-23 17:04:21 +080084 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 Liu87fd11c2020-11-23 16:40:14 +080091 /** @brief Pointer to Group object */
92 Group* groupObj;
93
94 /** all the Physical paths */
95 std::vector<std::string> physicalLEDPaths;
96
George Liub6151622020-11-23 18:16:18 +080097 /** @brief Queue to save LED states during lamp test */
Patrick Williams158b2c12022-03-17 05:57:44 -050098 std::queue<std::pair<ActionSet, ActionSet>> updatedLEDsDuringLampTest;
George Liub6151622020-11-23 18:16:18 +080099
100 /** @brief Get state of the lamp test operation */
101 bool isLampTestRunning{false};
102
103 /** @brief Physical LED states prior to lamp test */
Patrick Williams158b2c12022-03-17 05:57:44 -0500104 ActionSet physicalLEDStatesPriorToLampTest;
George Liub6151622020-11-23 18:16:18 +0800105
George Liu82150322021-03-03 17:13:13 +0800106 /** @brief Vector of names of physical LEDs, whose changes will be forcibly
107 * updated even during lamp test. */
108 std::vector<std::string> forceUpdateLEDs;
109
110 /** @brief Vector of names of physical LEDs, that will be exempted from lamp
111 * test */
112 std::vector<std::string> skipUpdateLEDs;
113
George Liuc777bef2020-11-23 17:04:21 +0800114 /** @brief Start and restart lamp test depending on what is the current
115 * state. */
116 void start();
117
118 /** @brief Stop lamp test. */
119 void stop();
120
121 /** @brief This method gets called when the lamp test procedure is done as
122 * part of timeout. */
123 void timeOutHandler();
George Liub6151622020-11-23 18:16:18 +0800124
125 /** @brief Restore the physical LEDs states after the lamp test finishes */
126 void restorePhysicalLedStates();
127
128 /** @brief Store the physical LEDs states before the lamp test start */
129 void storePhysicalLEDsStates();
130
131 /** @brief Returns action enum based on string
132 *
133 * @param[in] str - Action string
134 *
135 * @return enumeration equivalent of the passed in string
136 */
George Liuf0592552024-08-23 09:46:17 +0800137 static Layout::Action getActionFromString(const std::string& str);
George Liuce4d1c52021-01-25 11:32:37 +0800138
PriyangaRamasamy180090c2022-10-10 10:50:52 +0530139 /** @brief Notify host to start / stop the lamp test
George Liuce4d1c52021-01-25 11:32:37 +0800140 *
141 * @param[in] value - the Asserted property value
142 */
George Liuf0592552024-08-23 09:46:17 +0800143 static void doHostLampTest(bool value);
George Liu82150322021-03-03 17:13:13 +0800144
145 /** @brief Get physical LED names from lamp test JSON config file
146 *
147 * @param[in] path - path of LED JSON file
148 *
149 * return
150 */
151 void getPhysicalLEDNamesFromJson(const fs::path& path);
George Liuc777bef2020-11-23 17:04:21 +0800152};
153
154} // namespace led
155} // namespace phosphor