Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <sdbusplus/server.hpp> |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace fan |
| 10 | { |
| 11 | namespace monitor |
| 12 | { |
| 13 | |
| 14 | class Fan; |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * @class TachSensor |
| 19 | * |
| 20 | * This class represents the sensor that reads a tach value. |
| 21 | * It may also support a Target, which is the property used to |
| 22 | * set a speed. Since it doesn't necessarily have a Target, it |
| 23 | * won't for sure know if it is running too slow, so it leaves |
| 24 | * that determination to other code. |
| 25 | * |
| 26 | * This class has a parent Fan object that knows about all |
| 27 | * sensors for that fan. |
| 28 | */ |
| 29 | class TachSensor |
| 30 | { |
| 31 | public: |
| 32 | |
| 33 | TachSensor() = delete; |
| 34 | TachSensor(const TachSensor&) = delete; |
| 35 | TachSensor(TachSensor&&) = default; |
| 36 | TachSensor& operator=(const TachSensor&) = delete; |
| 37 | TachSensor& operator=(TachSensor&&) = default; |
| 38 | ~TachSensor() = default; |
| 39 | |
| 40 | /** |
| 41 | * @brief Constructor |
| 42 | * |
| 43 | * @param[in] bus - the dbus object |
| 44 | * @param[in] fan - the parent fan object |
| 45 | * @param[in] id - the id of the sensor |
| 46 | * @param[in] hasTarget - if the sensor supports |
| 47 | * setting the speed |
| 48 | * @param[in] timeout - Normal timeout value to use |
| 49 | */ |
| 50 | TachSensor(sdbusplus::bus::bus& bus, |
| 51 | Fan& fan, |
| 52 | const std::string& id, |
| 53 | bool hasTarget, |
| 54 | size_t timeout); |
| 55 | |
| 56 | /** |
| 57 | * @brief Returns the target speed value |
| 58 | */ |
| 59 | inline uint64_t getTarget() const |
| 60 | { |
| 61 | return _tachTarget; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @brief Returns the input speed value |
| 66 | */ |
| 67 | inline int64_t getInput() const |
| 68 | { |
| 69 | return _tachInput; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @brief Returns true if sensor has a target |
| 74 | */ |
| 75 | inline bool hasTarget() const |
| 76 | { |
| 77 | return _hasTarget; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns true if the hardware behind this |
| 82 | * sensor is considered working OK/functional. |
| 83 | */ |
| 84 | inline bool functional() const |
| 85 | { |
| 86 | return _functional; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets functional status |
| 91 | */ |
| 92 | inline void setFunctional(bool functional) |
| 93 | { |
| 94 | _functional = functional; |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | |
| 99 | /** |
| 100 | * @brief the dbus object |
| 101 | */ |
| 102 | sdbusplus::bus::bus& _bus; |
| 103 | |
| 104 | /** |
| 105 | * @brief Reference to the parent Fan object |
| 106 | */ |
| 107 | Fan& _fan; |
| 108 | |
| 109 | /** |
| 110 | * @brief The name of the sensor, including the full path |
| 111 | * |
| 112 | * For example /xyz/openbmc_project/sensors/fan_tach/fan0 |
| 113 | */ |
| 114 | const std::string _name; |
| 115 | |
| 116 | /** |
| 117 | * @brief If functional (not too slow). The parent |
| 118 | * fan object sets this. |
| 119 | */ |
| 120 | bool _functional = true; |
| 121 | |
| 122 | /** |
| 123 | * @brief If the sensor has a Target property (can set speed) |
| 124 | */ |
| 125 | const bool _hasTarget; |
| 126 | |
| 127 | /** |
| 128 | * @brief The input speed, from the Value dbus property |
| 129 | */ |
| 130 | int64_t _tachInput = 0; |
| 131 | |
| 132 | /** |
| 133 | * @brief The current target speed, from the Target dbus property |
| 134 | * (if applicable) |
| 135 | */ |
| 136 | uint64_t _tachTarget = 0; |
| 137 | |
| 138 | /** |
| 139 | * @brief The timeout value to use |
| 140 | */ |
| 141 | const size_t _timeout; |
| 142 | }; |
| 143 | |
| 144 | } |
| 145 | } |
| 146 | } |