blob: b160a6020990144a4a04e73fff7716e4e17cca21 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
James Feist7b18b1e2019-05-14 13:42:09 -07003#include <systemd/sd-journal.h>
4
James Feist6714a252018-09-10 15:26:18 -07005#include <Thresholds.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -07006#include <boost/container/flat_map.hpp>
7#include <boost/container/flat_set.hpp>
James Feist6714a252018-09-10 15:26:18 -07008#include <sdbusplus/asio/object_server.hpp>
James Feist251c7822018-09-12 12:54:15 -07009#include <sensor.hpp>
James Feist6714a252018-09-10 15:26:18 -070010
James Feistd8705872019-02-08 13:26:09 -080011constexpr const char* gpioPath = "/sys/class/gpio/";
James Feist7bc2bab2018-10-26 14:09:45 -070012class PresenceSensor
13{
14
15 public:
16 PresenceSensor(const size_t index, bool inverted,
James Feist7b18b1e2019-05-14 13:42:09 -070017 boost::asio::io_service& io, const std::string& name);
James Feist7bc2bab2018-10-26 14:09:45 -070018 ~PresenceSensor();
19
20 void monitorPresence(void);
21 void read(void);
22 bool getValue(void);
23
24 private:
25 bool status = true;
26 bool inverted;
27 boost::asio::ip::tcp::socket inputDev;
28 int fd;
James Feist7b18b1e2019-05-14 13:42:09 -070029 std::string name;
James Feist7bc2bab2018-10-26 14:09:45 -070030};
James Feistdc6c55f2018-10-31 12:53:20 -070031
James Feist7b18b1e2019-05-14 13:42:09 -070032namespace redundancy
33{
34constexpr const char* full = "Full";
35constexpr const char* degraded = "Degraded";
36constexpr const char* failed = "Failed";
37} // namespace redundancy
38
James Feistdc6c55f2018-10-31 12:53:20 -070039class RedundancySensor
40{
41 public:
James Feistd8705872019-02-08 13:26:09 -080042 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070043 sdbusplus::asio::object_server& objectServer,
44 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070045 ~RedundancySensor();
46
James Feistd8705872019-02-08 13:26:09 -080047 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070048
49 private:
50 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070051 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070052 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070053 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080054 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070055 boost::container::flat_map<std::string, bool> statuses;
56};
57
James Feist251c7822018-09-12 12:54:15 -070058class TachSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -070059{
60 public:
James Feistd8705872019-02-08 13:26:09 -080061 TachSensor(const std::string& path, const std::string& objectType,
62 sdbusplus::asio::object_server& objectServer,
63 std::shared_ptr<sdbusplus::asio::connection>& conn,
64 std::unique_ptr<PresenceSensor>&& presence,
James Feist7b18b1e2019-05-14 13:42:09 -070065 std::optional<RedundancySensor>* redundancy,
James Feistd8705872019-02-08 13:26:09 -080066 boost::asio::io_service& io, const std::string& fanName,
67 std::vector<thresholds::Threshold>&& thresholds,
68 const std::string& sensorConfiguration,
69 const std::pair<size_t, size_t>& limits);
James Feist6714a252018-09-10 15:26:18 -070070 ~TachSensor();
71
72 private:
James Feistd8705872019-02-08 13:26:09 -080073 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070074 std::optional<RedundancySensor>* redundancy;
James Feist7bc2bab2018-10-26 14:09:45 -070075 std::unique_ptr<PresenceSensor> presence;
James Feist60c0ec72019-03-18 15:08:43 -070076 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070077 boost::asio::posix::stream_descriptor inputDev;
78 boost::asio::deadline_timer waitTimer;
79 boost::asio::streambuf readBuf;
80 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070081 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080082 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080083 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070084};
James Feist7b18b1e2019-05-14 13:42:09 -070085
86inline void logFanInserted(const std::string& device)
87{
88
89 sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
90 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanInserted",
91 "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
92}
93
94inline void logFanRemoved(const std::string& device)
95{
96
97 sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
98 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRemoved",
99 "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
100}
101
102inline void logFanRedundancyLost(void)
103{
104
105 sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
106 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRedundancyLost",
107 NULL);
108}
109
110inline void logFanRedundancyRestored(void)
111{
112
113 sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
114 "REDFISH_MESSAGE_ID=%s",
115 "OpenBMC.0.1.FanRedundancyRegained", NULL);
116}