xref: /openbmc/phosphor-pid-control/util.hpp (revision efda1ced)
1 #pragma once
2 
3 #include "conf.hpp"
4 #include "pid/ec/pid.hpp"
5 
6 #include <phosphor-logging/log.hpp>
7 #include <sdbusplus/bus.hpp>
8 
9 #include <cstdint>
10 #include <limits>
11 #include <map>
12 #include <string>
13 
14 namespace pid_control
15 {
16 
17 void tryRestartControlLoops(bool first = true);
18 
19 /*
20  * Given a configuration structure, fill out the information we use within the
21  * PID loop.
22  */
23 void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial);
24 
25 void dumpPIDStruct(ec::pid_info_t* info);
26 
27 struct SensorThresholds
28 {
29     double lowerThreshold = std::numeric_limits<double>::quiet_NaN();
30     double upperThreshold = std::numeric_limits<double>::quiet_NaN();
31 };
32 
33 const std::string sensorintf = "xyz.openbmc_project.Sensor.Value";
34 const std::string criticalThreshInf =
35     "xyz.openbmc_project.Sensor.Threshold.Critical";
36 const std::string propertiesintf = "org.freedesktop.DBus.Properties";
37 
38 /*
39  * Given a path that optionally has a glob portion, fill it out.
40  */
41 std::string FixupPath(std::string original);
42 
43 /*
44  * Splice together two vectors, "Inputs" and "TempToMargin" from JSON,
45  * into one vector of SensorInput structures containing info from both.
46  */
47 std::vector<conf::SensorInput>
48     spliceInputs(const std::vector<std::string>& inputNames,
49                  const std::vector<double>& inputTempToMargin,
50                  const std::vector<std::string>& missingAcceptableNames);
51 
52 /*
53  * Recovers the original "Inputs" vector from spliceInputs().
54  */
55 std::vector<std::string>
56     splitNames(const std::vector<conf::SensorInput>& sensorInputs);
57 
58 /*
59  * Dump active configuration.
60  */
61 void debugPrint(const std::map<std::string, conf::SensorConfig>& sensorConfig,
62                 const std::map<int64_t, conf::PIDConf>& zoneConfig,
63                 const std::map<int64_t, conf::ZoneConfig>& zoneDetailsConfig);
64 
65 } // namespace pid_control
66