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