| Alexander Hansen | 46a755f | 2025-10-27 16:31:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2017 Google Inc |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 3 | |
| 4 | /* Configuration. */ |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 5 | #include "zone.hpp" |
| 6 | |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 7 | #include "conf.hpp" |
| James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 8 | #include "failsafeloggers/failsafe_logger_utility.hpp" |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 9 | #include "interfaces.hpp" |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 10 | #include "pid/controller.hpp" |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 11 | #include "pid/tuning.hpp" |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 12 | |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 15 | #include <algorithm> |
| 16 | #include <chrono> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 17 | #include <cstdint> |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 18 | #include <cstring> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 19 | #include <exception> |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 20 | #include <fstream> |
| 21 | #include <iostream> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 22 | #include <limits> |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 23 | #include <memory> |
| Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 24 | #include <sstream> |
| Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 25 | #include <string> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 26 | #include <string_view> |
| 27 | #include <utility> |
| 28 | #include <vector> |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 29 | |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 30 | using tstamp = std::chrono::high_resolution_clock::time_point; |
| 31 | using namespace std::literals::chrono_literals; |
| 32 | |
| Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 33 | // Enforces minimum duration between events |
| 34 | // Rreturns true if event should be allowed, false if disallowed |
| 35 | bool allowThrottle(const tstamp& now, const std::chrono::seconds& pace) |
| 36 | { |
| 37 | static tstamp then; |
| 38 | static bool first = true; |
| 39 | |
| 40 | if (first) |
| 41 | { |
| 42 | // Special case initialization |
| 43 | then = now; |
| 44 | first = false; |
| 45 | |
| 46 | // Initialization, always allow |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | auto elapsed = now - then; |
| 51 | if (elapsed < pace) |
| 52 | { |
| 53 | // Too soon since last time, disallow |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | // It has been long enough, allow |
| 58 | then = now; |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | namespace pid_control |
| 63 | { |
| 64 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 65 | double DbusPidZone::getMaxSetPointRequest(void) const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 66 | { |
| Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 67 | return _maximumSetPoint; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 70 | bool DbusPidZone::getManualMode(void) const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 71 | { |
| 72 | return _manualMode; |
| 73 | } |
| 74 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 75 | void DbusPidZone::setManualMode(bool mode) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 76 | { |
| 77 | _manualMode = mode; |
| Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 78 | |
| 79 | // If returning to automatic mode, need to restore PWM from PID loop |
| 80 | if (!mode) |
| 81 | { |
| 82 | _redundantWrite = true; |
| 83 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 86 | bool DbusPidZone::getFailSafeMode(void) const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 87 | { |
| 88 | // If any keys are present at least one sensor is in fail safe mode. |
| 89 | return !_failSafeSensors.empty(); |
| 90 | } |
| 91 | |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 92 | FailSafeSensorsMap DbusPidZone::getFailSafeSensors(void) const |
| 93 | { |
| 94 | return _failSafeSensors; |
| 95 | } |
| 96 | |
| 97 | void DbusPidZone::markSensorMissing(const std::string& name, |
| 98 | const std::string& failReason) |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 99 | { |
| 100 | if (_missingAcceptable.find(name) != _missingAcceptable.end()) |
| 101 | { |
| 102 | // Disallow sensors in MissingIsAcceptable list from causing failsafe |
| James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 103 | outputFailsafeLogWithZone(_zoneId, this->getFailSafeMode(), name, |
| 104 | "The sensor is missing but is acceptable."); |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 108 | if (_sensorFailSafePercent[name] == 0) |
| 109 | { |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 110 | _failSafeSensors[name] = std::pair(failReason, _zoneFailSafePercent); |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 111 | } |
| 112 | else |
| 113 | { |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 114 | _failSafeSensors[name] = |
| 115 | std::pair(failReason, _sensorFailSafePercent[name]); |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (debugEnabled) |
| 119 | { |
| 120 | std::cerr << "Sensor " << name << " marked missing\n"; |
| 121 | } |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 124 | int64_t DbusPidZone::getZoneID(void) const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 125 | { |
| 126 | return _zoneId; |
| 127 | } |
| 128 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 129 | void DbusPidZone::addSetPoint(double setPoint, const std::string& name) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 130 | { |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 131 | /* exclude disabled pidloop from _maximumSetPoint calculation*/ |
| 132 | if (!isPidProcessEnabled(name)) |
| 133 | { |
| 134 | return; |
| 135 | } |
| 136 | |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 137 | auto profileName = name; |
| 138 | if (getAccSetPoint()) |
| 139 | { |
| 140 | /* |
| 141 | * If the name of controller is Linear_Temp_CPU0. |
| 142 | * The profile name will be Temp_CPU0. |
| 143 | */ |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 144 | profileName = name.substr(name.find('_') + 1); |
| 145 | setPoints[profileName] += setPoint; |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 146 | } |
| 147 | else |
| 148 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 149 | if (setPoints[profileName] < setPoint) |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 150 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 151 | setPoints[profileName] = setPoint; |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 155 | /* |
| 156 | * if there are multiple thermal controllers with the same |
| 157 | * value, pick the first one in the iterator |
| 158 | */ |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 159 | if (_maximumSetPoint < setPoints[profileName]) |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 160 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 161 | _maximumSetPoint = setPoints[profileName]; |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 162 | _maximumSetPointName = profileName; |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 163 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 166 | void DbusPidZone::addRPMCeiling(double ceiling) |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 167 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 168 | rpmCeilings.push_back(ceiling); |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 171 | void DbusPidZone::clearRPMCeilings(void) |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 172 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 173 | rpmCeilings.clear(); |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 176 | void DbusPidZone::clearSetPoints(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 177 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 178 | setPoints.clear(); |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 179 | _maximumSetPoint = 0; |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 180 | _maximumSetPointName.clear(); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 183 | double DbusPidZone::getFailSafePercent(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 184 | { |
| Eric Yang | d59ccac | 2025-06-05 19:18:03 +0800 | [diff] [blame] | 185 | if (_failSafeSensors.empty()) |
| 186 | { |
| 187 | return _zoneFailSafePercent; |
| 188 | } |
| 189 | |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 190 | FailSafeSensorsMap::iterator maxData = std::max_element( |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 191 | _failSafeSensors.begin(), _failSafeSensors.end(), |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 192 | [](const FailSafeSensorPair& firstData, |
| 193 | const FailSafeSensorPair& secondData) { |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 194 | return firstData.second.second < secondData.second.second; |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 195 | }); |
| 196 | |
| 197 | // In dbus/dbusconfiguration.cpp, the default sensor failsafepercent is 0 if |
| 198 | // there is no setting in json. |
| 199 | // Therfore, if the max failsafe duty in _failSafeSensors is 0, set final |
| 200 | // failsafe duty to _zoneFailSafePercent. |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 201 | if ((*maxData).second.second == 0) |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 202 | { |
| 203 | return _zoneFailSafePercent; |
| 204 | } |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 205 | |
| 206 | return (*maxData).second.second; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 209 | double DbusPidZone::getMinThermalSetPoint(void) const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 210 | { |
| James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 211 | return _minThermalOutputSetPt; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 214 | uint64_t DbusPidZone::getCycleIntervalTime(void) const |
| 215 | { |
| 216 | return _cycleTime.cycleIntervalTimeMS; |
| 217 | } |
| 218 | |
| 219 | uint64_t DbusPidZone::getUpdateThermalsCycle(void) const |
| 220 | { |
| 221 | return _cycleTime.updateThermalsTimeMS; |
| 222 | } |
| 223 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 224 | void DbusPidZone::addFanPID(std::unique_ptr<Controller> pid) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 225 | { |
| 226 | _fans.push_back(std::move(pid)); |
| 227 | } |
| 228 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 229 | void DbusPidZone::addThermalPID(std::unique_ptr<Controller> pid) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 230 | { |
| 231 | _thermals.push_back(std::move(pid)); |
| 232 | } |
| 233 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 234 | double DbusPidZone::getCachedValue(const std::string& name) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 235 | { |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 236 | return _cachedValuesByName.at(name).scaled; |
| 237 | } |
| 238 | |
| 239 | ValueCacheEntry DbusPidZone::getCachedValues(const std::string& name) |
| 240 | { |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 241 | return _cachedValuesByName.at(name); |
| 242 | } |
| 243 | |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 244 | void DbusPidZone::setOutputCache(std::string_view name, |
| 245 | const ValueCacheEntry& values) |
| 246 | { |
| 247 | _cachedFanOutputs[std::string{name}] = values; |
| 248 | } |
| 249 | |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 250 | void DbusPidZone::addFanInput(const std::string& fan, bool missingAcceptable) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 251 | { |
| 252 | _fanInputs.push_back(fan); |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 253 | |
| 254 | if (missingAcceptable) |
| 255 | { |
| 256 | _missingAcceptable.emplace(fan); |
| 257 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 260 | void DbusPidZone::addThermalInput(const std::string& therm, |
| 261 | bool missingAcceptable) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 262 | { |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 263 | /* |
| 264 | * One sensor may have stepwise and PID at the same time. |
| 265 | * Searching the sensor name before inserting it to avoid duplicated sensor |
| 266 | * names. |
| 267 | */ |
| 268 | if (std::find(_thermalInputs.begin(), _thermalInputs.end(), therm) == |
| 269 | _thermalInputs.end()) |
| 270 | { |
| 271 | _thermalInputs.push_back(therm); |
| 272 | } |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 273 | |
| 274 | if (missingAcceptable) |
| 275 | { |
| 276 | _missingAcceptable.emplace(therm); |
| 277 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 280 | // Updates desired RPM setpoint from optional text file |
| 281 | // Returns true if rpmValue updated, false if left unchanged |
| 282 | static bool fileParseRpm(const std::string& fileName, double& rpmValue) |
| 283 | { |
| 284 | static constexpr std::chrono::seconds throttlePace{3}; |
| 285 | |
| 286 | std::string errText; |
| 287 | |
| 288 | try |
| 289 | { |
| 290 | std::ifstream ifs; |
| 291 | ifs.open(fileName); |
| 292 | if (ifs) |
| 293 | { |
| 294 | int value; |
| 295 | ifs >> value; |
| 296 | |
| 297 | if (value <= 0) |
| 298 | { |
| 299 | errText = "File content could not be parsed to a number"; |
| 300 | } |
| 301 | else if (value <= 100) |
| 302 | { |
| 303 | errText = "File must contain RPM value, not PWM value"; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | rpmValue = static_cast<double>(value); |
| 308 | return true; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | catch (const std::exception& e) |
| 313 | { |
| 314 | errText = "Exception: "; |
| 315 | errText += e.what(); |
| 316 | } |
| 317 | |
| 318 | // The file is optional, intentionally not an error if file not found |
| 319 | if (!(errText.empty())) |
| 320 | { |
| 321 | tstamp now = std::chrono::high_resolution_clock::now(); |
| 322 | if (allowThrottle(now, throttlePace)) |
| 323 | { |
| 324 | std::cerr << "Unable to read from '" << fileName << "': " << errText |
| 325 | << "\n"; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | return false; |
| 330 | } |
| 331 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 332 | void DbusPidZone::determineMaxSetPointRequest(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 333 | { |
| Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 334 | std::vector<double>::iterator result; |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 335 | double minThermalThreshold = getMinThermalSetPoint(); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 336 | |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 337 | if (rpmCeilings.size() > 0) |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 338 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 339 | result = std::min_element(rpmCeilings.begin(), rpmCeilings.end()); |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 340 | // if Max set point is larger than the lowest ceiling, reset to lowest |
| 341 | // ceiling. |
| 342 | if (*result < _maximumSetPoint) |
| 343 | { |
| 344 | _maximumSetPoint = *result; |
| 345 | // When using lowest ceiling, controller name is ceiling. |
| 346 | _maximumSetPointName = "Ceiling"; |
| 347 | } |
| James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 350 | /* |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 351 | * Combine the maximum SetPoint Name if the controllers have same profile |
| 352 | * name. e.g., PID_BB_INLET_TEMP_C + Stepwise_BB_INLET_TEMP_C. |
| 353 | */ |
| 354 | if (getAccSetPoint()) |
| 355 | { |
| 356 | auto profileName = _maximumSetPointName; |
| 357 | _maximumSetPointName = ""; |
| 358 | |
| 359 | for (auto& p : _thermals) |
| 360 | { |
| 361 | auto controllerID = p->getID(); |
| 362 | auto found = controllerID.find(profileName); |
| 363 | if (found != std::string::npos) |
| 364 | { |
| 365 | if (_maximumSetPointName.empty()) |
| 366 | { |
| 367 | _maximumSetPointName = controllerID; |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | _maximumSetPointName += " + " + controllerID; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* |
| Patrick Venture | 7280e27 | 2019-02-11 10:45:32 -0800 | [diff] [blame] | 378 | * If the maximum RPM setpoint output is below the minimum RPM |
| 379 | * setpoint, set it to the minimum. |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 380 | */ |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 381 | if (minThermalThreshold >= _maximumSetPoint) |
| 382 | { |
| 383 | _maximumSetPoint = minThermalThreshold; |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 384 | _maximumSetPointName = "Minimum"; |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 385 | } |
| 386 | else if (_maximumSetPointName.compare(_maximumSetPointNamePrev)) |
| 387 | { |
| 388 | std::cerr << "PID Zone " << _zoneId << " max SetPoint " |
| 389 | << _maximumSetPoint << " requested by " |
| 390 | << _maximumSetPointName; |
| 391 | for (const auto& sensor : _failSafeSensors) |
| 392 | { |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 393 | if (sensor.first.find("Fan") == std::string::npos) |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 394 | { |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 395 | std::cerr << " " << sensor.first; |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | std::cerr << "\n"; |
| 399 | _maximumSetPointNamePrev.assign(_maximumSetPointName); |
| 400 | } |
| Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 401 | if (tuningEnabled) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 402 | { |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 403 | /* |
| 404 | * We received no setpoints from thermal sensors. |
| 405 | * This is a case experienced during tuning where they only specify |
| 406 | * fan sensors and one large fan PID for all the fans. |
| 407 | */ |
| 408 | static constexpr auto setpointpath = "/etc/thermal.d/setpoint"; |
| Patrick Venture | df766f2 | 2018-10-13 09:30:58 -0700 | [diff] [blame] | 409 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 410 | fileParseRpm(setpointpath, _maximumSetPoint); |
| Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 411 | |
| 412 | // Allow per-zone setpoint files to override overall setpoint file |
| 413 | std::ostringstream zoneSuffix; |
| 414 | zoneSuffix << ".zone" << _zoneId; |
| 415 | std::string zoneSetpointPath = setpointpath + zoneSuffix.str(); |
| 416 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 417 | fileParseRpm(zoneSetpointPath, _maximumSetPoint); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 418 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 422 | void DbusPidZone::initializeLog(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 423 | { |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 424 | /* Print header for log file: |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 425 | * epoch_ms,setpt,fan1,fan1_raw,fan1_pwm,fan1_pwm_raw,fan2,fan2_raw,fan2_pwm,fan2_pwm_raw,fanN,fanN_raw,fanN_pwm,fanN_pwm_raw,sensor1,sensor1_raw,sensor2,sensor2_raw,sensorN,sensorN_raw,failsafe |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 426 | */ |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 427 | |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 428 | _log << "epoch_ms,setpt,requester"; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 429 | |
| Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 430 | for (const auto& f : _fanInputs) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 431 | { |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 432 | _log << "," << f << "," << f << "_raw"; |
| 433 | _log << "," << f << "_pwm," << f << "_pwm_raw"; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 434 | } |
| Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 435 | for (const auto& t : _thermalInputs) |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 436 | { |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 437 | _log << "," << t << "," << t << "_raw"; |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 438 | } |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 439 | |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 440 | _log << ",failsafe"; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 441 | _log << std::endl; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 444 | void DbusPidZone::writeLog(const std::string& value) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 445 | { |
| Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 446 | _log << value; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 447 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 448 | |
| 449 | /* |
| 450 | * TODO(venture) This is effectively updating the cache and should check if the |
| 451 | * values they're using to update it are new or old, or whatnot. For instance, |
| 452 | * if we haven't heard from the host in X time we need to detect this failure. |
| 453 | * |
| 454 | * I haven't decided if the Sensor should have a lastUpdated method or whether |
| 455 | * that should be for the ReadInterface or etc... |
| 456 | */ |
| 457 | |
| 458 | /** |
| 459 | * We want the PID loop to run with values cached, so this will get all the |
| 460 | * fan tachs for the loop. |
| 461 | */ |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 462 | void DbusPidZone::updateFanTelemetry(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 463 | { |
| 464 | /* TODO(venture): Should I just make _log point to /dev/null when logging |
| 465 | * is disabled? I think it's a waste to try and log things even if the |
| 466 | * data is just being dropped though. |
| 467 | */ |
| Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 468 | const auto now = std::chrono::high_resolution_clock::now(); |
| Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 469 | if (loggingEnabled) |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 470 | { |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 471 | _log << std::chrono::duration_cast<std::chrono::milliseconds>( |
| 472 | now.time_since_epoch()) |
| 473 | .count(); |
| Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 474 | _log << "," << _maximumSetPoint; |
| Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 475 | _log << "," << _maximumSetPointName; |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 476 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 477 | |
| Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 478 | processSensorInputs</* fanSensorLogging */ true>(_fanInputs, now); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 479 | |
| Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 480 | if (loggingEnabled) |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 481 | { |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 482 | for (const auto& t : _thermalInputs) |
| 483 | { |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 484 | const auto& v = _cachedValuesByName[t]; |
| 485 | _log << "," << v.scaled << "," << v.unscaled; |
| Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 486 | } |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 487 | } |
| Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 488 | |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 489 | return; |
| 490 | } |
| 491 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 492 | void DbusPidZone::updateSensors(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 493 | { |
| Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 494 | processSensorInputs</* fanSensorLogging */ false>( |
| 495 | _thermalInputs, std::chrono::high_resolution_clock::now()); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 496 | |
| 497 | return; |
| 498 | } |
| 499 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 500 | void DbusPidZone::initializeCache(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 501 | { |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 502 | auto nan = std::numeric_limits<double>::quiet_NaN(); |
| 503 | |
| Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 504 | for (const auto& f : _fanInputs) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 505 | { |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 506 | _cachedValuesByName[f] = {nan, nan}; |
| 507 | _cachedFanOutputs[f] = {nan, nan}; |
| Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 508 | |
| 509 | // Start all fans in fail-safe mode. |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 510 | markSensorMissing(f, ""); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 511 | } |
| 512 | |
| Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 513 | for (const auto& t : _thermalInputs) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 514 | { |
| Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 515 | _cachedValuesByName[t] = {nan, nan}; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 516 | |
| 517 | // Start all sensors in fail-safe mode. |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 518 | markSensorMissing(t, ""); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 522 | void DbusPidZone::dumpCache(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 523 | { |
| 524 | std::cerr << "Cache values now: \n"; |
| Patrick Venture | 2a50eda | 2020-08-16 08:26:35 -0700 | [diff] [blame] | 525 | for (const auto& [name, value] : _cachedValuesByName) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 526 | { |
| Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 527 | std::cerr << name << ": " << value.scaled << " " << value.unscaled |
| 528 | << "\n"; |
| 529 | } |
| 530 | |
| 531 | std::cerr << "Fan outputs now: \n"; |
| 532 | for (const auto& [name, value] : _cachedFanOutputs) |
| 533 | { |
| 534 | std::cerr << name << ": " << value.scaled << " " << value.unscaled |
| 535 | << "\n"; |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 539 | void DbusPidZone::processFans(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 540 | { |
| 541 | for (auto& p : _fans) |
| 542 | { |
| James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 543 | p->process(); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 544 | } |
| Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 545 | |
| 546 | if (_redundantWrite) |
| 547 | { |
| 548 | // This is only needed once |
| 549 | _redundantWrite = false; |
| 550 | } |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 553 | void DbusPidZone::processThermals(void) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 554 | { |
| 555 | for (auto& p : _thermals) |
| 556 | { |
| James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 557 | p->process(); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 561 | Sensor* DbusPidZone::getSensor(const std::string& name) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 562 | { |
| Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 563 | return _mgr.getSensor(name); |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 566 | std::vector<std::string> DbusPidZone::getSensorNames(void) |
| 567 | { |
| 568 | return _thermalInputs; |
| 569 | } |
| 570 | |
| Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 571 | bool DbusPidZone::getRedundantWrite(void) const |
| 572 | { |
| 573 | return _redundantWrite; |
| 574 | } |
| 575 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 576 | bool DbusPidZone::manual(bool value) |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 577 | { |
| 578 | std::cerr << "manual: " << value << std::endl; |
| 579 | setManualMode(value); |
| 580 | return ModeObject::manual(value); |
| 581 | } |
| 582 | |
| Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 583 | bool DbusPidZone::failSafe() const |
| Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 584 | { |
| 585 | return getFailSafeMode(); |
| 586 | } |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 587 | |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 588 | void DbusPidZone::addPidControlProcess( |
| 589 | const std::string& name, const std::string& type, double setpoint, |
| 590 | sdbusplus::bus_t& bus, const std::string& objPath, bool defer) |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 591 | { |
| 592 | _pidsControlProcess[name] = std::make_unique<ProcessObject>( |
| 593 | bus, objPath.c_str(), |
| 594 | defer ? ProcessObject::action::defer_emit |
| 595 | : ProcessObject::action::emit_object_added); |
| 596 | // Default enable setting = true |
| 597 | _pidsControlProcess[name]->enabled(true); |
| Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 598 | _pidsControlProcess[name]->setpoint(setpoint); |
| 599 | |
| 600 | if (type == "temp") |
| 601 | { |
| 602 | _pidsControlProcess[name]->classType("Temperature"); |
| 603 | } |
| 604 | else if (type == "margin") |
| 605 | { |
| 606 | _pidsControlProcess[name]->classType("Margin"); |
| 607 | } |
| 608 | else if (type == "power") |
| 609 | { |
| 610 | _pidsControlProcess[name]->classType("Power"); |
| 611 | } |
| 612 | else if (type == "powersum") |
| 613 | { |
| 614 | _pidsControlProcess[name]->classType("PowerSum"); |
| 615 | } |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 616 | } |
| 617 | |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 618 | bool DbusPidZone::isPidProcessEnabled(const std::string& name) |
| ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 619 | { |
| 620 | return _pidsControlProcess[name]->enabled(); |
| 621 | } |
| 622 | |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 623 | void DbusPidZone::addPidFailSafePercent(const std::vector<std::string>& inputs, |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 624 | double percent) |
| ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 625 | { |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 626 | for (const auto& sensorName : inputs) |
| ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 627 | { |
| Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 628 | if (_sensorFailSafePercent.find(sensorName) != |
| 629 | _sensorFailSafePercent.end()) |
| 630 | { |
| 631 | _sensorFailSafePercent[sensorName] = |
| 632 | std::max(_sensorFailSafePercent[sensorName], percent); |
| 633 | if (debugEnabled) |
| 634 | { |
| 635 | std::cerr << "Sensor " << sensorName |
| 636 | << " failsafe percent updated to " |
| 637 | << _sensorFailSafePercent[sensorName] << "\n"; |
| 638 | } |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | _sensorFailSafePercent[sensorName] = percent; |
| 643 | if (debugEnabled) |
| 644 | { |
| 645 | std::cerr << "Sensor " << sensorName |
| 646 | << " failsafe percent set to " << percent << "\n"; |
| 647 | } |
| 648 | } |
| ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 649 | } |
| ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 650 | } |
| 651 | |
| Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame] | 652 | std::string DbusPidZone::leader() const |
| 653 | { |
| 654 | return _maximumSetPointName; |
| 655 | } |
| 656 | |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 657 | void DbusPidZone::updateThermalPowerDebugInterface( |
| 658 | std::string pidName, std::string leader, double input, double output) |
| Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 659 | { |
| 660 | if (leader.empty()) |
| 661 | { |
| 662 | _pidsControlProcess[pidName]->output(output); |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | _pidsControlProcess[pidName]->leader(leader); |
| 667 | _pidsControlProcess[pidName]->input(input); |
| 668 | } |
| 669 | } |
| 670 | |
| Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 671 | bool DbusPidZone::getAccSetPoint(void) const |
| 672 | { |
| 673 | return _accumulateSetPoint; |
| 674 | } |
| 675 | |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 676 | } // namespace pid_control |