James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 17 | #include "TachSensor.hpp" |
| 18 | |
| 19 | #include "Utils.hpp" |
| 20 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 23 | #include <boost/algorithm/string/predicate.hpp> |
| 24 | #include <boost/algorithm/string/replace.hpp> |
| 25 | #include <boost/date_time/posix_time/posix_time.hpp> |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 26 | #include <fstream> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 27 | #include <iostream> |
| 28 | #include <limits> |
| 29 | #include <sdbusplus/asio/connection.hpp> |
| 30 | #include <sdbusplus/asio/object_server.hpp> |
| 31 | #include <string> |
| 32 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 33 | static constexpr unsigned int pwmPollMs = 500; |
| 34 | static constexpr size_t warnAfterErrorCount = 10; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 35 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 36 | TachSensor::TachSensor(const std::string& path, const std::string& objectType, |
| 37 | sdbusplus::asio::object_server& objectServer, |
| 38 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 39 | std::unique_ptr<PresenceSensor>&& presenceSensor, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 40 | std::optional<RedundancySensor>* redundancy, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 41 | boost::asio::io_service& io, const std::string& fanName, |
| 42 | std::vector<thresholds::Threshold>&& _thresholds, |
| 43 | const std::string& sensorConfiguration, |
| 44 | const std::pair<size_t, size_t>& limits) : |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 45 | Sensor(boost::replace_all_copy(fanName, " ", "_"), path, |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 46 | std::move(_thresholds), sensorConfiguration, objectType, |
| 47 | limits.second, limits.first), |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 48 | objServer(objectServer), presence(std::move(presenceSensor)), |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 49 | redundancy(redundancy), inputDev(io, open(path.c_str(), O_RDONLY)), |
| 50 | waitTimer(io), errCount(0) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 51 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 52 | sensorInterface = objectServer.add_interface( |
| 53 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 54 | "xyz.openbmc_project.Sensor.Value"); |
| 55 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 56 | if (thresholds::hasWarningInterface(thresholds)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 57 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 58 | thresholdInterfaceWarning = objectServer.add_interface( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 59 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 60 | "xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 61 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 62 | if (thresholds::hasCriticalInterface(thresholds)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 63 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 64 | thresholdInterfaceCritical = objectServer.add_interface( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 65 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 66 | "xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 67 | } |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 68 | association = objectServer.add_interface( |
| 69 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 70 | "org.openbmc.Associations"); |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 71 | |
| 72 | if (presence) |
| 73 | { |
| 74 | itemIface = |
| 75 | objectServer.add_interface("/xyz/openbmc_project/Inventory/" + name, |
| 76 | "xyz.openbmc_project.Inventory.Item"); |
| 77 | itemIface->register_property("PrettyName", |
| 78 | std::string()); // unused property |
| 79 | itemIface->register_property("Present", true); |
| 80 | itemIface->initialize(); |
| 81 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 82 | setInitialProperties(conn); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 83 | setupPowerMatch(conn); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 84 | setupRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | TachSensor::~TachSensor() |
| 88 | { |
| 89 | // close the input dev to cancel async operations |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 90 | inputDev.close(); |
| 91 | waitTimer.cancel(); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 92 | objServer.remove_interface(thresholdInterfaceWarning); |
| 93 | objServer.remove_interface(thresholdInterfaceCritical); |
| 94 | objServer.remove_interface(sensorInterface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 95 | objServer.remove_interface(association); |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 96 | objServer.remove_interface(itemIface); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 99 | void TachSensor::setupRead(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 100 | { |
| 101 | boost::asio::async_read_until( |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 102 | inputDev, readBuf, '\n', |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 103 | [&](const boost::system::error_code& ec, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 104 | std::size_t /*bytes_transfered*/) { handleResponse(ec); }); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 105 | } |
| 106 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 107 | void TachSensor::handleResponse(const boost::system::error_code& err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 108 | { |
| 109 | if (err == boost::system::errc::bad_file_descriptor) |
| 110 | { |
| 111 | return; // we're being destroyed |
| 112 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 113 | bool missing = false; |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 114 | size_t pollTime = pwmPollMs; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 115 | if (presence) |
| 116 | { |
| 117 | if (!presence->getValue()) |
| 118 | { |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 119 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 120 | missing = true; |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 121 | pollTime = sensorFailedPollTimeMs; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 122 | } |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 123 | itemIface->set_property("Present", !missing); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 124 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 125 | std::istream responseStream(&readBuf); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 126 | if (!missing) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 127 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 128 | if (!err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 129 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 130 | std::string response; |
| 131 | try |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 132 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 133 | std::getline(responseStream, response); |
| 134 | float nvalue = std::stof(response); |
| 135 | responseStream.clear(); |
| 136 | if (nvalue != value) |
| 137 | { |
| 138 | updateValue(nvalue); |
| 139 | } |
| 140 | errCount = 0; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 141 | } |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 142 | catch (const std::invalid_argument&) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 143 | { |
| 144 | errCount++; |
| 145 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 146 | } |
| 147 | else |
| 148 | { |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 149 | if (!isPowerOn()) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 150 | { |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 151 | errCount = 0; |
| 152 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 153 | } |
| 154 | else |
| 155 | { |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 156 | pollTime = sensorFailedPollTimeMs; |
| 157 | errCount++; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 158 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 159 | } |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 160 | if (errCount >= warnAfterErrorCount) |
| 161 | { |
| 162 | // only print once |
| 163 | if (errCount == warnAfterErrorCount) |
| 164 | { |
| 165 | std::cerr << "Failure to read sensor " << name << " at " << path |
| 166 | << " ec:" << err << "\n"; |
| 167 | } |
| 168 | updateValue(0); |
| 169 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 170 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 171 | responseStream.clear(); |
| 172 | inputDev.close(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 173 | int fd = open(path.c_str(), O_RDONLY); |
| 174 | if (fd <= 0) |
| 175 | { |
| 176 | return; // we're no longer valid |
| 177 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 178 | inputDev.assign(fd); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 179 | waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime)); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 180 | waitTimer.async_wait([&](const boost::system::error_code& ec) { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 181 | if (ec == boost::asio::error::operation_aborted) |
| 182 | { |
| 183 | return; // we're being canceled |
| 184 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 185 | setupRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 186 | }); |
| 187 | } |
| 188 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 189 | void TachSensor::checkThresholds(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 190 | { |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 191 | bool status = thresholds::checkThresholds(this); |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 192 | if (redundancy && *redundancy) |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 193 | { |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 194 | (*redundancy) |
| 195 | ->update("/xyz/openbmc_project/sensors/fan_tach/" + name, !status); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 196 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 197 | } |
| 198 | |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 199 | PresenceSensor::PresenceSensor(const size_t index, bool inverted, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 200 | boost::asio::io_service& io, |
| 201 | const std::string& name) : |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 202 | inverted(inverted), |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 203 | inputDev(io), name(name) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 204 | { |
| 205 | // todo: use gpiodaemon |
| 206 | std::string device = gpioPath + std::string("gpio") + std::to_string(index); |
| 207 | fd = open((device + "/value").c_str(), O_RDONLY); |
| 208 | if (fd < 0) |
| 209 | { |
| 210 | std::cerr << "Error opening gpio " << index << "\n"; |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | std::ofstream deviceFile(device + "/edge"); |
| 215 | if (!deviceFile.good()) |
| 216 | { |
| 217 | std::cerr << "Error setting edge " << device << "\n"; |
| 218 | return; |
| 219 | } |
| 220 | deviceFile << "both"; |
| 221 | deviceFile.close(); |
| 222 | |
| 223 | inputDev.assign(boost::asio::ip::tcp::v4(), fd); |
| 224 | monitorPresence(); |
| 225 | read(); |
| 226 | } |
| 227 | |
| 228 | PresenceSensor::~PresenceSensor() |
| 229 | { |
| 230 | inputDev.close(); |
| 231 | close(fd); |
| 232 | } |
| 233 | |
| 234 | void PresenceSensor::monitorPresence(void) |
| 235 | { |
| 236 | inputDev.async_wait(boost::asio::ip::tcp::socket::wait_error, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 237 | [this](const boost::system::error_code& ec) { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 238 | if (ec == boost::system::errc::bad_file_descriptor) |
| 239 | { |
| 240 | return; // we're being destroyed |
| 241 | } |
| 242 | else if (ec) |
| 243 | { |
| 244 | std::cerr |
| 245 | << "Error on presence sensor socket\n"; |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | read(); |
| 250 | } |
| 251 | monitorPresence(); |
| 252 | }); |
| 253 | } |
| 254 | |
| 255 | void PresenceSensor::read(void) |
| 256 | { |
| 257 | constexpr size_t readSize = sizeof("0"); |
| 258 | std::string readBuf; |
| 259 | readBuf.resize(readSize); |
| 260 | lseek(fd, 0, SEEK_SET); |
| 261 | size_t r = ::read(fd, readBuf.data(), readSize); |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 262 | if (r != readSize) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 263 | { |
| 264 | std::cerr << "Error reading gpio\n"; |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | bool value = std::stoi(readBuf); |
| 269 | if (inverted) |
| 270 | { |
| 271 | value = !value; |
| 272 | } |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 273 | if (value != status) |
| 274 | { |
| 275 | status = value; |
| 276 | if (status) |
| 277 | { |
| 278 | logFanInserted(name); |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | logFanRemoved(name); |
| 283 | } |
| 284 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | bool PresenceSensor::getValue(void) |
| 289 | { |
| 290 | return status; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 291 | } |
| 292 | |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 293 | RedundancySensor::RedundancySensor(size_t count, |
| 294 | const std::vector<std::string>& children, |
| 295 | sdbusplus::asio::object_server& objectServer, |
| 296 | const std::string& sensorConfiguration) : |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 297 | count(count), |
| 298 | iface(objectServer.add_interface( |
| 299 | "/xyz/openbmc_project/control/FanRedundancy/Tach", |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 300 | "xyz.openbmc_project.Control.FanRedundancy")), |
| 301 | association(objectServer.add_interface( |
| 302 | "/xyz/openbmc_project/control/FanRedundancy/Tach", |
| 303 | "org.openbmc.Associations")), |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 304 | objectServer(objectServer) |
| 305 | { |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 306 | createAssociation(association, sensorConfiguration); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 307 | iface->register_property("Collection", children); |
| 308 | iface->register_property("Status", std::string("Full")); |
| 309 | iface->register_property("AllowedFailures", static_cast<uint8_t>(count)); |
| 310 | iface->initialize(); |
| 311 | } |
| 312 | RedundancySensor::~RedundancySensor() |
| 313 | { |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 314 | objectServer.remove_interface(association); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 315 | objectServer.remove_interface(iface); |
| 316 | } |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 317 | void RedundancySensor::update(const std::string& name, bool failed) |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 318 | { |
| 319 | statuses[name] = failed; |
| 320 | size_t failedCount = 0; |
| 321 | |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 322 | std::string newState = redundancy::full; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 323 | for (const auto& status : statuses) |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 324 | { |
| 325 | if (status.second) |
| 326 | { |
| 327 | failedCount++; |
| 328 | } |
| 329 | if (failedCount > count) |
| 330 | { |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 331 | newState = redundancy::failed; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 332 | break; |
| 333 | } |
| 334 | else if (failedCount) |
| 335 | { |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 336 | newState = redundancy::degraded; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 339 | if (state != newState) |
| 340 | { |
| 341 | if (state == redundancy::full) |
| 342 | { |
| 343 | logFanRedundancyLost(); |
| 344 | } |
| 345 | else if (newState == redundancy::full) |
| 346 | { |
| 347 | logFanRedundancyRestored(); |
| 348 | } |
| 349 | state = newState; |
| 350 | iface->set_property("Status", state); |
| 351 | } |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 352 | } |