usb-dbg: Support sensor out of threshold message present
Description:
- Modified sensors config for greatlakes platform those currently supported.
- Support OCP debug card sensor frame threshold message shown when sensor value is out of threshold.
e.g “P0_temp XXC/UCR”
- Support OCP debug card screen blink and invert the color if the sensor out of threshold.
Test Case:
Sensor threshold message should be shown on debug card when the sensor value is out of threshold.
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Change-Id: I894b50bee33ad84abc07c5aa086fe1b798b7079b
diff --git a/src/storagecommands.cpp b/src/storagecommands.cpp
index 6cc51e5..1b69e68 100644
--- a/src/storagecommands.cpp
+++ b/src/storagecommands.cpp
@@ -25,6 +25,7 @@
#include <sdbusplus/timer.hpp>
#include <sensorutils.hpp>
#include <storagecommands.hpp>
+#include <unordered_map>
#include <iostream>
@@ -75,6 +76,47 @@
static sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
+using InterfaceName = std::string;
+using PropertyName = std::string;
+using ThresholdStr = std::string;
+
+enum class AlarmType
+{
+ low,
+ high
+};
+
+struct Property
+{
+ PropertyName name;
+ ThresholdStr threshold;
+};
+
+const std::vector<InterfaceName> thresholdCheckedOrder{
+ "xyz.openbmc_project.Sensor.Threshold.HardShutdown",
+ "xyz.openbmc_project.Sensor.Threshold.SoftShutdown",
+ "xyz.openbmc_project.Sensor.Threshold.Critical",
+ "xyz.openbmc_project.Sensor.Threshold.Warning"};
+
+const std::unordered_map<std::string, std::map<AlarmType, Property>>
+ alarmProperties{
+ {"xyz.openbmc_project.Sensor.Threshold.HardShutdown",
+ {{AlarmType::low, Property{"HardShutdownAlarmLow", "LNR"}},
+ {AlarmType::high, Property{"HardShutdownAlarmHigh", "UNR"}}}},
+
+ {"xyz.openbmc_project.Sensor.Threshold.SoftShutdown",
+ {{AlarmType::low, Property{"SoftShutdownAlarmLow", "LNR"}},
+ {AlarmType::high, Property{"SoftShutdownAlarmHigh", "UNR"}}}},
+
+ {"xyz.openbmc_project.Sensor.Threshold.Critical",
+ {{AlarmType::low, Property{"CriticalAlarmLow", "LCR"}},
+ {AlarmType::high, Property{"CriticalAlarmHigh", "UCR"}}}},
+
+ {"xyz.openbmc_project.Sensor.Threshold.Warning",
+ {{AlarmType::low, Property{"WarningAlarmLow", "LNC"}},
+ {AlarmType::high, Property{"WarningAlarmHigh", "UNC"}}}},
+ };
+
static bool getSensorMap(std::string sensorConnection, std::string sensorPath,
SensorMap& sensorMap)
{
@@ -821,6 +863,73 @@
return -1;
}
+int getSensorThreshold(std::string& name, std::string& thresholdStr)
+{
+ std::string connection;
+ std::string path;
+ int ret = -1;
+ thresholdStr = "";
+
+ ret = getSensorConnectionByName(name, connection, path);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ SensorMap sensorMap;
+ if (!getSensorMap(connection, path, sensorMap))
+ {
+ return ret;
+ }
+
+ // Iterate threshold interfaces with priority order
+ for (auto& interface : thresholdCheckedOrder)
+ {
+ auto interfaceProperty = alarmProperties.find(interface);
+ if (interfaceProperty == alarmProperties.end())
+ {
+ continue;
+ }
+
+ auto propertyValue = interfaceProperty->second;
+
+ // Checks threshold properties value in sensorMap
+ auto thresholdInterfaceSensorMap = sensorMap.find(interface);
+
+ // Ignore if interface not set
+ if (thresholdInterfaceSensorMap == sensorMap.end())
+ {
+ continue;
+ }
+
+ auto& thresholdMap = thresholdInterfaceSensorMap->second;
+
+ auto& propertyAlarmHigh = propertyValue.at(AlarmType::high);
+ auto alarmHigh = thresholdMap.find(propertyAlarmHigh.name);
+ if (alarmHigh != thresholdMap.end())
+ {
+ if (std::get<bool>(alarmHigh->second))
+ {
+ thresholdStr = propertyAlarmHigh.threshold;
+ break;
+ }
+ }
+
+ auto& propertyAlarmLow = propertyValue.at(AlarmType::low);
+ auto alarmLow = thresholdMap.find(propertyAlarmLow.name);
+ if (alarmLow != thresholdMap.end())
+ {
+ if (std::get<bool>(alarmLow->second))
+ {
+ thresholdStr = propertyAlarmLow.threshold;
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+
int getSensorValue(std::string& name, double& val)
{
std::string connection;
diff --git a/src/usb-dbg.cpp b/src/usb-dbg.cpp
index a97a998..751d78d 100644
--- a/src/usb-dbg.cpp
+++ b/src/usb-dbg.cpp
@@ -40,6 +40,7 @@
{
int getSensorValue(std::string&, double&);
int getSensorUnit(std::string&, std::string&);
+int getSensorThreshold(std::string&, std::string&);
} // namespace storage
void getMaxHostPosition(size_t& maxPosition)
@@ -756,7 +757,28 @@
if (ipmi::storage::getSensorUnit(senName, unitStr) == 0)
senStr += unitStr;
- frame_snr.append(senStr.c_str(), 0);
+ std::string thresholdStr;
+ int ret =
+ ipmi::storage::getSensorThreshold(senName, thresholdStr);
+ if (ret < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error getting critical sensor threshold status",
+ phosphor::logging::entry("CRI_SENSOR_NAME=%s",
+ senName.c_str()));
+ return -1;
+ }
+ if (thresholdStr.size() != 0)
+ {
+ senStr += ("/" + thresholdStr);
+ std::string senStrWithBlinkAndInvertColor =
+ ESC_ALT + senStr + ESC_RST;
+ frame_snr.append(senStrWithBlinkAndInvertColor.c_str(), 0);
+ }
+ else
+ {
+ frame_snr.append(senStr.c_str(), 0);
+ }
}
else
{