xref: /openbmc/dbus-sensors/src/SensorPaths.hpp (revision d85c89518604abc63f9f0121f334277234271dfb)
1 #pragma once
2 
3 #include <array>
4 #include <string>
5 
6 namespace sensor_paths
7 {
8 
9 struct UnitMap
10 {
11     std::string_view dbusPathName;
12     std::string_view dbusUnitName;
13     std::string_view emUnitName;
14 };
15 
16 constexpr std::array<UnitMap, 11> unitsMap = {{
17     {"xyz.openbmc_project.Sensor.Value.Unit.DegreesC", "DegreesC",
18      "temperature"},
19     {"xyz.openbmc_project.Sensor.Value.Unit.RPMS", "RPMS", "fan_tach"},
20     {"xyz.openbmc_project.Sensor.Value.Unit.Volts", "Volts", "voltage"},
21     {"xyz.openbmc_project.Sensor.Value.Unit.Meters", "Meters", "distance"},
22     {"xyz.openbmc_project.Sensor.Value.Unit.Amperes", "Amperes", "current"},
23     {"xyz.openbmc_project.Sensor.Value.Unit.Watts", "Watts", "power"},
24     {"xyz.openbmc_project.Sensor.Value.Unit.Joules", "Joules", "energy"},
25     {"xyz.openbmc_project.Sensor.Value.Unit.Percent", "Percent", "percent"},
26     {"xyz.openbmc_project.Sensor.Value.Unit.CFM", "CFM", "airflow"},
27     {"xyz.openbmc_project.Sensor.Value.Unit.Pascals", "Pascals", "pressure"},
28     {"xyz.openbmc_project.Sensor.Value.Unit.PercentRH", "PercentRH",
29      "humidity"},
30 }};
31 // This is an allowlist of the units a sensor can measure. Should be in sync
32 // with
33 // phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml#L38
34 
35 constexpr const char* unitDegreesC =
36     "xyz.openbmc_project.Sensor.Value.Unit.DegreesC";
37 constexpr const char* unitRPMs = "xyz.openbmc_project.Sensor.Value.Unit.RPMS";
38 constexpr const char* unitVolts = "xyz.openbmc_project.Sensor.Value.Unit.Volts";
39 constexpr const char* unitMeters =
40     "xyz.openbmc_project.Sensor.Value.Unit.Meters";
41 constexpr const char* unitAmperes =
42     "xyz.openbmc_project.Sensor.Value.Unit.Amperes";
43 constexpr const char* unitWatts = "xyz.openbmc_project.Sensor.Value.Unit.Watts";
44 constexpr const char* unitJoules =
45     "xyz.openbmc_project.Sensor.Value.Unit.Joules";
46 constexpr const char* unitPercent =
47     "xyz.openbmc_project.Sensor.Value.Unit.Percent";
48 constexpr const char* unitCFM = "xyz.openbmc_project.Sensor.Value.Unit.CFM";
49 constexpr const char* unitPascals =
50     "xyz.openbmc_project.Sensor.Value.Unit.Pascals";
51 constexpr const char* unitPercentRH =
52     "xyz.openbmc_project.Sensor.Value.Unit.PercentRH";
53 
54 std::string getPathForUnits(const std::string& units);
55 
56 std::string escapePathForDbus(const std::string& name);
57 
58 std::string convertToFullUnits(const std::string& units);
59 
60 } // namespace sensor_paths
61