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