Move GPIO presence object to its own files
This commit moves and renames the PresenceSensor to PresenceGpio
from TachSensors to its own file so that it can be used for more
than just fans.
It is currently only used for GPIO presence monitoring for fans.
This commit maintains the same functionality as the original code.
Once the objects is created for a GPIO, it will be monitoring for
gpiod::line_request::EVENT_BOTH_EDGES changes. The user can call
isPresent() anytime to read the presence status.
Interface:
EventPresenceGpio(const std::string& iDeviceType,
const std::string& iDeviceName,
const std::string& gpioName, bool inverted,
boost::asio::io_context& io);
Sample usage:
presenceGpio = std::make_unique<EventPresenceGpio>(
"Fan", "Fan4b", "FAN4_PRESENCE_R_N", true, io);
if (presenceGpio->isPresent())
{
// Fan is present
}
Testing: Unable to test this update because no hardware supporting
event driven GPIO detection available.
Change-Id: I1f1a4cbab39d3e3ab38b30288f6aa199ee0cfe3c
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/src/TachSensor.hpp b/src/TachSensor.hpp
index 15ed2e4..d2ca101 100644
--- a/src/TachSensor.hpp
+++ b/src/TachSensor.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "PresenceGpio.hpp"
#include "Thresholds.hpp"
#include "sensor.hpp"
@@ -16,24 +17,6 @@
#include <utility>
#include <vector>
-class PresenceSensor
-{
- public:
- PresenceSensor(const std::string& gpioName, bool inverted,
- boost::asio::io_context& io, const std::string& name);
- ~PresenceSensor();
-
- void monitorPresence();
- void read();
- bool getValue() const;
-
- private:
- bool status = true;
- gpiod::line gpioLine;
- boost::asio::posix::stream_descriptor gpioFd;
- std::string name;
-};
-
namespace redundancy
{
constexpr const char* full = "Full";
@@ -58,6 +41,18 @@
std::shared_ptr<sdbusplus::asio::dbus_interface> association;
sdbusplus::asio::object_server& objectServer;
boost::container::flat_map<std::string, bool> statuses;
+
+ static void logFanRedundancyLost()
+ {
+ const auto* msg = "OpenBMC.0.1.FanRedundancyLost";
+ lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg);
+ }
+
+ static void logFanRedundancyRestored()
+ {
+ const auto* msg = "OpenBMC.0.1.FanRedundancyRegained";
+ lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg);
+ }
};
class TachSensor :
@@ -68,7 +63,7 @@
TachSensor(const std::string& path, const std::string& objectType,
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
- std::shared_ptr<PresenceSensor>& presence,
+ std::shared_ptr<PresenceGpio>& presence,
std::optional<RedundancySensor>* redundancy,
boost::asio::io_context& io, const std::string& fanName,
std::vector<thresholds::Threshold>&& thresholds,
@@ -85,7 +80,7 @@
std::array<char, 128> readBuf{};
sdbusplus::asio::object_server& objServer;
std::optional<RedundancySensor>* redundancy;
- std::shared_ptr<PresenceSensor> presence;
+ std::shared_ptr<PresenceGpio> presence;
std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
boost::asio::random_access_file inputDev;
@@ -98,29 +93,3 @@
void restartRead(size_t pollTime);
void checkThresholds() override;
};
-
-inline void logFanInserted(const std::string& device)
-{
- const auto* msg = "OpenBMC.0.1.FanInserted";
- lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg,
- "REDFISH_MESSAGE_ARGS", device);
-}
-
-inline void logFanRemoved(const std::string& device)
-{
- const auto* msg = "OpenBMC.0.1.FanRemoved";
- lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg, "REDFISH_MESSAGE_ARGS",
- device);
-}
-
-inline void logFanRedundancyLost()
-{
- const auto* msg = "OpenBMC.0.1.FanRedundancyLost";
- lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg);
-}
-
-inline void logFanRedundancyRestored()
-{
- const auto* msg = "OpenBMC.0.1.FanRedundancyRegained";
- lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg);
-}