Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 1 | #include <SensorPaths.hpp> |
| 2 | |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 3 | #include <cstring> |
| 4 | #include <regex> |
| 5 | #include <string> |
| 6 | |
| 7 | namespace sensor_paths |
| 8 | { |
| 9 | |
| 10 | // This is an allowlist of the units a sensor can measure. Should be in sync |
| 11 | // with |
| 12 | // phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Sensor/Value.interface.yaml#L35 |
| 13 | |
| 14 | std::string getPathForUnits(const std::string& units) |
| 15 | { |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 16 | if (units == "DegreesC" || units == unitDegreesC) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 17 | { |
| 18 | return "temperature"; |
| 19 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 20 | if (units == "RPMS" || units == unitRPMs) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 21 | { |
| 22 | return "fan_tach"; |
| 23 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 24 | if (units == "Volts" || units == unitVolts) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 25 | { |
| 26 | return "voltage"; |
| 27 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 28 | if (units == "Meters" || units == unitMeters) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 29 | { |
| 30 | return "altitude"; |
| 31 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 32 | if (units == "Amperes" || units == unitAmperes) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 33 | { |
| 34 | return "current"; |
| 35 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 36 | if (units == "Watts" || units == unitWatts) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 37 | { |
| 38 | return "power"; |
| 39 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 40 | if (units == "Joules" || units == unitJoules) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 41 | { |
| 42 | return "energy"; |
| 43 | } |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 44 | if (units == "Percent" || units == unitPercent) |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 45 | { |
| 46 | return "Utilization"; |
| 47 | } |
Bruce Mitchell | 5a86e56 | 2021-12-10 12:26:22 -0600 | [diff] [blame] | 48 | if (units == "Pascals" || units == unitPascals) |
| 49 | { |
| 50 | return "pressure"; |
| 51 | } |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 52 | return ""; |
| 53 | } |
| 54 | |
| 55 | std::string escapePathForDbus(const std::string& name) |
| 56 | { |
| 57 | return std::regex_replace(name, std::regex("[^a-zA-Z0-9_/]+"), "_"); |
| 58 | } |
| 59 | |
| 60 | } // namespace sensor_paths |