blob: e383fc138ca802ddb6ae562134692145b4bb41de [file] [log] [blame]
Matt Spinlerafb39132017-08-14 13:53:07 -05001/**
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 */
16#include <chrono>
17#include <iostream>
Matt Spinler56d90a82017-08-14 14:05:11 -050018#include <phosphor-logging/log.hpp>
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -070019#include <sdeventplus/event.hpp>
Matt Spinlerafb39132017-08-14 13:53:07 -050020#include "argument.hpp"
Matt Spinler56d90a82017-08-14 14:05:11 -050021#include "pgood_monitor.hpp"
Matt Spinler70849272017-08-22 09:14:40 -050022#include "runtime_monitor.hpp"
Matt Spinlerb2d72512017-08-22 09:07:01 -050023#include "ucd90160.hpp"
Matt Spinlerafb39132017-08-14 13:53:07 -050024
25using namespace witherspoon::power;
Matt Spinler56d90a82017-08-14 14:05:11 -050026using namespace phosphor::logging;
Matt Spinlerafb39132017-08-14 13:53:07 -050027
28int main(int argc, char** argv)
29{
30 ArgumentParser args{argc, argv};
31 auto action = args["action"];
32
Matt Spinler70849272017-08-22 09:14:40 -050033 if ((action != "pgood-monitor") && (action != "runtime-monitor"))
Matt Spinlerafb39132017-08-14 13:53:07 -050034 {
35 std::cerr << "Invalid action\n";
36 args.usage(argv);
37 exit(EXIT_FAILURE);
38 }
39
40 auto i = strtoul(args["interval"].c_str(), nullptr, 10);
41 if (i == 0)
42 {
43 std::cerr << "Invalid interval value\n";
44 exit(EXIT_FAILURE);
45 }
46
Matt Spinler78c5c2b2017-12-14 10:42:07 -060047 std::chrono::milliseconds interval{i};
Matt Spinlerafb39132017-08-14 13:53:07 -050048
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -070049 auto event = sdeventplus::Event::get_default();
Matt Spinler56d90a82017-08-14 14:05:11 -050050 auto bus = sdbusplus::bus::new_default();
51 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
52
Matt Spinlera8269652017-09-19 15:13:28 -050053 auto device = std::make_unique<UCD90160>(0, bus);
Matt Spinlerb2d72512017-08-22 09:07:01 -050054
Matt Spinler70849272017-08-22 09:14:40 -050055 std::unique_ptr<DeviceMonitor> monitor;
Matt Spinler56d90a82017-08-14 14:05:11 -050056
Matt Spinler70849272017-08-22 09:14:40 -050057 if (action == "pgood-monitor")
58 {
59 //If PGOOD doesn't turn on within a certain
60 //time, analyze the device for errors
61 monitor = std::make_unique<PGOODMonitor>(
62 std::move(device), bus, event, interval);
63 }
64 else //runtime-monitor
65 {
66 //Continuously monitor this device both by polling
67 //and on 'power lost' signals.
68 monitor = std::make_unique<RuntimeMonitor>(
69 std::move(device), bus, event, interval);
70 }
71
72 return monitor->run();
Matt Spinlerafb39132017-08-14 13:53:07 -050073}