Make hwmon work with double or int64 interface
Deduce type based on interface using decltype
and if it is double apply scale to the value.
Tested-by: Noticed that on dbus using busctl and debug
server that doubles were produced and scaled.
Also verifed that hwmon still produced int64_t values when
building with current phosphor-dbus-interfaces.
Change-Id: I00e21d5ef0ea6cee0eb30baa0b39cde95e7f4a86
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/thresholds.hpp b/thresholds.hpp
index 7e8dbf5..188dc76 100644
--- a/thresholds.hpp
+++ b/thresholds.hpp
@@ -1,6 +1,9 @@
#pragma once
#include "env.hpp"
+#include "interface.hpp"
+
+#include <cmath>
/** @class Thresholds
* @brief Threshold type traits.
@@ -23,10 +26,10 @@
static constexpr InterfaceType type = InterfaceType::WARN;
static constexpr const char* envLo = "WARNLO";
static constexpr const char* envHi = "WARNHI";
- static int64_t (WarningObject::*const setLo)(int64_t);
- static int64_t (WarningObject::*const setHi)(int64_t);
- static int64_t (WarningObject::*const getLo)() const;
- static int64_t (WarningObject::*const getHi)() const;
+ static SensorValueType (WarningObject::*const setLo)(SensorValueType);
+ static SensorValueType (WarningObject::*const setHi)(SensorValueType);
+ static SensorValueType (WarningObject::*const getLo)() const;
+ static SensorValueType (WarningObject::*const getHi)() const;
static bool (WarningObject::*const alarmLo)(bool);
static bool (WarningObject::*const alarmHi)(bool);
};
@@ -38,10 +41,10 @@
static constexpr InterfaceType type = InterfaceType::CRIT;
static constexpr const char* envLo = "CRITLO";
static constexpr const char* envHi = "CRITHI";
- static int64_t (CriticalObject::*const setLo)(int64_t);
- static int64_t (CriticalObject::*const setHi)(int64_t);
- static int64_t (CriticalObject::*const getLo)() const;
- static int64_t (CriticalObject::*const getHi)() const;
+ static SensorValueType (CriticalObject::*const setLo)(SensorValueType);
+ static SensorValueType (CriticalObject::*const setHi)(SensorValueType);
+ static SensorValueType (CriticalObject::*const getLo)() const;
+ static SensorValueType (CriticalObject::*const getHi)() const;
static bool (CriticalObject::*const alarmLo)(bool);
static bool (CriticalObject::*const alarmHi)(bool);
};
@@ -57,7 +60,7 @@
* @param[in] value - The sensor reading to compare to thresholds.
*/
template <typename T>
-void checkThresholds(std::any& iface, int64_t value)
+void checkThresholds(std::any& iface, SensorValueType value)
{
auto realIface = std::any_cast<std::shared_ptr<T>>(iface);
auto lo = (*realIface.*Thresholds<T>::getLo)();
@@ -80,7 +83,7 @@
*/
template <typename T>
auto addThreshold(const std::string& sensorType, const std::string& sensorID,
- int64_t value, ObjectInfo& info)
+ int64_t value, ObjectInfo& info, int64_t scale)
{
auto& objPath = std::get<std::string>(info);
auto& obj = std::get<Object>(info);
@@ -94,8 +97,8 @@
auto& bus = *std::get<sdbusplus::bus::bus*>(info);
iface = std::make_shared<T>(bus, objPath.c_str(), deferSignals);
- auto lo = stoll(tLo);
- auto hi = stoll(tHi);
+ auto lo = stod(tLo) * std::pow(10, scale);
+ auto hi = stod(tHi) * std::pow(10, scale);
(*iface.*Thresholds<T>::setLo)(lo);
(*iface.*Thresholds<T>::setHi)(hi);
(*iface.*Thresholds<T>::alarmLo)(value <= lo);