Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM 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 | */ |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 16 | #include <phosphor-logging/log.hpp> |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 17 | #include <vector> |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 18 | #include "fan_enclosure.hpp" |
| 19 | #include "fan_detect_defs.hpp" |
Brad Bishop | 76596b2 | 2017-06-13 14:39:13 -0400 | [diff] [blame^] | 20 | #include "generated.hpp" |
Brad Bishop | ec613db | 2017-06-08 12:12:53 -0400 | [diff] [blame] | 21 | #include "sdbusplus.hpp" |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 22 | #include "tach_sensor.hpp" |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 23 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 24 | |
| 25 | int main(void) |
| 26 | { |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 27 | using namespace phosphor::fan; |
| 28 | using namespace std::literals::string_literals; |
| 29 | using namespace phosphor::logging; |
| 30 | |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 31 | std::vector<std::unique_ptr<phosphor::fan::presence::FanEnclosure>> fans; |
| 32 | |
| 33 | for (auto const& detectMap: fanDetectMap) |
| 34 | { |
| 35 | if (detectMap.first == "tach") |
| 36 | { |
| 37 | for (auto const& fanProp: detectMap.second) |
| 38 | { |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 39 | auto path = "/xyz/openbmc_project/inventory"s + |
| 40 | std::get<0>(fanProp); |
| 41 | |
| 42 | auto state = presence::UNKNOWN; |
| 43 | try |
| 44 | { |
| 45 | auto boolstate = util::SDBusPlus::getProperty<bool>( |
| 46 | path, |
| 47 | "xyz.openbmc_project.Inventory.Item"s, |
| 48 | "Present"s); |
| 49 | state = boolstate ? |
| 50 | presence::PRESENT : presence::NOT_PRESENT; |
| 51 | } |
| 52 | catch (const std::exception& err) |
| 53 | { |
| 54 | log<level::INFO>(err.what()); |
| 55 | } |
| 56 | |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 57 | auto fan = std::make_unique< |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 58 | phosphor::fan::presence::FanEnclosure>(fanProp, |
| 59 | state); |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 60 | for (auto const &fanSensor: std::get<2>(fanProp)) |
| 61 | { |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 62 | auto initialSpeed = static_cast<int64_t>(0); |
| 63 | auto sensorPath = |
| 64 | "/xyz/openbmc_project/sensors/fan_tach/"s + |
| 65 | fanSensor; |
| 66 | initialSpeed = util::SDBusPlus::getProperty<int64_t>( |
| 67 | sensorPath, |
| 68 | "xyz.openbmc_project.Sensor.Value"s, |
| 69 | "Value"s); |
| 70 | |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 71 | auto sensor = std::make_unique< |
Brad Bishop | ec613db | 2017-06-08 12:12:53 -0400 | [diff] [blame] | 72 | phosphor::fan::presence::TachSensor>(fanSensor, |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 73 | *fan, |
| 74 | initialSpeed != 0); |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 75 | fan->addSensor(std::move(sensor)); |
| 76 | } |
Brad Bishop | 0dea38e | 2017-06-08 11:48:37 -0400 | [diff] [blame] | 77 | |
| 78 | fan->updInventory(); |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 79 | fans.push_back(std::move(fan)); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 84 | while (true) |
| 85 | { |
| 86 | // Respond to dbus signals |
Brad Bishop | 8e9a8e7 | 2017-06-08 23:21:03 -0400 | [diff] [blame] | 87 | util::SDBusPlus::getBus().process_discard(); |
| 88 | util::SDBusPlus::getBus().wait(); |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 89 | } |
| 90 | return 0; |
| 91 | } |