James Feist | 6ef2040 | 2019-01-07 16:45:08 -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 | */ |
| 16 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 17 | #include <IpmbSensor.hpp> |
| 18 | #include <Utils.hpp> |
| 19 | #include <VariantVisitors.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 20 | #include <boost/container/flat_map.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 21 | #include <sdbusplus/asio/connection.hpp> |
| 22 | #include <sdbusplus/asio/object_server.hpp> |
| 23 | #include <sdbusplus/bus/match.hpp> |
| 24 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 25 | #include <chrono> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 26 | #include <cmath> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 27 | #include <functional> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 28 | #include <iostream> |
| 29 | #include <limits> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <memory> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 31 | #include <numeric> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 32 | #include <string> |
| 33 | #include <tuple> |
| 34 | #include <variant> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 35 | #include <vector> |
| 36 | |
| 37 | constexpr const bool debug = false; |
| 38 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 39 | constexpr const char* sensorType = "IpmbSensor"; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 40 | static constexpr double ipmbMaxReading = 0xFF; |
| 41 | static constexpr double ipmbMinReading = 0; |
| 42 | |
| 43 | static constexpr uint8_t meAddress = 1; |
| 44 | static constexpr uint8_t lun = 0; |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 45 | static constexpr uint8_t hostSMbusIndexDefault = 0x03; |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame] | 46 | static constexpr float pollRateDefault = 1; // in seconds |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 47 | |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 48 | static constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/"; |
| 49 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 50 | using IpmbMethodType = |
| 51 | std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; |
| 52 | |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 53 | boost::container::flat_map<std::string, std::unique_ptr<IpmbSensor>> sensors; |
| 54 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 55 | std::unique_ptr<boost::asio::steady_timer> initCmdTimer; |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 56 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 57 | IpmbSensor::IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 58 | boost::asio::io_service& io, |
| 59 | const std::string& sensorName, |
| 60 | const std::string& sensorConfiguration, |
| 61 | sdbusplus::asio::object_server& objectServer, |
| 62 | std::vector<thresholds::Threshold>&& thresholdData, |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 63 | uint8_t deviceAddress, uint8_t hostSMbusIndex, |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame] | 64 | const float pollRate, std::string& sensorTypeName) : |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 65 | Sensor(escapeName(sensorName), std::move(thresholdData), |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 66 | sensorConfiguration, "IpmbSensor", false, false, ipmbMaxReading, |
| 67 | ipmbMinReading, conn, PowerState::on), |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 68 | deviceAddress(deviceAddress), hostSMbusIndex(hostSMbusIndex), |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame] | 69 | sensorPollMs(static_cast<int>(pollRate * 1000)), objectServer(objectServer), |
| 70 | waitTimer(io) |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 71 | { |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 72 | std::string dbusPath = sensorPathPrefix + sensorTypeName + "/" + name; |
| 73 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 74 | sensorInterface = objectServer.add_interface( |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 75 | dbusPath, "xyz.openbmc_project.Sensor.Value"); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 76 | |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 77 | for (const auto& threshold : thresholds) |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 78 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 79 | std::string interface = thresholds::getInterface(threshold.level); |
| 80 | thresholdInterfaces[static_cast<size_t>(threshold.level)] = |
| 81 | objectServer.add_interface(dbusPath, interface); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 82 | } |
James Feist | 2adc95c | 2019-09-30 14:55:28 -0700 | [diff] [blame] | 83 | association = objectServer.add_interface(dbusPath, association::interface); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | IpmbSensor::~IpmbSensor() |
| 87 | { |
| 88 | waitTimer.cancel(); |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 89 | for (const auto& iface : thresholdInterfaces) |
| 90 | { |
| 91 | objectServer.remove_interface(iface); |
| 92 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 93 | objectServer.remove_interface(sensorInterface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 94 | objectServer.remove_interface(association); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 97 | std::string IpmbSensor::getSubTypeUnits(void) const |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 98 | { |
| 99 | switch (subType) |
| 100 | { |
| 101 | case IpmbSubType::temp: |
| 102 | return sensor_paths::unitDegreesC; |
| 103 | case IpmbSubType::curr: |
| 104 | return sensor_paths::unitAmperes; |
| 105 | case IpmbSubType::power: |
| 106 | return sensor_paths::unitWatts; |
| 107 | case IpmbSubType::volt: |
| 108 | return sensor_paths::unitVolts; |
| 109 | case IpmbSubType::util: |
| 110 | return sensor_paths::unitPercent; |
| 111 | default: |
| 112 | throw std::runtime_error("Invalid sensor type"); |
| 113 | } |
| 114 | } |
| 115 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 116 | void IpmbSensor::init(void) |
| 117 | { |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 118 | loadDefaults(); |
Andrei Kartashev | 3928741 | 2022-02-04 16:04:47 +0300 | [diff] [blame] | 119 | setInitialProperties(getSubTypeUnits()); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 120 | if (initCommand) |
| 121 | { |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 122 | runInitCmd(); |
| 123 | } |
| 124 | read(); |
| 125 | } |
| 126 | |
| 127 | void IpmbSensor::runInitCmd() |
| 128 | { |
| 129 | if (initCommand) |
| 130 | { |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 131 | dbusConnection->async_method_call( |
| 132 | [this](boost::system::error_code ec, |
| 133 | const IpmbMethodType& response) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 134 | const int& status = std::get<0>(response); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 135 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 136 | if (ec || (status != 0)) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 137 | { |
| 138 | std::cerr << "Error setting init command for device: " << name |
| 139 | << "\n"; |
| 140 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 141 | }, |
| 142 | "xyz.openbmc_project.Ipmi.Channel.Ipmb", |
| 143 | "/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb", |
| 144 | "sendRequest", commandAddress, netfn, lun, *initCommand, initData); |
| 145 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | void IpmbSensor::loadDefaults() |
| 149 | { |
| 150 | if (type == IpmbType::meSensor) |
| 151 | { |
| 152 | commandAddress = meAddress; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 153 | netfn = ipmi::sensor::netFn; |
| 154 | command = ipmi::sensor::getSensorReading; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 155 | commandData = {deviceAddress}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 156 | readingFormat = ReadingFormat::byte0; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 157 | } |
| 158 | else if (type == IpmbType::PXE1410CVR) |
| 159 | { |
| 160 | commandAddress = meAddress; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 161 | netfn = ipmi::me_bridge::netFn; |
| 162 | command = ipmi::me_bridge::sendRawPmbus; |
| 163 | initCommand = ipmi::me_bridge::sendRawPmbus; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 164 | // pmbus read temp |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 165 | commandData = {0x57, 0x01, 0x00, 0x16, hostSMbusIndex, |
| 166 | deviceAddress, 0x00, 0x00, 0x00, 0x00, |
| 167 | 0x01, 0x02, 0x8d}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 168 | // goto page 0 |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 169 | initData = {0x57, 0x01, 0x00, 0x14, hostSMbusIndex, |
| 170 | deviceAddress, 0x00, 0x00, 0x00, 0x00, |
| 171 | 0x02, 0x00, 0x00, 0x00}; |
Jayashree-D | 3732257 | 2021-03-19 17:40:56 +0530 | [diff] [blame] | 172 | readingFormat = ReadingFormat::linearElevenBit; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 173 | } |
| 174 | else if (type == IpmbType::IR38363VR) |
| 175 | { |
| 176 | commandAddress = meAddress; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 177 | netfn = ipmi::me_bridge::netFn; |
| 178 | command = ipmi::me_bridge::sendRawPmbus; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 179 | // pmbus read temp |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 180 | commandData = {0x57, 0x01, 0x00, 0x16, hostSMbusIndex, |
| 181 | deviceAddress, 00, 0x00, 0x00, 0x00, |
| 182 | 0x01, 0x02, 0x8D}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 183 | readingFormat = ReadingFormat::elevenBitShift; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 184 | } |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 185 | else if (type == IpmbType::ADM1278HSC) |
| 186 | { |
| 187 | commandAddress = meAddress; |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 188 | uint8_t snsNum = 0; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 189 | switch (subType) |
| 190 | { |
| 191 | case IpmbSubType::temp: |
| 192 | case IpmbSubType::curr: |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 193 | if (subType == IpmbSubType::temp) |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 194 | { |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 195 | snsNum = 0x8d; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 196 | } |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 197 | else |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 198 | { |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 199 | snsNum = 0x8c; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 200 | } |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 201 | netfn = ipmi::me_bridge::netFn; |
| 202 | command = ipmi::me_bridge::sendRawPmbus; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 203 | commandData = {0x57, 0x01, 0x00, 0x86, deviceAddress, |
| 204 | 0x00, 0x00, 0x01, 0x02, snsNum}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 205 | readingFormat = ReadingFormat::elevenBit; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 206 | break; |
| 207 | case IpmbSubType::power: |
| 208 | case IpmbSubType::volt: |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 209 | netfn = ipmi::sensor::netFn; |
| 210 | command = ipmi::sensor::getSensorReading; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 211 | commandData = {deviceAddress}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 212 | readingFormat = ReadingFormat::byte0; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 213 | break; |
| 214 | default: |
| 215 | throw std::runtime_error("Invalid sensor type"); |
| 216 | } |
| 217 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 218 | else if (type == IpmbType::mpsVR) |
| 219 | { |
| 220 | commandAddress = meAddress; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 221 | netfn = ipmi::me_bridge::netFn; |
| 222 | command = ipmi::me_bridge::sendRawPmbus; |
| 223 | initCommand = ipmi::me_bridge::sendRawPmbus; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 224 | // pmbus read temp |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 225 | commandData = {0x57, 0x01, 0x00, 0x16, hostSMbusIndex, |
| 226 | deviceAddress, 0x00, 0x00, 0x00, 0x00, |
| 227 | 0x01, 0x02, 0x8d}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 228 | // goto page 0 |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 229 | initData = {0x57, 0x01, 0x00, 0x14, hostSMbusIndex, |
| 230 | deviceAddress, 0x00, 0x00, 0x00, 0x00, |
| 231 | 0x02, 0x00, 0x00, 0x00}; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 232 | readingFormat = ReadingFormat::byte3; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 233 | } |
| 234 | else |
| 235 | { |
| 236 | throw std::runtime_error("Invalid sensor type"); |
| 237 | } |
Adrian Ambrożewicz | 45e9277 | 2020-06-04 13:59:55 +0200 | [diff] [blame] | 238 | |
| 239 | if (subType == IpmbSubType::util) |
| 240 | { |
| 241 | // Utilization need to be scaled to percent |
| 242 | maxValue = 100; |
| 243 | minValue = 0; |
| 244 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void IpmbSensor::checkThresholds(void) |
| 248 | { |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 249 | thresholds::checkThresholds(this); |
| 250 | } |
| 251 | |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 252 | bool IpmbSensor::processReading(const std::vector<uint8_t>& data, double& resp) |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 253 | { |
| 254 | |
| 255 | switch (readingFormat) |
| 256 | { |
| 257 | case (ReadingFormat::byte0): |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 258 | { |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 259 | if (command == ipmi::sensor::getSensorReading && |
| 260 | !ipmi::sensor::isValid(data)) |
James Feist | cf4238e | 2020-07-28 16:40:03 -0700 | [diff] [blame] | 261 | { |
| 262 | return false; |
| 263 | } |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 264 | resp = data[0]; |
| 265 | return true; |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 266 | } |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 267 | case (ReadingFormat::byte3): |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 268 | { |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 269 | if (data.size() < 4) |
| 270 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 271 | if (errCount == 0U) |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 272 | { |
| 273 | std::cerr << "Invalid data length returned for " << name |
| 274 | << "\n"; |
| 275 | } |
| 276 | return false; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 277 | } |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 278 | resp = data[3]; |
| 279 | return true; |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 280 | } |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 281 | case (ReadingFormat::elevenBit): |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 282 | { |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 283 | if (data.size() < 5) |
| 284 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 285 | if (errCount == 0U) |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 286 | { |
| 287 | std::cerr << "Invalid data length returned for " << name |
| 288 | << "\n"; |
| 289 | } |
| 290 | return false; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 291 | } |
| 292 | |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 293 | int16_t value = ((data[4] << 8) | data[3]); |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 294 | resp = value; |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 295 | return true; |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 296 | } |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 297 | case (ReadingFormat::elevenBitShift): |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 298 | { |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 299 | if (data.size() < 5) |
| 300 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 301 | if (errCount == 0U) |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 302 | { |
| 303 | std::cerr << "Invalid data length returned for " << name |
| 304 | << "\n"; |
| 305 | } |
| 306 | return false; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 307 | } |
| 308 | |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 309 | resp = ((data[4] << 8) | data[3]) >> 3; |
| 310 | return true; |
James Feist | e4a970d | 2020-08-19 11:21:58 -0700 | [diff] [blame] | 311 | } |
Jayashree-D | 3732257 | 2021-03-19 17:40:56 +0530 | [diff] [blame] | 312 | case (ReadingFormat::linearElevenBit): |
| 313 | { |
| 314 | if (data.size() < 5) |
| 315 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 316 | if (errCount == 0U) |
Jayashree-D | 3732257 | 2021-03-19 17:40:56 +0530 | [diff] [blame] | 317 | { |
| 318 | std::cerr << "Invalid data length returned for " << name |
| 319 | << "\n"; |
| 320 | } |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | int16_t value = ((data[4] << 8) | data[3]); |
| 325 | constexpr const size_t shift = 16 - 11; // 11bit into 16bit |
| 326 | value <<= shift; |
| 327 | value >>= shift; |
| 328 | resp = value; |
| 329 | return true; |
| 330 | } |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 331 | default: |
| 332 | throw std::runtime_error("Invalid reading type"); |
| 333 | } |
| 334 | } |
| 335 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 336 | void IpmbSensor::read(void) |
| 337 | { |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 338 | waitTimer.expires_from_now(std::chrono::milliseconds(sensorPollMs)); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 339 | waitTimer.async_wait([this](const boost::system::error_code& ec) { |
| 340 | if (ec == boost::asio::error::operation_aborted) |
| 341 | { |
| 342 | return; // we're being canceled |
| 343 | } |
Adrian Ambrożewicz | 623723b | 2020-07-29 12:53:54 +0200 | [diff] [blame] | 344 | if (!readingStateGood()) |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 345 | { |
Adrian Ambrożewicz | 623723b | 2020-07-29 12:53:54 +0200 | [diff] [blame] | 346 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 347 | read(); |
| 348 | return; |
| 349 | } |
| 350 | dbusConnection->async_method_call( |
| 351 | [this](boost::system::error_code ec, |
| 352 | const IpmbMethodType& response) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 353 | const int& status = std::get<0>(response); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 354 | if (ec || (status != 0)) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 355 | { |
| 356 | incrementError(); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 357 | read(); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 358 | return; |
| 359 | } |
| 360 | const std::vector<uint8_t>& data = std::get<5>(response); |
| 361 | if constexpr (debug) |
| 362 | { |
| 363 | std::cout << name << ": "; |
| 364 | for (size_t d : data) |
| 365 | { |
| 366 | std::cout << d << " "; |
| 367 | } |
| 368 | std::cout << "\n"; |
| 369 | } |
| 370 | if (data.empty()) |
| 371 | { |
| 372 | incrementError(); |
| 373 | read(); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | double value = 0; |
| 378 | |
| 379 | if (!processReading(data, value)) |
| 380 | { |
| 381 | incrementError(); |
| 382 | read(); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | // rawValue only used in debug logging |
| 387 | // up to 5th byte in data are used to derive value |
| 388 | size_t end = std::min(sizeof(uint64_t), data.size()); |
| 389 | uint64_t rawData = 0; |
| 390 | for (size_t i = 0; i < end; i++) |
| 391 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 392 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 393 | reinterpret_cast<uint8_t*>(&rawData)[i] = data[i]; |
| 394 | } |
| 395 | rawValue = static_cast<double>(rawData); |
| 396 | |
| 397 | /* Adjust value as per scale and offset */ |
| 398 | value = (value * scaleVal) + offsetVal; |
| 399 | updateValue(value); |
| 400 | read(); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 401 | }, |
| 402 | "xyz.openbmc_project.Ipmi.Channel.Ipmb", |
| 403 | "/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb", |
| 404 | "sendRequest", commandAddress, netfn, lun, command, commandData); |
| 405 | }); |
| 406 | } |
Jayashree Dhanapal | 8418975 | 2022-03-07 12:51:54 +0530 | [diff] [blame] | 407 | |
| 408 | bool IpmbSensor::sensorClassType(const std::string& sensorClass) |
| 409 | { |
| 410 | if (sensorClass == "PxeBridgeTemp") |
| 411 | { |
| 412 | type = IpmbType::PXE1410CVR; |
| 413 | } |
| 414 | else if (sensorClass == "IRBridgeTemp") |
| 415 | { |
| 416 | type = IpmbType::IR38363VR; |
| 417 | } |
| 418 | else if (sensorClass == "HSCBridge") |
| 419 | { |
| 420 | type = IpmbType::ADM1278HSC; |
| 421 | } |
| 422 | else if (sensorClass == "MpsBridgeTemp") |
| 423 | { |
| 424 | type = IpmbType::mpsVR; |
| 425 | } |
| 426 | else if (sensorClass == "METemp" || sensorClass == "MESensor") |
| 427 | { |
| 428 | type = IpmbType::meSensor; |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | std::cerr << "Invalid class " << sensorClass << "\n"; |
| 433 | return false; |
| 434 | } |
| 435 | return true; |
| 436 | } |
| 437 | |
| 438 | void IpmbSensor::sensorSubType(const std::string& sensorTypeName) |
| 439 | { |
| 440 | if (sensorTypeName == "voltage") |
| 441 | { |
| 442 | subType = IpmbSubType::volt; |
| 443 | } |
| 444 | else if (sensorTypeName == "power") |
| 445 | { |
| 446 | subType = IpmbSubType::power; |
| 447 | } |
| 448 | else if (sensorTypeName == "current") |
| 449 | { |
| 450 | subType = IpmbSubType::curr; |
| 451 | } |
| 452 | else if (sensorTypeName == "utilization") |
| 453 | { |
| 454 | subType = IpmbSubType::util; |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | subType = IpmbSubType::temp; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void IpmbSensor::parseConfigValues(const SensorBaseConfigMap& entry) |
| 463 | { |
| 464 | auto findScaleVal = entry.find("ScaleValue"); |
| 465 | if (findScaleVal != entry.end()) |
| 466 | { |
| 467 | scaleVal = std::visit(VariantToDoubleVisitor(), findScaleVal->second); |
| 468 | } |
| 469 | |
| 470 | auto findOffsetVal = entry.find("OffsetValue"); |
| 471 | if (findOffsetVal != entry.end()) |
| 472 | { |
| 473 | offsetVal = std::visit(VariantToDoubleVisitor(), findOffsetVal->second); |
| 474 | } |
| 475 | |
Zev Weiss | a4d2768 | 2022-07-19 15:30:36 -0700 | [diff] [blame] | 476 | readState = getPowerState(entry); |
Jayashree Dhanapal | 8418975 | 2022-03-07 12:51:54 +0530 | [diff] [blame] | 477 | } |
| 478 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 479 | void createSensors( |
| 480 | boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, |
| 481 | boost::container::flat_map<std::string, std::unique_ptr<IpmbSensor>>& |
| 482 | sensors, |
| 483 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) |
| 484 | { |
| 485 | if (!dbusConnection) |
| 486 | { |
| 487 | std::cerr << "Connection not created\n"; |
| 488 | return; |
| 489 | } |
| 490 | dbusConnection->async_method_call( |
| 491 | [&](boost::system::error_code ec, const ManagedObjectType& resp) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 492 | if (ec) |
| 493 | { |
| 494 | std::cerr << "Error contacting entity manager\n"; |
| 495 | return; |
| 496 | } |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 497 | for (const auto& [path, interfaces] : resp) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 498 | { |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 499 | for (const auto& [intf, cfg] : interfaces) |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 500 | { |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 501 | if (intf != configInterfaceName(sensorType)) |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 502 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 503 | continue; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 504 | } |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 505 | std::string name = loadVariant<std::string>(cfg, "Name"); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 506 | |
| 507 | std::vector<thresholds::Threshold> sensorThresholds; |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 508 | if (!parseThresholdsFromConfig(interfaces, sensorThresholds)) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 509 | { |
| 510 | std::cerr << "error populating thresholds for " << name |
| 511 | << "\n"; |
| 512 | } |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 513 | uint8_t deviceAddress = loadVariant<uint8_t>(cfg, "Address"); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 514 | |
| 515 | std::string sensorClass = |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 516 | loadVariant<std::string>(cfg, "Class"); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 517 | |
| 518 | uint8_t hostSMbusIndex = hostSMbusIndexDefault; |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 519 | auto findSmType = cfg.find("HostSMbusIndex"); |
| 520 | if (findSmType != cfg.end()) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 521 | { |
| 522 | hostSMbusIndex = std::visit(VariantToUnsignedIntVisitor(), |
| 523 | findSmType->second); |
| 524 | } |
| 525 | |
Zev Weiss | 8569bf2 | 2022-10-11 15:37:44 -0700 | [diff] [blame] | 526 | float pollRate = getPollRate(cfg, pollRateDefault); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 527 | |
| 528 | /* Default sensor type is "temperature" */ |
| 529 | std::string sensorTypeName = "temperature"; |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 530 | auto findType = cfg.find("SensorType"); |
| 531 | if (findType != cfg.end()) |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 532 | { |
| 533 | sensorTypeName = |
| 534 | std::visit(VariantToStringVisitor(), findType->second); |
| 535 | } |
| 536 | |
| 537 | auto& sensor = sensors[name]; |
| 538 | sensor = std::make_unique<IpmbSensor>( |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 539 | dbusConnection, io, name, path, objectServer, |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 540 | std::move(sensorThresholds), deviceAddress, hostSMbusIndex, |
| 541 | pollRate, sensorTypeName); |
| 542 | |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 543 | sensor->parseConfigValues(cfg); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 544 | if (!(sensor->sensorClassType(sensorClass))) |
| 545 | { |
| 546 | continue; |
| 547 | } |
| 548 | sensor->sensorSubType(sensorTypeName); |
| 549 | sensor->init(); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 550 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 551 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 552 | }, |
JeffLin | 2c5a1f2 | 2022-10-05 15:19:09 +0800 | [diff] [blame] | 553 | entityManagerName, "/xyz/openbmc_project/inventory", |
| 554 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 557 | void reinitSensors(sdbusplus::message_t& message) |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 558 | { |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 559 | constexpr const size_t reinitWaitSeconds = 2; |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 560 | std::string objectName; |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 561 | boost::container::flat_map<std::string, std::variant<std::string>> values; |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 562 | message.read(objectName, values); |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 563 | |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 564 | auto findStatus = values.find(power::property); |
| 565 | if (findStatus != values.end()) |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 566 | { |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 567 | bool powerStatus = |
| 568 | std::get<std::string>(findStatus->second).ends_with(".Running"); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 569 | if (powerStatus) |
| 570 | { |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 571 | if (!initCmdTimer) |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 572 | { |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 573 | // this should be impossible |
| 574 | return; |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 575 | } |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 576 | // we seem to send this command too fast sometimes, wait before |
| 577 | // sending |
| 578 | initCmdTimer->expires_from_now( |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 579 | std::chrono::seconds(reinitWaitSeconds)); |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 580 | |
| 581 | initCmdTimer->async_wait([](const boost::system::error_code ec) { |
| 582 | if (ec == boost::asio::error::operation_aborted) |
| 583 | { |
| 584 | return; // we're being canceled |
| 585 | } |
| 586 | |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 587 | for (const auto& [name, sensor] : sensors) |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 588 | { |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 589 | if (sensor) |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 590 | { |
Zev Weiss | 8ba551b | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 591 | sensor->runInitCmd(); |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | }); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 599 | int main() |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 600 | { |
| 601 | |
| 602 | boost::asio::io_service io; |
| 603 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
Ed Tanous | 14ed5e9 | 2022-07-12 15:50:23 -0700 | [diff] [blame^] | 604 | sdbusplus::asio::object_server objectServer(systemBus, true); |
| 605 | objectServer.add_manager("/xyz/openbmc_project/sensors"); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 606 | systemBus->request_name("xyz.openbmc_project.IpmbSensor"); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 607 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 608 | initCmdTimer = std::make_unique<boost::asio::steady_timer>(io); |
James Feist | 0d4f2bd | 2019-03-05 13:15:40 -0800 | [diff] [blame] | 609 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 610 | io.post([&]() { createSensors(io, objectServer, sensors, systemBus); }); |
| 611 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 612 | boost::asio::steady_timer configTimer(io); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 613 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 614 | std::function<void(sdbusplus::message_t&)> eventHandler = |
| 615 | [&](sdbusplus::message_t&) { |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 616 | configTimer.expires_from_now(std::chrono::seconds(1)); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 617 | // create a timer because normally multiple properties change |
| 618 | configTimer.async_wait([&](const boost::system::error_code& ec) { |
| 619 | if (ec == boost::asio::error::operation_aborted) |
| 620 | { |
| 621 | return; // we're being canceled |
| 622 | } |
| 623 | createSensors(io, objectServer, sensors, systemBus); |
| 624 | if (sensors.empty()) |
| 625 | { |
| 626 | std::cout << "Configuration not detected\n"; |
| 627 | } |
| 628 | }); |
| 629 | }; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 630 | |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 631 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches = |
| 632 | setupPropertiesChangedMatches( |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 633 | *systemBus, std::to_array<const char*>({sensorType}), eventHandler); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 634 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 635 | sdbusplus::bus::match_t powerChangeMatch( |
| 636 | static_cast<sdbusplus::bus_t&>(*systemBus), |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 637 | "type='signal',interface='" + std::string(properties::interface) + |
| 638 | "',path='" + std::string(power::path) + "',arg0='" + |
| 639 | std::string(power::interface) + "'", |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 640 | reinitSensors); |
| 641 | |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 642 | setupManufacturingModeMatch(*systemBus); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 643 | io.run(); |
Zhikui Ren | e76a5a6 | 2021-07-09 15:16:32 -0700 | [diff] [blame] | 644 | return 0; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 645 | } |