presence: Tach input to double
It was found that after the Value property on the Sensor.Value interface
was changed to be of double type, the tach input failed to get converted
correctly from double to int64 type when the property changed. Need to
set the tach input to be of double type explicitly.
Tested:
Tach input values correctly read from dbus signal
Change-Id: Ia12697e12b4003c62868f1fb97576df03c46c53f
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/tach.cpp b/presence/tach.cpp
index 3372d8e..6cddc23 100644
--- a/presence/tach.cpp
+++ b/presence/tach.cpp
@@ -63,14 +63,14 @@
// Get an initial tach speed.
try
{
- std::get<int64_t>(s) = util::SDBusPlus::getProperty<int64_t>(
+ std::get<double>(s) = util::SDBusPlus::getProperty<double>(
tachPath, tachIface, tachProperty);
}
catch (std::exception&)
{
// Assume not spinning.
- std::get<int64_t>(s) = 0;
+ std::get<double>(s) = 0;
log<level::INFO>("Unable to read fan tach sensor.",
entry("SENSOR=%s", tachPath.c_str()));
}
@@ -78,7 +78,7 @@
// Set the initial state of the sensor.
currentState = std::any_of(state.begin(), state.end(), [](const auto& s) {
- return std::get<int64_t>(s) != 0;
+ return std::get<double>(s) != 0;
});
return currentState;
@@ -96,10 +96,10 @@
bool Tach::present()
{
// Live query the tach readings.
- std::vector<int64_t> values;
+ std::vector<double> values;
for (const auto& s : state)
{
- values.push_back(util::SDBusPlus::getProperty<int64_t>(
+ values.push_back(util::SDBusPlus::getProperty<double>(
tachNamespace + std::get<std::string>(s), tachIface, tachProperty));
}
@@ -110,26 +110,25 @@
void Tach::propertiesChanged(size_t sensor, sdbusplus::message::message& msg)
{
std::string iface;
- util::Properties<int64_t> properties;
+ util::Properties<double> properties;
msg.read(iface, properties);
propertiesChanged(sensor, properties);
}
void Tach::propertiesChanged(size_t sensor,
- const util::Properties<int64_t>& props)
+ const util::Properties<double>& props)
{
// Find the Value property containing the speed.
auto it = props.find(tachProperty);
if (it != props.end())
{
auto& s = state[sensor];
- std::get<int64_t>(s) = std::get<int64_t>(it->second);
+ std::get<double>(s) = std::get<double>(it->second);
auto newState =
- std::any_of(state.begin(), state.end(), [](const auto& s) {
- return std::get<int64_t>(s) != 0;
- });
+ std::any_of(state.begin(), state.end(),
+ [](const auto& s) { return std::get<double>(s) != 0; });
if (currentState != newState)
{
diff --git a/presence/tach.hpp b/presence/tach.hpp
index 9f2654d..4432660 100644
--- a/presence/tach.hpp
+++ b/presence/tach.hpp
@@ -83,8 +83,9 @@
* @param[in] sensor - The sensor that changed.
* @param[in] props - The properties that changed.
*/
- void propertiesChanged(
- size_t sensor, const phosphor::fan::util::Properties<int64_t>& props);
+ void
+ propertiesChanged(size_t sensor,
+ const phosphor::fan::util::Properties<double>& props);
/**
* @brief Properties changed handler for tach sensor updates.
@@ -96,7 +97,7 @@
/** @brief array of tach sensors dbus matches, and tach values. */
std::vector<std::tuple<
- std::string, std::unique_ptr<sdbusplus::bus::match::match>, int64_t>>
+ std::string, std::unique_ptr<sdbusplus::bus::match::match>, double>>
state;
/** The current state of the sensor. */