xref: /openbmc/phosphor-pid-control/util.cpp (revision 8f73ad76)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #include "util.hpp"
17 
18 #include "conf.hpp"
19 
20 #include <cstdint>
21 #include <iostream>
22 #include <map>
23 #include <string>
24 
25 namespace pid_control
26 {
27 
28 void debugPrint(const std::map<std::string, conf::SensorConfig>& sensorConfig,
29                 const std::map<int64_t, conf::PIDConf>& zoneConfig,
30                 const std::map<int64_t, conf::ZoneConfig>& zoneDetailsConfig)
31 {
32     if constexpr (!conf::DEBUG)
33     {
34         return;
35     }
36     // print sensor config
37     std::cout << "sensor config:\n";
38     std::cout << "{\n";
39     for (const auto& pair : sensorConfig)
40     {
41 
42         std::cout << "\t{" << pair.first << ",\n\t\t{";
43         std::cout << pair.second.type << ", ";
44         std::cout << pair.second.readPath << ", ";
45         std::cout << pair.second.writePath << ", ";
46         std::cout << pair.second.min << ", ";
47         std::cout << pair.second.max << ", ";
48         std::cout << pair.second.timeout << ", ";
49         std::cout << pair.second.unavailableAsFailed << "},\n\t},\n";
50     }
51     std::cout << "}\n\n";
52     std::cout << "ZoneDetailsConfig\n";
53     std::cout << "{\n";
54     for (const auto& zone : zoneDetailsConfig)
55     {
56         std::cout << "\t{" << zone.first << ",\n";
57         std::cout << "\t\t{" << zone.second.minThermalOutput << ", ";
58         std::cout << zone.second.failsafePercent << "}\n\t},\n";
59     }
60     std::cout << "}\n\n";
61     std::cout << "ZoneConfig\n";
62     std::cout << "{\n";
63     for (const auto& zone : zoneConfig)
64     {
65         std::cout << "\t{" << zone.first << "\n";
66         for (const auto& pidconf : zone.second)
67         {
68             std::cout << "\t\t{" << pidconf.first << ",\n";
69             std::cout << "\t\t\t{" << pidconf.second.type << ",\n";
70             std::cout << "\t\t\t{";
71             for (const auto& input : pidconf.second.inputs)
72             {
73                 std::cout << "\n\t\t\t" << input << ",\n";
74             }
75             std::cout << "\t\t\t}\n";
76             std::cout << "\t\t\t" << pidconf.second.setpoint << ",\n";
77             std::cout << "\t\t\t{" << pidconf.second.pidInfo.ts << ",\n";
78             std::cout << "\t\t\t" << pidconf.second.pidInfo.proportionalCoeff
79                       << ",\n";
80             std::cout << "\t\t\t" << pidconf.second.pidInfo.integralCoeff
81                       << ",\n";
82             std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdOffset
83                       << ",\n";
84             std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdGain
85                       << ",\n";
86             std::cout << "\t\t\t{" << pidconf.second.pidInfo.integralLimit.min
87                       << "," << pidconf.second.pidInfo.integralLimit.max
88                       << "},\n";
89             std::cout << "\t\t\t{" << pidconf.second.pidInfo.outLim.min << ","
90                       << pidconf.second.pidInfo.outLim.max << "},\n";
91             std::cout << "\t\t\t" << pidconf.second.pidInfo.slewNeg << ",\n";
92             std::cout << "\t\t\t" << pidconf.second.pidInfo.slewPos << ",\n";
93             std::cout << "\t\t\t}\n\t\t}\n";
94         }
95         std::cout << "\t},\n";
96     }
97     std::cout << "}\n\n";
98 }
99 
100 } // namespace pid_control
101