Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 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 | */ |
Josh Lehan | 0830c7b | 2019-10-08 16:35:09 -0700 | [diff] [blame] | 16 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 17 | #include <PSUEvent.hpp> |
| 18 | #include <PSUSensor.hpp> |
| 19 | #include <Utils.hpp> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 20 | #include <boost/algorithm/string/predicate.hpp> |
| 21 | #include <boost/algorithm/string/replace.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 22 | #include <boost/container/flat_map.hpp> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 23 | #include <boost/container/flat_set.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 24 | #include <sdbusplus/asio/connection.hpp> |
| 25 | #include <sdbusplus/asio/object_server.hpp> |
| 26 | #include <sdbusplus/bus/match.hpp> |
| 27 | |
| 28 | #include <array> |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 29 | #include <cmath> |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 30 | #include <filesystem> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 31 | #include <fstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 32 | #include <functional> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 33 | #include <iostream> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 34 | #include <regex> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 35 | #include <string> |
Lei YU | a2c7cea | 2020-12-23 14:07:28 +0800 | [diff] [blame] | 36 | #include <string_view> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 37 | #include <utility> |
| 38 | #include <variant> |
| 39 | #include <vector> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 40 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 41 | static constexpr bool debug = false; |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 42 | |
Zev Weiss | eb0b84d | 2021-04-22 15:03:38 -0500 | [diff] [blame^] | 43 | static constexpr std::array<const char*, 24> sensorTypes = { |
Josh Lehan | 62084c8 | 2020-06-22 15:27:12 -0700 | [diff] [blame] | 44 | "xyz.openbmc_project.Configuration.ADM1272", |
Paul Fertser | 678f53b | 2021-04-06 07:06:28 +0000 | [diff] [blame] | 45 | "xyz.openbmc_project.Configuration.ADM1275", |
Josh Lehan | 62084c8 | 2020-06-22 15:27:12 -0700 | [diff] [blame] | 46 | "xyz.openbmc_project.Configuration.ADM1278", |
Jeff Lin | a0683a8 | 2021-02-22 13:56:55 +0800 | [diff] [blame] | 47 | "xyz.openbmc_project.Configuration.DPS800", |
Josh Lehan | 62084c8 | 2020-06-22 15:27:12 -0700 | [diff] [blame] | 48 | "xyz.openbmc_project.Configuration.INA219", |
Devjit Gopalpur | de65ef7 | 2019-10-30 04:47:35 -0700 | [diff] [blame] | 49 | "xyz.openbmc_project.Configuration.INA230", |
Alex Qiu | 6690d8f | 2020-01-22 17:56:33 -0800 | [diff] [blame] | 50 | "xyz.openbmc_project.Configuration.ISL68137", |
Jason Ling | dfad1ff | 2020-07-29 15:43:11 -0700 | [diff] [blame] | 51 | "xyz.openbmc_project.Configuration.ISL68220", |
Gaurav Gandhi | 4958558 | 2020-12-22 01:01:24 +0000 | [diff] [blame] | 52 | "xyz.openbmc_project.Configuration.ISL68223", |
| 53 | "xyz.openbmc_project.Configuration.ISL69243", |
Jeff Lin | a0683a8 | 2021-02-22 13:56:55 +0800 | [diff] [blame] | 54 | "xyz.openbmc_project.Configuration.ISL69260", |
Zev Weiss | eb0b84d | 2021-04-22 15:03:38 -0500 | [diff] [blame^] | 55 | "xyz.openbmc_project.Configuration.LM25066", |
Alex Qiu | f5709b4 | 2020-01-29 13:29:50 -0800 | [diff] [blame] | 56 | "xyz.openbmc_project.Configuration.MAX16601", |
Gaurav Gandhi | 4958558 | 2020-12-22 01:01:24 +0000 | [diff] [blame] | 57 | "xyz.openbmc_project.Configuration.MAX20710", |
Alex Qiu | 6690d8f | 2020-01-22 17:56:33 -0800 | [diff] [blame] | 58 | "xyz.openbmc_project.Configuration.MAX20730", |
| 59 | "xyz.openbmc_project.Configuration.MAX20734", |
| 60 | "xyz.openbmc_project.Configuration.MAX20796", |
| 61 | "xyz.openbmc_project.Configuration.MAX34451", |
Josh Lehan | 62084c8 | 2020-06-22 15:27:12 -0700 | [diff] [blame] | 62 | "xyz.openbmc_project.Configuration.pmbus", |
| 63 | "xyz.openbmc_project.Configuration.PXE1610", |
Jeff Lin | a0683a8 | 2021-02-22 13:56:55 +0800 | [diff] [blame] | 64 | "xyz.openbmc_project.Configuration.RAA228000", |
| 65 | "xyz.openbmc_project.Configuration.RAA228228", |
| 66 | "xyz.openbmc_project.Configuration.RAA229004", |
| 67 | "xyz.openbmc_project.Configuration.TPS546D24"}; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 68 | |
Alex Qiu | 6690d8f | 2020-01-22 17:56:33 -0800 | [diff] [blame] | 69 | static std::vector<std::string> pmbusNames = { |
Zev Weiss | eb0b84d | 2021-04-22 15:03:38 -0500 | [diff] [blame^] | 70 | "adm1272", "adm1275", "adm1278", "dps800", "ina219", "ina230", |
| 71 | "isl68137", "isl68220", "isl68223", "isl69243", "isl69260", "lm25066", |
| 72 | "max16601", "max20710", "max20730", "max20734", "max20796", "max34451", |
| 73 | "pmbus", "pxe1610", "raa228000", "raa228228", "raa229004", "tps546d24"}; |
Josh Lehan | 0830c7b | 2019-10-08 16:35:09 -0700 | [diff] [blame] | 74 | |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 75 | namespace fs = std::filesystem; |
| 76 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 77 | static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>> |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 78 | sensors; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 79 | static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>> |
| 80 | combineEvents; |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 81 | static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>> |
| 82 | pwmSensors; |
| 83 | static boost::container::flat_map<std::string, std::string> sensorTable; |
| 84 | static boost::container::flat_map<std::string, PSUProperty> labelMatch; |
| 85 | static boost::container::flat_map<std::string, std::string> pwmTable; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 86 | static boost::container::flat_map<std::string, std::vector<std::string>> |
| 87 | eventMatch; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 88 | static boost::container::flat_map< |
| 89 | std::string, |
| 90 | boost::container::flat_map<std::string, std::vector<std::string>>> |
| 91 | groupEventMatch; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 92 | static boost::container::flat_map<std::string, std::vector<std::string>> |
| 93 | limitEventMatch; |
| 94 | |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 95 | static std::vector<PSUProperty> psuProperties; |
| 96 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 97 | // Function CheckEvent will check each attribute from eventMatch table in the |
| 98 | // sysfs. If the attributes exists in sysfs, then store the complete path |
| 99 | // of the attribute into eventPathList. |
| 100 | void checkEvent( |
| 101 | const std::string& directory, |
| 102 | const boost::container::flat_map<std::string, std::vector<std::string>>& |
| 103 | eventMatch, |
| 104 | boost::container::flat_map<std::string, std::vector<std::string>>& |
| 105 | eventPathList) |
| 106 | { |
| 107 | for (const auto& match : eventMatch) |
| 108 | { |
| 109 | const std::vector<std::string>& eventAttrs = match.second; |
| 110 | const std::string& eventName = match.first; |
| 111 | for (const auto& eventAttr : eventAttrs) |
| 112 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 113 | std::string eventPath = directory; |
| 114 | eventPath += "/"; |
| 115 | eventPath += eventAttr; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 116 | |
| 117 | std::ifstream eventFile(eventPath); |
| 118 | if (!eventFile.good()) |
| 119 | { |
| 120 | continue; |
| 121 | } |
| 122 | |
| 123 | eventPathList[eventName].push_back(eventPath); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 128 | // Check Group Events which contains more than one targets in each combine |
| 129 | // events. |
| 130 | void checkGroupEvent( |
| 131 | const std::string& directory, |
| 132 | const boost::container::flat_map< |
| 133 | std::string, |
| 134 | boost::container::flat_map<std::string, std::vector<std::string>>>& |
| 135 | groupEventMatch, |
| 136 | boost::container::flat_map< |
| 137 | std::string, |
| 138 | boost::container::flat_map<std::string, std::vector<std::string>>>& |
| 139 | groupEventPathList) |
| 140 | { |
| 141 | for (const auto& match : groupEventMatch) |
| 142 | { |
| 143 | const std::string& groupEventName = match.first; |
| 144 | const boost::container::flat_map<std::string, std::vector<std::string>> |
| 145 | events = match.second; |
| 146 | boost::container::flat_map<std::string, std::vector<std::string>> |
| 147 | pathList; |
| 148 | for (const auto& match : events) |
| 149 | { |
| 150 | const std::string& eventName = match.first; |
| 151 | const std::vector<std::string>& eventAttrs = match.second; |
| 152 | for (const auto& eventAttr : eventAttrs) |
| 153 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 154 | std::string eventPath = directory; |
| 155 | eventPath += "/"; |
| 156 | eventPath += eventAttr; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 157 | std::ifstream eventFile(eventPath); |
| 158 | if (!eventFile.good()) |
| 159 | { |
| 160 | continue; |
| 161 | } |
| 162 | |
| 163 | pathList[eventName].push_back(eventPath); |
| 164 | } |
| 165 | } |
| 166 | groupEventPathList[groupEventName] = pathList; |
| 167 | } |
| 168 | } |
| 169 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 170 | // Function checkEventLimits will check all the psu related xxx_input attributes |
| 171 | // in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm |
| 172 | // xxx_min_alarm exist, then store the existing paths of the alarm attributes |
| 173 | // to eventPathList. |
| 174 | void checkEventLimits( |
| 175 | const std::string& sensorPathStr, |
| 176 | const boost::container::flat_map<std::string, std::vector<std::string>>& |
| 177 | limitEventMatch, |
| 178 | boost::container::flat_map<std::string, std::vector<std::string>>& |
| 179 | eventPathList) |
| 180 | { |
Lei YU | a2c7cea | 2020-12-23 14:07:28 +0800 | [diff] [blame] | 181 | auto attributePartPos = sensorPathStr.find_last_of('_'); |
| 182 | if (attributePartPos == std::string::npos) |
| 183 | { |
| 184 | // There is no '_' in the string, skip it |
| 185 | return; |
| 186 | } |
| 187 | auto attributePart = |
| 188 | std::string_view(sensorPathStr).substr(attributePartPos + 1); |
| 189 | if (attributePart != "input") |
| 190 | { |
| 191 | // If the sensor is not xxx_input, skip it |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 196 | for (const auto& limitMatch : limitEventMatch) |
| 197 | { |
| 198 | const std::vector<std::string>& limitEventAttrs = limitMatch.second; |
| 199 | const std::string& eventName = limitMatch.first; |
| 200 | for (const auto& limitEventAttr : limitEventAttrs) |
| 201 | { |
Lei YU | a2c7cea | 2020-12-23 14:07:28 +0800 | [diff] [blame] | 202 | auto limitEventPath = prefixPart + limitEventAttr; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 203 | std::ifstream eventFile(limitEventPath); |
| 204 | if (!eventFile.good()) |
| 205 | { |
| 206 | continue; |
| 207 | } |
| 208 | eventPathList[eventName].push_back(limitEventPath); |
| 209 | } |
| 210 | } |
| 211 | } |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 212 | |
AppaRao Puli | d9d8caf | 2020-02-27 20:56:59 +0530 | [diff] [blame] | 213 | static void |
| 214 | checkPWMSensor(const fs::path& sensorPath, std::string& labelHead, |
| 215 | const std::string& interfacePath, |
| 216 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 217 | sdbusplus::asio::object_server& objectServer, |
| 218 | const std::string& psuName) |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 219 | { |
| 220 | for (const auto& pwmName : pwmTable) |
| 221 | { |
| 222 | if (pwmName.first != labelHead) |
| 223 | { |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | const std::string& sensorPathStr = sensorPath.string(); |
| 228 | const std::string& pwmPathStr = |
| 229 | boost::replace_all_copy(sensorPathStr, "input", "target"); |
| 230 | std::ifstream pwmFile(pwmPathStr); |
| 231 | if (!pwmFile.good()) |
| 232 | { |
| 233 | continue; |
| 234 | } |
| 235 | |
| 236 | auto findPWMSensor = pwmSensors.find(psuName + labelHead); |
| 237 | if (findPWMSensor != pwmSensors.end()) |
| 238 | { |
| 239 | continue; |
| 240 | } |
| 241 | |
| 242 | pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>( |
AppaRao Puli | d9d8caf | 2020-02-27 20:56:59 +0530 | [diff] [blame] | 243 | "Pwm_" + psuName + "_" + pwmName.second, pwmPathStr, dbusConnection, |
| 244 | objectServer, interfacePath + "_" + pwmName.second, "PSU"); |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 248 | static void createSensorsCallback( |
| 249 | boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, |
| 250 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 251 | const ManagedObjectType& sensorConfigs, |
| 252 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
| 253 | sensorsChanged) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 254 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 255 | int numCreated = 0; |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 256 | bool firstScan = sensorsChanged == nullptr; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 257 | |
| 258 | std::vector<fs::path> pmbusPaths; |
| 259 | if (!findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths)) |
| 260 | { |
| 261 | std::cerr << "No PSU sensors in system\n"; |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | boost::container::flat_set<std::string> directories; |
| 266 | for (const auto& pmbusPath : pmbusPaths) |
| 267 | { |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 268 | boost::container::flat_map<std::string, std::vector<std::string>> |
| 269 | eventPathList; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 270 | boost::container::flat_map< |
| 271 | std::string, |
| 272 | boost::container::flat_map<std::string, std::vector<std::string>>> |
| 273 | groupEventPathList; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 274 | |
| 275 | std::ifstream nameFile(pmbusPath); |
| 276 | if (!nameFile.good()) |
| 277 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 278 | std::cerr << "Failure finding pmbus path " << pmbusPath << "\n"; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 279 | continue; |
| 280 | } |
| 281 | |
| 282 | std::string pmbusName; |
| 283 | std::getline(nameFile, pmbusName); |
| 284 | nameFile.close(); |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 285 | |
| 286 | if (std::find(pmbusNames.begin(), pmbusNames.end(), pmbusName) == |
| 287 | pmbusNames.end()) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 288 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 289 | // To avoid this error message, add your driver name to |
| 290 | // the pmbusNames vector at the top of this file. |
| 291 | std::cerr << "Driver name " << pmbusName |
| 292 | << " not found in sensor whitelist\n"; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 293 | continue; |
| 294 | } |
| 295 | |
| 296 | const std::string* psuName; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 297 | auto directory = pmbusPath.parent_path(); |
| 298 | |
| 299 | auto ret = directories.insert(directory.string()); |
| 300 | if (!ret.second) |
| 301 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 302 | std::cerr << "Duplicate path " << directory.string() << "\n"; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 303 | continue; // check if path has already been searched |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 304 | } |
| 305 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 306 | fs::path device = directory / "device"; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 307 | std::string deviceName = fs::canonical(device).stem(); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 308 | auto findHyphen = deviceName.find('-'); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 309 | if (findHyphen == std::string::npos) |
| 310 | { |
| 311 | std::cerr << "found bad device" << deviceName << "\n"; |
| 312 | continue; |
| 313 | } |
| 314 | std::string busStr = deviceName.substr(0, findHyphen); |
| 315 | std::string addrStr = deviceName.substr(findHyphen + 1); |
| 316 | |
| 317 | size_t bus = 0; |
| 318 | size_t addr = 0; |
| 319 | |
| 320 | try |
| 321 | { |
| 322 | bus = std::stoi(busStr); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 323 | addr = std::stoi(addrStr, nullptr, 16); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 324 | } |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 325 | catch (std::invalid_argument&) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 326 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 327 | std::cerr << "Error parsing bus " << busStr << " addr " << addrStr |
| 328 | << "\n"; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 329 | continue; |
| 330 | } |
| 331 | |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 332 | const std::pair<std::string, boost::container::flat_map< |
| 333 | std::string, BasicVariantType>>* |
| 334 | baseConfig = nullptr; |
| 335 | const SensorData* sensorData = nullptr; |
| 336 | const std::string* interfacePath = nullptr; |
| 337 | const char* sensorType = nullptr; |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 338 | size_t thresholdConfSize = 0; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 339 | |
| 340 | for (const std::pair<sdbusplus::message::object_path, SensorData>& |
| 341 | sensor : sensorConfigs) |
| 342 | { |
| 343 | sensorData = &(sensor.second); |
| 344 | for (const char* type : sensorTypes) |
| 345 | { |
| 346 | auto sensorBase = sensorData->find(type); |
| 347 | if (sensorBase != sensorData->end()) |
| 348 | { |
| 349 | baseConfig = &(*sensorBase); |
| 350 | sensorType = type; |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | if (baseConfig == nullptr) |
| 355 | { |
| 356 | std::cerr << "error finding base configuration for " |
| 357 | << deviceName << "\n"; |
| 358 | continue; |
| 359 | } |
| 360 | |
| 361 | auto configBus = baseConfig->second.find("Bus"); |
| 362 | auto configAddress = baseConfig->second.find("Address"); |
| 363 | |
| 364 | if (configBus == baseConfig->second.end() || |
| 365 | configAddress == baseConfig->second.end()) |
| 366 | { |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 367 | std::cerr << "error finding necessary entry in configuration\n"; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 368 | continue; |
| 369 | } |
| 370 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 371 | const uint64_t* confBus; |
| 372 | const uint64_t* confAddr; |
| 373 | if (!(confBus = std::get_if<uint64_t>(&(configBus->second))) || |
| 374 | !(confAddr = std::get_if<uint64_t>(&(configAddress->second)))) |
| 375 | { |
| 376 | std::cerr |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 377 | << "Cannot get bus or address, invalid configuration\n"; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 378 | continue; |
| 379 | } |
| 380 | |
| 381 | if ((*confBus != bus) || (*confAddr != addr)) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 382 | { |
Josh Lehan | 432d1ed | 2019-10-16 12:23:31 -0700 | [diff] [blame] | 383 | std::cerr << "Configuration skipping " << *confBus << "-" |
| 384 | << *confAddr << " because not " << bus << "-" << addr |
| 385 | << "\n"; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 386 | continue; |
| 387 | } |
| 388 | |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 389 | std::vector<thresholds::Threshold> confThresholds; |
| 390 | if (!parseThresholdsFromConfig(*sensorData, confThresholds)) |
| 391 | { |
| 392 | std::cerr << "error populating totoal thresholds\n"; |
| 393 | } |
| 394 | thresholdConfSize = confThresholds.size(); |
| 395 | |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 396 | interfacePath = &(sensor.first.str); |
| 397 | break; |
| 398 | } |
| 399 | if (interfacePath == nullptr) |
| 400 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 401 | // To avoid this error message, add your export map entry, |
| 402 | // from Entity Manager, to sensorTypes at the top of this file. |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 403 | std::cerr << "failed to find match for " << deviceName << "\n"; |
| 404 | continue; |
| 405 | } |
| 406 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 407 | auto findPSUName = baseConfig->second.find("Name"); |
| 408 | if (findPSUName == baseConfig->second.end()) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 409 | { |
| 410 | std::cerr << "could not determine configuration name for " |
| 411 | << deviceName << "\n"; |
| 412 | continue; |
| 413 | } |
| 414 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 415 | if (!(psuName = std::get_if<std::string>(&(findPSUName->second)))) |
| 416 | { |
| 417 | std::cerr << "Cannot find psu name, invalid configuration\n"; |
| 418 | continue; |
| 419 | } |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 420 | |
| 421 | // on rescans, only update sensors we were signaled by |
| 422 | if (!firstScan) |
| 423 | { |
| 424 | std::string psuNameStr = "/" + *psuName; |
| 425 | auto it = |
| 426 | std::find_if(sensorsChanged->begin(), sensorsChanged->end(), |
| 427 | [psuNameStr](std::string& s) { |
| 428 | return boost::ends_with(s, psuNameStr); |
| 429 | }); |
| 430 | |
| 431 | if (it == sensorsChanged->end()) |
| 432 | { |
| 433 | continue; |
| 434 | } |
| 435 | sensorsChanged->erase(it); |
| 436 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 437 | checkEvent(directory.string(), eventMatch, eventPathList); |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 438 | checkGroupEvent(directory.string(), groupEventMatch, |
| 439 | groupEventPathList); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 440 | |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 441 | /* Check if there are more sensors in the same interface */ |
| 442 | int i = 1; |
| 443 | std::vector<std::string> psuNames; |
| 444 | do |
| 445 | { |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 446 | // Individual string fields: Name, Name1, Name2, Name3, ... |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 447 | psuNames.push_back(std::get<std::string>(findPSUName->second)); |
| 448 | findPSUName = baseConfig->second.find("Name" + std::to_string(i++)); |
| 449 | } while (findPSUName != baseConfig->second.end()); |
| 450 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 451 | std::vector<fs::path> sensorPaths; |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 452 | if (!findFiles(directory, R"(\w\d+_input$)", sensorPaths, 0)) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 453 | { |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 454 | std::cerr << "No PSU non-label sensor in PSU\n"; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 455 | continue; |
| 456 | } |
| 457 | |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 458 | /* read max value in sysfs for in, curr, power, temp, ... */ |
| 459 | if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0)) |
| 460 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 461 | if constexpr (debug) |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 462 | { |
| 463 | std::cerr << "No max name in PSU \n"; |
| 464 | } |
| 465 | } |
| 466 | |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 467 | /* Find array of labels to be exposed if it is defined in config */ |
| 468 | std::vector<std::string> findLabels; |
| 469 | auto findLabelObj = baseConfig->second.find("Labels"); |
| 470 | if (findLabelObj != baseConfig->second.end()) |
| 471 | { |
| 472 | findLabels = |
| 473 | std::get<std::vector<std::string>>(findLabelObj->second); |
| 474 | } |
| 475 | |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 476 | std::regex sensorNameRegEx("([A-Za-z]+)[0-9]*_"); |
| 477 | std::smatch matches; |
| 478 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 479 | for (const auto& sensorPath : sensorPaths) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 480 | { |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 481 | bool maxLabel = false; |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 482 | std::string labelHead; |
| 483 | std::string sensorPathStr = sensorPath.string(); |
| 484 | std::string sensorNameStr = sensorPath.filename(); |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 485 | std::string sensorNameSubStr{""}; |
| 486 | if (std::regex_search(sensorNameStr, matches, sensorNameRegEx)) |
| 487 | { |
Josh Lehan | 0649445 | 2019-10-31 09:49:16 -0700 | [diff] [blame] | 488 | // hwmon *_input filename without number: |
| 489 | // in, curr, power, temp, ... |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 490 | sensorNameSubStr = matches[1]; |
| 491 | } |
| 492 | else |
| 493 | { |
Josh Lehan | 0649445 | 2019-10-31 09:49:16 -0700 | [diff] [blame] | 494 | std::cerr << "Could not extract the alpha prefix from " |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 495 | << sensorNameStr; |
| 496 | continue; |
| 497 | } |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 498 | |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 499 | std::string labelPath; |
| 500 | |
| 501 | /* find and differentiate _max and _input to replace "label" */ |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 502 | size_t pos = sensorPathStr.find('_'); |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 503 | if (pos != std::string::npos) |
| 504 | { |
| 505 | |
| 506 | std::string sensorPathStrMax = sensorPathStr.substr(pos); |
| 507 | if (sensorPathStrMax.compare("_max") == 0) |
| 508 | { |
| 509 | labelPath = |
| 510 | boost::replace_all_copy(sensorPathStr, "max", "label"); |
| 511 | maxLabel = true; |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | labelPath = boost::replace_all_copy(sensorPathStr, "input", |
| 516 | "label"); |
| 517 | maxLabel = false; |
| 518 | } |
| 519 | } |
| 520 | else |
| 521 | { |
| 522 | continue; |
| 523 | } |
| 524 | |
Cheng C Yang | ecba9de | 2019-09-12 23:41:50 +0800 | [diff] [blame] | 525 | std::ifstream labelFile(labelPath); |
| 526 | if (!labelFile.good()) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 527 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 528 | if constexpr (debug) |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 529 | { |
| 530 | std::cerr << "Input file " << sensorPath |
| 531 | << " has no corresponding label file\n"; |
| 532 | } |
Josh Lehan | 0649445 | 2019-10-31 09:49:16 -0700 | [diff] [blame] | 533 | // hwmon *_input filename with number: |
| 534 | // temp1, temp2, temp3, ... |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 535 | labelHead = sensorNameStr.substr(0, sensorNameStr.find('_')); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 536 | } |
| 537 | else |
| 538 | { |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 539 | std::string label; |
| 540 | std::getline(labelFile, label); |
| 541 | labelFile.close(); |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 542 | auto findSensor = sensors.find(label); |
| 543 | if (findSensor != sensors.end()) |
| 544 | { |
| 545 | continue; |
| 546 | } |
| 547 | |
Josh Lehan | 0649445 | 2019-10-31 09:49:16 -0700 | [diff] [blame] | 548 | // hwmon corresponding *_label file contents: |
| 549 | // vin1, vout1, ... |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 550 | labelHead = label.substr(0, label.find(' ')); |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 551 | } |
| 552 | |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 553 | /* append "max" for labelMatch */ |
| 554 | if (maxLabel) |
| 555 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 556 | labelHead.insert(0, "max"); |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 557 | } |
| 558 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 559 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 560 | { |
| 561 | std::cerr << "Sensor type=\"" << sensorNameSubStr |
| 562 | << "\" label=\"" << labelHead << "\"\n"; |
| 563 | } |
| 564 | |
AppaRao Puli | d9d8caf | 2020-02-27 20:56:59 +0530 | [diff] [blame] | 565 | checkPWMSensor(sensorPath, labelHead, *interfacePath, |
| 566 | dbusConnection, objectServer, psuNames[0]); |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 567 | |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 568 | if (!findLabels.empty()) |
| 569 | { |
| 570 | /* Check if this labelHead is enabled in config file */ |
| 571 | if (std::find(findLabels.begin(), findLabels.end(), |
| 572 | labelHead) == findLabels.end()) |
| 573 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 574 | if constexpr (debug) |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 575 | { |
| 576 | std::cerr << "could not find " << labelHead |
| 577 | << " in the Labels list\n"; |
| 578 | } |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 579 | continue; |
| 580 | } |
| 581 | } |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 582 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 583 | auto findProperty = labelMatch.find(labelHead); |
| 584 | if (findProperty == labelMatch.end()) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 585 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 586 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 587 | { |
| 588 | std::cerr << "Could not find matching default property for " |
| 589 | << labelHead << "\n"; |
| 590 | } |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 591 | continue; |
| 592 | } |
| 593 | |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 594 | // Protect the hardcoded labelMatch list from changes, |
| 595 | // by making a copy and modifying that instead. |
| 596 | // Avoid bleedthrough of one device's customizations to |
| 597 | // the next device, as each should be independently customizable. |
| 598 | psuProperties.push_back(findProperty->second); |
| 599 | auto psuProperty = psuProperties.rbegin(); |
| 600 | |
| 601 | // Use label head as prefix for reading from config file, |
| 602 | // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ... |
| 603 | std::string keyName = labelHead + "_Name"; |
| 604 | std::string keyScale = labelHead + "_Scale"; |
| 605 | std::string keyMin = labelHead + "_Min"; |
| 606 | std::string keyMax = labelHead + "_Max"; |
| 607 | |
| 608 | bool customizedName = false; |
| 609 | auto findCustomName = baseConfig->second.find(keyName); |
| 610 | if (findCustomName != baseConfig->second.end()) |
Josh Lehan | 432d1ed | 2019-10-16 12:23:31 -0700 | [diff] [blame] | 611 | { |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 612 | try |
| 613 | { |
| 614 | psuProperty->labelTypeName = std::visit( |
| 615 | VariantToStringVisitor(), findCustomName->second); |
| 616 | } |
| 617 | catch (std::invalid_argument&) |
| 618 | { |
| 619 | std::cerr << "Unable to parse " << keyName << "\n"; |
| 620 | continue; |
| 621 | } |
| 622 | |
| 623 | // All strings are valid, including empty string |
| 624 | customizedName = true; |
| 625 | } |
| 626 | |
| 627 | bool customizedScale = false; |
| 628 | auto findCustomScale = baseConfig->second.find(keyScale); |
| 629 | if (findCustomScale != baseConfig->second.end()) |
| 630 | { |
| 631 | try |
| 632 | { |
| 633 | psuProperty->sensorScaleFactor = std::visit( |
| 634 | VariantToUnsignedIntVisitor(), findCustomScale->second); |
| 635 | } |
| 636 | catch (std::invalid_argument&) |
| 637 | { |
| 638 | std::cerr << "Unable to parse " << keyScale << "\n"; |
| 639 | continue; |
| 640 | } |
| 641 | |
| 642 | // Avoid later division by zero |
| 643 | if (psuProperty->sensorScaleFactor > 0) |
| 644 | { |
| 645 | customizedScale = true; |
| 646 | } |
| 647 | else |
| 648 | { |
| 649 | std::cerr << "Unable to accept " << keyScale << "\n"; |
| 650 | continue; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | auto findCustomMin = baseConfig->second.find(keyMin); |
| 655 | if (findCustomMin != baseConfig->second.end()) |
| 656 | { |
| 657 | try |
| 658 | { |
| 659 | psuProperty->minReading = std::visit( |
| 660 | VariantToDoubleVisitor(), findCustomMin->second); |
| 661 | } |
| 662 | catch (std::invalid_argument&) |
| 663 | { |
| 664 | std::cerr << "Unable to parse " << keyMin << "\n"; |
| 665 | continue; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | auto findCustomMax = baseConfig->second.find(keyMax); |
| 670 | if (findCustomMax != baseConfig->second.end()) |
| 671 | { |
| 672 | try |
| 673 | { |
| 674 | psuProperty->maxReading = std::visit( |
| 675 | VariantToDoubleVisitor(), findCustomMax->second); |
| 676 | } |
| 677 | catch (std::invalid_argument&) |
| 678 | { |
| 679 | std::cerr << "Unable to parse " << keyMax << "\n"; |
| 680 | continue; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | if (!(psuProperty->minReading < psuProperty->maxReading)) |
| 685 | { |
| 686 | std::cerr << "Min must be less than Max\n"; |
| 687 | continue; |
| 688 | } |
| 689 | |
| 690 | // If the sensor name is being customized by config file, |
| 691 | // then prefix/suffix composition becomes not necessary, |
| 692 | // and in fact not wanted, because it gets in the way. |
| 693 | std::string psuNameFromIndex; |
| 694 | if (!customizedName) |
| 695 | { |
| 696 | /* Find out sensor name index for this label */ |
| 697 | std::regex rgx("[A-Za-z]+([0-9]+)"); |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 698 | size_t nameIndex{0}; |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 699 | if (std::regex_search(labelHead, matches, rgx)) |
| 700 | { |
| 701 | nameIndex = std::stoi(matches[1]); |
| 702 | |
| 703 | // Decrement to preserve alignment, because hwmon |
| 704 | // human-readable filenames and labels use 1-based |
| 705 | // numbering, but the "Name", "Name1", "Name2", etc. naming |
| 706 | // convention (the psuNames vector) uses 0-based numbering. |
| 707 | if (nameIndex > 0) |
| 708 | { |
| 709 | --nameIndex; |
| 710 | } |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | nameIndex = 0; |
| 715 | } |
| 716 | |
| 717 | if (psuNames.size() <= nameIndex) |
| 718 | { |
| 719 | std::cerr << "Could not pair " << labelHead |
| 720 | << " with a Name field\n"; |
| 721 | continue; |
| 722 | } |
| 723 | |
| 724 | psuNameFromIndex = psuNames[nameIndex]; |
| 725 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 726 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 727 | { |
| 728 | std::cerr << "Sensor label head " << labelHead |
| 729 | << " paired with " << psuNameFromIndex |
| 730 | << " at index " << nameIndex << "\n"; |
| 731 | } |
Josh Lehan | 432d1ed | 2019-10-16 12:23:31 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 734 | checkEventLimits(sensorPathStr, limitEventMatch, eventPathList); |
| 735 | |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 736 | // Similarly, if sensor scaling factor is being customized, |
| 737 | // then the below power-of-10 constraint becomes unnecessary, |
| 738 | // as config should be able to specify an arbitrary divisor. |
| 739 | unsigned int factor = psuProperty->sensorScaleFactor; |
| 740 | if (!customizedScale) |
Vijay Khemka | 53ca444 | 2019-07-23 11:03:55 -0700 | [diff] [blame] | 741 | { |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 742 | // Preserve existing usage of hardcoded labelMatch table below |
| 743 | factor = std::pow(10.0, factor); |
Vijay Khemka | 53ca444 | 2019-07-23 11:03:55 -0700 | [diff] [blame] | 744 | |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 745 | /* Change first char of substring to uppercase */ |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 746 | char firstChar = |
| 747 | static_cast<char>(std::toupper(sensorNameSubStr[0])); |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 748 | std::string strScaleFactor = |
| 749 | firstChar + sensorNameSubStr.substr(1) + "ScaleFactor"; |
| 750 | |
| 751 | // Preserve existing configs by accepting earlier syntax, |
| 752 | // example CurrScaleFactor, PowerScaleFactor, ... |
| 753 | auto findScaleFactor = baseConfig->second.find(strScaleFactor); |
| 754 | if (findScaleFactor != baseConfig->second.end()) |
| 755 | { |
| 756 | factor = std::visit(VariantToIntVisitor(), |
| 757 | findScaleFactor->second); |
| 758 | } |
| 759 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 760 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 761 | { |
| 762 | std::cerr << "Sensor scaling factor " << factor |
| 763 | << " string " << strScaleFactor << "\n"; |
| 764 | } |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 767 | std::vector<thresholds::Threshold> sensorThresholds; |
Joshi, Mansi | 14f0ad8 | 2019-11-21 10:52:30 +0530 | [diff] [blame] | 768 | if (!parseThresholdsFromConfig(*sensorData, sensorThresholds, |
| 769 | &labelHead)) |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 770 | { |
James Feist | 17ab6e0 | 2019-06-25 12:28:13 -0700 | [diff] [blame] | 771 | std::cerr << "error populating thresholds for " |
| 772 | << sensorNameSubStr << "\n"; |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | auto findSensorType = sensorTable.find(sensorNameSubStr); |
| 776 | if (findSensorType == sensorTable.end()) |
| 777 | { |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 778 | std::cerr << sensorNameSubStr |
Josh Lehan | 0649445 | 2019-10-31 09:49:16 -0700 | [diff] [blame] | 779 | << " is not a recognized sensor type\n"; |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 780 | continue; |
| 781 | } |
| 782 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 783 | if constexpr (debug) |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 784 | { |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 785 | std::cerr << "Sensor properties: Name \"" |
| 786 | << psuProperty->labelTypeName << "\" Scale " |
| 787 | << psuProperty->sensorScaleFactor << " Min " |
| 788 | << psuProperty->minReading << " Max " |
| 789 | << psuProperty->maxReading << "\n"; |
| 790 | } |
| 791 | |
| 792 | std::string sensorName = psuProperty->labelTypeName; |
| 793 | if (customizedName) |
| 794 | { |
| 795 | if (sensorName.empty()) |
| 796 | { |
| 797 | // Allow selective disabling of an individual sensor, |
| 798 | // by customizing its name to an empty string. |
| 799 | std::cerr << "Sensor disabled, empty string\n"; |
| 800 | continue; |
| 801 | } |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | // Sensor name not customized, do prefix/suffix composition, |
| 806 | // preserving default behavior by using psuNameFromIndex. |
| 807 | sensorName = |
| 808 | psuNameFromIndex + " " + psuProperty->labelTypeName; |
| 809 | } |
| 810 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 811 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 812 | { |
| 813 | std::cerr << "Sensor name \"" << sensorName << "\" path \"" |
| 814 | << sensorPathStr << "\" type \"" << sensorType |
| 815 | << "\"\n"; |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 816 | } |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 817 | // destruct existing one first if already created |
| 818 | sensors[sensorName] = nullptr; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 819 | sensors[sensorName] = std::make_shared<PSUSensor>( |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 820 | sensorPathStr, sensorType, objectServer, dbusConnection, io, |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 821 | sensorName, std::move(sensorThresholds), *interfacePath, |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 822 | findSensorType->second, factor, psuProperty->maxReading, |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 823 | psuProperty->minReading, labelHead, thresholdConfSize); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 824 | sensors[sensorName]->setupRead(); |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 825 | ++numCreated; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 826 | if constexpr (debug) |
Josh Lehan | 74d9bd9 | 2019-10-31 08:51:58 -0700 | [diff] [blame] | 827 | { |
| 828 | std::cerr << "Created " << numCreated << " sensors so far\n"; |
| 829 | } |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 830 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 831 | |
| 832 | // OperationalStatus event |
Cheng C Yang | 92498eb | 2019-09-26 21:59:25 +0800 | [diff] [blame] | 833 | combineEvents[*psuName + "OperationalStatus"] = nullptr; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 834 | combineEvents[*psuName + "OperationalStatus"] = |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 835 | std::make_unique<PSUCombineEvent>( |
| 836 | objectServer, dbusConnection, io, *psuName, eventPathList, |
| 837 | groupEventPathList, "OperationalStatus"); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 838 | } |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 839 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 840 | if constexpr (debug) |
Josh Lehan | 49cfba9 | 2019-10-08 16:50:42 -0700 | [diff] [blame] | 841 | { |
| 842 | std::cerr << "Created total of " << numCreated << " sensors\n"; |
| 843 | } |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 844 | return; |
| 845 | } |
| 846 | |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 847 | void createSensors( |
| 848 | boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, |
| 849 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 850 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
| 851 | sensorsChanged) |
| 852 | { |
| 853 | auto getter = std::make_shared<GetSensorConfiguration>( |
| 854 | dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged]( |
| 855 | const ManagedObjectType& sensorConfigs) { |
| 856 | createSensorsCallback(io, objectServer, dbusConnection, |
| 857 | sensorConfigs, sensorsChanged); |
| 858 | }); |
| 859 | getter->getConfiguration( |
| 860 | std::vector<std::string>(sensorTypes.begin(), sensorTypes.end())); |
| 861 | } |
| 862 | |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 863 | void propertyInitialize(void) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 864 | { |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 865 | sensorTable = {{"power", "power/"}, |
| 866 | {"curr", "current/"}, |
| 867 | {"temp", "temperature/"}, |
| 868 | {"in", "voltage/"}, |
| 869 | {"fan", "fan_tach/"}}; |
| 870 | |
| 871 | labelMatch = {{"pin", PSUProperty("Input Power", 3000, 0, 6)}, |
| 872 | {"pout1", PSUProperty("Output Power", 3000, 0, 6)}, |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 873 | {"pout2", PSUProperty("Output Power", 3000, 0, 6)}, |
| 874 | {"pout3", PSUProperty("Output Power", 3000, 0, 6)}, |
Vijay Khemka | be66441 | 2019-06-28 12:10:04 -0700 | [diff] [blame] | 875 | {"power1", PSUProperty("Output Power", 3000, 0, 6)}, |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 876 | {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6)}, |
Cheng C Yang | bdbde96 | 2019-04-26 22:50:34 +0800 | [diff] [blame] | 877 | {"vin", PSUProperty("Input Voltage", 300, 0, 3)}, |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 878 | {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3)}, |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 879 | {"vout1", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 880 | {"vout2", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 881 | {"vout3", PSUProperty("Output Voltage", 255, 0, 3)}, |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 882 | {"vout4", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 883 | {"vout5", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 884 | {"vout6", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 885 | {"vout7", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 886 | {"vout8", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 887 | {"vout9", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 888 | {"vout10", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 889 | {"vout11", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 890 | {"vout12", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 891 | {"vout13", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 892 | {"vout14", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 893 | {"vout15", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 894 | {"vout16", PSUProperty("Output Voltage", 255, 0, 3)}, |
Jason Ling | 32047ef | 2020-09-30 15:43:32 -0700 | [diff] [blame] | 895 | {"vout17", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 896 | {"vout18", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 897 | {"vout19", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 898 | {"vout20", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 899 | {"vout21", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 900 | {"vout22", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 901 | {"vout23", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 902 | {"vout24", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 903 | {"vout25", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 904 | {"vout26", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 905 | {"vout27", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 906 | {"vout28", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 907 | {"vout29", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 908 | {"vout30", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 909 | {"vout31", PSUProperty("Output Voltage", 255, 0, 3)}, |
| 910 | {"vout32", PSUProperty("Output Voltage", 255, 0, 3)}, |
Zev Weiss | eb0b84d | 2021-04-22 15:03:38 -0500 | [diff] [blame^] | 911 | {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3)}, |
Vijay Khemka | be66441 | 2019-06-28 12:10:04 -0700 | [diff] [blame] | 912 | {"in1", PSUProperty("Output Voltage", 255, 0, 3)}, |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 913 | {"iin", PSUProperty("Input Current", 20, 0, 3)}, |
| 914 | {"iout1", PSUProperty("Output Current", 255, 0, 3)}, |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 915 | {"iout2", PSUProperty("Output Current", 255, 0, 3)}, |
| 916 | {"iout3", PSUProperty("Output Current", 255, 0, 3)}, |
Peter Lundgren | 48b4423 | 2020-01-30 16:02:11 -0800 | [diff] [blame] | 917 | {"iout4", PSUProperty("Output Current", 255, 0, 3)}, |
| 918 | {"iout5", PSUProperty("Output Current", 255, 0, 3)}, |
| 919 | {"iout6", PSUProperty("Output Current", 255, 0, 3)}, |
| 920 | {"iout7", PSUProperty("Output Current", 255, 0, 3)}, |
| 921 | {"iout8", PSUProperty("Output Current", 255, 0, 3)}, |
| 922 | {"iout9", PSUProperty("Output Current", 255, 0, 3)}, |
| 923 | {"iout10", PSUProperty("Output Current", 255, 0, 3)}, |
| 924 | {"iout11", PSUProperty("Output Current", 255, 0, 3)}, |
| 925 | {"iout12", PSUProperty("Output Current", 255, 0, 3)}, |
| 926 | {"iout13", PSUProperty("Output Current", 255, 0, 3)}, |
| 927 | {"iout14", PSUProperty("Output Current", 255, 0, 3)}, |
Vijay Khemka | be66441 | 2019-06-28 12:10:04 -0700 | [diff] [blame] | 928 | {"curr1", PSUProperty("Output Current", 255, 0, 3)}, |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 929 | {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3)}, |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 930 | {"temp1", PSUProperty("Temperature", 127, -128, 3)}, |
Vijay Khemka | 996bad1 | 2019-05-28 15:15:16 -0700 | [diff] [blame] | 931 | {"temp2", PSUProperty("Temperature", 127, -128, 3)}, |
| 932 | {"temp3", PSUProperty("Temperature", 127, -128, 3)}, |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 933 | {"temp4", PSUProperty("Temperature", 127, -128, 3)}, |
| 934 | {"temp5", PSUProperty("Temperature", 127, -128, 3)}, |
Alex Qiu | f5709b4 | 2020-01-29 13:29:50 -0800 | [diff] [blame] | 935 | {"temp6", PSUProperty("Temperature", 127, -128, 3)}, |
Manikandan Elumalai | c7e9562 | 2020-06-03 20:22:01 +0530 | [diff] [blame] | 936 | {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3)}, |
Cheng C Yang | 8dbb395 | 2019-05-23 00:03:12 +0800 | [diff] [blame] | 937 | {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0)}, |
| 938 | {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0)}}; |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 939 | |
| 940 | pwmTable = {{"fan1", "Fan_1"}, {"fan2", "Fan_2"}}; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 941 | |
| 942 | limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}}, |
| 943 | {"Failure", {"crit_alarm", "lcrit_alarm"}}}; |
| 944 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 945 | eventMatch = {{"PredictiveFailure", {"power1_alarm"}}, |
| 946 | {"Failure", {"in2_alarm"}}, |
| 947 | {"ACLost", {"in1_beep"}}, |
| 948 | {"ConfigureError", {"in1_fault"}}}; |
| 949 | |
| 950 | groupEventMatch = {{"FanFault", |
| 951 | {{"fan1", {"fan1_alarm", "fan1_fault"}}, |
| 952 | {"fan2", {"fan2_alarm", "fan2_fault"}}}}}; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 953 | } |
| 954 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 955 | int main() |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 956 | { |
| 957 | boost::asio::io_service io; |
| 958 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
| 959 | |
| 960 | systemBus->request_name("xyz.openbmc_project.PSUSensor"); |
| 961 | sdbusplus::asio::object_server objectServer(systemBus); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 962 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches; |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 963 | auto sensorsChanged = |
| 964 | std::make_shared<boost::container::flat_set<std::string>>(); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 965 | |
Cheng C Yang | 916360b | 2019-05-07 18:47:16 +0800 | [diff] [blame] | 966 | propertyInitialize(); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 967 | |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 968 | io.post([&]() { createSensors(io, objectServer, systemBus, nullptr); }); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 969 | boost::asio::deadline_timer filterTimer(io); |
| 970 | std::function<void(sdbusplus::message::message&)> eventHandler = |
| 971 | [&](sdbusplus::message::message& message) { |
| 972 | if (message.is_method_error()) |
| 973 | { |
| 974 | std::cerr << "callback method error\n"; |
| 975 | return; |
| 976 | } |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 977 | sensorsChanged->insert(message.get_path()); |
Cheng C Yang | a97f134 | 2020-02-11 15:10:41 +0800 | [diff] [blame] | 978 | filterTimer.expires_from_now(boost::posix_time::seconds(3)); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 979 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 980 | if (ec == boost::asio::error::operation_aborted) |
| 981 | { |
| 982 | return; |
| 983 | } |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 984 | if (ec) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 985 | { |
| 986 | std::cerr << "timer error\n"; |
| 987 | } |
Zhikui Ren | 23c96e7 | 2020-11-05 22:32:28 -0800 | [diff] [blame] | 988 | createSensors(io, objectServer, systemBus, sensorsChanged); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 989 | }); |
| 990 | }; |
| 991 | |
| 992 | for (const char* type : sensorTypes) |
| 993 | { |
| 994 | auto match = std::make_unique<sdbusplus::bus::match::match>( |
| 995 | static_cast<sdbusplus::bus::bus&>(*systemBus), |
| 996 | "type='signal',member='PropertiesChanged',path_namespace='" + |
| 997 | std::string(inventoryPath) + "',arg0namespace='" + type + "'", |
| 998 | eventHandler); |
| 999 | matches.emplace_back(std::move(match)); |
| 1000 | } |
| 1001 | io.run(); |
| 1002 | } |