xref: /openbmc/phosphor-hwmon/hwmon.hpp (revision c635e860)
1 #pragma once
2 
3 #include <string>
4 #include <tuple>
5 
6 #include "interface.hpp"
7 
8 namespace hwmon
9 {
10 namespace entry
11 {
12 static constexpr auto cinput = "input";
13 static constexpr auto clabel = "label";
14 static constexpr auto ctarget = "target";
15 static constexpr auto cenable = "enable";
16 
17 static const std::string input = cinput;
18 static const std::string label = clabel;
19 static const std::string target = ctarget;
20 static const std::string enable = cenable;
21 }
22 
23 namespace type
24 {
25 static constexpr auto cfan = "fan";
26 static constexpr auto ctemp = "temp";
27 static constexpr auto cvolt = "in";
28 static constexpr auto ccurr = "curr";
29 static constexpr auto cenergy = "energy";
30 static constexpr auto cpower = "power";
31 static constexpr auto cpwm = "pwm";
32 
33 
34 static const std::string fan = cfan;
35 static const std::string temp = ctemp;
36 static const std::string volt = cvolt;
37 static const std::string curr = ccurr;
38 static const std::string energy = cenergy;
39 static const std::string power = cpower;
40 static const std::string pwm = cpwm;
41 }
42 
43 static constexpr auto typeAttrMap =
44 {
45     // 1 - hwmon class
46     // 2 - unit
47     // 3 - sysfs scaling factor
48     // 4 - namespace
49     std::make_tuple(
50         hwmon::type::ctemp,
51         ValueInterface::Unit::DegreesC,
52         -3,
53         "temperature"),
54     std::make_tuple(
55         hwmon::type::cfan,
56         ValueInterface::Unit::RPMS,
57         0,
58         "fan_tach"),
59     std::make_tuple(
60         hwmon::type::cvolt,
61         ValueInterface::Unit::Volts,
62         -3,
63         "voltage"),
64     std::make_tuple(
65         hwmon::type::ccurr,
66         ValueInterface::Unit::Amperes,
67         -3,
68         "current"),
69     std::make_tuple(
70         hwmon::type::cenergy,
71         ValueInterface::Unit::Joules,
72         -6,
73         "energy"),
74     std::make_tuple(
75         hwmon::type::cpower,
76         ValueInterface::Unit::Watts,
77         -6,
78         "power"),
79 };
80 
81 inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
82 {
83     return std::get<0>(attrs);
84 }
85 
86 inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
87 {
88     return std::get<1>(attrs);
89 }
90 
91 inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
92 {
93     return std::get<2>(attrs);
94 }
95 
96 inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
97 {
98     return std::get<3>(attrs);
99 }
100 
101 using AttributeIterator = decltype(*typeAttrMap.begin());
102 using Attributes
103     = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
104 
105 /** @brief Get Attribute tuple for the type
106  *
107  *  Given a type, it tries to find the corresponding tuple
108  *
109  *  @param[in] type the sensor type
110  *  @param[in,out] A pointer to the Attribute tuple
111  */
112 bool getAttributes(const std::string& type, Attributes& attributes);
113 
114 }  //  namespace hwmon
115 
116 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
117