blob: e5ed60fed7c618d39cbab16ce8bce5abe58f4e67 [file] [log] [blame]
Andrew Jefferye73bd0a2023-01-25 10:39:57 +10301#include "SensorPaths.hpp"
Zev Weiss6b6891c2021-04-22 02:46:21 -05002
Ed Tanous6cb732a2021-02-18 15:33:51 -08003#include <regex>
4#include <string>
5
6namespace sensor_paths
7{
8
9// This is an allowlist of the units a sensor can measure. Should be in sync
10// with
Konstantin Aladyshevce6bcdf2022-06-09 20:03:46 +030011// phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml#L38
Ed Tanous6cb732a2021-02-18 15:33:51 -080012
13std::string getPathForUnits(const std::string& units)
14{
Zev Weiss6b6891c2021-04-22 02:46:21 -050015 if (units == "DegreesC" || units == unitDegreesC)
Ed Tanous6cb732a2021-02-18 15:33:51 -080016 {
17 return "temperature";
18 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050019 if (units == "RPMS" || units == unitRPMs)
Ed Tanous6cb732a2021-02-18 15:33:51 -080020 {
21 return "fan_tach";
22 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050023 if (units == "Volts" || units == unitVolts)
Ed Tanous6cb732a2021-02-18 15:33:51 -080024 {
25 return "voltage";
26 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050027 if (units == "Meters" || units == unitMeters)
Ed Tanous6cb732a2021-02-18 15:33:51 -080028 {
29 return "altitude";
30 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050031 if (units == "Amperes" || units == unitAmperes)
Ed Tanous6cb732a2021-02-18 15:33:51 -080032 {
33 return "current";
34 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050035 if (units == "Watts" || units == unitWatts)
Ed Tanous6cb732a2021-02-18 15:33:51 -080036 {
37 return "power";
38 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050039 if (units == "Joules" || units == unitJoules)
Ed Tanous6cb732a2021-02-18 15:33:51 -080040 {
41 return "energy";
42 }
Zev Weiss6b6891c2021-04-22 02:46:21 -050043 if (units == "Percent" || units == unitPercent)
Ed Tanous6cb732a2021-02-18 15:33:51 -080044 {
45 return "Utilization";
46 }
Bruce Mitchell5a86e562021-12-10 12:26:22 -060047 if (units == "Pascals" || units == unitPascals)
48 {
49 return "pressure";
50 }
Ed Tanous6cb732a2021-02-18 15:33:51 -080051 return "";
52}
53
54std::string escapePathForDbus(const std::string& name)
55{
56 return std::regex_replace(name, std::regex("[^a-zA-Z0-9_/]+"), "_");
57}
58
59} // namespace sensor_paths