blob: 7005ea9b39ccb55e60ca2b294d1d24ac05229afe [file] [log] [blame]
Matthew Barth35819382018-04-18 14:53:01 -05001#pragma once
2
Matthew Barth9c431062018-05-07 13:55:29 -05003#include "hwmonio.hpp"
Patrick Venture043d3232018-08-31 10:10:53 -07004#include "sensorset.hpp"
5#include "types.hpp"
6
7#include <unordered_set>
Matthew Barth35819382018-04-18 14:53:01 -05008
9namespace sensor
10{
11
Matthew Barthcb3daaf2018-05-07 15:03:16 -050012struct valueAdjust
13{
14 double gain = 1.0;
15 int offset = 0;
16 std::unordered_set<int> rmRCs;
17};
18
Matthew Barth9c431062018-05-07 13:55:29 -050019/** @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 */
25class Sensor
26{
Patrick Venture043d3232018-08-31 10:10:53 -070027 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 Barth9c431062018-05-07 13:55:29 -050034
Patrick Venture043d3232018-08-31 10:10:53 -070035 /**
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 Barth2e41b132018-05-07 14:15:45 -050045
Patrick Venture043d3232018-08-31 10:10:53 -070046 /**
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 Barthcb3daaf2018-05-07 15:03:16 -050054
Patrick Venture043d3232018-08-31 10:10:53 -070055 /**
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 Barthac473092018-05-07 14:41:46 -050064
Patrick Venture043d3232018-08-31 10:10:53 -070065 /**
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 Barthcb3daaf2018-05-07 15:03:16 -050075
Patrick Venture043d3232018-08-31 10:10:53 -070076 /**
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 Barthcb3daaf2018-05-07 15:03:16 -050090
Patrick Venture043d3232018-08-31 10:10:53 -070091 /**
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 Barth9c431062018-05-07 13:55:29 -0500103
Patrick Venture043d3232018-08-31 10:10:53 -0700104 private:
105 /** @brief Sensor object's identifiers */
106 SensorSet::key_type sensor;
Matthew Barth9c431062018-05-07 13:55:29 -0500107
Patrick Venture043d3232018-08-31 10:10:53 -0700108 /** @brief Hwmon sysfs access. */
109 const hwmonio::HwmonIO& ioAccess;
Matthew Barth2e41b132018-05-07 14:15:45 -0500110
Patrick Venture043d3232018-08-31 10:10:53 -0700111 /** @brief Physical device sysfs path. */
112 const std::string& devPath;
Matthew Barthcb3daaf2018-05-07 15:03:16 -0500113
Patrick Venture043d3232018-08-31 10:10:53 -0700114 /** @brief Structure for storing sensor adjustments */
115 valueAdjust sensorAdjusts;
Matthew Barth2e41b132018-05-07 14:15:45 -0500116};
Matthew Barth35819382018-04-18 14:53:01 -0500117
118} // namespace sensor