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 | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 15 | /** |
| 16 | * @class TachSensor |
| 17 | * @brief OpenBMC Tach feedback sensor presence implementation |
| 18 | * @details Derived sensor type that uses the tach feedback value to determine |
| 19 | * the presence of the fan enclosure that contains this sensor |
| 20 | */ |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 21 | class TachSensor : public Sensor |
| 22 | { |
| 23 | public: |
| 24 | TachSensor() = delete; |
| 25 | TachSensor(const TachSensor&) = delete; |
| 26 | TachSensor(TachSensor&&) = delete; |
| 27 | TachSensor& operator=(const TachSensor&) = delete; |
| 28 | TachSensor& operator=(TachSensor&&) = delete; |
| 29 | ~TachSensor() = default; |
| 30 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 31 | /** |
| 32 | * @brief Constructs Tach Sensor Object |
| 33 | * |
| 34 | * @param[in] bus - Dbus bus object |
| 35 | * @param[in] id - ID name of this sensor |
| 36 | * @param[in] fanEnc - Reference to the fan enclosure with this sensor |
| 37 | */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 38 | TachSensor( |
| 39 | sdbusplus::bus::bus& bus, |
| 40 | const std::string& id, |
| 41 | FanEnclosure& fanEnc) : |
| 42 | Sensor(id, fanEnc), |
| 43 | bus(bus), |
| 44 | tachSignal(bus, |
| 45 | match(id).c_str(), |
| 46 | handleTachChangeSignal, |
| 47 | this) |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 48 | { |
| 49 | // Nothing to do here |
| 50 | } |
| 51 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 52 | /** |
| 53 | * @brief Determine the presence of this sensor using the tach feedback |
| 54 | * |
| 55 | * @return Presence state based on tach feedback |
| 56 | */ |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 57 | bool isPresent(); |
| 58 | |
| 59 | private: |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 60 | /** @brief Connection for sdbusplus bus */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 61 | sdbusplus::bus::bus& bus; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 62 | /** @brief Used to subscribe to dbus signals */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 63 | sdbusplus::server::match::match tachSignal; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 64 | /** @brief Tach speed value given from the signal */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 65 | int64_t tach = 0; |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 66 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 67 | /** |
| 68 | * @brief Appends the fan sensor id to construct a match string |
| 69 | * |
| 70 | * @param[in] id - Fan sensor id |
| 71 | * |
| 72 | * @return Match string to register signal for the fan sensor id |
| 73 | */ |
| 74 | static std::string match(const std::string& id) |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 75 | { |
| 76 | return std::string("type='signal'," |
| 77 | "interface='org.freedesktop.DBus.Properties'," |
| 78 | "member='PropertiesChanged'," |
| 79 | "path='/xyz/openbmc_project/sensors/fan_tach/" + |
| 80 | id + "'"); |
| 81 | } |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 82 | /** |
| 83 | * @brief Callback function on tach change signals |
| 84 | * |
| 85 | * @param[out] msg - Data associated with the subscribed signal |
| 86 | * @param[out] data - Pointer to this tach sensor object instance |
| 87 | * @param[out] err - Contains any sdbus error reference if occurred |
| 88 | * |
| 89 | * @return 0 |
| 90 | */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 91 | static int handleTachChangeSignal(sd_bus_message* msg, |
| 92 | void* data, |
| 93 | sd_bus_error* err); |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 94 | /** |
| 95 | * @brief Determine & handle when the signal was a tach change |
| 96 | * |
| 97 | * @param[in] msg - Expanded sdbusplus message data |
| 98 | * @param[in] err - Contains any sdbus error reference if occurred |
| 99 | */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 100 | void handleTachChange(sdbusplus::message::message& msg, |
| 101 | sd_bus_error* err); |
| 102 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace presence |
| 106 | } // namespace fan |
| 107 | } // namespace phosphor |