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 if (type == "margin")
27     {
28         layer = "temperature";
29     }
30     else
31     {
32         layer = "unknown"; // TODO(venture): Need to handle.
33     }
34 
35     return std::string("/xyz/openbmc_project/sensors/" + layer + "/" + id);
36 }
37 
38 std::string getMatch(const std::string& type, const std::string& id)
39 {
40     return std::string("type='signal',"
41                        "interface='org.freedesktop.DBus.Properties',"
42                        "member='PropertiesChanged',"
43                        "path='" +
44                        getSensorPath(type, id) + "'");
45 }
46 
47 bool validType(const std::string& type)
48 {
49     static std::set<std::string> valid = {"fan", "temp", "margin"};
50     return (valid.find(type) != valid.end());
51 }
52 
53 void scaleSensorReading(const double min, const double max, double& value)
54 {
55     if (max <= 0 || max <= min)
56     {
57         return;
58     }
59     value -= min;
60     value /= (max - min);
61 }
62 
63 } // namespace pid_control
64