summaryrefslogtreecommitdiffstats
path: root/hwmon.hpp
blob: 7e005280ef14a3317310204eb46ea8c11b509189 (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
#pragma once

#include "interface.hpp"

#include <string>
#include <tuple>

namespace hwmon
{
namespace entry
{
static constexpr auto cinput = "input";
static constexpr auto clabel = "label";
static constexpr auto ctarget = "target";
static constexpr auto cenable = "enable";
static constexpr auto cfault = "fault";
static constexpr auto crawpwm = "";

static const std::string input = cinput;
static const std::string label = clabel;
static const std::string target = ctarget;
static const std::string enable = cenable;
static const std::string fault = cfault;
static const std::string rawpwm = crawpwm;
} // namespace entry

namespace type
{
static constexpr auto cfan = "fan";
static constexpr auto ctemp = "temp";
static constexpr auto cvolt = "in";
static constexpr auto ccurr = "curr";
static constexpr auto cenergy = "energy";
static constexpr auto cpower = "power";
static constexpr auto cpwm = "pwm";
static constexpr auto cfreq = "freq";

static const std::string fan = cfan;
static const std::string temp = ctemp;
static const std::string volt = cvolt;
static const std::string curr = ccurr;
static const std::string energy = cenergy;
static const std::string power = cpower;
static const std::string pwm = cpwm;
static const std::string freq = cfreq;
} // namespace type

static constexpr auto typeAttrMap = {
    // 1 - hwmon class
    // 2 - unit
    // 3 - sysfs scaling factor
    // 4 - namespace
    std::make_tuple(hwmon::type::ctemp, ValueInterface::Unit::DegreesC, -3,
                    "temperature"),
    std::make_tuple(hwmon::type::cfan, ValueInterface::Unit::RPMS, 0,
                    "fan_tach"),
    std::make_tuple(hwmon::type::cvolt, ValueInterface::Unit::Volts, -3,
                    "voltage"),
    std::make_tuple(hwmon::type::ccurr, ValueInterface::Unit::Amperes, -3,
                    "current"),
    std::make_tuple(hwmon::type::cenergy, ValueInterface::Unit::Joules, -6,
                    "energy"),
    std::make_tuple(hwmon::type::cpower, ValueInterface::Unit::Watts, -6,
                    "power"),
    std::make_tuple(hwmon::type::cfreq, ValueInterface::Unit::MHz, 0,
                    "frequency"),
};

inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
{
    return std::get<0>(attrs);
}

inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
{
    return std::get<1>(attrs);
}

inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
{
    return std::get<2>(attrs);
}

inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
{
    return std::get<3>(attrs);
}

using AttributeIterator = decltype(*typeAttrMap.begin());
using Attributes =
    std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;

/** @brief Get Attribute tuple for the type
 *
 *  Given a type, it tries to find the corresponding tuple
 *
 *  @param[in] type the sensor type
 *  @param[in,out] A pointer to the Attribute tuple
 */
bool getAttributes(const std::string& type, Attributes& attributes);

} //  namespace hwmon

// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud