summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--monitor/fan.cpp48
-rw-r--r--monitor/fan.hpp11
-rw-r--r--monitor/tach_sensor.cpp75
-rw-r--r--monitor/tach_sensor.hpp15
4 files changed, 78 insertions, 71 deletions
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 9d2593f..b1aa233 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -40,34 +40,36 @@ Fan::Fan(Mode mode,
_numSensorFailsForNonFunc(std::get<numSensorFailsForNonfuncField>(def)),
_trustManager(trust)
{
+ // Setup tach sensors for monitoring
+ auto& sensors = std::get<sensorListField>(def);
+ for (auto& s : sensors)
+ {
+ try
+ {
+ _sensors.emplace_back(
+ std::make_unique<TachSensor>(
+ mode,
+ bus,
+ *this,
+ std::get<sensorNameField>(s),
+ std::get<hasTargetField>(s),
+ std::get<timeoutField>(def),
+ events));
+
+ _trustManager->registerSensor(_sensors.back());
+ }
+ catch (InvalidSensorError& e)
+ {
+
+ }
+ }
+
//Start from a known state of functional
updateInventory(true);
- // Setup tach sensors for monitoring when in monitor mode
+ // Check current tach state when entering monitor mode
if (mode != Mode::init)
{
- auto& sensors = std::get<sensorListField>(def);
- for (auto& s : sensors)
- {
- try
- {
- _sensors.emplace_back(
- std::make_unique<TachSensor>(
- bus,
- *this,
- std::get<sensorNameField>(s),
- std::get<hasTargetField>(s),
- std::get<timeoutField>(def),
- events));
-
- _trustManager->registerSensor(_sensors.back());
- }
- catch (InvalidSensorError& e)
- {
-
- }
- }
-
//The TachSensors will now have already read the input
//and target values, so check them.
tachChanged();
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index bd8179f..0b0c047 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -16,17 +16,6 @@ namespace monitor
{
/**
- * The mode fan monitor will run in:
- * - init - only do the initialization steps
- * - monitor - run normal monitoring algorithm
- */
-enum class Mode
-{
- init,
- monitor
-};
-
-/**
* @class InvalidSensorError
*
* An exception type for sensors that don't exist or
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 2aa1609..22875a2 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -64,7 +64,8 @@ static void readProperty(const std::string& interface,
}
-TachSensor::TachSensor(sdbusplus::bus::bus& bus,
+TachSensor::TachSensor(Mode mode,
+ sdbusplus::bus::bus& bus,
Fan& fan,
const std::string& id,
bool hasTarget,
@@ -81,48 +82,50 @@ TachSensor::TachSensor(sdbusplus::bus::bus& bus,
// Start from a known state of functional
setFunctional(true);
- // Load in starting Target and Input values
- try
- {
- // Use getProperty directly to allow a missing sensor object
- // to abort construction.
- _tachInput = util::SDBusPlus::getProperty<decltype(_tachInput)>(
- _bus,
- _name,
- FAN_SENSOR_VALUE_INTF,
- FAN_VALUE_PROPERTY);
- }
- catch (std::exception& e)
+ // Load in current Target and Input values when entering monitor mode
+ if (mode != Mode::init)
{
- throw InvalidSensorError();
- }
+ try
+ {
+ // Use getProperty directly to allow a missing sensor object
+ // to abort construction.
+ _tachInput = util::SDBusPlus::getProperty<decltype(_tachInput)>(
+ _bus,
+ _name,
+ FAN_SENSOR_VALUE_INTF,
+ FAN_VALUE_PROPERTY);
+ }
+ catch (std::exception& e)
+ {
+ throw InvalidSensorError();
+ }
- if (_hasTarget)
- {
- readProperty(FAN_SENSOR_CONTROL_INTF,
- FAN_TARGET_PROPERTY,
- _name,
- _bus,
- _tachTarget);
- }
+ if (_hasTarget)
+ {
+ readProperty(FAN_SENSOR_CONTROL_INTF,
+ FAN_TARGET_PROPERTY,
+ _name,
+ _bus,
+ _tachTarget);
+ }
- auto match = getMatchString(FAN_SENSOR_VALUE_INTF);
+ auto match = getMatchString(FAN_SENSOR_VALUE_INTF);
- tachSignal = std::make_unique<sdbusplus::server::match::match>(
- _bus,
- match.c_str(),
- [this](auto& msg){ this->handleTachChange(msg); });
+ tachSignal = std::make_unique<sdbusplus::server::match::match>(
+ _bus,
+ match.c_str(),
+ [this](auto& msg){ this->handleTachChange(msg); });
- if (_hasTarget)
- {
- match = getMatchString(FAN_SENSOR_CONTROL_INTF);
+ if (_hasTarget)
+ {
+ match = getMatchString(FAN_SENSOR_CONTROL_INTF);
- targetSignal = std::make_unique<sdbusplus::server::match::match>(
- _bus,
- match.c_str(),
- [this](auto& msg){ this->handleTargetChange(msg); });
+ targetSignal = std::make_unique<sdbusplus::server::match::match>(
+ _bus,
+ match.c_str(),
+ [this](auto& msg){ this->handleTargetChange(msg); });
+ }
}
-
}
std::string TachSensor::getMatchString(const std::string& interface)
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index 4e57ef5..dd89bbf 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -18,6 +18,17 @@ class Fan;
constexpr auto FAN_SENSOR_PATH = "/xyz/openbmc_project/sensors/fan_tach/";
/**
+ * The mode fan monitor will run in:
+ * - init - only do the initialization steps
+ * - monitor - run normal monitoring algorithm
+ */
+enum class Mode
+{
+ init,
+ monitor
+};
+
+/**
* @class TachSensor
*
* This class represents the sensor that reads a tach value.
@@ -45,6 +56,7 @@ class TachSensor
/**
* @brief Constructor
*
+ * @param[in] mode - mode of fan monitor
* @param[in] bus - the dbus object
* @param[in] fan - the parent fan object
* @param[in] id - the id of the sensor
@@ -53,7 +65,8 @@ class TachSensor
* @param[in] timeout - Normal timeout value to use
* @param[in] events - sd_event pointer
*/
- TachSensor(sdbusplus::bus::bus& bus,
+ TachSensor(Mode mode,
+ sdbusplus::bus::bus& bus,
Fan& fan,
const std::string& id,
bool hasTarget,
OpenPOWER on IntegriCloud