Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 3 | #include <sdbusplus/bus.hpp> |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 5 | #include "sensor_base.hpp" |
| 6 | |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace fan |
| 11 | { |
| 12 | namespace presence |
| 13 | { |
| 14 | |
Matthew Barth | f85dddc | 2017-06-02 11:31:06 -0500 | [diff] [blame] | 15 | using namespace sdbusplus::bus::match::rules; |
| 16 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 17 | /** |
| 18 | * @class TachSensor |
| 19 | * @brief OpenBMC Tach feedback sensor presence implementation |
| 20 | * @details Derived sensor type that uses the tach feedback value to determine |
| 21 | * the presence of the fan enclosure that contains this sensor |
| 22 | */ |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 23 | class TachSensor : public Sensor |
| 24 | { |
| 25 | public: |
| 26 | TachSensor() = delete; |
| 27 | TachSensor(const TachSensor&) = delete; |
| 28 | TachSensor(TachSensor&&) = delete; |
| 29 | TachSensor& operator=(const TachSensor&) = delete; |
| 30 | TachSensor& operator=(TachSensor&&) = delete; |
| 31 | ~TachSensor() = default; |
| 32 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 33 | /** |
| 34 | * @brief Constructs Tach Sensor Object |
| 35 | * |
| 36 | * @param[in] bus - Dbus bus object |
| 37 | * @param[in] id - ID name of this sensor |
| 38 | * @param[in] fanEnc - Reference to the fan enclosure with this sensor |
| 39 | */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 40 | TachSensor( |
| 41 | sdbusplus::bus::bus& bus, |
| 42 | const std::string& id, |
| 43 | FanEnclosure& fanEnc) : |
| 44 | Sensor(id, fanEnc), |
| 45 | bus(bus), |
| 46 | tachSignal(bus, |
| 47 | match(id).c_str(), |
Matthew Barth | f85dddc | 2017-06-02 11:31:06 -0500 | [diff] [blame] | 48 | std::bind( |
| 49 | std::mem_fn(&TachSensor::handleTachChange), |
| 50 | this, |
| 51 | std::placeholders::_1)) |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 52 | { |
| 53 | // Nothing to do here |
| 54 | } |
| 55 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 56 | /** |
| 57 | * @brief Determine the presence of this sensor using the tach feedback |
| 58 | * |
| 59 | * @return Presence state based on tach feedback |
| 60 | */ |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 61 | bool isPresent(); |
| 62 | |
| 63 | private: |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 64 | /** @brief Connection for sdbusplus bus */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 65 | sdbusplus::bus::bus& bus; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 66 | /** @brief Used to subscribe to dbus signals */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 67 | sdbusplus::server::match::match tachSignal; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 68 | /** @brief Tach speed value given from the signal */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 69 | int64_t tach = 0; |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 70 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 71 | /** |
| 72 | * @brief Appends the fan sensor id to construct a match string |
| 73 | * |
| 74 | * @param[in] id - Fan sensor id |
| 75 | * |
| 76 | * @return Match string to register signal for the fan sensor id |
| 77 | */ |
| 78 | static std::string match(const std::string& id) |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 79 | { |
Matthew Barth | f85dddc | 2017-06-02 11:31:06 -0500 | [diff] [blame] | 80 | return std::string( |
| 81 | interface("org.freedesktop.DBus.Properties") + |
| 82 | member("PropertiesChanged") + |
| 83 | type::signal() + |
| 84 | path("/xyz/openbmc_project/sensors/fan_tach/" + id) + |
| 85 | argN(0, "xyz.openbmc_project.Sensor.Value")); |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 86 | } |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 87 | /** |
Matthew Barth | f85dddc | 2017-06-02 11:31:06 -0500 | [diff] [blame] | 88 | * @brief Handle when the signal was a tach change |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 89 | * |
| 90 | * @param[in] msg - Expanded sdbusplus message data |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 91 | */ |
Matthew Barth | f85dddc | 2017-06-02 11:31:06 -0500 | [diff] [blame] | 92 | void handleTachChange(sdbusplus::message::message& msg); |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 93 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace presence |
| 97 | } // namespace fan |
| 98 | } // namespace phosphor |