1 #pragma once 2 3 #include <algorithm> 4 #include <format> 5 #include <ranges> 6 #include <string> 7 #include <string_view> 8 #include <utility> 9 #include <vector> 10 11 namespace redfish 12 { 13 namespace sensor_utils 14 { 15 16 inline std::string getSensorId(std::string_view sensorName, 17 std::string_view sensorType) 18 { 19 std::string normalizedType(sensorType); 20 auto remove = std::ranges::remove(normalizedType, '_'); 21 normalizedType.erase(std::ranges::begin(remove), normalizedType.end()); 22 23 return std::format("{}_{}", normalizedType, sensorName); 24 } 25 26 inline std::pair<std::string, std::string> 27 splitSensorNameAndType(std::string_view sensorId) 28 { 29 size_t index = sensorId.find('_'); 30 if (index == std::string::npos) 31 { 32 return std::make_pair<std::string, std::string>("", ""); 33 } 34 std::string sensorType{sensorId.substr(0, index)}; 35 std::string sensorName{sensorId.substr(index + 1)}; 36 // fan_pwm and fan_tach need special handling 37 if (sensorType == "fantach" || sensorType == "fanpwm") 38 { 39 sensorType.insert(3, 1, '_'); 40 } 41 return std::make_pair(sensorType, sensorName); 42 } 43 44 } // namespace sensor_utils 45 } // namespace redfish 46