Josh Lehan | 2a40e93 | 2020-09-02 11:48:14 -0700 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstring> |
| 4 | #include <string> |
| 5 | |
| 6 | namespace sensors |
| 7 | { |
| 8 | |
| 9 | // This is the leading prefix of the object path for sensors. |
| 10 | // The full path is /xyz/openbmc_project/sensors/<Measure>/<Name> |
| 11 | // Note C++20 would allow this to be "constexpr std::string" |
| 12 | const char* objectPathPrefix = "/xyz/openbmc_project/sensors/"; |
| 13 | |
| 14 | // This is an allowlist of the units a sensor can measure. Should be in sync |
| 15 | // with |
| 16 | // phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Sensor/Value.interface.yaml#L35 |
| 17 | |
| 18 | std::string getPathForUnits(const std::string& units) |
| 19 | { |
| 20 | if (units == "DegreesC") |
| 21 | { |
| 22 | return "temperature"; |
| 23 | } |
| 24 | if (units == "RPMS") |
| 25 | { |
| 26 | return "fan_tach"; |
| 27 | } |
| 28 | if (units == "Volts") |
| 29 | { |
| 30 | return "voltage"; |
| 31 | } |
| 32 | if (units == "Meters") |
| 33 | { |
| 34 | return "altitude"; |
| 35 | } |
| 36 | if (units == "Amperes") |
| 37 | { |
| 38 | return "current"; |
| 39 | } |
| 40 | if (units == "Watts") |
| 41 | { |
| 42 | return "power"; |
| 43 | } |
| 44 | if (units == "Joules") |
| 45 | { |
| 46 | return "energy"; |
| 47 | } |
| 48 | if (units == "Percent") |
| 49 | { |
| 50 | return "Utilization"; |
| 51 | } |
| 52 | return ""; |
| 53 | } |
| 54 | |
| 55 | } // namespace sensors |