|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file ProgramOnuStatus.cxx |
| 12 | +/// \brief Tool that returns the ONU status of RoCs. |
| 13 | +/// |
| 14 | +/// \author Kostas Alexopoulos ([email protected]) |
| 15 | + |
| 16 | +#include <iostream> |
| 17 | +#include "Cru/CruBar.h" |
| 18 | +#include "ReadoutCard/ChannelFactory.h" |
| 19 | +#include "CommandLineUtilities/Options.h" |
| 20 | +#include "CommandLineUtilities/Program.h" |
| 21 | +#include <boost/format.hpp> |
| 22 | +#include <boost/property_tree/ptree.hpp> |
| 23 | +#include <boost/property_tree/json_parser.hpp> |
| 24 | + |
| 25 | +using namespace AliceO2::roc::CommandLineUtilities; |
| 26 | +using namespace AliceO2::roc; |
| 27 | +namespace pt = boost::property_tree; |
| 28 | +namespace po = boost::program_options; |
| 29 | + |
| 30 | +class ProgramOnuStatus : public Program |
| 31 | +{ |
| 32 | + public: |
| 33 | + virtual Description getDescription() |
| 34 | + { |
| 35 | + return { "Status", "Return ONU status", |
| 36 | + "roc-onu-status --id 42:00.0\n" |
| 37 | + "roc-onu-status --id 42:00.0 --json" }; |
| 38 | + } |
| 39 | + |
| 40 | + virtual void addOptions(boost::program_options::options_description& options) |
| 41 | + { |
| 42 | + Options::addOptionCardId(options); |
| 43 | + options.add_options()("json-out", |
| 44 | + po::bool_switch(&mOptions.jsonOut), |
| 45 | + "Toggle json-formatted output"); |
| 46 | + } |
| 47 | + |
| 48 | + virtual void run(const boost::program_options::variables_map& map) |
| 49 | + { |
| 50 | + // initialize ptree |
| 51 | + pt::ptree root; |
| 52 | + |
| 53 | + auto cardId = Options::getOptionCardId(map); |
| 54 | + auto params = Parameters::makeParameters(cardId, 2); //status available on BAR2 |
| 55 | + // We care for all of the links |
| 56 | + //params.setLinkMask(Parameters::linkMaskFromString("0-23")); |
| 57 | + auto bar2 = ChannelFactory().getBar(params); |
| 58 | + |
| 59 | + CardType::type cardType = bar2->getCardType(); |
| 60 | + if (cardType == CardType::type::Crorc) { |
| 61 | + std::cout << "CRORC status report not yet supported" << std::endl; |
| 62 | + return; |
| 63 | + } else if (cardType != CardType::type::Cru) { |
| 64 | + std::cout << "Invalid card type" << std::endl; |
| 65 | + return; |
| 66 | + } |
| 67 | + |
| 68 | + auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2); |
| 69 | + |
| 70 | + Cru::OnuStatus onuStatus = cruBar2->reportOnuStatus(); |
| 71 | + |
| 72 | + if (mOptions.jsonOut) { |
| 73 | + root.put("ONU address", onuStatus.onuAddress); |
| 74 | + root.put("ONU RX40 locked", onuStatus.rx40Locked); |
| 75 | + root.put("ONU phase good", onuStatus.phaseGood); |
| 76 | + root.put("ONU RX locked", onuStatus.rxLocked); |
| 77 | + root.put("ONU operational", onuStatus.operational); |
| 78 | + root.put("ONU MGT TX ready", onuStatus.mgtTxReady); |
| 79 | + root.put("ONU MGT RX ready", onuStatus.mgtRxReady); |
| 80 | + root.put("ONU MGT TX PLL locked", onuStatus.mgtTxPllLocked); |
| 81 | + root.put("ONU MGT RX PLL locked", onuStatus.mgtRxPllLocked); |
| 82 | + } else { |
| 83 | + std::cout << "ONU address: \t\t0x" << std::hex << onuStatus.onuAddress << std::endl; |
| 84 | + std::cout << "-----------------------------" << std::endl; |
| 85 | + std::cout << "ONU RX40 locked: \t" << std::boolalpha << onuStatus.rx40Locked << std::endl; |
| 86 | + std::cout << "ONU phase good: \t" << std::boolalpha << onuStatus.phaseGood << std::endl; |
| 87 | + std::cout << "ONU RX locked: \t\t" << std::boolalpha << onuStatus.rxLocked << std::endl; |
| 88 | + std::cout << "ONU operational: \t" << std::boolalpha << onuStatus.operational << std::endl; |
| 89 | + std::cout << "ONU MGT TX ready: \t" << std::boolalpha << onuStatus.mgtTxReady << std::endl; |
| 90 | + std::cout << "ONU MGT RX ready: \t" << std::boolalpha << onuStatus.mgtRxReady << std::endl; |
| 91 | + std::cout << "ONU MGT TX PLL locked: \t" << std::boolalpha << onuStatus.mgtTxPllLocked << std::endl; |
| 92 | + std::cout << "ONU MGT RX PLL locked: \t" << std::boolalpha << onuStatus.mgtRxPllLocked << std::endl; |
| 93 | + } |
| 94 | + |
| 95 | + if (mOptions.jsonOut) { |
| 96 | + pt::write_json(std::cout, root); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + private: |
| 101 | + struct OptionsStruct { |
| 102 | + bool jsonOut = false; |
| 103 | + } mOptions; |
| 104 | +}; |
| 105 | + |
| 106 | +int main(int argc, char** argv) |
| 107 | +{ |
| 108 | + return ProgramOnuStatus().execute(argc, argv); |
| 109 | +} |
0 commit comments