Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 3 | #include "hwmonio.hpp" |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 4 | #include "sensorset.hpp" |
| 5 | #include "types.hpp" |
| 6 | |
Patrick Venture | b28f432 | 2018-09-14 10:19:14 -0700 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <gpioplus/handle.hpp> |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 9 | #include <unordered_set> |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 10 | |
| 11 | namespace sensor |
| 12 | { |
| 13 | |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 14 | struct valueAdjust |
| 15 | { |
| 16 | double gain = 1.0; |
| 17 | int offset = 0; |
| 18 | std::unordered_set<int> rmRCs; |
| 19 | }; |
| 20 | |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 21 | /** @class Sensor |
| 22 | * @brief Sensor object based on a SensorSet container's key type |
| 23 | * @details Sensor object to create and modify an associated device's sensor |
| 24 | * attributes based on the key type of each sensor in the set provided by the |
| 25 | * device. |
| 26 | */ |
| 27 | class Sensor |
| 28 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 29 | public: |
| 30 | Sensor() = delete; |
| 31 | Sensor(const Sensor&) = delete; |
| 32 | Sensor(Sensor&&) = default; |
| 33 | Sensor& operator=(const Sensor&) = delete; |
| 34 | Sensor& operator=(Sensor&&) = default; |
| 35 | ~Sensor() = default; |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 36 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 37 | /** |
| 38 | * @brief Constructs Sensor object |
| 39 | * |
| 40 | * @param[in] sensor - A pair of sensor indentifiers |
| 41 | * @param[in] ioAccess - Hwmon sysfs access |
| 42 | * @param[in] devPath - Device sysfs path |
| 43 | */ |
| 44 | explicit Sensor(const SensorSet::key_type& sensor, |
| 45 | const hwmonio::HwmonIO& ioAccess, |
| 46 | const std::string& devPath); |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 47 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 48 | /** |
| 49 | * @brief Adds any sensor removal return codes for the sensor |
| 50 | * @details Add all return codes defined within a device's config file |
| 51 | * for the entire device or for the specific sensor. |
| 52 | * |
| 53 | * @param[in] rcList - List of return codes found for the sensor |
| 54 | */ |
| 55 | void addRemoveRCs(const std::string& rcList); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 56 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 57 | /** |
| 58 | * @brief Get the adjustments struct for the sensor |
| 59 | * |
| 60 | * @return - Sensor adjustment struct |
| 61 | */ |
| 62 | inline const valueAdjust& getAdjusts() |
| 63 | { |
| 64 | return sensorAdjusts; |
| 65 | } |
Matthew Barth | ac47309 | 2018-05-07 14:41:46 -0500 | [diff] [blame] | 66 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 67 | /** |
| 68 | * @brief Adjusts a sensor value |
| 69 | * @details Adjusts the value given by any gain and/or offset defined |
| 70 | * for this sensor object and returns that adjusted value. |
| 71 | * |
| 72 | * @param[in] value - Value to be adjusted |
| 73 | * |
| 74 | * @return - Adjusted sensor value |
| 75 | */ |
James Feist | ee73f5b | 2018-08-01 16:31:42 -0700 | [diff] [blame] | 76 | SensorValueType adjustValue(SensorValueType value); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 77 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 78 | /** |
| 79 | * @brief Add value interface and value property for sensor |
| 80 | * @details When a sensor has an associated input file, the Sensor.Value |
| 81 | * interface is added along with setting the Value property to the |
| 82 | * corresponding value found in the input file. |
| 83 | * |
| 84 | * @param[in] retryIO - Hwmon sysfs file retry constraints |
| 85 | * (number of and delay between) |
| 86 | * @param[in] info - Sensor object information |
| 87 | * |
| 88 | * @return - Shared pointer to the value object |
| 89 | */ |
| 90 | std::shared_ptr<ValueObject> addValue(const RetryIO& retryIO, |
| 91 | ObjectInfo& info); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 92 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 93 | /** |
| 94 | * @brief Add status interface and functional property for sensor |
| 95 | * @details When a sensor has an associated fault file, the |
| 96 | * OperationalStatus interface is added along with setting the |
| 97 | * Functional property to the corresponding value found in the |
| 98 | * fault file. |
| 99 | * |
| 100 | * @param[in] info - Sensor object information |
| 101 | * |
| 102 | * @return - Shared pointer to the status object |
| 103 | */ |
| 104 | std::shared_ptr<StatusObject> addStatus(ObjectInfo& info); |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 105 | |
Patrick Venture | b28f432 | 2018-09-14 10:19:14 -0700 | [diff] [blame] | 106 | /** |
| 107 | * @brief Unlock the gpio, set to high if relevant. |
| 108 | */ |
| 109 | void unlockGpio(); |
| 110 | |
| 111 | /** |
| 112 | * @brief Lock the gpio, set to low if relevant. |
| 113 | */ |
| 114 | void lockGpio(); |
| 115 | |
James Feist | ee73f5b | 2018-08-01 16:31:42 -0700 | [diff] [blame] | 116 | /** |
| 117 | * @brief Get the scale from the sensor. |
| 118 | * |
| 119 | * @return - Scale value |
| 120 | */ |
| 121 | inline int64_t getScale(void) |
| 122 | { |
| 123 | return scale; |
| 124 | } |
| 125 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 126 | private: |
| 127 | /** @brief Sensor object's identifiers */ |
| 128 | SensorSet::key_type sensor; |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 129 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 130 | /** @brief Hwmon sysfs access. */ |
| 131 | const hwmonio::HwmonIO& ioAccess; |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 132 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 133 | /** @brief Physical device sysfs path. */ |
| 134 | const std::string& devPath; |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 135 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 136 | /** @brief Structure for storing sensor adjustments */ |
| 137 | valueAdjust sensorAdjusts; |
Patrick Venture | b28f432 | 2018-09-14 10:19:14 -0700 | [diff] [blame] | 138 | |
| 139 | /** @brief Optional pointer to GPIO handle. */ |
| 140 | std::unique_ptr<gpioplus::Handle> handle; |
| 141 | |
| 142 | /** @brief default pause after unlocking gpio. */ |
| 143 | static constexpr std::chrono::milliseconds pause{500}; |
James Feist | ee73f5b | 2018-08-01 16:31:42 -0700 | [diff] [blame] | 144 | |
| 145 | /** @brief sensor scale from configuration. */ |
| 146 | int64_t scale; |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 147 | }; |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 148 | |
| 149 | } // namespace sensor |