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