1 #pragma once 2 3 #include "hwmonio.hpp" 4 #include "sensorset.hpp" 5 #include "types.hpp" 6 7 #include <unordered_set> 8 9 namespace sensor 10 { 11 12 struct valueAdjust 13 { 14 double gain = 1.0; 15 int offset = 0; 16 std::unordered_set<int> rmRCs; 17 }; 18 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 { 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; 34 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); 45 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); 54 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 } 64 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); 75 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); 90 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); 103 104 private: 105 /** @brief Sensor object's identifiers */ 106 SensorSet::key_type sensor; 107 108 /** @brief Hwmon sysfs access. */ 109 const hwmonio::HwmonIO& ioAccess; 110 111 /** @brief Physical device sysfs path. */ 112 const std::string& devPath; 113 114 /** @brief Structure for storing sensor adjustments */ 115 valueAdjust sensorAdjusts; 116 }; 117 118 } // namespace sensor 119