blob: 6ec5a5cacf9501140d49cf5fe31d04bbb84e6605 [file] [log] [blame]
Matthew Barth5c15b792017-03-01 11:17:00 -06001/**
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 Bishop8e9a8e72017-06-08 23:21:03 -040016#include <phosphor-logging/log.hpp>
Matthew Barth293477d2017-02-17 15:39:36 -060017#include <vector>
Matthew Barthb8034452017-02-17 16:39:46 -060018#include "fan_enclosure.hpp"
19#include "fan_detect_defs.hpp"
Brad Bishop76596b22017-06-13 14:39:13 -040020#include "generated.hpp"
Brad Bishopec613db2017-06-08 12:12:53 -040021#include "sdbusplus.hpp"
Matthew Barthd6403822017-02-17 17:10:19 -060022#include "tach_sensor.hpp"
Matthew Barthb8034452017-02-17 16:39:46 -060023
Matthew Barth293477d2017-02-17 15:39:36 -060024
25int main(void)
26{
Brad Bishop8e9a8e72017-06-08 23:21:03 -040027 using namespace phosphor::fan;
28 using namespace std::literals::string_literals;
29 using namespace phosphor::logging;
30
Matthew Barthb8034452017-02-17 16:39:46 -060031 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 Bishop8e9a8e72017-06-08 23:21:03 -040039 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 Barthb8034452017-02-17 16:39:46 -060057 auto fan = std::make_unique<
Brad Bishop8e9a8e72017-06-08 23:21:03 -040058 phosphor::fan::presence::FanEnclosure>(fanProp,
59 state);
Matthew Barthd6403822017-02-17 17:10:19 -060060 for (auto const &fanSensor: std::get<2>(fanProp))
61 {
Brad Bishop8e9a8e72017-06-08 23:21:03 -040062 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 Barthd6403822017-02-17 17:10:19 -060071 auto sensor = std::make_unique<
Brad Bishopec613db2017-06-08 12:12:53 -040072 phosphor::fan::presence::TachSensor>(fanSensor,
Brad Bishop8e9a8e72017-06-08 23:21:03 -040073 *fan,
74 initialSpeed != 0);
Matthew Barthd6403822017-02-17 17:10:19 -060075 fan->addSensor(std::move(sensor));
76 }
Brad Bishop0dea38e2017-06-08 11:48:37 -040077
78 fan->updInventory();
Matthew Barthb8034452017-02-17 16:39:46 -060079 fans.push_back(std::move(fan));
80 }
81 }
82 }
83
Matthew Barth293477d2017-02-17 15:39:36 -060084 while (true)
85 {
86 // Respond to dbus signals
Brad Bishop8e9a8e72017-06-08 23:21:03 -040087 util::SDBusPlus::getBus().process_discard();
88 util::SDBusPlus::getBus().wait();
Matthew Barth293477d2017-02-17 15:39:36 -060089 }
90 return 0;
91}