blob: b80dff846d2d4248bb5ff709460d3c33338201e2 [file] [log] [blame]
Patrick Ventureaadb30d2020-08-10 09:17:11 -07001#include "util.hpp"
2
3#include <cmath>
4#include <iostream>
5#include <set>
6#include <variant>
7
8using Property = std::string;
9using Value = std::variant<int64_t, double, std::string, bool>;
10using PropertyMap = std::map<Property, Value>;
11
12namespace pid_control
13{
14
15std::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
34std::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
43bool validType(const std::string& type)
44{
45 static std::set<std::string> valid = {"fan", "temp"};
46 return (valid.find(type) != valid.end());
47}
48
49void scaleSensorReading(const double min, const double max, double& value)
50{
51 if (max <= 0 || max <= min)
52 {
53 return;
54 }
Josh Lehan91fe17f2020-09-20 22:50:26 -070055 value -= min;
Patrick Ventureaadb30d2020-08-10 09:17:11 -070056 value /= (max - min);
57}
58
59} // namespace pid_control