summaryrefslogtreecommitdiffstats
path: root/dcmihandler.cpp
diff options
context:
space:
mode:
authorJames Feist <james.feist@linux.intel.com>2018-10-09 10:53:11 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2018-11-21 18:59:39 +0000
commit9cc0ea5f245b215e9eea41b9861f704c6b305671 (patch)
treee7aacf5991a768c40ddc128057d6dd1c76af7fcb /dcmihandler.cpp
parentc64f802317db74512f51e25f6d16d14f4a43b43c (diff)
downloadphosphor-host-ipmid-9cc0ea5f245b215e9eea41b9861f704c6b305671.tar.gz
phosphor-host-ipmid-9cc0ea5f245b215e9eea41b9861f704c6b305671.zip
dcmihandler: use visitor to pull sensor values
This will help upgrade us to using doubles in the future. Change-Id: I94bb26fc43ae410a15402b4966e135d847a1fa33 Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'dcmihandler.cpp')
-rw-r--r--dcmihandler.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index 6ea7dd8..e1a44b5 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -796,32 +796,27 @@ Temperature readTemp(const std::string& dbusService,
{
// Read the temperature value from d-bus object. Need some conversion.
// As per the interface xyz.openbmc_project.Sensor.Value, the temperature
- // is an int64_t and in degrees C. It needs to be scaled by using the
+ // is an double and in degrees C. It needs to be scaled by using the
// formula Value * 10^Scale. The ipmi spec has the temperature as a uint8_t,
// with a separate single bit for the sign.
sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
auto result = ipmi::getAllDbusProperties(
bus, dbusService, dbusPath, "xyz.openbmc_project.Sensor.Value");
- auto temperature = variant_ns::get<int64_t>(result.at("Value"));
- uint64_t absTemp = std::abs(temperature);
-
- auto factor = variant_ns::get<int64_t>(result.at("Scale"));
- uint64_t scale = std::pow(10, factor); // pow() returns float/double
- unsigned long long tempDegrees = 0;
- // Overflow safe multiplication when the scale is > 0
- if (scale && __builtin_umulll_overflow(absTemp, scale, &tempDegrees))
- {
- log<level::ERR>("Multiplication overflow detected",
- entry("TEMP_VALUE=%llu", absTemp),
- entry("SCALE_FACTOR=%llu", scale));
- elog<InternalFailure>();
- }
- else
+ auto temperature = sdbusplus::message::variant_ns::visit(
+ ipmi::VariantToDoubleVisitor(), result.at("Value"));
+ double absTemp = std::abs(temperature);
+
+ auto findFactor = result.find("Scale");
+ double factor = 0.0;
+ if (findFactor != result.end())
{
- // The (uint64_t)scale value is 0, effectively this is division
- tempDegrees = absTemp * std::pow(10, factor);
+ factor = sdbusplus::message::variant_ns::visit(
+ ipmi::VariantToDoubleVisitor(), findFactor->second);
}
+ double scale = std::pow(10, factor);
+
+ auto tempDegrees = absTemp * scale;
// Max absolute temp as per ipmi spec is 128.
if (tempDegrees > maxTemp)
{
OpenPOWER on IntegriCloud