Support both double and int64 sensor value
Currently there are two style of sensors, one is scaled int64
sensor value and another is actual double value, but the
"threshold event monitor" is designed to monitor double-style
sensors that store the actual value. Add the handling to accept
both double and int64 style sensors.
Change-Id: I0198423da1c43f9d425269773fe25bb310185e09
Signed-off-by: George Hung <george.hung@quantatw.com>
diff --git a/include/threshold_event_monitor.hpp b/include/threshold_event_monitor.hpp
index 81cd3aa..843d672 100644
--- a/include/threshold_event_monitor.hpp
+++ b/include/threshold_event_monitor.hpp
@@ -113,7 +113,7 @@
conn->new_method_call(msg.get_sender(), msg.get_path(),
"org.freedesktop.DBus.Properties", "GetAll");
getSensorValue.append("xyz.openbmc_project.Sensor.Value");
- boost::container::flat_map<std::string, std::variant<double>>
+ boost::container::flat_map<std::string, std::variant<double, int64_t>>
sensorValue;
try
{
@@ -146,6 +146,15 @@
sensorVal =
std::visit(ipmi::VariantToDoubleVisitor(), findVal->second);
}
+ double scale = 0;
+ auto findScale = sensorValue.find("Scale");
+ if (findScale != sensorValue.end())
+ {
+ scale =
+ std::visit(ipmi::VariantToDoubleVisitor(), findScale->second);
+
+ sensorVal *= std::pow(10, scale);
+ }
try
{
eventData[1] = ipmi::getScaledIPMIValue(sensorVal, max, min);
@@ -169,7 +178,7 @@
conn->new_method_call(msg.get_sender(), msg.get_path(),
"org.freedesktop.DBus.Properties", "Get");
getThreshold.append(thresholdInterface, event);
- std::variant<double> thresholdValue;
+ std::variant<double, int64_t> thresholdValue;
try
{
sdbusplus::message::message getThresholdResp =
@@ -184,6 +193,10 @@
}
double thresholdVal =
std::visit(ipmi::VariantToDoubleVisitor(), thresholdValue);
+ if (findScale != sensorValue.end())
+ {
+ thresholdVal *= std::pow(10, scale);
+ }
try
{
eventData[2] = ipmi::getScaledIPMIValue(thresholdVal, max, min);