blob: 04db6fdabb01d285e15388ab2d9a8f375f08a9ac [file] [log] [blame]
George Liuc777bef2020-11-23 17:04:21 +08001#include "config.h"
2
3#include "lamptest.hpp"
4
George Liu87fd11c2020-11-23 16:40:14 +08005#include <phosphor-logging/log.hpp>
6
George Liuc777bef2020-11-23 17:04:21 +08007namespace phosphor
8{
9namespace led
10{
11
12void LampTest::stop()
13{
14 timer.setEnabled(false);
George Liu87fd11c2020-11-23 16:40:14 +080015
16 // Set all the Physical action to Off
17 for (const auto& path : physicalLEDPaths)
18 {
19 manager.drivePhysicalLED(path, Layout::Action::Off, 0, 0);
20 }
George Liuc777bef2020-11-23 17:04:21 +080021}
22
23void LampTest::start()
24{
George Liu87fd11c2020-11-23 16:40:14 +080025 // Get paths of all the Physical LED objects
26 physicalLEDPaths = dBusHandler.getSubTreePaths(PHY_LED_PATH, PHY_LED_IFACE);
27
George Liuc777bef2020-11-23 17:04:21 +080028 // restart lamp test, it contains initiate or reset the timer.
29 timer.restart(std::chrono::seconds(LAMP_TEST_TIMEOUT_IN_SECS));
George Liu87fd11c2020-11-23 16:40:14 +080030
31 // Set all the Physical action to On for lamp test
32 for (const auto& path : physicalLEDPaths)
33 {
34 manager.drivePhysicalLED(path, Layout::Action::On, 0, 0);
35 }
George Liuc777bef2020-11-23 17:04:21 +080036}
37
38void LampTest::timeOutHandler()
39{
George Liu87fd11c2020-11-23 16:40:14 +080040 using namespace phosphor::logging;
41
George Liuc777bef2020-11-23 17:04:21 +080042 // set the Asserted property of lamp test to false
George Liu87fd11c2020-11-23 16:40:14 +080043 if (!groupObj)
44 {
45 log<level::ERR>("the Group object is nullptr");
46 throw std::runtime_error("the Group object is nullptr");
47 }
48
49 groupObj->asserted(false);
George Liuc777bef2020-11-23 17:04:21 +080050}
51
George Liu87fd11c2020-11-23 16:40:14 +080052void LampTest::requestHandler(Group* group, bool value)
George Liuc777bef2020-11-23 17:04:21 +080053{
George Liu87fd11c2020-11-23 16:40:14 +080054 if (groupObj == NULL)
55 {
56 groupObj = std::move(group);
57 }
58
George Liuc777bef2020-11-23 17:04:21 +080059 if (value)
60 {
61 start();
62 }
63 else
64 {
65 stop();
66 }
67}
68
69} // namespace led
70} // namespace phosphor