-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathSensorPaths.cpp
59 lines (53 loc) · 1.28 KB
/
SensorPaths.cpp
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
#include "SensorPaths.hpp"
#include <regex>
#include <string>
namespace sensor_paths
{
// This is an allowlist of the units a sensor can measure. Should be in sync
// with
// phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml#L38
std::string getPathForUnits(const std::string& units)
{
if (units == "DegreesC" || units == unitDegreesC)
{
return "temperature";
}
if (units == "RPMS" || units == unitRPMs)
{
return "fan_tach";
}
if (units == "Volts" || units == unitVolts)
{
return "voltage";
}
if (units == "Meters" || units == unitMeters)
{
return "altitude";
}
if (units == "Amperes" || units == unitAmperes)
{
return "current";
}
if (units == "Watts" || units == unitWatts)
{
return "power";
}
if (units == "Joules" || units == unitJoules)
{
return "energy";
}
if (units == "Percent" || units == unitPercent)
{
return "utilization";
}
if (units == "Pascals" || units == unitPascals)
{
return "pressure";
}
return "";
}
std::string escapePathForDbus(const std::string& name)
{
return std::regex_replace(name, std::regex("[^a-zA-Z0-9_/]+"), "_");
}
} // namespace sensor_paths