blob: c2eaf367fe269efb393af30d8a444d6de9abbbff [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
Ed Tanous8a57ec02020-10-09 12:46:52 -07002#include <Thresholds.hpp>
James Feist8086aba2020-08-25 16:00:59 -07003#include <boost/asio/streambuf.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -07004#include <boost/container/flat_map.hpp>
5#include <boost/container/flat_set.hpp>
Zhikui Ren347dd4e2019-12-12 13:39:50 -08006#include <gpiod.hpp>
Patrick Williams0c42f402021-08-27 16:05:45 -05007#include <phosphor-logging/lg2.hpp>
James Feist38fb5982020-05-28 10:09:54 -07008#include <sdbusplus/asio/object_server.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07009#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -070010
Patrick Venturefd6ba732019-10-31 14:27:39 -070011#include <memory>
12#include <optional>
Patrick Venturefd6ba732019-10-31 14:27:39 -070013#include <string>
14#include <utility>
15#include <vector>
James Feist6714a252018-09-10 15:26:18 -070016
James Feist7bc2bab2018-10-26 14:09:45 -070017class PresenceSensor
18{
James Feist7bc2bab2018-10-26 14:09:45 -070019 public:
Ed Tanous2049bd22022-07-09 07:20:26 -070020 PresenceSensor(const std::string& gpioName, bool inverted,
James Feist7b18b1e2019-05-14 13:42:09 -070021 boost::asio::io_service& io, const std::string& name);
James Feist7bc2bab2018-10-26 14:09:45 -070022 ~PresenceSensor();
23
24 void monitorPresence(void);
25 void read(void);
Ed Tanous2049bd22022-07-09 07:20:26 -070026 bool getValue(void) const;
James Feist7bc2bab2018-10-26 14:09:45 -070027
28 private:
29 bool status = true;
Zhikui Ren347dd4e2019-12-12 13:39:50 -080030 gpiod::line gpioLine;
31 boost::asio::posix::stream_descriptor gpioFd;
James Feist7b18b1e2019-05-14 13:42:09 -070032 std::string name;
James Feist7bc2bab2018-10-26 14:09:45 -070033};
James Feistdc6c55f2018-10-31 12:53:20 -070034
James Feist7b18b1e2019-05-14 13:42:09 -070035namespace redundancy
36{
37constexpr const char* full = "Full";
38constexpr const char* degraded = "Degraded";
39constexpr const char* failed = "Failed";
40} // namespace redundancy
41
James Feistdc6c55f2018-10-31 12:53:20 -070042class RedundancySensor
43{
44 public:
James Feistd8705872019-02-08 13:26:09 -080045 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070046 sdbusplus::asio::object_server& objectServer,
47 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070048 ~RedundancySensor();
49
James Feistd8705872019-02-08 13:26:09 -080050 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070051
52 private:
53 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070054 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070055 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070056 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080057 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070058 boost::container::flat_map<std::string, bool> statuses;
59};
60
James Feist251c7822018-09-12 12:54:15 -070061class TachSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -070062{
63 public:
James Feistd8705872019-02-08 13:26:09 -080064 TachSensor(const std::string& path, const std::string& objectType,
65 sdbusplus::asio::object_server& objectServer,
66 std::shared_ptr<sdbusplus::asio::connection>& conn,
67 std::unique_ptr<PresenceSensor>&& presence,
James Feist7b18b1e2019-05-14 13:42:09 -070068 std::optional<RedundancySensor>* redundancy,
James Feistd8705872019-02-08 13:26:09 -080069 boost::asio::io_service& io, const std::string& fanName,
70 std::vector<thresholds::Threshold>&& thresholds,
71 const std::string& sensorConfiguration,
Ed Tanousf69fbf92022-01-14 10:15:33 -080072 const std::pair<double, double>& limits,
James Feist49a8ccd2020-09-16 16:09:52 -070073 const PowerState& powerState,
74 const std::optional<std::string>& led);
Ed Tanous8a57ec02020-10-09 12:46:52 -070075 ~TachSensor() override;
James Feist6714a252018-09-10 15:26:18 -070076
77 private:
James Feistd8705872019-02-08 13:26:09 -080078 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070079 std::optional<RedundancySensor>* redundancy;
James Feist7bc2bab2018-10-26 14:09:45 -070080 std::unique_ptr<PresenceSensor> presence;
James Feist60c0ec72019-03-18 15:08:43 -070081 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
James Feistd8bd5622019-06-26 12:09:05 -070082 std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
Ed Tanous77518b22021-11-05 13:02:23 -070083 boost::asio::streambuf readBuf;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070084 boost::asio::posix::stream_descriptor inputDev;
85 boost::asio::deadline_timer waitTimer;
James Feist930fcde2019-05-28 12:58:43 -070086 std::string path;
James Feist49a8ccd2020-09-16 16:09:52 -070087 std::optional<std::string> led;
88 bool ledState = false;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070089 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080090 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080091 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070092};
James Feist7b18b1e2019-05-14 13:42:09 -070093
94inline void logFanInserted(const std::string& device)
95{
Ed Tanous2049bd22022-07-09 07:20:26 -070096 const auto* msg = "OpenBMC.0.1.FanInserted";
Patrick Williams0c42f402021-08-27 16:05:45 -050097 lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg,
98 "REDFISH_MESSAGE_ARGS", device);
James Feist7b18b1e2019-05-14 13:42:09 -070099}
100
101inline void logFanRemoved(const std::string& device)
102{
Ed Tanous2049bd22022-07-09 07:20:26 -0700103 const auto* msg = "OpenBMC.0.1.FanRemoved";
Patrick Williams0c42f402021-08-27 16:05:45 -0500104 lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg, "REDFISH_MESSAGE_ARGS",
105 device);
James Feist7b18b1e2019-05-14 13:42:09 -0700106}
107
108inline void logFanRedundancyLost(void)
109{
Ed Tanous2049bd22022-07-09 07:20:26 -0700110 const auto* msg = "OpenBMC.0.1.FanRedundancyLost";
Patrick Williams0c42f402021-08-27 16:05:45 -0500111 lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg);
James Feist7b18b1e2019-05-14 13:42:09 -0700112}
113
114inline void logFanRedundancyRestored(void)
115{
Ed Tanous2049bd22022-07-09 07:20:26 -0700116 const auto* msg = "OpenBMC.0.1.FanRedundancyRegained";
Patrick Williams0c42f402021-08-27 16:05:45 -0500117 lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg);
James Feist7b18b1e2019-05-14 13:42:09 -0700118}