manager: add timer for failed LED actions
The current manager performs LED ActionSet one-time only when LED group
asserted property changes, so if the physical LED object path is not
ready when it is set, the LED will be in an error state. Most of time
this error occurs at BMC booting due phospohr-led-manager starts before
LED driver is probed.
In order to correct LED state after physical LED is ready, add a timer
to repeatedly setting failed LED after 1 second.
Change-Id: I0bb46189c79c961cdaa501a7386346c2bb351252
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/manager/manager.hpp b/manager/manager.hpp
index d8573b6..caa7ba8 100644
--- a/manager/manager.hpp
+++ b/manager/manager.hpp
@@ -3,6 +3,9 @@
#include "ledlayout.hpp"
#include "utils.hpp"
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+
#include <set>
#include <string>
#include <unordered_map>
@@ -75,9 +78,13 @@
*
* @param [in] bus - sdbusplus handler
* @param [in] GroupMap - LEDs group layout
+ * @param [in] Event - sd event handler
*/
- Manager(sdbusplus::bus_t& bus, const GroupMap& ledLayout) :
- ledMap(ledLayout), bus(bus)
+ Manager(
+ sdbusplus::bus_t& bus, const GroupMap& ledLayout,
+ const sdeventplus::Event& event = sdeventplus::Event::get_default()) :
+ ledMap(ledLayout),
+ bus(bus), timer(event, [this](auto&) { driveLedsHandler(); })
{
// Nothing here
}
@@ -112,9 +119,11 @@
* @param[in] action - Intended action to be triggered
* @param[in] dutyOn - Duty Cycle ON percentage
* @param[in] period - Time taken for one blink cycle
+ *
+ * @return: - 0: success, -1: LED set failed
*/
- void drivePhysicalLED(const std::string& objPath, Layout::Action action,
- uint8_t dutyOn, const uint16_t period);
+ int drivePhysicalLED(const std::string& objPath, Layout::Action action,
+ uint8_t dutyOn, const uint16_t period);
/** @brief Set lamp test callback when enabled lamp test.
*
@@ -149,6 +158,18 @@
std::function<bool(ActionSet& ledsAssert, ActionSet& ledsDeAssert)>
lampTestCallBack;
+ /** @brief Timer used for LEDs handler callback*/
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
+
+ /** @brief Contains the required set of assert LEDs action */
+ ActionSet reqLedsAssert;
+
+ /** @brief Contains the required set of deassert LEDs action */
+ ActionSet reqLedsDeAssert;
+
+ /** @brief LEDs handler callback */
+ void driveLedsHandler();
+
/** @brief Returns action string based on enum
*
* @param[in] action - Action enum