92 lines
3.4 KiB
Diff
Executable File
92 lines
3.4 KiB
Diff
Executable File
From 5a8896cc3a8e02e3d09be450a0c7fcc5a5266b55 Mon Sep 17 00:00:00 2001
|
|
From: "Wang.Bin" <Bin-B.Wang@luxshare-ict.com>
|
|
Date: Wed, 23 Oct 2024 13:34:12 +0800
|
|
Subject: [PATCH 7/7] Add power button sensor
|
|
|
|
---
|
|
src/power_control.cpp | 27 +++++++++++++++++++++------
|
|
1 file changed, 21 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/src/power_control.cpp b/src/power_control.cpp
|
|
index b671b23..fbc9605 100644
|
|
--- a/src/power_control.cpp
|
|
+++ b/src/power_control.cpp
|
|
@@ -277,6 +277,7 @@ enum class PowerState
|
|
transitionToCycleOff,
|
|
gracefulTransitionToCycleOff,
|
|
checkForWarmReset,
|
|
+ powerButtonPressed,
|
|
};
|
|
static PowerState powerState;
|
|
static std::string getPowerStateName(PowerState state)
|
|
@@ -553,6 +554,9 @@ static constexpr std::string_view getChassisState(const PowerState state)
|
|
case PowerState::cycleOff:
|
|
return "xyz.openbmc_project.State.Chassis.PowerState.Off";
|
|
break;
|
|
+ case PowerState::powerButtonPressed:
|
|
+ return "ButtonPressed";
|
|
+ break;
|
|
default:
|
|
return "";
|
|
break;
|
|
@@ -565,7 +569,7 @@ static void powerStateLog(const PowerState state)
|
|
constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
|
|
constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
|
|
constexpr const char* selMethod = "IpmiSelAdd";
|
|
- constexpr const char* sensorPath =
|
|
+ std::string sensorPath =
|
|
"/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/ACPI_State";
|
|
|
|
auto bus = sdbusplus::bus::new_default();
|
|
@@ -574,21 +578,30 @@ static void powerStateLog(const PowerState state)
|
|
auto method =
|
|
bus.new_method_call(selService, selPath, selInterface, selMethod);
|
|
|
|
- method.append("SEL Entry");
|
|
- method.append(sensorPath);
|
|
+ method.append("SEL Entry");
|
|
|
|
if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.On")
|
|
{
|
|
std::cerr << "Send Power State On SEL Log\n";
|
|
+ method.append(sensorPath.c_str());
|
|
method.append(
|
|
std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // S0/G0: working
|
|
}
|
|
else if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.Off")
|
|
{
|
|
std::cerr << "Send Power State Off SEL Log\n";
|
|
+ method.append(sensorPath.c_str());
|
|
method.append(
|
|
std::array<uint8_t, 3>({0x06, 0xFF, 0xFF})); // S4/S5: soft-off
|
|
}
|
|
+ else if (stateStr == "ButtonPressed")
|
|
+ {
|
|
+ std::cerr << "Send Power State Button Pressed SEL Log\n";
|
|
+ sensorPath = "/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/Power_Button";
|
|
+ method.append(sensorPath.c_str());
|
|
+ method.append(
|
|
+ std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // power button pressed
|
|
+ }
|
|
else
|
|
{
|
|
std::cerr << "Send Power State SEL Log Error\n";
|
|
@@ -826,9 +839,11 @@ static void powerRestorePolicyLog()
|
|
|
|
static void powerButtonPressLog()
|
|
{
|
|
- sd_journal_send("MESSAGE=PowerControl: power button pressed", "PRIORITY=%i",
|
|
- LOG_INFO, "REDFISH_MESSAGE_ID=%s",
|
|
- "OpenBMC.0.1.PowerButtonPressed", NULL);
|
|
+ // sd_journal_send("MESSAGE=PowerControl: power button pressed", "PRIORITY=%i",
|
|
+ // LOG_INFO, "REDFISH_MESSAGE_ID=%s",
|
|
+ // "OpenBMC.0.1.PowerButtonPressed", NULL);
|
|
+ powerStateLog(PowerState::powerButtonPressed);
|
|
+
|
|
}
|
|
|
|
static void resetButtonPressLog()
|
|
--
|
|
2.25.1
|
|
|