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