blob: 90d955b5b72742637e2faea1b77b81c4c198712b [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 Barth5c15b792017-03-01 11:17:00 -060015/**
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 Barth293477d2017-02-17 15:39:36 -060021class 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 Barth5c15b792017-03-01 11:17:00 -060031 /**
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 Barthcd4f4d12017-02-17 17:48:56 -060038 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 Barthd6403822017-02-17 17:10:19 -060048 {
49 // Nothing to do here
50 }
51
Matthew Barth5c15b792017-03-01 11:17:00 -060052 /**
53 * @brief Determine the presence of this sensor using the tach feedback
54 *
55 * @return Presence state based on tach feedback
56 */
Matthew Barth293477d2017-02-17 15:39:36 -060057 bool isPresent();
58
59 private:
Matthew Barth5c15b792017-03-01 11:17:00 -060060 /** @brief Connection for sdbusplus bus */
Matthew Barthd6403822017-02-17 17:10:19 -060061 sdbusplus::bus::bus& bus;
Matthew Barth5c15b792017-03-01 11:17:00 -060062 /** @brief Used to subscribe to dbus signals */
Matthew Barthcd4f4d12017-02-17 17:48:56 -060063 sdbusplus::server::match::match tachSignal;
Matthew Barth5c15b792017-03-01 11:17:00 -060064 /** @brief Tach speed value given from the signal */
Matthew Barthd6403822017-02-17 17:10:19 -060065 int64_t tach = 0;
Matthew Barth293477d2017-02-17 15:39:36 -060066
Matthew Barth5c15b792017-03-01 11:17:00 -060067 /**
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 Barthcd4f4d12017-02-17 17:48:56 -060075 {
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 Barth5c15b792017-03-01 11:17:00 -060082 /**
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 Barthcd4f4d12017-02-17 17:48:56 -060091 static int handleTachChangeSignal(sd_bus_message* msg,
92 void* data,
93 sd_bus_error* err);
Matthew Barth5c15b792017-03-01 11:17:00 -060094 /**
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 Barthcd4f4d12017-02-17 17:48:56 -0600100 void handleTachChange(sdbusplus::message::message& msg,
101 sd_bus_error* err);
102
Matthew Barth293477d2017-02-17 15:39:36 -0600103};
104
105} // namespace presence
106} // namespace fan
107} // namespace phosphor