blob: 3de5d69c2a7e9feb6b3b537aa19610fa74db652c [file] [log] [blame]
Matthew Barth293477d2017-02-17 15:39:36 -06001#pragma once
2
Matthew Barthd6403822017-02-17 17:10:19 -06003#include <sdbusplus/bus.hpp>
Matthew Barthcd4f4d12017-02-17 17:48:56 -06004#include <sdbusplus/server.hpp>
Matthew Barth293477d2017-02-17 15:39:36 -06005#include "sensor_base.hpp"
6
7
8namespace phosphor
9{
10namespace fan
11{
12namespace presence
13{
14
Matthew Barthf85dddc2017-06-02 11:31:06 -050015using namespace sdbusplus::bus::match::rules;
16
Matthew Barth5c15b792017-03-01 11:17:00 -060017/**
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 Barth293477d2017-02-17 15:39:36 -060023class 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 Barth5c15b792017-03-01 11:17:00 -060033 /**
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 Barthcd4f4d12017-02-17 17:48:56 -060040 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 Barthf85dddc2017-06-02 11:31:06 -050048 std::bind(
49 std::mem_fn(&TachSensor::handleTachChange),
50 this,
51 std::placeholders::_1))
Matthew Barthd6403822017-02-17 17:10:19 -060052 {
53 // Nothing to do here
54 }
55
Matthew Barth5c15b792017-03-01 11:17:00 -060056 /**
57 * @brief Determine the presence of this sensor using the tach feedback
58 *
59 * @return Presence state based on tach feedback
60 */
Matthew Barth293477d2017-02-17 15:39:36 -060061 bool isPresent();
62
63 private:
Matthew Barth5c15b792017-03-01 11:17:00 -060064 /** @brief Connection for sdbusplus bus */
Matthew Barthd6403822017-02-17 17:10:19 -060065 sdbusplus::bus::bus& bus;
Matthew Barth5c15b792017-03-01 11:17:00 -060066 /** @brief Used to subscribe to dbus signals */
Matthew Barthcd4f4d12017-02-17 17:48:56 -060067 sdbusplus::server::match::match tachSignal;
Matthew Barth5c15b792017-03-01 11:17:00 -060068 /** @brief Tach speed value given from the signal */
Matthew Barthd6403822017-02-17 17:10:19 -060069 int64_t tach = 0;
Matthew Barth293477d2017-02-17 15:39:36 -060070
Matthew Barth5c15b792017-03-01 11:17:00 -060071 /**
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 Barthcd4f4d12017-02-17 17:48:56 -060079 {
Matthew Barthf85dddc2017-06-02 11:31:06 -050080 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 Barthcd4f4d12017-02-17 17:48:56 -060086 }
Matthew Barth5c15b792017-03-01 11:17:00 -060087 /**
Matthew Barthf85dddc2017-06-02 11:31:06 -050088 * @brief Handle when the signal was a tach change
Matthew Barth5c15b792017-03-01 11:17:00 -060089 *
90 * @param[in] msg - Expanded sdbusplus message data
Matthew Barth5c15b792017-03-01 11:17:00 -060091 */
Matthew Barthf85dddc2017-06-02 11:31:06 -050092 void handleTachChange(sdbusplus::message::message& msg);
Matthew Barthcd4f4d12017-02-17 17:48:56 -060093
Matthew Barth293477d2017-02-17 15:39:36 -060094};
95
96} // namespace presence
97} // namespace fan
98} // namespace phosphor