James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 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 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "ExitAirTempSensor.hpp" |
| 18 | |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 19 | #include "SensorPaths.hpp" |
| 20 | #include "Thresholds.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 21 | #include "Utils.hpp" |
| 22 | #include "VariantVisitors.hpp" |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 23 | #include "sensor.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 24 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 25 | #include <boost/algorithm/string/replace.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 26 | #include <boost/asio/error.hpp> |
| 27 | #include <boost/asio/io_context.hpp> |
| 28 | #include <boost/asio/post.hpp> |
| 29 | #include <boost/asio/steady_timer.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <boost/container/flat_map.hpp> |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 31 | #include <phosphor-logging/lg2.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 32 | #include <sdbusplus/asio/connection.hpp> |
| 33 | #include <sdbusplus/asio/object_server.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 34 | #include <sdbusplus/bus.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 35 | #include <sdbusplus/bus/match.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 36 | #include <sdbusplus/message.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 37 | |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 38 | #include <algorithm> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 39 | #include <array> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 40 | #include <chrono> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 41 | #include <cmath> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 42 | #include <cstddef> |
| 43 | #include <cstdint> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 44 | #include <functional> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 45 | #include <limits> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 46 | #include <memory> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 47 | #include <stdexcept> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 48 | #include <string> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 49 | #include <utility> |
| 50 | #include <variant> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 51 | #include <vector> |
| 52 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 53 | constexpr const double altitudeFactor = 1.14; |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 54 | constexpr const char* exitAirType = "ExitAirTempSensor"; |
| 55 | constexpr const char* cfmType = "CFMSensor"; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 56 | |
| 57 | // todo: this *might* need to be configurable |
| 58 | constexpr const char* inletTemperatureSensor = "temperature/Front_Panel_Temp"; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 59 | constexpr const char* pidConfigurationType = |
| 60 | "xyz.openbmc_project.Configuration.Pid"; |
| 61 | constexpr const char* settingsDaemon = "xyz.openbmc_project.Settings"; |
| 62 | constexpr const char* cfmSettingPath = "/xyz/openbmc_project/control/cfm_limit"; |
| 63 | constexpr const char* cfmSettingIface = "xyz.openbmc_project.Control.CFMLimit"; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 64 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 65 | static constexpr bool debug = false; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 66 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 67 | static constexpr double cfmMaxReading = 255; |
| 68 | static constexpr double cfmMinReading = 0; |
| 69 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 70 | static constexpr size_t minSystemCfm = 50; |
| 71 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 72 | constexpr const auto monitorTypes{ |
| 73 | std::to_array<const char*>({exitAirType, cfmType})}; |
James Feist | 655f376 | 2020-10-05 15:28:15 -0700 | [diff] [blame] | 74 | |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 75 | static std::vector<std::shared_ptr<CFMSensor>> cfmSensors; |
| 76 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 77 | static void setupSensorMatch( |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 78 | std::vector<sdbusplus::bus::match_t>& matches, sdbusplus::bus_t& connection, |
| 79 | const std::string& type, |
| 80 | std::function<void(const double&, sdbusplus::message_t&)>&& callback) |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 81 | { |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 82 | std::function<void(sdbusplus::message_t & message)> eventHandler = |
| 83 | [callback{std::move(callback)}](sdbusplus::message_t& message) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 84 | std::string objectName; |
| 85 | boost::container::flat_map<std::string, |
| 86 | std::variant<double, int64_t>> |
| 87 | values; |
| 88 | message.read(objectName, values); |
| 89 | auto findValue = values.find("Value"); |
| 90 | if (findValue == values.end()) |
| 91 | { |
| 92 | return; |
| 93 | } |
| 94 | double value = |
| 95 | std::visit(VariantToDoubleVisitor(), findValue->second); |
| 96 | if (std::isnan(value)) |
| 97 | { |
| 98 | return; |
| 99 | } |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 100 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 101 | callback(value, message); |
| 102 | }; |
| 103 | matches.emplace_back( |
| 104 | connection, |
| 105 | "type='signal'," |
| 106 | "member='PropertiesChanged',interface='org." |
| 107 | "freedesktop.DBus.Properties',path_" |
| 108 | "namespace='/xyz/openbmc_project/sensors/" + |
| 109 | std::string(type) + "',arg0='xyz.openbmc_project.Sensor.Value'", |
| 110 | std::move(eventHandler)); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 111 | } |
| 112 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 113 | static void setMaxPWM(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 114 | double value) |
| 115 | { |
| 116 | using GetSubTreeType = std::vector<std::pair< |
| 117 | std::string, |
| 118 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; |
| 119 | |
| 120 | conn->async_method_call( |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 121 | [conn, |
| 122 | value](const boost::system::error_code ec, const GetSubTreeType& ret) { |
| 123 | if (ec) |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 124 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 125 | lg2::error("Error calling mapper"); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 126 | return; |
| 127 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 128 | for (const auto& [path, objDict] : ret) |
| 129 | { |
| 130 | if (objDict.empty()) |
| 131 | { |
| 132 | return; |
| 133 | } |
| 134 | const std::string& owner = objDict.begin()->first; |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 135 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 136 | conn->async_method_call( |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 137 | [conn, value, owner, |
| 138 | path{path}](const boost::system::error_code ec, |
| 139 | const std::variant<std::string>& classType) { |
| 140 | if (ec) |
| 141 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 142 | lg2::error("Error getting pid class"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | const auto* classStr = |
| 146 | std::get_if<std::string>(&classType); |
| 147 | if (classStr == nullptr || *classStr != "fan") |
| 148 | { |
| 149 | return; |
| 150 | } |
| 151 | conn->async_method_call( |
| 152 | [](boost::system::error_code& ec) { |
| 153 | if (ec) |
| 154 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 155 | lg2::error("Error setting pid class"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | }, |
| 159 | owner, path, "org.freedesktop.DBus.Properties", |
| 160 | "Set", pidConfigurationType, "OutLimitMax", |
| 161 | std::variant<double>(value)); |
| 162 | }, |
| 163 | owner, path, "org.freedesktop.DBus.Properties", "Get", |
| 164 | pidConfigurationType, "Class"); |
| 165 | } |
| 166 | }, |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 167 | mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/", |
| 168 | 0, std::array<std::string, 1>{pidConfigurationType}); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 169 | } |
| 170 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 171 | CFMSensor::CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 172 | const std::string& sensorName, |
| 173 | const std::string& sensorConfiguration, |
| 174 | sdbusplus::asio::object_server& objectServer, |
James Feist | b839c05 | 2019-05-15 10:25:24 -0700 | [diff] [blame] | 175 | std::vector<thresholds::Threshold>&& thresholdData, |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 176 | std::shared_ptr<ExitAirTempSensor>& parent) : |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 177 | Sensor(escapeName(sensorName), std::move(thresholdData), |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 178 | sensorConfiguration, "CFMSensor", false, false, cfmMaxReading, |
| 179 | cfmMinReading, conn, PowerState::on), |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 180 | parent(parent), objServer(objectServer) |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 181 | { |
Basheer Ahmed Muddebihal | e5b867b | 2021-07-26 08:32:19 -0700 | [diff] [blame] | 182 | sensorInterface = objectServer.add_interface( |
| 183 | "/xyz/openbmc_project/sensors/airflow/" + name, |
| 184 | "xyz.openbmc_project.Sensor.Value"); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 185 | |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 186 | for (const auto& threshold : thresholds) |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 187 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 188 | std::string interface = thresholds::getInterface(threshold.level); |
| 189 | thresholdInterfaces[static_cast<size_t>(threshold.level)] = |
| 190 | objectServer.add_interface( |
| 191 | "/xyz/openbmc_project/sensors/airflow/" + name, interface); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 192 | } |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 193 | |
| 194 | association = objectServer.add_interface( |
Basheer Ahmed Muddebihal | e5b867b | 2021-07-26 08:32:19 -0700 | [diff] [blame] | 195 | "/xyz/openbmc_project/sensors/airflow/" + name, association::interface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 196 | |
Andrei Kartashev | 3928741 | 2022-02-04 16:04:47 +0300 | [diff] [blame] | 197 | setInitialProperties(sensor_paths::unitCFM); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 198 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 199 | pwmLimitIface = |
| 200 | objectServer.add_interface("/xyz/openbmc_project/control/pwm_limit", |
| 201 | "xyz.openbmc_project.Control.PWMLimit"); |
| 202 | cfmLimitIface = |
| 203 | objectServer.add_interface("/xyz/openbmc_project/control/MaxCFM", |
| 204 | "xyz.openbmc_project.Control.CFMLimit"); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 205 | } |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 206 | |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 207 | void CFMSensor::setupMatches() |
| 208 | { |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 209 | std::weak_ptr<CFMSensor> weakRef = weak_from_this(); |
Ed Tanous | 8a17c30 | 2021-09-02 15:07:11 -0700 | [diff] [blame] | 210 | setupSensorMatch( |
| 211 | matches, *dbusConnection, "fan_tach", |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 212 | [weakRef](const double& value, sdbusplus::message_t& message) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 213 | auto self = weakRef.lock(); |
| 214 | if (!self) |
| 215 | { |
| 216 | return; |
| 217 | } |
| 218 | self->tachReadings[message.get_path()] = value; |
| 219 | if (self->tachRanges.find(message.get_path()) == |
| 220 | self->tachRanges.end()) |
| 221 | { |
| 222 | // calls update reading after updating ranges |
| 223 | self->addTachRanges(message.get_sender(), message.get_path()); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | self->updateReading(); |
| 228 | } |
| 229 | }); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 230 | |
| 231 | dbusConnection->async_method_call( |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 232 | [weakRef](const boost::system::error_code ec, |
| 233 | const std::variant<double> cfmVariant) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 234 | auto self = weakRef.lock(); |
| 235 | if (!self) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 236 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 237 | return; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 238 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 239 | |
| 240 | uint64_t maxRpm = 100; |
| 241 | if (!ec) |
| 242 | { |
| 243 | const auto* cfm = std::get_if<double>(&cfmVariant); |
| 244 | if (cfm != nullptr && *cfm >= minSystemCfm) |
| 245 | { |
| 246 | maxRpm = self->getMaxRpm(*cfm); |
| 247 | } |
| 248 | } |
| 249 | self->pwmLimitIface->register_property("Limit", maxRpm); |
| 250 | self->pwmLimitIface->initialize(); |
| 251 | setMaxPWM(self->dbusConnection, maxRpm); |
| 252 | }, |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 253 | settingsDaemon, cfmSettingPath, "org.freedesktop.DBus.Properties", |
| 254 | "Get", cfmSettingIface, "Limit"); |
| 255 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 256 | matches.emplace_back( |
| 257 | *dbusConnection, |
| 258 | "type='signal'," |
| 259 | "member='PropertiesChanged',interface='org." |
| 260 | "freedesktop.DBus.Properties',path='" + |
| 261 | std::string(cfmSettingPath) + "',arg0='" + |
| 262 | std::string(cfmSettingIface) + "'", |
| 263 | [weakRef](sdbusplus::message_t& message) { |
| 264 | auto self = weakRef.lock(); |
| 265 | if (!self) |
| 266 | { |
| 267 | return; |
| 268 | } |
| 269 | boost::container::flat_map<std::string, std::variant<double>> |
| 270 | values; |
| 271 | std::string objectName; |
| 272 | message.read(objectName, values); |
| 273 | const auto findValue = values.find("Limit"); |
| 274 | if (findValue == values.end()) |
| 275 | { |
| 276 | return; |
| 277 | } |
| 278 | auto* const reading = std::get_if<double>(&(findValue->second)); |
| 279 | if (reading == nullptr) |
| 280 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 281 | lg2::error("Got CFM Limit of wrong type"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | if (*reading < minSystemCfm && *reading != 0) |
| 285 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 286 | lg2::error("Illegal CFM setting detected"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 287 | return; |
| 288 | } |
| 289 | uint64_t maxRpm = self->getMaxRpm(*reading); |
| 290 | self->pwmLimitIface->set_property("Limit", maxRpm); |
| 291 | setMaxPWM(self->dbusConnection, maxRpm); |
| 292 | }); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 293 | } |
| 294 | |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 295 | CFMSensor::~CFMSensor() |
| 296 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 297 | for (const auto& iface : thresholdInterfaces) |
| 298 | { |
| 299 | objServer.remove_interface(iface); |
| 300 | } |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 301 | objServer.remove_interface(sensorInterface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 302 | objServer.remove_interface(association); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 303 | objServer.remove_interface(cfmLimitIface); |
| 304 | objServer.remove_interface(pwmLimitIface); |
| 305 | } |
| 306 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 307 | void CFMSensor::createMaxCFMIface() |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 308 | { |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 309 | cfmLimitIface->register_property("Limit", c2 * maxCFM * tachs.size()); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 310 | cfmLimitIface->initialize(); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 311 | } |
| 312 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 313 | void CFMSensor::addTachRanges(const std::string& serviceName, |
| 314 | const std::string& path) |
| 315 | { |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 316 | std::weak_ptr<CFMSensor> weakRef = weak_from_this(); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 317 | dbusConnection->async_method_call( |
Zev Weiss | afd1504 | 2022-07-18 12:28:40 -0700 | [diff] [blame] | 318 | [weakRef, path](const boost::system::error_code ec, |
| 319 | const SensorBaseConfigMap& data) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 320 | if (ec) |
| 321 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 322 | lg2::error("Error getting properties from '{PATH}'", "PATH", |
| 323 | path); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | auto self = weakRef.lock(); |
| 327 | if (!self) |
| 328 | { |
| 329 | return; |
| 330 | } |
| 331 | double max = loadVariant<double>(data, "MaxValue"); |
| 332 | double min = loadVariant<double>(data, "MinValue"); |
| 333 | self->tachRanges[path] = std::make_pair(min, max); |
| 334 | self->updateReading(); |
| 335 | }, |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 336 | serviceName, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 337 | "xyz.openbmc_project.Sensor.Value"); |
| 338 | } |
| 339 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 340 | void CFMSensor::checkThresholds() |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 341 | { |
| 342 | thresholds::checkThresholds(this); |
| 343 | } |
| 344 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 345 | void CFMSensor::updateReading() |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 346 | { |
| 347 | double val = 0.0; |
| 348 | if (calculate(val)) |
| 349 | { |
| 350 | if (value != val && parent) |
| 351 | { |
| 352 | parent->updateReading(); |
| 353 | } |
| 354 | updateValue(val); |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
| 359 | } |
| 360 | } |
| 361 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 362 | uint64_t CFMSensor::getMaxRpm(uint64_t cfmMaxSetting) const |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 363 | { |
| 364 | uint64_t pwmPercent = 100; |
| 365 | double totalCFM = std::numeric_limits<double>::max(); |
| 366 | if (cfmMaxSetting == 0) |
| 367 | { |
| 368 | return pwmPercent; |
| 369 | } |
| 370 | |
James Feist | 5242795 | 2019-04-05 14:23:35 -0700 | [diff] [blame] | 371 | bool firstLoop = true; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 372 | while (totalCFM > cfmMaxSetting) |
| 373 | { |
James Feist | 5242795 | 2019-04-05 14:23:35 -0700 | [diff] [blame] | 374 | if (firstLoop) |
| 375 | { |
| 376 | firstLoop = false; |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | pwmPercent--; |
| 381 | } |
| 382 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 383 | double ci = 0; |
| 384 | if (pwmPercent == 0) |
| 385 | { |
| 386 | ci = 0; |
| 387 | } |
| 388 | else if (pwmPercent < tachMinPercent) |
| 389 | { |
| 390 | ci = c1; |
| 391 | } |
| 392 | else if (pwmPercent > tachMaxPercent) |
| 393 | { |
| 394 | ci = c2; |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | ci = c1 + (((c2 - c1) * (pwmPercent - tachMinPercent)) / |
| 399 | (tachMaxPercent - tachMinPercent)); |
| 400 | } |
| 401 | |
| 402 | // Now calculate the CFM for this tach |
| 403 | // CFMi = Ci * Qmaxi * TACHi |
| 404 | totalCFM = ci * maxCFM * pwmPercent; |
| 405 | totalCFM *= tachs.size(); |
| 406 | // divide by 100 since pwm is in percent |
| 407 | totalCFM /= 100; |
| 408 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 409 | if (pwmPercent <= 0) |
| 410 | { |
| 411 | break; |
| 412 | } |
| 413 | } |
James Feist | 5242795 | 2019-04-05 14:23:35 -0700 | [diff] [blame] | 414 | |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 415 | return pwmPercent; |
| 416 | } |
| 417 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 418 | bool CFMSensor::calculate(double& value) |
| 419 | { |
| 420 | double totalCFM = 0; |
| 421 | for (const std::string& tachName : tachs) |
| 422 | { |
| 423 | auto findReading = std::find_if( |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 424 | tachReadings.begin(), tachReadings.end(), |
| 425 | [&](const auto& item) { return item.first.ends_with(tachName); }); |
Patrick Williams | 597e842 | 2023-10-20 11:19:01 -0500 | [diff] [blame] | 426 | auto findRange = std::find_if( |
| 427 | tachRanges.begin(), tachRanges.end(), |
| 428 | [&](const auto& item) { return item.first.ends_with(tachName); }); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 429 | if (findReading == tachReadings.end()) |
| 430 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 431 | if constexpr (debug) |
James Feist | a96329f | 2019-01-24 10:08:27 -0800 | [diff] [blame] | 432 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 433 | lg2::error("Can't find '{NAME}' in readings", "NAME", tachName); |
James Feist | a96329f | 2019-01-24 10:08:27 -0800 | [diff] [blame] | 434 | } |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 435 | continue; // haven't gotten a reading |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | if (findRange == tachRanges.end()) |
| 439 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 440 | lg2::error("Can't find '{NAME}' in ranges", "NAME", tachName); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 441 | return false; // haven't gotten a max / min |
| 442 | } |
| 443 | |
| 444 | // avoid divide by 0 |
| 445 | if (findRange->second.second == 0) |
| 446 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 447 | lg2::error("Tach Max Set to 0, tachName: '{NAME}'", "NAME", |
| 448 | tachName); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | |
| 452 | double rpm = findReading->second; |
| 453 | |
| 454 | // for now assume the min for a fan is always 0, divide by max to get |
| 455 | // percent and mult by 100 |
| 456 | rpm /= findRange->second.second; |
| 457 | rpm *= 100; |
| 458 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 459 | if constexpr (debug) |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 460 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 461 | lg2::info("Tach '{NAME}' at '{RPM}'", "NAME", tachName, "RPM", rpm); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | // Do a linear interpolation to get Ci |
| 465 | // Ci = C1 + (C2 - C1)/(RPM2 - RPM1) * (TACHi - TACH1) |
| 466 | |
| 467 | double ci = 0; |
| 468 | if (rpm == 0) |
| 469 | { |
| 470 | ci = 0; |
| 471 | } |
| 472 | else if (rpm < tachMinPercent) |
| 473 | { |
| 474 | ci = c1; |
| 475 | } |
| 476 | else if (rpm > tachMaxPercent) |
| 477 | { |
| 478 | ci = c2; |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | ci = c1 + (((c2 - c1) * (rpm - tachMinPercent)) / |
| 483 | (tachMaxPercent - tachMinPercent)); |
| 484 | } |
| 485 | |
| 486 | // Now calculate the CFM for this tach |
| 487 | // CFMi = Ci * Qmaxi * TACHi |
| 488 | totalCFM += ci * maxCFM * rpm; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 489 | if constexpr (debug) |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 490 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 491 | lg2::error( |
| 492 | "totalCFM = {CFM}, Ci = {CI}, MaxCFM = {MAXCFM}, rpm = {RPM}, c1 = {C1}" |
| 493 | ", c2 = {C2}, max = {MAX}, min = {MIN}", |
| 494 | "CFM", totalCFM, "CI", ci, "MAXCFM", maxCFM, "RPM", rpm, "C1", |
| 495 | c1, "C2", c2, "MAX", tachMaxPercent, "MIN", tachMinPercent); |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 496 | } |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // divide by 100 since rpm is in percent |
| 500 | value = totalCFM / 100; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 501 | if constexpr (debug) |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 502 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 503 | lg2::error("cfm value = {VALUE}", "VALUE", value); |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 504 | } |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 505 | return true; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static constexpr double exitAirMaxReading = 127; |
| 509 | static constexpr double exitAirMinReading = -128; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 510 | ExitAirTempSensor::ExitAirTempSensor( |
| 511 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 512 | const std::string& sensorName, const std::string& sensorConfiguration, |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 513 | sdbusplus::asio::object_server& objectServer, |
James Feist | b839c05 | 2019-05-15 10:25:24 -0700 | [diff] [blame] | 514 | std::vector<thresholds::Threshold>&& thresholdData) : |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 515 | Sensor(escapeName(sensorName), std::move(thresholdData), |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 516 | sensorConfiguration, "ExitAirTemp", false, false, exitAirMaxReading, |
| 517 | exitAirMinReading, conn, PowerState::on), |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 518 | objServer(objectServer) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 519 | { |
| 520 | sensorInterface = objectServer.add_interface( |
| 521 | "/xyz/openbmc_project/sensors/temperature/" + name, |
| 522 | "xyz.openbmc_project.Sensor.Value"); |
| 523 | |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 524 | for (const auto& threshold : thresholds) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 525 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 526 | std::string interface = thresholds::getInterface(threshold.level); |
| 527 | thresholdInterfaces[static_cast<size_t>(threshold.level)] = |
| 528 | objectServer.add_interface( |
| 529 | "/xyz/openbmc_project/sensors/temperature/" + name, interface); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 530 | } |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 531 | association = objectServer.add_interface( |
| 532 | "/xyz/openbmc_project/sensors/temperature/" + name, |
James Feist | 2adc95c | 2019-09-30 14:55:28 -0700 | [diff] [blame] | 533 | association::interface); |
Andrei Kartashev | 3928741 | 2022-02-04 16:04:47 +0300 | [diff] [blame] | 534 | setInitialProperties(sensor_paths::unitDegreesC); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | ExitAirTempSensor::~ExitAirTempSensor() |
| 538 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 539 | for (const auto& iface : thresholdInterfaces) |
| 540 | { |
| 541 | objServer.remove_interface(iface); |
| 542 | } |
James Feist | 523828e | 2019-03-04 14:38:37 -0800 | [diff] [blame] | 543 | objServer.remove_interface(sensorInterface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 544 | objServer.remove_interface(association); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 547 | void ExitAirTempSensor::setupMatches() |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 548 | { |
Brandon Kim | 6655823 | 2021-11-09 16:53:08 -0800 | [diff] [blame] | 549 | constexpr const auto matchTypes{ |
| 550 | std::to_array<const char*>({"power", inletTemperatureSensor})}; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 551 | |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 552 | std::weak_ptr<ExitAirTempSensor> weakRef = weak_from_this(); |
Ed Tanous | 13b63f8 | 2021-05-11 16:12:52 -0700 | [diff] [blame] | 553 | for (const std::string type : matchTypes) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 554 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 555 | setupSensorMatch( |
| 556 | matches, *dbusConnection, type, |
| 557 | [weakRef, |
| 558 | type](const double& value, sdbusplus::message_t& message) { |
| 559 | auto self = weakRef.lock(); |
| 560 | if (!self) |
| 561 | { |
| 562 | return; |
| 563 | } |
| 564 | if (type == "power") |
| 565 | { |
| 566 | std::string path = message.get_path(); |
| 567 | if (path.find("PS") != std::string::npos && |
| 568 | path.ends_with("Input_Power")) |
| 569 | { |
| 570 | self->powerReadings[message.get_path()] = value; |
| 571 | } |
| 572 | } |
| 573 | else if (type == inletTemperatureSensor) |
| 574 | { |
| 575 | self->inletTemp = value; |
| 576 | } |
| 577 | self->updateReading(); |
| 578 | }); |
| 579 | } |
| 580 | dbusConnection->async_method_call( |
| 581 | [weakRef](boost::system::error_code ec, |
| 582 | const std::variant<double>& value) { |
| 583 | if (ec) |
| 584 | { |
| 585 | // sensor not ready yet |
| 586 | return; |
| 587 | } |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 588 | auto self = weakRef.lock(); |
| 589 | if (!self) |
| 590 | { |
| 591 | return; |
| 592 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 593 | self->inletTemp = std::visit(VariantToDoubleVisitor(), value); |
| 594 | }, |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 595 | "xyz.openbmc_project.HwmonTempSensor", |
| 596 | std::string("/xyz/openbmc_project/sensors/") + inletTemperatureSensor, |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 597 | properties::interface, properties::get, sensorValueInterface, "Value"); |
| 598 | dbusConnection->async_method_call( |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 599 | [weakRef](boost::system::error_code ec, const GetSubTreeType& subtree) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 600 | if (ec) |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 601 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 602 | lg2::error("Error contacting mapper"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 603 | return; |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 604 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 605 | auto self = weakRef.lock(); |
| 606 | if (!self) |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 607 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 608 | return; |
Zhikui Ren | dbb73aa | 2021-04-02 13:39:04 -0700 | [diff] [blame] | 609 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 610 | for (const auto& [path, matches] : subtree) |
| 611 | { |
| 612 | size_t lastSlash = path.rfind('/'); |
| 613 | if (lastSlash == std::string::npos || |
| 614 | lastSlash == path.size() || matches.empty()) |
| 615 | { |
| 616 | continue; |
| 617 | } |
| 618 | std::string sensorName = path.substr(lastSlash + 1); |
| 619 | if (sensorName.starts_with("PS") && |
| 620 | sensorName.ends_with("Input_Power")) |
| 621 | { |
| 622 | // lambda capture requires a proper variable (not a |
| 623 | // structured binding) |
| 624 | const std::string& cbPath = path; |
| 625 | self->dbusConnection->async_method_call( |
| 626 | [weakRef, cbPath](boost::system::error_code ec, |
| 627 | const std::variant<double>& value) { |
| 628 | if (ec) |
| 629 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 630 | lg2::error("Error getting value from '{PATH}'", |
| 631 | "PATH", cbPath); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 632 | } |
| 633 | auto self = weakRef.lock(); |
| 634 | if (!self) |
| 635 | { |
| 636 | return; |
| 637 | } |
| 638 | double reading = |
| 639 | std::visit(VariantToDoubleVisitor(), value); |
| 640 | if constexpr (debug) |
| 641 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 642 | lg2::error("'{PATH}' reading '{VALUE}'", "PATH", |
| 643 | cbPath, "VALUE", reading); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 644 | } |
| 645 | self->powerReadings[cbPath] = reading; |
| 646 | }, |
| 647 | matches[0].first, cbPath, properties::interface, |
| 648 | properties::get, sensorValueInterface, "Value"); |
| 649 | } |
| 650 | } |
| 651 | }, |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 652 | mapper::busName, mapper::path, mapper::interface, mapper::subtree, |
| 653 | "/xyz/openbmc_project/sensors/power", 0, |
| 654 | std::array<const char*, 1>{sensorValueInterface}); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 657 | void ExitAirTempSensor::updateReading() |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 658 | { |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 659 | double val = 0.0; |
| 660 | if (calculate(val)) |
| 661 | { |
James Feist | 18af423 | 2019-03-13 11:14:00 -0700 | [diff] [blame] | 662 | val = std::floor(val + 0.5); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 663 | updateValue(val); |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
| 668 | } |
| 669 | } |
| 670 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 671 | double ExitAirTempSensor::getTotalCFM() |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 672 | { |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 673 | double sum = 0; |
| 674 | for (auto& sensor : cfmSensors) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 675 | { |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 676 | double reading = 0; |
| 677 | if (!sensor->calculate(reading)) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 678 | { |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 679 | return -1; |
| 680 | } |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 681 | sum += reading; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 682 | } |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 683 | |
| 684 | return sum; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | bool ExitAirTempSensor::calculate(double& val) |
| 688 | { |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 689 | constexpr size_t maxErrorPrint = 5; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 690 | static bool firstRead = false; |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 691 | static size_t errorPrint = maxErrorPrint; |
| 692 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 693 | double cfm = getTotalCFM(); |
| 694 | if (cfm <= 0) |
| 695 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 696 | lg2::error("Error getting cfm"); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 697 | return false; |
| 698 | } |
| 699 | |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 700 | // Though cfm is not expected to be less than qMin normally, |
| 701 | // it is not a hard limit for exit air temp calculation. |
| 702 | // 50% qMin is chosen as a generic limit between providing |
| 703 | // a valid derived exit air temp and reporting exit air temp not available. |
| 704 | constexpr const double cfmLimitFactor = 0.5; |
| 705 | if (cfm < (qMin * cfmLimitFactor)) |
| 706 | { |
| 707 | if (errorPrint > 0) |
| 708 | { |
| 709 | errorPrint--; |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 710 | lg2::error("cfm '{CFM}' is too low, expected qMin '{QMIN}'", "CFM", |
| 711 | cfm, "QMIN", qMin); |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 712 | } |
| 713 | val = 0; |
| 714 | return false; |
| 715 | } |
| 716 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 717 | // if there is an error getting inlet temp, return error |
| 718 | if (std::isnan(inletTemp)) |
| 719 | { |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 720 | if (errorPrint > 0) |
| 721 | { |
| 722 | errorPrint--; |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 723 | lg2::error("Cannot get inlet temp"); |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 724 | } |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 725 | val = 0; |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | // if fans are off, just make the exit temp equal to inlet |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 730 | if (!isPowerOn()) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 731 | { |
| 732 | val = inletTemp; |
| 733 | return true; |
| 734 | } |
| 735 | |
| 736 | double totalPower = 0; |
Zev Weiss | 72f322f | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 737 | for (const auto& [path, reading] : powerReadings) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 738 | { |
Zev Weiss | 72f322f | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 739 | if (std::isnan(reading)) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 740 | { |
| 741 | continue; |
| 742 | } |
Zev Weiss | 72f322f | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 743 | totalPower += reading; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Calculate power correction factor |
| 747 | // Ci = CL + (CH - CL)/(QMax - QMin) * (CFM - QMin) |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 748 | double powerFactor = 0.0; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 749 | if (cfm <= qMin) |
| 750 | { |
| 751 | powerFactor = powerFactorMin; |
| 752 | } |
| 753 | else if (cfm >= qMax) |
| 754 | { |
| 755 | powerFactor = powerFactorMax; |
| 756 | } |
| 757 | else |
| 758 | { |
| 759 | powerFactor = powerFactorMin + ((powerFactorMax - powerFactorMin) / |
| 760 | (qMax - qMin) * (cfm - qMin)); |
| 761 | } |
| 762 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 763 | totalPower *= powerFactor; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 764 | totalPower += pOffset; |
| 765 | |
| 766 | if (totalPower == 0) |
| 767 | { |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 768 | if (errorPrint > 0) |
| 769 | { |
| 770 | errorPrint--; |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 771 | lg2::error("total power 0"); |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 772 | } |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 773 | val = 0; |
| 774 | return false; |
| 775 | } |
| 776 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 777 | if constexpr (debug) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 778 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 779 | lg2::info( |
| 780 | "Power Factor: {POWER_FACTOR}, Inlet Temp: {INLET_TEMP}, Total Power: {TOTAL_POWER}", |
| 781 | "POWER_FACTOR", powerFactor, "INLET_TEMP", inletTemp, "TOTAL_POWER", |
| 782 | totalPower); |
| 783 | }; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 784 | |
| 785 | // Calculate the exit air temp |
| 786 | // Texit = Tfp + (1.76 * TotalPower / CFM * Faltitude) |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 787 | double reading = 1.76 * totalPower * altitudeFactor; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 788 | reading /= cfm; |
| 789 | reading += inletTemp; |
| 790 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 791 | if constexpr (debug) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 792 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 793 | lg2::info("Reading 1: '{VALUE}'", "VALUE", reading); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | // Now perform the exponential average |
| 797 | // Calculate alpha based on SDR values and CFM |
| 798 | // Ai = As + (Af - As)/(QMax - QMin) * (CFM - QMin) |
| 799 | |
| 800 | double alpha = 0.0; |
| 801 | if (cfm < qMin) |
| 802 | { |
| 803 | alpha = alphaS; |
| 804 | } |
| 805 | else if (cfm >= qMax) |
| 806 | { |
| 807 | alpha = alphaF; |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | alpha = alphaS + ((alphaF - alphaS) * (cfm - qMin) / (qMax - qMin)); |
| 812 | } |
| 813 | |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 814 | auto time = std::chrono::steady_clock::now(); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 815 | if (!firstRead) |
| 816 | { |
| 817 | firstRead = true; |
| 818 | lastTime = time; |
| 819 | lastReading = reading; |
| 820 | } |
| 821 | double alphaDT = |
| 822 | std::chrono::duration_cast<std::chrono::seconds>(time - lastTime) |
| 823 | .count() * |
| 824 | alpha; |
| 825 | |
| 826 | // cap at 1.0 or the below fails |
| 827 | if (alphaDT > 1.0) |
| 828 | { |
| 829 | alphaDT = 1.0; |
| 830 | } |
| 831 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 832 | if constexpr (debug) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 833 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 834 | lg2::info("AlphaDT: '{ADT}'", "ADT", alphaDT); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | reading = ((reading * alphaDT) + (lastReading * (1.0 - alphaDT))); |
| 838 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 839 | if constexpr (debug) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 840 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 841 | lg2::info("Reading 2: '{VALUE}'", "VALUE", reading); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | val = reading; |
| 845 | lastReading = reading; |
| 846 | lastTime = time; |
James Feist | ae11cfc | 2019-05-07 15:01:20 -0700 | [diff] [blame] | 847 | errorPrint = maxErrorPrint; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 848 | return true; |
| 849 | } |
| 850 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 851 | void ExitAirTempSensor::checkThresholds() |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 852 | { |
| 853 | thresholds::checkThresholds(this); |
| 854 | } |
| 855 | |
Zev Weiss | afd1504 | 2022-07-18 12:28:40 -0700 | [diff] [blame] | 856 | static void loadVariantPathArray(const SensorBaseConfigMap& data, |
| 857 | const std::string& key, |
| 858 | std::vector<std::string>& resp) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 859 | { |
| 860 | auto it = data.find(key); |
| 861 | if (it == data.end()) |
| 862 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 863 | lg2::error("Configuration missing '{KEY}'", "KEY", key); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 864 | throw std::invalid_argument("Key Missing"); |
| 865 | } |
| 866 | BasicVariantType copy = it->second; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 867 | std::vector<std::string> config = std::get<std::vector<std::string>>(copy); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 868 | for (auto& str : config) |
| 869 | { |
| 870 | boost::replace_all(str, " ", "_"); |
| 871 | } |
| 872 | resp = std::move(config); |
| 873 | } |
| 874 | |
| 875 | void createSensor(sdbusplus::asio::object_server& objectServer, |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 876 | std::shared_ptr<ExitAirTempSensor>& exitAirSensor, |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 877 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) |
| 878 | { |
| 879 | if (!dbusConnection) |
| 880 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 881 | lg2::error("Connection not created"); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 882 | return; |
| 883 | } |
James Feist | 655f376 | 2020-10-05 15:28:15 -0700 | [diff] [blame] | 884 | auto getter = std::make_shared<GetSensorConfiguration>( |
Patrick Williams | 597e842 | 2023-10-20 11:19:01 -0500 | [diff] [blame] | 885 | dbusConnection, [&objectServer, &dbusConnection, |
| 886 | &exitAirSensor](const ManagedObjectType& resp) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 887 | cfmSensors.clear(); |
| 888 | for (const auto& [path, interfaces] : resp) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 889 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 890 | for (const auto& [intf, cfg] : interfaces) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 891 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 892 | if (intf == configInterfaceName(exitAirType)) |
| 893 | { |
| 894 | // thresholds should be under the same path |
| 895 | std::vector<thresholds::Threshold> sensorThresholds; |
| 896 | parseThresholdsFromConfig(interfaces, sensorThresholds); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 897 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 898 | std::string name = |
| 899 | loadVariant<std::string>(cfg, "Name"); |
| 900 | exitAirSensor = nullptr; |
| 901 | exitAirSensor = std::make_shared<ExitAirTempSensor>( |
| 902 | dbusConnection, name, path.str, objectServer, |
| 903 | std::move(sensorThresholds)); |
| 904 | exitAirSensor->powerFactorMin = |
| 905 | loadVariant<double>(cfg, "PowerFactorMin"); |
| 906 | exitAirSensor->powerFactorMax = |
| 907 | loadVariant<double>(cfg, "PowerFactorMax"); |
| 908 | exitAirSensor->qMin = loadVariant<double>(cfg, "QMin"); |
| 909 | exitAirSensor->qMax = loadVariant<double>(cfg, "QMax"); |
| 910 | exitAirSensor->alphaS = |
| 911 | loadVariant<double>(cfg, "AlphaS"); |
| 912 | exitAirSensor->alphaF = |
| 913 | loadVariant<double>(cfg, "AlphaF"); |
| 914 | } |
| 915 | else if (intf == configInterfaceName(cfmType)) |
| 916 | { |
| 917 | // thresholds should be under the same path |
| 918 | std::vector<thresholds::Threshold> sensorThresholds; |
| 919 | parseThresholdsFromConfig(interfaces, sensorThresholds); |
| 920 | std::string name = |
| 921 | loadVariant<std::string>(cfg, "Name"); |
| 922 | auto sensor = std::make_shared<CFMSensor>( |
| 923 | dbusConnection, name, path.str, objectServer, |
| 924 | std::move(sensorThresholds), exitAirSensor); |
| 925 | loadVariantPathArray(cfg, "Tachs", sensor->tachs); |
| 926 | sensor->maxCFM = loadVariant<double>(cfg, "MaxCFM"); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 927 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 928 | // change these into percent upon getting the data |
| 929 | sensor->c1 = loadVariant<double>(cfg, "C1") / 100; |
| 930 | sensor->c2 = loadVariant<double>(cfg, "C2") / 100; |
| 931 | sensor->tachMinPercent = |
| 932 | loadVariant<double>(cfg, "TachMinPercent"); |
| 933 | sensor->tachMaxPercent = |
| 934 | loadVariant<double>(cfg, "TachMaxPercent"); |
| 935 | sensor->createMaxCFMIface(); |
| 936 | sensor->setupMatches(); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 937 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 938 | cfmSensors.emplace_back(std::move(sensor)); |
| 939 | } |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 940 | } |
| 941 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 942 | if (exitAirSensor) |
| 943 | { |
| 944 | exitAirSensor->setupMatches(); |
| 945 | exitAirSensor->updateReading(); |
| 946 | } |
| 947 | }); |
James Feist | 655f376 | 2020-10-05 15:28:15 -0700 | [diff] [blame] | 948 | getter->getConfiguration( |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 949 | std::vector<std::string>(monitorTypes.begin(), monitorTypes.end())); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 950 | } |
| 951 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 952 | int main() |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 953 | { |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 954 | boost::asio::io_context io; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 955 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
Johnathan Mantey | 661d437 | 2022-10-27 09:00:59 -0700 | [diff] [blame] | 956 | sdbusplus::asio::object_server objectServer(systemBus, true); |
| 957 | objectServer.add_manager("/xyz/openbmc_project/sensors"); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 958 | systemBus->request_name("xyz.openbmc_project.ExitAirTempSensor"); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 959 | std::shared_ptr<ExitAirTempSensor> sensor = |
| 960 | nullptr; // wait until we find the config |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 961 | |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 962 | boost::asio::post(io, |
| 963 | [&]() { createSensor(objectServer, sensor, systemBus); }); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 964 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 965 | boost::asio::steady_timer configTimer(io); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 966 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 967 | std::function<void(sdbusplus::message_t&)> eventHandler = |
| 968 | [&](sdbusplus::message_t&) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 969 | configTimer.expires_after(std::chrono::seconds(1)); |
| 970 | // create a timer because normally multiple properties change |
| 971 | configTimer.async_wait([&](const boost::system::error_code& ec) { |
| 972 | if (ec == boost::asio::error::operation_aborted) |
| 973 | { |
| 974 | return; // we're being canceled |
| 975 | } |
| 976 | createSensor(objectServer, sensor, systemBus); |
| 977 | if (!sensor) |
| 978 | { |
George Liu | ce1abb6 | 2025-02-20 10:44:47 +0800 | [diff] [blame] | 979 | lg2::info("Configuration not detected"); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 980 | } |
| 981 | }); |
| 982 | }; |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 983 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches = |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 984 | setupPropertiesChangedMatches(*systemBus, monitorTypes, eventHandler); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 985 | |
Bruce Lee | 913d4d0 | 2021-07-22 10:18:42 +0800 | [diff] [blame] | 986 | setupManufacturingModeMatch(*systemBus); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 987 | io.run(); |
Zhikui Ren | 8685b17 | 2021-06-29 15:16:52 -0700 | [diff] [blame] | 988 | return 0; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 989 | } |