blob: 6284f8943b017f690a5878363ff396576b8618dd [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 Bishopec613db2017-06-08 12:12:53 -040020#include "sdbusplus.hpp"
Matthew Barthd6403822017-02-17 17:10:19 -060021#include "tach_sensor.hpp"
Matthew Barthb8034452017-02-17 16:39:46 -060022
Matthew Barth293477d2017-02-17 15:39:36 -060023
24int main(void)
25{
Brad Bishop8e9a8e72017-06-08 23:21:03 -040026 using namespace phosphor::fan;
27 using namespace std::literals::string_literals;
28 using namespace phosphor::logging;
29
Matthew Barthb8034452017-02-17 16:39:46 -060030 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 Bishop8e9a8e72017-06-08 23:21:03 -040038 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 Barthb8034452017-02-17 16:39:46 -060056 auto fan = std::make_unique<
Brad Bishop8e9a8e72017-06-08 23:21:03 -040057 phosphor::fan::presence::FanEnclosure>(fanProp,
58 state);
Matthew Barthd6403822017-02-17 17:10:19 -060059 for (auto const &fanSensor: std::get<2>(fanProp))
60 {
Brad Bishop8e9a8e72017-06-08 23:21:03 -040061 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 Barthd6403822017-02-17 17:10:19 -060070 auto sensor = std::make_unique<
Brad Bishopec613db2017-06-08 12:12:53 -040071 phosphor::fan::presence::TachSensor>(fanSensor,
Brad Bishop8e9a8e72017-06-08 23:21:03 -040072 *fan,
73 initialSpeed != 0);
Matthew Barthd6403822017-02-17 17:10:19 -060074 fan->addSensor(std::move(sensor));
75 }
Brad Bishop0dea38e2017-06-08 11:48:37 -040076
77 fan->updInventory();
Matthew Barthb8034452017-02-17 16:39:46 -060078 fans.push_back(std::move(fan));
79 }
80 }
81 }
82
Matthew Barth293477d2017-02-17 15:39:36 -060083 while (true)
84 {
85 // Respond to dbus signals
Brad Bishop8e9a8e72017-06-08 23:21:03 -040086 util::SDBusPlus::getBus().process_discard();
87 util::SDBusPlus::getBus().wait();
Matthew Barth293477d2017-02-17 15:39:36 -060088 }
89 return 0;
90}