1 #pragma once 2 3 #include "conf.hpp" 4 #include "controller.hpp" 5 #include "pidcontroller.hpp" 6 #include "sensors/manager.hpp" 7 #include "sensors/sensor.hpp" 8 #include "tuning.hpp" 9 #include "zone_interface.hpp" 10 11 #include <sdbusplus/bus.hpp> 12 #include <sdbusplus/server.hpp> 13 #include <xyz/openbmc_project/Control/Mode/server.hpp> 14 15 #include <fstream> 16 #include <map> 17 #include <memory> 18 #include <set> 19 #include <string> 20 #include <vector> 21 22 template <typename... T> 23 using ServerObject = typename sdbusplus::server::object::object<T...>; 24 using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode; 25 using ModeObject = ServerObject<ModeInterface>; 26 27 namespace pid_control 28 { 29 30 /* 31 * The PIDZone inherits from the Mode object so that it can listen for control 32 * mode changes. It primarily holds all PID loops and holds the sensor value 33 * cache that's used per iteration of the PID loops. 34 */ 35 class PIDZone : public ZoneInterface, public ModeObject 36 { 37 public: 38 PIDZone(int64_t zone, double minThermalOutput, double failSafePercent, 39 const SensorManager& mgr, sdbusplus::bus::bus& bus, 40 const char* objPath, bool defer) : 41 ModeObject(bus, objPath, defer), 42 _zoneId(zone), _maximumSetPoint(), 43 _minThermalOutputSetPt(minThermalOutput), 44 _failSafePercent(failSafePercent), _mgr(mgr) 45 { 46 if (loggingEnabled) 47 { 48 _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log"); 49 } 50 } 51 52 double getMaxSetPointRequest(void) const override; 53 bool getManualMode(void) const; 54 55 /* Could put lock around this since it's accessed from two threads, but 56 * only one reader/one writer. 57 */ 58 void setManualMode(bool mode); 59 bool getFailSafeMode(void) const override; 60 int64_t getZoneID(void) const; 61 void addSetPoint(double setpoint) override; 62 void addRPMCeiling(double ceiling) override; 63 void clearSetPoints(void); 64 void clearRPMCeilings(void); 65 double getFailSafePercent(void) const override; 66 double getMinThermalSetpoint(void) const; 67 68 Sensor* getSensor(const std::string& name) override; 69 void determineMaxSetPointRequest(void); 70 void updateFanTelemetry(void); 71 void updateSensors(void); 72 void initializeCache(void); 73 void dumpCache(void); 74 void processFans(void); 75 void processThermals(void); 76 77 void addFanPID(std::unique_ptr<Controller> pid); 78 void addThermalPID(std::unique_ptr<Controller> pid); 79 double getCachedValue(const std::string& name) override; 80 void addFanInput(const std::string& fan); 81 void addThermalInput(const std::string& therm); 82 83 void initializeLog(void); 84 std::ofstream& getLogHandle(void); 85 86 /* Method for setting the manual mode over dbus */ 87 bool manual(bool value) override; 88 /* Method for reading whether in fail-safe mode over dbus */ 89 bool failSafe() const override; 90 91 private: 92 std::ofstream _log; 93 94 const int64_t _zoneId; 95 double _maximumSetPoint = 0; 96 bool _manualMode = false; 97 const double _minThermalOutputSetPt; 98 const double _failSafePercent; 99 100 std::set<std::string> _failSafeSensors; 101 102 std::vector<double> _SetPoints; 103 std::vector<double> _RPMCeilings; 104 std::vector<std::string> _fanInputs; 105 std::vector<std::string> _thermalInputs; 106 std::map<std::string, double> _cachedValuesByName; 107 const SensorManager& _mgr; 108 109 std::vector<std::unique_ptr<Controller>> _fans; 110 std::vector<std::unique_ptr<Controller>> _thermals; 111 }; 112 113 } // namespace pid_control 114