blob: d19a254be0bcc91564f92410559b0694f738fe36 [file] [log] [blame]
Brandon Wyman2ad76bd2019-08-26 17:15:04 -05001/**
2 * Copyright © 2019 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 */
Brandon Wyman2bac8602019-09-12 18:12:21 -050016#include "psu_manager.hpp"
17
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050018#include <CLI/CLI.hpp>
Brandon Wyman57939e82019-08-26 17:53:57 -050019#include <phosphor-logging/log.hpp>
Brandon Wyman2bac8602019-09-12 18:12:21 -050020#include <sdbusplus/bus.hpp>
21#include <sdeventplus/event.hpp>
Brandon Wyman57939e82019-08-26 17:53:57 -050022
23#include <filesystem>
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050024
25int main(int argc, char* argv[])
26{
Brandon Wyman57939e82019-08-26 17:53:57 -050027 using namespace phosphor::logging;
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050028
29 CLI::App app{"OpenBMC Power Supply Unit Monitor"};
Brandon Wyman57939e82019-08-26 17:53:57 -050030
31 std::string configfile;
32 app.add_option("-c,--config", configfile, "JSON configuration file path")
33 ->check(CLI::ExistingFile);
34
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050035 // Read the arguments.
36 CLI11_PARSE(app, argc, argv);
Brandon Wyman57939e82019-08-26 17:53:57 -050037 if (configfile.empty())
38 {
39 configfile = "/etc/phosphor-psu-monitor/psu_config.json";
40 }
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050041
Brandon Wyman57939e82019-08-26 17:53:57 -050042 if (!std::filesystem::exists(configfile))
43 {
44 log<level::ERR>("Configuration file does not exist",
45 entry("FILENAME=%s", configfile.c_str()));
46 return -1;
47 }
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050048
Brandon Wyman2bac8602019-09-12 18:12:21 -050049 auto bus = sdbusplus::bus::new_default();
50 auto event = sdeventplus::Event::get_default();
51
52 // Attach the event object to the bus object so we can
53 // handle both sd_events (for the timers) and dbus signals.
54 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
55
56 // TODO: Should get polling interval from JSON file.
57 auto pollInterval = std::chrono::milliseconds(1000);
58
59 return phosphor::power::manager::PSUManager(bus, event, pollInterval).run();
Brandon Wyman2ad76bd2019-08-26 17:15:04 -050060}