TachSensor: Accept PowerState from configuration
Accept the PowerState configuration parameter,
similar to other sensors.
This allows it to optionally be set to "Always",
while still preserving the default of "On".
Some systems have their chassis fans not tied to host power,
so they can continue working, even when host powered off,
and "Always" allows the BMC to continue to monitor them.
Tested: Without this patch, or set to "On",
the tachometers show RPM of 0,
even though the fans are still running correctly,
when host is powered off (but BMC and chassis fans
still have power). After this patch, and setting "Always",
the tachometers once again indicate proper RPM.
Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: I1774f0bec180f52e18d37500fcdd87d32620d519
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index c91e21f..af39d0c 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -72,7 +72,8 @@
boost::asio::io_service& io, const std::string& fanName,
std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
- const std::pair<size_t, size_t>& limits);
+ const std::pair<size_t, size_t>& limits,
+ const PowerState& powerState = PowerState::on);
~TachSensor();
private:
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index e8f1fff..122bba0 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -298,6 +298,18 @@
redundancy = &systemRedundancy;
}
+ PowerState powerState = PowerState::on;
+ auto findPower = baseConfiguration->second.find("PowerState");
+ if (findPower != baseConfiguration->second.end())
+ {
+ auto ptrPower =
+ std::get_if<std::string>(&(findPower->second));
+ if (ptrPower)
+ {
+ setReadState(*ptrPower, powerState);
+ }
+ }
+
constexpr double defaultMaxReading = 25000;
constexpr double defaultMinReading = 0;
auto limits =
@@ -307,7 +319,8 @@
tachSensors[sensorName] = std::make_unique<TachSensor>(
path.string(), baseType, objectServer, dbusConnection,
std::move(presenceSensor), redundancy, io, sensorName,
- std::move(sensorThresholds), *interfacePath, limits);
+ std::move(sensorThresholds), *interfacePath, limits,
+ powerState);
auto connector =
sensorData->find(baseType + std::string(".Connector"));
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index cb3d2a8..ba3b0a1 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -50,10 +50,11 @@
boost::asio::io_service& io, const std::string& fanName,
std::vector<thresholds::Threshold>&& _thresholds,
const std::string& sensorConfiguration,
- const std::pair<size_t, size_t>& limits) :
+ const std::pair<size_t, size_t>& limits,
+ const PowerState& powerState) :
Sensor(boost::replace_all_copy(fanName, " ", "_"), std::move(_thresholds),
sensorConfiguration, objectType, limits.second, limits.first,
- PowerState::on),
+ powerState),
objServer(objectServer), redundancy(redundancy),
presence(std::move(presenceSensor)),
inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path)