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