summaryrefslogtreecommitdiffstats
path: root/sensor.hpp
blob: 565fd01c4a831ab149cb6b72c7437ed843ec2193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once

#include <unordered_set>
#include "types.hpp"
#include "sensorset.hpp"
#include "hwmonio.hpp"

namespace sensor
{

struct valueAdjust
{
    double gain = 1.0;
    int offset = 0;
    std::unordered_set<int> rmRCs;
};

/** @class Sensor
 *  @brief Sensor object based on a SensorSet container's key type
 *  @details Sensor object to create and modify an associated device's sensor
 *  attributes based on the key type of each sensor in the set provided by the
 *  device.
 */
class Sensor
{
    public:
        Sensor() = delete;
        Sensor(const Sensor&) = delete;
        Sensor(Sensor&&) = default;
        Sensor& operator=(const Sensor&) = delete;
        Sensor& operator=(Sensor&&) = default;
        ~Sensor() = default;

        /**
         * @brief Constructs Sensor object
         *
         * @param[in] sensor - A pair of sensor indentifiers
         * @param[in] ioAccess - Hwmon sysfs access
         * @param[in] devPath - Device sysfs path
         */
        explicit Sensor(const SensorSet::key_type& sensor,
                        const hwmonio::HwmonIO& ioAccess,
                        const std::string& devPath);

        /**
         * @brief Adds any sensor removal return codes for the sensor
         * @details Add all return codes defined within a device's config file
         * for the entire device or for the specific sensor.
         *
         * @param[in] rcList - List of return codes found for the sensor
         */
        void addRemoveRCs(const std::string& rcList);

        /**
         * @brief Adjusts a sensor value
         * @details Adjusts the value given by any gain and/or offset defined
         * for this sensor object and returns that adjusted value.
         *
         * @param[in] value - Value to be adjusted
         *
         * @return - Adjusted sensor value
         */
        int64_t adjustValue(int64_t value);

        /**
         * @brief Add value interface and value property for sensor
         * @details When a sensor has an associated input file, the Sensor.Value
         * interface is added along with setting the Value property to the
         * corresponding value found in the input file.
         *
         * @param[in] retryIO - Hwmon sysfs file retry constraints
         *                      (number of and delay between)
         * @param[in] info - Sensor object information
         *
         * @return - Shared pointer to the value object
         */
        std::shared_ptr<ValueObject> addValue(
                const RetryIO& retryIO,
                ObjectInfo& info);

        /**
         * @brief Add status interface and functional property for sensor
         * @details When a sensor has an associated fault file, the
         * OperationalStatus interface is added along with setting the
         * Functional property to the corresponding value found in the
         * fault file.
         *
         * @param[in] info - Sensor object information
         *
         * @return - Shared pointer to the status object
         */
        std::shared_ptr<StatusObject> addStatus(
                ObjectInfo& info);

    private:
        /** @brief Sensor object's identifiers */
        SensorSet::key_type sensor;

        /** @brief Hwmon sysfs access. */
        const hwmonio::HwmonIO& ioAccess;

        /** @brief Physical device sysfs path. */
        const std::string& devPath;

        /** @brief Structure for storing sensor adjustments */
        valueAdjust sensorAdjusts;
};

} // namespace sensor
OpenPOWER on IntegriCloud