| James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once | 
| Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 2 |  | 
| Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 3 | #include "PresenceGpio.hpp" | 
| Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 4 | #include "Thresholds.hpp" | 
| Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 5 | #include "Utils.hpp" | 
| Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 6 | #include "sensor.hpp" | 
 | 7 |  | 
| Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 8 | #include <boost/asio/io_context.hpp> | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 9 | #include <boost/asio/random_access_file.hpp> | 
| Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 10 | #include <boost/asio/steady_timer.hpp> | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 11 | #include <boost/container/flat_map.hpp> | 
| Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/lg2.hpp> | 
| Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 13 | #include <sdbusplus/asio/connection.hpp> | 
| James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 14 | #include <sdbusplus/asio/object_server.hpp> | 
 | 15 |  | 
| Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 16 | #include <array> | 
 | 17 | #include <cstddef> | 
| Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 18 | #include <memory> | 
 | 19 | #include <optional> | 
| Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 20 | #include <string> | 
 | 21 | #include <utility> | 
 | 22 | #include <vector> | 
| James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 23 |  | 
| James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 24 | namespace redundancy | 
 | 25 | { | 
 | 26 | constexpr const char* full = "Full"; | 
 | 27 | constexpr const char* degraded = "Degraded"; | 
 | 28 | constexpr const char* failed = "Failed"; | 
 | 29 | } // namespace redundancy | 
 | 30 |  | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 31 | class RedundancySensor | 
 | 32 | { | 
 | 33 |   public: | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 34 |     RedundancySensor(size_t count, const std::vector<std::string>& children, | 
| James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 35 |                      sdbusplus::asio::object_server& objectServer, | 
 | 36 |                      const std::string& sensorConfiguration); | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 37 |     ~RedundancySensor(); | 
 | 38 |  | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 39 |     void update(const std::string& name, bool failed); | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 40 |  | 
 | 41 |   private: | 
 | 42 |     size_t count; | 
| James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 43 |     std::string state = redundancy::full; | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 44 |     std::shared_ptr<sdbusplus::asio::dbus_interface> iface; | 
| James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 45 |     std::shared_ptr<sdbusplus::asio::dbus_interface> association; | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 46 |     sdbusplus::asio::object_server& objectServer; | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 47 |     boost::container::flat_map<std::string, bool> statuses; | 
| Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 48 |  | 
 | 49 |     static void logFanRedundancyLost() | 
 | 50 |     { | 
 | 51 |         const auto* msg = "OpenBMC.0.1.FanRedundancyLost"; | 
 | 52 |         lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg); | 
 | 53 |     } | 
 | 54 |  | 
 | 55 |     static void logFanRedundancyRestored() | 
 | 56 |     { | 
 | 57 |         const auto* msg = "OpenBMC.0.1.FanRedundancyRegained"; | 
 | 58 |         lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg); | 
 | 59 |     } | 
| James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 60 | }; | 
 | 61 |  | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 62 | class TachSensor : | 
 | 63 |     public Sensor, | 
 | 64 |     public std::enable_shared_from_this<TachSensor> | 
| James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 65 | { | 
 | 66 |   public: | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 67 |     TachSensor(const std::string& path, const std::string& objectType, | 
 | 68 |                sdbusplus::asio::object_server& objectServer, | 
 | 69 |                std::shared_ptr<sdbusplus::asio::connection>& conn, | 
| Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 70 |                std::shared_ptr<PresenceGpio>& presence, | 
| James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 71 |                std::optional<RedundancySensor>* redundancy, | 
| Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 72 |                boost::asio::io_context& io, const std::string& fanName, | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 73 |                std::vector<thresholds::Threshold>&& thresholds, | 
 | 74 |                const std::string& sensorConfiguration, | 
| Ed Tanous | f69fbf9 | 2022-01-14 10:15:33 -0800 | [diff] [blame] | 75 |                const std::pair<double, double>& limits, | 
| James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 76 |                const PowerState& powerState, | 
 | 77 |                const std::optional<std::string>& led); | 
| Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 78 |     ~TachSensor() override; | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 79 |     void setupRead(); | 
| James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 80 |  | 
 | 81 |   private: | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 82 |     // Ordering is important here; readBuf is first so that it's not destroyed | 
 | 83 |     // while async operations from other member fields might still be using it. | 
 | 84 |     std::array<char, 128> readBuf{}; | 
| James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 85 |     sdbusplus::asio::object_server& objServer; | 
| James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 86 |     std::optional<RedundancySensor>* redundancy; | 
| Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 87 |     std::shared_ptr<PresenceGpio> presence; | 
| James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 88 |     std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface; | 
| James Feist | d8bd562 | 2019-06-26 12:09:05 -0700 | [diff] [blame] | 89 |     std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc; | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 90 |     boost::asio::random_access_file inputDev; | 
| Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 91 |     boost::asio::steady_timer waitTimer; | 
| James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 92 |     std::string path; | 
| James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 93 |     std::optional<std::string> led; | 
 | 94 |     bool ledState = false; | 
| Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 95 |  | 
 | 96 |     void handleResponse(const boost::system::error_code& err, size_t bytesRead); | 
 | 97 |     void restartRead(size_t pollTime); | 
| Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 98 |     void checkThresholds() override; | 
| James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 99 | }; |