blob: f10e60b9684679cdfb3968d3fc0e96358e978a3c [file] [log] [blame]
Ed Tanous6cb732a2021-02-18 15:33:51 -08001#include <cstring>
2#include <regex>
3#include <string>
4
5namespace sensor_paths
6{
7
8// This is an allowlist of the units a sensor can measure. Should be in sync
9// with
10// phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Sensor/Value.interface.yaml#L35
11
12std::string getPathForUnits(const std::string& units)
13{
14 if (units == "DegreesC")
15 {
16 return "temperature";
17 }
18 if (units == "RPMS")
19 {
20 return "fan_tach";
21 }
22 if (units == "Volts")
23 {
24 return "voltage";
25 }
26 if (units == "Meters")
27 {
28 return "altitude";
29 }
30 if (units == "Amperes")
31 {
32 return "current";
33 }
34 if (units == "Watts")
35 {
36 return "power";
37 }
38 if (units == "Joules")
39 {
40 return "energy";
41 }
42 if (units == "Percent")
43 {
44 return "Utilization";
45 }
46 return "";
47}
48
49std::string escapePathForDbus(const std::string& name)
50{
51 return std::regex_replace(name, std::regex("[^a-zA-Z0-9_/]+"), "_");
52}
53
54} // namespace sensor_paths