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 */ 16 #include "config.h" 17 18 #include "argument.hpp" 19 #include "mihawk-cpld.hpp" 20 #include "pgood_monitor.hpp" 21 #include "runtime_monitor.hpp" 22 #include "ucd90160.hpp" 23 24 #include <phosphor-logging/log.hpp> 25 #include <sdeventplus/event.hpp> 26 27 #include <chrono> 28 #include <iostream> 29 30 using namespace phosphor::power; 31 using namespace phosphor::logging; 32 33 int main(int argc, char** argv) 34 { 35 ArgumentParser args{argc, argv}; 36 auto action = args["action"]; 37 38 if ((action != "pgood-monitor") && (action != "runtime-monitor")) 39 { 40 std::cerr << "Invalid action\n"; 41 args.usage(argv); 42 exit(EXIT_FAILURE); 43 } 44 45 auto i = strtoul(args["interval"].c_str(), nullptr, 10); 46 if (i == 0) 47 { 48 std::cerr << "Invalid interval value\n"; 49 exit(EXIT_FAILURE); 50 } 51 52 std::chrono::milliseconds interval{i}; 53 54 auto event = sdeventplus::Event::get_default(); 55 auto bus = sdbusplus::bus::new_default(); 56 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 57 58 auto device = std::make_unique<SEQUENCER>(0, bus); 59 60 std::unique_ptr<DeviceMonitor> monitor; 61 62 if (action == "pgood-monitor") 63 { 64 // If PGOOD doesn't turn on within a certain 65 // time, analyze the device for errors 66 monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event, 67 interval); 68 } 69 else // runtime-monitor 70 { 71 // Continuously monitor this device both by polling 72 // and on 'power lost' signals. 73 monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus, 74 event, interval); 75 } 76 77 return monitor->run(); 78 } 79