1 #include "util.hpp" 2 3 #include <cmath> 4 #include <iostream> 5 #include <set> 6 #include <variant> 7 8 using Property = std::string; 9 using Value = std::variant<int64_t, double, std::string, bool>; 10 using PropertyMap = std::map<Property, Value>; 11 12 namespace pid_control 13 { 14 15 std::string getSensorPath(const std::string& type, const std::string& id) 16 { 17 std::string layer = type; 18 if (type == "fan") 19 { 20 layer = "fan_tach"; 21 } 22 else if (type == "temp") 23 { 24 layer = "temperature"; 25 } 26 else 27 { 28 layer = "unknown"; // TODO(venture): Need to handle. 29 } 30 31 return std::string("/xyz/openbmc_project/sensors/" + layer + "/" + id); 32 } 33 34 std::string getMatch(const std::string& type, const std::string& id) 35 { 36 return std::string("type='signal'," 37 "interface='org.freedesktop.DBus.Properties'," 38 "member='PropertiesChanged'," 39 "path='" + 40 getSensorPath(type, id) + "'"); 41 } 42 43 bool validType(const std::string& type) 44 { 45 static std::set<std::string> valid = {"fan", "temp"}; 46 return (valid.find(type) != valid.end()); 47 } 48 49 void scaleSensorReading(const double min, const double max, double& value) 50 { 51 if (max <= 0 || max <= min) 52 { 53 return; 54 } 55 value -= min; 56 value /= (max - min); 57 } 58 59 } // namespace pid_control 60