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 "mihawk-cpld.hpp" 19 #include "pgood_monitor.hpp" 20 #include "runtime_monitor.hpp" 21 #include "ucd90160.hpp" 22 23 #include <CLI/CLI.hpp> 24 #include <sdeventplus/event.hpp> 25 26 #include <chrono> 27 #include <iostream> 28 29 using namespace phosphor::power; 30 31 int main(int argc, char** argv) 32 { 33 CLI::App app{"Phosphor sequencer monitor"}; 34 std::string action{}; 35 std::string interVal{}; 36 37 std::vector<std::string> actionTypes = {"pgood-monitor", "runtime-monitor"}; 38 app.add_option("-a,--action", action, 39 "Action: pgood-monitor or runtime-monitor\n") 40 ->required() 41 ->transform(CLI::IsMember(actionTypes)); 42 app.add_option("-i,--interval", interVal, 43 "Interval in milliseconds:\n" 44 "PGOOD monitor: time allowed for PGOOD to come up\n" 45 "Runtime monitor: polling interval.\n") 46 ->required(); 47 48 try 49 { 50 app.parse(argc, argv); 51 } 52 catch (CLI::Error& e) 53 { 54 return app.exit(e); 55 } 56 57 auto i = strtoul(interVal.c_str(), nullptr, 10); 58 if (i == 0) 59 { 60 std::cerr << "Invalid interval value\n"; 61 exit(EXIT_FAILURE); 62 } 63 64 std::chrono::milliseconds interval{i}; 65 66 auto event = sdeventplus::Event::get_default(); 67 auto bus = sdbusplus::bus::new_default(); 68 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 69 70 auto device = std::make_unique<SEQUENCER>(0, bus); 71 72 std::unique_ptr<DeviceMonitor> monitor; 73 74 if (action == "pgood-monitor") 75 { 76 // If PGOOD doesn't turn on within a certain 77 // time, analyze the device for errors 78 monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event, 79 interval); 80 } 81 else // runtime-monitor 82 { 83 // Continuously monitor this device both by polling 84 // and on 'power lost' signals. 85 monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus, 86 event, interval); 87 } 88 89 return monitor->run(); 90 } 91