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