blob: 565fd01c4a831ab149cb6b72c7437ed843ec2193 [file] [log] [blame]
Matthew Barth35819382018-04-18 14:53:01 -05001#pragma once
2
Matthew Barthcb3daaf2018-05-07 15:03:16 -05003#include <unordered_set>
Matthew Barth9c431062018-05-07 13:55:29 -05004#include "types.hpp"
Matthew Barth35819382018-04-18 14:53:01 -05005#include "sensorset.hpp"
Matthew Barth9c431062018-05-07 13:55:29 -05006#include "hwmonio.hpp"
Matthew Barth35819382018-04-18 14:53:01 -05007
8namespace sensor
9{
10
Matthew Barthcb3daaf2018-05-07 15:03:16 -050011struct valueAdjust
12{
13 double gain = 1.0;
14 int offset = 0;
15 std::unordered_set<int> rmRCs;
16};
17
Matthew Barth9c431062018-05-07 13:55:29 -050018/** @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 */
24class 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 Barth2e41b132018-05-07 14:15:45 -050038 * @param[in] ioAccess - Hwmon sysfs access
39 * @param[in] devPath - Device sysfs path
Matthew Barth9c431062018-05-07 13:55:29 -050040 */
Matthew Barth2e41b132018-05-07 14:15:45 -050041 explicit Sensor(const SensorSet::key_type& sensor,
42 const hwmonio::HwmonIO& ioAccess,
43 const std::string& devPath);
44
45 /**
Matthew Barthcb3daaf2018-05-07 15:03:16 -050046 * @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 /**
55 * @brief Adjusts a sensor value
56 * @details Adjusts the value given by any gain and/or offset defined
57 * for this sensor object and returns that adjusted value.
58 *
59 * @param[in] value - Value to be adjusted
60 *
61 * @return - Adjusted sensor value
62 */
63 int64_t adjustValue(int64_t value);
64
65 /**
66 * @brief Add value interface and value property for sensor
67 * @details When a sensor has an associated input file, the Sensor.Value
68 * interface is added along with setting the Value property to the
69 * corresponding value found in the input file.
70 *
71 * @param[in] retryIO - Hwmon sysfs file retry constraints
72 * (number of and delay between)
73 * @param[in] info - Sensor object information
74 *
75 * @return - Shared pointer to the value object
76 */
77 std::shared_ptr<ValueObject> addValue(
78 const RetryIO& retryIO,
79 ObjectInfo& info);
80
81 /**
Matthew Barth2e41b132018-05-07 14:15:45 -050082 * @brief Add status interface and functional property for sensor
83 * @details When a sensor has an associated fault file, the
84 * OperationalStatus interface is added along with setting the
85 * Functional property to the corresponding value found in the
86 * fault file.
87 *
88 * @param[in] info - Sensor object information
89 *
90 * @return - Shared pointer to the status object
91 */
92 std::shared_ptr<StatusObject> addStatus(
93 ObjectInfo& info);
Matthew Barth9c431062018-05-07 13:55:29 -050094
95 private:
96 /** @brief Sensor object's identifiers */
97 SensorSet::key_type sensor;
Matthew Barth9c431062018-05-07 13:55:29 -050098
Matthew Barth2e41b132018-05-07 14:15:45 -050099 /** @brief Hwmon sysfs access. */
100 const hwmonio::HwmonIO& ioAccess;
101
102 /** @brief Physical device sysfs path. */
103 const std::string& devPath;
Matthew Barthcb3daaf2018-05-07 15:03:16 -0500104
105 /** @brief Structure for storing sensor adjustments */
106 valueAdjust sensorAdjusts;
Matthew Barth2e41b132018-05-07 14:15:45 -0500107};
Matthew Barth35819382018-04-18 14:53:01 -0500108
109} // namespace sensor