1 #include "SensorPaths.hpp" 2 3 #include <regex> 4 #include <string> 5 6 namespace sensor_paths 7 { 8 9 // This is an allowlist of the units a sensor can measure. Should be in sync 10 // with 11 // phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml#L38 12 getPathForUnits(const std::string & units)13std::string getPathForUnits(const std::string& units) 14 { 15 if (units == "DegreesC" || units == unitDegreesC) 16 { 17 return "temperature"; 18 } 19 if (units == "RPMS" || units == unitRPMs) 20 { 21 return "fan_tach"; 22 } 23 if (units == "Volts" || units == unitVolts) 24 { 25 return "voltage"; 26 } 27 if (units == "Meters" || units == unitMeters) 28 { 29 return "altitude"; 30 } 31 if (units == "Amperes" || units == unitAmperes) 32 { 33 return "current"; 34 } 35 if (units == "Watts" || units == unitWatts) 36 { 37 return "power"; 38 } 39 if (units == "Joules" || units == unitJoules) 40 { 41 return "energy"; 42 } 43 if (units == "Percent" || units == unitPercent) 44 { 45 return "utilization"; 46 } 47 if (units == "Pascals" || units == unitPascals) 48 { 49 return "pressure"; 50 } 51 return ""; 52 } 53 escapePathForDbus(const std::string & name)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 60