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 | |
| 7 | #include <unordered_set> |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 8 | |
| 9 | namespace sensor |
| 10 | { |
| 11 | |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 12 | struct valueAdjust |
| 13 | { |
| 14 | double gain = 1.0; |
| 15 | int offset = 0; |
| 16 | std::unordered_set<int> rmRCs; |
| 17 | }; |
| 18 | |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 19 | /** @class Sensor |
| 20 | * @brief Sensor object based on a SensorSet container's key type |
| 21 | * @details Sensor object to create and modify an associated device's sensor |
| 22 | * attributes based on the key type of each sensor in the set provided by the |
| 23 | * device. |
| 24 | */ |
| 25 | class Sensor |
| 26 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 27 | public: |
| 28 | Sensor() = delete; |
| 29 | Sensor(const Sensor&) = delete; |
| 30 | Sensor(Sensor&&) = default; |
| 31 | Sensor& operator=(const Sensor&) = delete; |
| 32 | Sensor& operator=(Sensor&&) = default; |
| 33 | ~Sensor() = default; |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 34 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 35 | /** |
| 36 | * @brief Constructs Sensor object |
| 37 | * |
| 38 | * @param[in] sensor - A pair of sensor indentifiers |
| 39 | * @param[in] ioAccess - Hwmon sysfs access |
| 40 | * @param[in] devPath - Device sysfs path |
| 41 | */ |
| 42 | explicit Sensor(const SensorSet::key_type& sensor, |
| 43 | const hwmonio::HwmonIO& ioAccess, |
| 44 | const std::string& devPath); |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 45 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 46 | /** |
| 47 | * @brief Adds any sensor removal return codes for the sensor |
| 48 | * @details Add all return codes defined within a device's config file |
| 49 | * for the entire device or for the specific sensor. |
| 50 | * |
| 51 | * @param[in] rcList - List of return codes found for the sensor |
| 52 | */ |
| 53 | void addRemoveRCs(const std::string& rcList); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 54 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 55 | /** |
| 56 | * @brief Get the adjustments struct for the sensor |
| 57 | * |
| 58 | * @return - Sensor adjustment struct |
| 59 | */ |
| 60 | inline const valueAdjust& getAdjusts() |
| 61 | { |
| 62 | return sensorAdjusts; |
| 63 | } |
Matthew Barth | ac47309 | 2018-05-07 14:41:46 -0500 | [diff] [blame] | 64 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 65 | /** |
| 66 | * @brief Adjusts a sensor value |
| 67 | * @details Adjusts the value given by any gain and/or offset defined |
| 68 | * for this sensor object and returns that adjusted value. |
| 69 | * |
| 70 | * @param[in] value - Value to be adjusted |
| 71 | * |
| 72 | * @return - Adjusted sensor value |
| 73 | */ |
| 74 | int64_t adjustValue(int64_t value); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 75 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 76 | /** |
| 77 | * @brief Add value interface and value property for sensor |
| 78 | * @details When a sensor has an associated input file, the Sensor.Value |
| 79 | * interface is added along with setting the Value property to the |
| 80 | * corresponding value found in the input file. |
| 81 | * |
| 82 | * @param[in] retryIO - Hwmon sysfs file retry constraints |
| 83 | * (number of and delay between) |
| 84 | * @param[in] info - Sensor object information |
| 85 | * |
| 86 | * @return - Shared pointer to the value object |
| 87 | */ |
| 88 | std::shared_ptr<ValueObject> addValue(const RetryIO& retryIO, |
| 89 | ObjectInfo& info); |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 90 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 91 | /** |
| 92 | * @brief Add status interface and functional property for sensor |
| 93 | * @details When a sensor has an associated fault file, the |
| 94 | * OperationalStatus interface is added along with setting the |
| 95 | * Functional property to the corresponding value found in the |
| 96 | * fault file. |
| 97 | * |
| 98 | * @param[in] info - Sensor object information |
| 99 | * |
| 100 | * @return - Shared pointer to the status object |
| 101 | */ |
| 102 | std::shared_ptr<StatusObject> addStatus(ObjectInfo& info); |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 103 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 104 | private: |
| 105 | /** @brief Sensor object's identifiers */ |
| 106 | SensorSet::key_type sensor; |
Matthew Barth | 9c43106 | 2018-05-07 13:55:29 -0500 | [diff] [blame] | 107 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 108 | /** @brief Hwmon sysfs access. */ |
| 109 | const hwmonio::HwmonIO& ioAccess; |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 110 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 111 | /** @brief Physical device sysfs path. */ |
| 112 | const std::string& devPath; |
Matthew Barth | cb3daaf | 2018-05-07 15:03:16 -0500 | [diff] [blame] | 113 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 114 | /** @brief Structure for storing sensor adjustments */ |
| 115 | valueAdjust sensorAdjusts; |
Matthew Barth | 2e41b13 | 2018-05-07 14:15:45 -0500 | [diff] [blame] | 116 | }; |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 117 | |
| 118 | } // namespace sensor |