James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 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 | |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 17 | #include "PresenceGpio.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 18 | #include "PwmSensor.hpp" |
| 19 | #include "TachSensor.hpp" |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 20 | #include "Thresholds.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 21 | #include "Utils.hpp" |
| 22 | #include "VariantVisitors.hpp" |
| 23 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 24 | #include <boost/algorithm/string/replace.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 25 | #include <boost/asio/error.hpp> |
| 26 | #include <boost/asio/io_context.hpp> |
| 27 | #include <boost/asio/post.hpp> |
| 28 | #include <boost/asio/steady_timer.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 29 | #include <boost/container/flat_map.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 30 | #include <boost/container/flat_set.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 31 | #include <sdbusplus/asio/connection.hpp> |
| 32 | #include <sdbusplus/asio/object_server.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 33 | #include <sdbusplus/bus.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 34 | #include <sdbusplus/bus/match.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 35 | #include <sdbusplus/message.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 36 | |
| 37 | #include <array> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 38 | #include <chrono> |
| 39 | #include <cstddef> |
| 40 | #include <cstdint> |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 41 | #include <filesystem> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 42 | #include <fstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 43 | #include <functional> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 44 | #include <ios> |
| 45 | #include <iostream> |
| 46 | #include <map> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 47 | #include <memory> |
| 48 | #include <optional> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 49 | #include <regex> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 50 | #include <string> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 51 | #include <system_error> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 52 | #include <utility> |
| 53 | #include <variant> |
| 54 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 55 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 56 | namespace fs = std::filesystem; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 57 | |
Yong Zhao | a3e8f2a | 2021-01-09 02:22:43 +0000 | [diff] [blame] | 58 | // The following two structures need to be consistent |
Chris Sides | c361e22 | 2023-04-05 15:18:20 -0500 | [diff] [blame] | 59 | static auto sensorTypes{std::to_array<const char*>( |
| 60 | {"AspeedFan", "I2CFan", "NuvotonFan", "HPEFan"})}; |
Yong Zhao | a3e8f2a | 2021-01-09 02:22:43 +0000 | [diff] [blame] | 61 | |
| 62 | enum FanTypes |
| 63 | { |
| 64 | aspeed = 0, |
| 65 | i2c, |
| 66 | nuvoton, |
Chris Sides | c361e22 | 2023-04-05 15:18:20 -0500 | [diff] [blame] | 67 | hpe, |
Yong Zhao | a3e8f2a | 2021-01-09 02:22:43 +0000 | [diff] [blame] | 68 | max, |
| 69 | }; |
| 70 | |
| 71 | static_assert(std::tuple_size<decltype(sensorTypes)>::value == FanTypes::max, |
| 72 | "sensorTypes element number is not equal to FanTypes number"); |
| 73 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 74 | constexpr const char* redundancyConfiguration = |
| 75 | "xyz.openbmc_project.Configuration.FanRedundancy"; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 76 | static std::regex inputRegex(R"(fan(\d+)_input)"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 77 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 78 | // todo: power supply fan redundancy |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 79 | std::optional<RedundancySensor> systemRedundancy; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 80 | |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 81 | static const std::map<std::string, FanTypes> compatibleFanTypes = { |
| 82 | {"aspeed,ast2400-pwm-tacho", FanTypes::aspeed}, |
| 83 | {"aspeed,ast2500-pwm-tacho", FanTypes::aspeed}, |
Potin Lai | 40c4d68 | 2023-05-19 17:19:03 +0800 | [diff] [blame] | 84 | {"aspeed,ast2600-pwm-tach", FanTypes::aspeed}, |
Chris Sides | c361e22 | 2023-04-05 15:18:20 -0500 | [diff] [blame] | 85 | {"nuvoton,npcm750-pwm-fan", FanTypes::nuvoton}, |
Brian Ma | d37e1db | 2023-05-08 13:36:53 +0800 | [diff] [blame] | 86 | {"nuvoton,npcm845-pwm-fan", FanTypes::nuvoton}, |
Chris Sides | c361e22 | 2023-04-05 15:18:20 -0500 | [diff] [blame] | 87 | {"hpe,gxp-fan-ctrl", FanTypes::hpe} |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 88 | // add compatible string here for new fan type |
| 89 | }; |
| 90 | |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 91 | FanTypes getFanType(const fs::path& parentPath) |
| 92 | { |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 93 | fs::path linkPath = parentPath / "of_node"; |
Zhikui Ren | 3996322 | 2023-05-04 17:06:50 -0700 | [diff] [blame] | 94 | if (!fs::exists(linkPath)) |
| 95 | { |
| 96 | return FanTypes::i2c; |
| 97 | } |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 98 | |
Zhikui Ren | 3996322 | 2023-05-04 17:06:50 -0700 | [diff] [blame] | 99 | std::string canonical = fs::canonical(linkPath); |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 100 | std::string compatiblePath = canonical + "/compatible"; |
| 101 | std::ifstream compatibleStream(compatiblePath); |
| 102 | |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 103 | if (!compatibleStream) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 104 | { |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 105 | std::cerr << "Error opening " << compatiblePath << "\n"; |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 106 | return FanTypes::i2c; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 107 | } |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 108 | |
| 109 | std::string compatibleString; |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 110 | while (std::getline(compatibleStream, compatibleString)) |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 111 | { |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 112 | compatibleString.pop_back(); // trim EOL before comparisons |
| 113 | |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 114 | std::map<std::string, FanTypes>::const_iterator compatibleIterator = |
| 115 | compatibleFanTypes.find(compatibleString); |
| 116 | |
| 117 | if (compatibleIterator != compatibleFanTypes.end()) |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 118 | { |
Chris Sides | 3d5260d | 2023-04-10 15:45:00 -0500 | [diff] [blame] | 119 | return compatibleIterator->second; |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 120 | } |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 121 | } |
Chris Sides | 9a472e8 | 2023-04-03 15:13:37 -0500 | [diff] [blame] | 122 | |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 123 | return FanTypes::i2c; |
| 124 | } |
Jeff Lin | abf91de | 2020-12-23 10:55:42 +0800 | [diff] [blame] | 125 | void enablePwm(const fs::path& filePath) |
| 126 | { |
| 127 | std::fstream enableFile(filePath, std::ios::in | std::ios::out); |
| 128 | if (!enableFile.good()) |
| 129 | { |
| 130 | std::cerr << "Error read/write " << filePath << "\n"; |
| 131 | return; |
| 132 | } |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 133 | |
Jeff Lin | abf91de | 2020-12-23 10:55:42 +0800 | [diff] [blame] | 134 | std::string regulateMode; |
| 135 | std::getline(enableFile, regulateMode); |
| 136 | if (regulateMode == "0") |
| 137 | { |
| 138 | enableFile << 1; |
| 139 | } |
| 140 | } |
Howard Chiu | ddf25d1 | 2021-12-02 15:14:44 +0800 | [diff] [blame] | 141 | bool findPwmfanPath(unsigned int configPwmfanIndex, fs::path& pwmPath) |
| 142 | { |
| 143 | /* Search PWM since pwm-fan had separated |
| 144 | * PWM from tach directory and 1 channel only*/ |
| 145 | std::vector<fs::path> pwmfanPaths; |
| 146 | std::string pwnfanDevName("pwm-fan"); |
| 147 | |
| 148 | pwnfanDevName += std::to_string(configPwmfanIndex); |
| 149 | |
| 150 | if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwmfanPaths)) |
| 151 | { |
| 152 | std::cerr << "No PWMs are found!\n"; |
| 153 | return false; |
| 154 | } |
| 155 | for (const auto& path : pwmfanPaths) |
| 156 | { |
| 157 | std::error_code ec; |
| 158 | fs::path link = fs::read_symlink(path.parent_path() / "device", ec); |
| 159 | |
| 160 | if (ec) |
| 161 | { |
| 162 | std::cerr << "read_symlink() failed: " << ec.message() << " (" |
| 163 | << ec.value() << ")\n"; |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | if (link.filename().string() == pwnfanDevName) |
| 168 | { |
| 169 | pwmPath = path; |
| 170 | return true; |
| 171 | } |
| 172 | } |
| 173 | return false; |
| 174 | } |
| 175 | bool findPwmPath(const fs::path& directory, unsigned int pwm, fs::path& pwmPath) |
| 176 | { |
| 177 | std::error_code ec; |
| 178 | |
| 179 | /* Assuming PWM file is appeared in the same directory as fanX_input */ |
| 180 | auto path = directory / ("pwm" + std::to_string(pwm + 1)); |
| 181 | bool exists = fs::exists(path, ec); |
| 182 | |
| 183 | if (ec || !exists) |
| 184 | { |
| 185 | /* PWM file not exist or error happened */ |
| 186 | if (ec) |
| 187 | { |
| 188 | std::cerr << "exists() failed: " << ec.message() << " (" |
| 189 | << ec.value() << ")\n"; |
| 190 | } |
| 191 | /* try search form pwm-fanX directory */ |
| 192 | return findPwmfanPath(pwm, pwmPath); |
| 193 | } |
| 194 | |
| 195 | pwmPath = path; |
| 196 | return true; |
| 197 | } |
Justin Ledford | 9c47bd7 | 2022-08-27 01:02:09 +0000 | [diff] [blame] | 198 | |
| 199 | // The argument to this function should be the fanN_input file that we want to |
| 200 | // enable. The function will locate the corresponding fanN_enable file if it |
| 201 | // exists. Note that some drivers don't provide this file if the sensors are |
| 202 | // always enabled. |
| 203 | void enableFanInput(const fs::path& fanInputPath) |
| 204 | { |
| 205 | std::error_code ec; |
| 206 | std::string path(fanInputPath.string()); |
| 207 | boost::replace_last(path, "input", "enable"); |
| 208 | |
| 209 | bool exists = fs::exists(path, ec); |
| 210 | if (ec || !exists) |
| 211 | { |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | std::fstream enableFile(path, std::ios::out); |
| 216 | if (!enableFile.good()) |
| 217 | { |
| 218 | return; |
| 219 | } |
| 220 | enableFile << 1; |
| 221 | } |
| 222 | |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 223 | void createRedundancySensor( |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 224 | const boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>& |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 225 | sensors, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 226 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 227 | sdbusplus::asio::object_server& objectServer) |
| 228 | { |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 229 | conn->async_method_call( |
| 230 | [&objectServer, &sensors](boost::system::error_code& ec, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 231 | const ManagedObjectType& managedObj) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 232 | if (ec) |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 233 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 234 | std::cerr << "Error calling entity manager \n"; |
| 235 | return; |
| 236 | } |
| 237 | for (const auto& [path, interfaces] : managedObj) |
| 238 | { |
| 239 | for (const auto& [intf, cfg] : interfaces) |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 240 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 241 | if (intf == redundancyConfiguration) |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 242 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 243 | // currently only support one |
| 244 | auto findCount = cfg.find("AllowedFailures"); |
| 245 | if (findCount == cfg.end()) |
| 246 | { |
| 247 | std::cerr << "Malformed redundancy record \n"; |
| 248 | return; |
| 249 | } |
| 250 | std::vector<std::string> sensorList; |
| 251 | |
| 252 | for (const auto& [name, sensor] : sensors) |
| 253 | { |
| 254 | sensorList.push_back( |
| 255 | "/xyz/openbmc_project/sensors/fan_tach/" + |
| 256 | sensor->name); |
| 257 | } |
| 258 | systemRedundancy.reset(); |
| 259 | systemRedundancy.emplace(RedundancySensor( |
| 260 | std::get<uint64_t>(findCount->second), sensorList, |
| 261 | objectServer, path)); |
| 262 | |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 263 | return; |
| 264 | } |
| 265 | } |
| 266 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 267 | }, |
Nan Zhou | 3e620af | 2022-09-20 22:28:31 +0000 | [diff] [blame] | 268 | "xyz.openbmc_project.EntityManager", "/xyz/openbmc_project/inventory", |
Kuiying Wang | d540741 | 2020-09-09 16:06:56 +0800 | [diff] [blame] | 269 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 270 | } |
| 271 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 272 | void createSensors( |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 273 | boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 274 | boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>& |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 275 | tachSensors, |
| 276 | boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>& |
| 277 | pwmSensors, |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 278 | boost::container::flat_map<std::string, std::weak_ptr<PresenceGpio>>& |
| 279 | presenceGpios, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 280 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
James Feist | 5591cf08 | 2020-07-15 16:44:54 -0700 | [diff] [blame] | 281 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 282 | sensorsChanged, |
| 283 | size_t retries = 0) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 284 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 285 | auto getter = std::make_shared<GetSensorConfiguration>( |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 286 | dbusConnection, |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 287 | [&io, &objectServer, &tachSensors, &pwmSensors, &presenceGpios, |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 288 | &dbusConnection, |
| 289 | sensorsChanged](const ManagedObjectType& sensorConfigurations) { |
| 290 | bool firstScan = sensorsChanged == nullptr; |
| 291 | std::vector<fs::path> paths; |
| 292 | if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", |
| 293 | paths)) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 294 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 295 | std::cerr << "No fan sensors in system\n"; |
| 296 | return; |
| 297 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 298 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 299 | // iterate through all found fan sensors, and try to match them with |
| 300 | // configuration |
| 301 | for (const auto& path : paths) |
| 302 | { |
| 303 | std::smatch match; |
| 304 | std::string pathStr = path.string(); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 305 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 306 | std::regex_search(pathStr, match, inputRegex); |
| 307 | std::string indexStr = *(match.begin() + 1); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 308 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 309 | fs::path directory = path.parent_path(); |
| 310 | FanTypes fanType = getFanType(directory); |
| 311 | std::string cfgIntf = configInterfaceName(sensorTypes[fanType]); |
| 312 | |
| 313 | // convert to 0 based |
| 314 | size_t index = std::stoul(indexStr) - 1; |
| 315 | |
| 316 | const char* baseType = nullptr; |
| 317 | const SensorData* sensorData = nullptr; |
| 318 | const std::string* interfacePath = nullptr; |
| 319 | const SensorBaseConfiguration* baseConfiguration = nullptr; |
| 320 | for (const auto& [path, cfgData] : sensorConfigurations) |
| 321 | { |
| 322 | // find the base of the configuration to see if indexes |
| 323 | // match |
| 324 | auto sensorBaseFind = cfgData.find(cfgIntf); |
| 325 | if (sensorBaseFind == cfgData.end()) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 326 | { |
Akshit Shah | 03d333e | 2023-08-23 22:14:28 +0000 | [diff] [blame] | 327 | continue; |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 328 | } |
Zhikui Ren | 347dd4e | 2019-12-12 13:39:50 -0800 | [diff] [blame] | 329 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 330 | baseConfiguration = &(*sensorBaseFind); |
| 331 | interfacePath = &path.str; |
| 332 | baseType = sensorTypes[fanType]; |
| 333 | |
| 334 | auto findIndex = baseConfiguration->second.find("Index"); |
| 335 | if (findIndex == baseConfiguration->second.end()) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 336 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 337 | std::cerr |
| 338 | << baseConfiguration->first << " missing index\n"; |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 339 | continue; |
| 340 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 341 | unsigned int configIndex = std::visit( |
| 342 | VariantToUnsignedIntVisitor(), findIndex->second); |
| 343 | if (configIndex != index) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 344 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 345 | continue; |
| 346 | } |
| 347 | if (fanType == FanTypes::aspeed || |
| 348 | fanType == FanTypes::nuvoton || |
| 349 | fanType == FanTypes::hpe) |
| 350 | { |
| 351 | // there will be only 1 aspeed or nuvoton or hpe sensor |
| 352 | // object in sysfs, we found the fan |
Zev Weiss | 77636ec | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 353 | sensorData = &cfgData; |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 354 | break; |
| 355 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 356 | if (fanType == FanTypes::i2c) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 357 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 358 | std::string deviceName = |
| 359 | fs::read_symlink(directory / "device").filename(); |
| 360 | |
| 361 | size_t bus = 0; |
| 362 | size_t addr = 0; |
| 363 | if (!getDeviceBusAddr(deviceName, bus, addr)) |
| 364 | { |
| 365 | continue; |
| 366 | } |
| 367 | |
| 368 | auto findBus = baseConfiguration->second.find("Bus"); |
| 369 | auto findAddress = |
| 370 | baseConfiguration->second.find("Address"); |
| 371 | if (findBus == baseConfiguration->second.end() || |
| 372 | findAddress == baseConfiguration->second.end()) |
| 373 | { |
| 374 | std::cerr << baseConfiguration->first |
| 375 | << " missing bus or address\n"; |
| 376 | continue; |
| 377 | } |
| 378 | unsigned int configBus = std::visit( |
| 379 | VariantToUnsignedIntVisitor(), findBus->second); |
| 380 | unsigned int configAddress = std::visit( |
| 381 | VariantToUnsignedIntVisitor(), findAddress->second); |
| 382 | |
| 383 | if (configBus == bus && configAddress == addr) |
| 384 | { |
| 385 | sensorData = &cfgData; |
| 386 | break; |
| 387 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 390 | if (sensorData == nullptr) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 391 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 392 | std::cerr |
| 393 | << "failed to find match for " << path.string() << "\n"; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 394 | continue; |
| 395 | } |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 396 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 397 | auto findSensorName = baseConfiguration->second.find("Name"); |
Zhikui Ren | 347dd4e | 2019-12-12 13:39:50 -0800 | [diff] [blame] | 398 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 399 | if (findSensorName == baseConfiguration->second.end()) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 400 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 401 | std::cerr << "could not determine configuration name for " |
| 402 | << path.string() << "\n"; |
| 403 | continue; |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 404 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 405 | std::string sensorName = |
| 406 | std::get<std::string>(findSensorName->second); |
Patrick Rudolph | 8b34f2c | 2024-07-16 11:38:45 +0200 | [diff] [blame] | 407 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 408 | // on rescans, only update sensors we were signaled by |
| 409 | auto findSensor = tachSensors.find(sensorName); |
| 410 | if (!firstScan && findSensor != tachSensors.end()) |
| 411 | { |
| 412 | bool found = false; |
| 413 | for (auto it = sensorsChanged->begin(); |
| 414 | it != sensorsChanged->end(); it++) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 415 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 416 | if (it->ends_with(findSensor->second->name)) |
Patrick Rudolph | 8b34f2c | 2024-07-16 11:38:45 +0200 | [diff] [blame] | 417 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 418 | sensorsChanged->erase(it); |
| 419 | findSensor->second = nullptr; |
| 420 | found = true; |
| 421 | break; |
Patrick Rudolph | 8b34f2c | 2024-07-16 11:38:45 +0200 | [diff] [blame] | 422 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 423 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 424 | if (!found) |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 425 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 426 | continue; |
| 427 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 428 | } |
| 429 | std::vector<thresholds::Threshold> sensorThresholds; |
| 430 | if (!parseThresholdsFromConfig(*sensorData, sensorThresholds)) |
| 431 | { |
| 432 | std::cerr << "error populating thresholds for " |
| 433 | << sensorName << "\n"; |
| 434 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 435 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 436 | auto presenceConfig = |
| 437 | sensorData->find(cfgIntf + std::string(".Presence")); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 438 | |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 439 | std::shared_ptr<PresenceGpio> presenceGpio(nullptr); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 440 | |
| 441 | // presence sensors are optional |
| 442 | if (presenceConfig != sensorData->end()) |
| 443 | { |
| 444 | auto findPolarity = presenceConfig->second.find("Polarity"); |
| 445 | auto findPinName = presenceConfig->second.find("PinName"); |
| 446 | |
| 447 | if (findPinName == presenceConfig->second.end() || |
| 448 | findPolarity == presenceConfig->second.end()) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 449 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 450 | std::cerr << "Malformed Presence Configuration\n"; |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 451 | } |
| 452 | else |
| 453 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 454 | bool inverted = std::get<std::string>( |
| 455 | findPolarity->second) == "Low"; |
| 456 | const auto* pinName = |
| 457 | std::get_if<std::string>(&findPinName->second); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 458 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 459 | if (pinName != nullptr) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 460 | { |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 461 | auto findPresenceGpio = |
| 462 | presenceGpios.find(*pinName); |
| 463 | if (findPresenceGpio != presenceGpios.end()) |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 464 | { |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 465 | auto p = findPresenceGpio->second.lock(); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 466 | if (p) |
| 467 | { |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 468 | presenceGpio = p; |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 469 | } |
| 470 | } |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 471 | if (!presenceGpio) |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 472 | { |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 473 | presenceGpio = |
| 474 | std::make_shared<EventPresenceGpio>( |
| 475 | "Fan", sensorName, *pinName, inverted, |
| 476 | io); |
| 477 | presenceGpios[*pinName] = presenceGpio; |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | std::cerr |
| 483 | << "Malformed Presence pinName for sensor " |
| 484 | << sensorName << " \n"; |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 488 | std::optional<RedundancySensor>* redundancy = nullptr; |
| 489 | if (fanType == FanTypes::aspeed) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 490 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 491 | redundancy = &systemRedundancy; |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 494 | PowerState powerState = |
| 495 | getPowerState(baseConfiguration->second); |
| 496 | |
| 497 | constexpr double defaultMaxReading = 25000; |
| 498 | constexpr double defaultMinReading = 0; |
| 499 | std::pair<double, double> limits = |
| 500 | std::make_pair(defaultMinReading, defaultMaxReading); |
| 501 | |
| 502 | auto connector = |
| 503 | sensorData->find(cfgIntf + std::string(".Connector")); |
| 504 | |
| 505 | std::optional<std::string> led; |
| 506 | std::string pwmName; |
| 507 | fs::path pwmPath; |
| 508 | |
| 509 | // The Mutable parameter is optional, defaulting to false |
| 510 | bool isValueMutable = false; |
| 511 | if (connector != sensorData->end()) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 512 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 513 | auto findPwm = connector->second.find("Pwm"); |
| 514 | if (findPwm != connector->second.end()) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 515 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 516 | size_t pwm = std::visit(VariantToUnsignedIntVisitor(), |
| 517 | findPwm->second); |
| 518 | if (!findPwmPath(directory, pwm, pwmPath)) |
| 519 | { |
| 520 | std::cerr << "Connector for " << sensorName |
| 521 | << " no pwm channel found!\n"; |
| 522 | continue; |
| 523 | } |
| 524 | |
| 525 | fs::path pwmEnableFile = |
| 526 | "pwm" + std::to_string(pwm + 1) + "_enable"; |
| 527 | fs::path enablePath = |
| 528 | pwmPath.parent_path() / pwmEnableFile; |
| 529 | enablePwm(enablePath); |
| 530 | |
| 531 | /* use pwm name override if found in configuration else |
| 532 | * use default */ |
| 533 | auto findOverride = connector->second.find("PwmName"); |
| 534 | if (findOverride != connector->second.end()) |
| 535 | { |
| 536 | pwmName = std::visit(VariantToStringVisitor(), |
| 537 | findOverride->second); |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | pwmName = "Pwm_" + std::to_string(pwm + 1); |
| 542 | } |
| 543 | |
| 544 | // Check PWM sensor mutability |
| 545 | auto findMutable = connector->second.find("Mutable"); |
| 546 | if (findMutable != connector->second.end()) |
| 547 | { |
| 548 | const auto* ptrMutable = |
| 549 | std::get_if<bool>(&(findMutable->second)); |
| 550 | if (ptrMutable != nullptr) |
| 551 | { |
| 552 | isValueMutable = *ptrMutable; |
| 553 | } |
| 554 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 555 | } |
| 556 | else |
| 557 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 558 | std::cerr << "Connector for " << sensorName |
| 559 | << " missing pwm!\n"; |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 560 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 561 | |
| 562 | auto findLED = connector->second.find("LED"); |
| 563 | if (findLED != connector->second.end()) |
| 564 | { |
| 565 | const auto* ledName = |
| 566 | std::get_if<std::string>(&(findLED->second)); |
| 567 | if (ledName == nullptr) |
| 568 | { |
| 569 | std::cerr << "Wrong format for LED of " |
| 570 | << sensorName << "\n"; |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | led = *ledName; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | findLimits(limits, baseConfiguration); |
| 580 | |
| 581 | enableFanInput(path); |
| 582 | |
| 583 | auto& tachSensor = tachSensors[sensorName]; |
| 584 | tachSensor = nullptr; |
| 585 | tachSensor = std::make_shared<TachSensor>( |
| 586 | path.string(), baseType, objectServer, dbusConnection, |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 587 | presenceGpio, redundancy, io, sensorName, |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 588 | std::move(sensorThresholds), *interfacePath, limits, |
| 589 | powerState, led); |
| 590 | tachSensor->setupRead(); |
| 591 | |
| 592 | if (!pwmPath.empty() && fs::exists(pwmPath) && |
| 593 | (pwmSensors.count(pwmPath) == 0U)) |
| 594 | { |
| 595 | pwmSensors[pwmPath] = std::make_unique<PwmSensor>( |
| 596 | pwmName, pwmPath, dbusConnection, objectServer, |
| 597 | *interfacePath, "Fan", isValueMutable); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 601 | createRedundancySensor(tachSensors, dbusConnection, objectServer); |
| 602 | }); |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 603 | getter->getConfiguration( |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 604 | std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()}, |
| 605 | retries); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 606 | } |
| 607 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 608 | int main() |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 609 | { |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 610 | boost::asio::io_context io; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 611 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
Ed Tanous | 14ed5e9 | 2022-07-12 15:50:23 -0700 | [diff] [blame] | 612 | sdbusplus::asio::object_server objectServer(systemBus, true); |
| 613 | |
| 614 | objectServer.add_manager("/xyz/openbmc_project/sensors"); |
Ed Tanous | d906725 | 2022-10-22 15:35:52 -0700 | [diff] [blame] | 615 | objectServer.add_manager("/xyz/openbmc_project/control"); |
Lei YU | c2f83fe | 2022-12-02 14:49:47 +0800 | [diff] [blame] | 616 | objectServer.add_manager("/xyz/openbmc_project/inventory"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 617 | systemBus->request_name("xyz.openbmc_project.FanSensor"); |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 618 | boost::container::flat_map<std::string, std::shared_ptr<TachSensor>> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 619 | tachSensors; |
| 620 | boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>> |
| 621 | pwmSensors; |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 622 | boost::container::flat_map<std::string, std::weak_ptr<PresenceGpio>> |
| 623 | presenceGpios; |
James Feist | 5591cf08 | 2020-07-15 16:44:54 -0700 | [diff] [blame] | 624 | auto sensorsChanged = |
| 625 | std::make_shared<boost::container::flat_set<std::string>>(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 626 | |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 627 | boost::asio::post(io, [&]() { |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 628 | createSensors(io, objectServer, tachSensors, pwmSensors, presenceGpios, |
| 629 | systemBus, nullptr); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 630 | }); |
| 631 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 632 | boost::asio::steady_timer filterTimer(io); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 633 | std::function<void(sdbusplus::message_t&)> eventHandler = |
| 634 | [&](sdbusplus::message_t& message) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 635 | if (message.is_method_error()) |
| 636 | { |
| 637 | std::cerr << "callback method error\n"; |
| 638 | return; |
| 639 | } |
| 640 | sensorsChanged->insert(message.get_path()); |
| 641 | // this implicitly cancels the timer |
| 642 | filterTimer.expires_after(std::chrono::seconds(1)); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 643 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 644 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 645 | if (ec == boost::asio::error::operation_aborted) |
| 646 | { |
| 647 | /* we were canceled*/ |
| 648 | return; |
| 649 | } |
| 650 | if (ec) |
| 651 | { |
| 652 | std::cerr << "timer error\n"; |
| 653 | return; |
| 654 | } |
| 655 | createSensors(io, objectServer, tachSensors, pwmSensors, |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 656 | presenceGpios, systemBus, sensorsChanged, 5); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 657 | }); |
| 658 | }; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 659 | |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 660 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches = |
| 661 | setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 662 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 663 | // redundancy sensor |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 664 | std::function<void(sdbusplus::message_t&)> redundancyHandler = |
| 665 | [&tachSensors, &systemBus, &objectServer](sdbusplus::message_t&) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 666 | createRedundancySensor(tachSensors, systemBus, objectServer); |
| 667 | }; |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 668 | auto match = std::make_unique<sdbusplus::bus::match_t>( |
| 669 | static_cast<sdbusplus::bus_t&>(*systemBus), |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 670 | "type='signal',member='PropertiesChanged',path_namespace='" + |
| 671 | std::string(inventoryPath) + "',arg0namespace='" + |
| 672 | redundancyConfiguration + "'", |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 673 | std::move(redundancyHandler)); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 674 | matches.emplace_back(std::move(match)); |
| 675 | |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 676 | setupManufacturingModeMatch(*systemBus); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 677 | io.run(); |
Zhikui Ren | 8685b17 | 2021-06-29 15:16:52 -0700 | [diff] [blame] | 678 | return 0; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 679 | } |