LCOV - code coverage report
Current view: top level - mu2e-pcie-utils/cfoInterfaceLib - cfoRegDump.cc (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 0.0 % 61 0
Test Date: 2026-07-30 01:56:44 Functions: 0.0 % 3 0

            Line data    Source code
       1              : // This program is a simple Register Dump module
       2              : // Eric Flumerfelt, FNAL RSI
       3              : // 5/15/2015
       4              : 
       5              : #include <stdio.h>
       6              : #include <sys/ioctl.h>
       7              : #include <unistd.h>
       8              : #include <iostream>
       9              : 
      10              : #include "cfoInterfaceLib/CFO_Registers.h"
      11              : 
      12            0 : void printHelpMsg()
      13              : {
      14            0 :         std::cout << "Usage: CFORegDump [options]" << std::endl;
      15            0 :         std::cout << "Options are:" << std::endl
      16            0 :                           << "    -h: This message." << std::endl
      17            0 :                           << "    -R: DON'T Print Register Dump." << std::endl
      18            0 :                           << "    -s: Print SERDES Byte and Packet Counters." << std::endl
      19            0 :                           << "    -p: Print Performance Counters." << std::endl
      20            0 :                           << "    -d: CFO instance to use (defaults to CFOLIB_CFO if set, 0 otherwise)" << std::endl;
      21              : 
      22            0 :         exit(0);
      23              : }
      24              : 
      25            0 : unsigned getOptionValue(int* index, char** argv[])
      26              : {
      27            0 :         auto arg = (*argv)[*index];
      28            0 :         if (arg[2] == '\0')
      29              :         {
      30            0 :                 (*index)++;
      31            0 :                 unsigned ret = strtoul((*argv)[*index], nullptr, 0);
      32            0 :                 if (ret == 0 && (*argv)[*index][0] != '0')  // No option given
      33              :                 {
      34            0 :                         (*index)--;
      35              :                 }
      36            0 :                 return ret;
      37              :         }
      38            0 :         auto offset = 2;
      39            0 :         if (arg[2] == '=')
      40              :         {
      41            0 :                 offset = 3;
      42              :         }
      43              : 
      44            0 :         return strtoul(&arg[offset], nullptr, 0);
      45              : }
      46              : 
      47            0 : int main(int argc, char* argv[])
      48              : {
      49            0 :         auto printSERDESCounters = false;
      50            0 :         auto printRegisterDump = true;
      51            0 :         int CFO = -1;
      52              : 
      53            0 :         for (auto optind = 1; optind < argc; ++optind)
      54              :         {
      55            0 :                 if (argv[optind][0] == '-')
      56              :                 {
      57            0 :                         switch (argv[optind][1])
      58              :                         {
      59            0 :                                 case 's':
      60            0 :                                         printSERDESCounters = true;
      61            0 :                                         break;
      62            0 :                                 case 'R':
      63            0 :                                         printRegisterDump = false;
      64            0 :                                         break;
      65            0 :                                 case 'd':
      66            0 :                                         CFO = getOptionValue(&optind, &argv);
      67            0 :                                         break;
      68            0 :                                 default:
      69            0 :                                         std::cout << "Unknown option: " << argv[optind] << std::endl;
      70            0 :                                         printHelpMsg();
      71            0 :                                         break;
      72            0 :                                 case 'h':
      73            0 :                                         printHelpMsg();
      74            0 :                                         break;
      75              :                         }
      76              :                 }
      77              :         }
      78              : 
      79            0 :         auto thisCFO = new CFOLib::CFO_Registers(DTCLib::DTC_SimMode_Disabled, CFO, "", true);
      80              : 
      81            0 :         auto cols = 80;
      82            0 :         auto lines = 24;
      83              : 
      84              : #ifdef TIOCGSIZE
      85              :         struct ttysize ts;
      86              :         ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
      87              :         cols = ts.ts_cols;
      88              :         lines = ts.ts_lines;
      89              : #elif defined(TIOCGWINSZ)
      90              :         struct winsize ts;
      91            0 :         ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
      92            0 :         cols = ts.ws_col;
      93            0 :         lines = ts.ws_row;
      94              : #endif /* TIOCGSIZE */
      95              : 
      96            0 :         printf("Terminal is %dx%d\n", cols, lines);
      97              : 
      98            0 :         if (cols > 400)
      99              :         {
     100            0 :                 cols = 120;
     101              :         }
     102              : 
     103            0 :         if (printRegisterDump)
     104              :         {
     105            0 :                 std::cout << thisCFO->FormattedRegDump(cols, thisCFO->formattedDumpFunctions_) << std::endl;
     106              :         }
     107              : 
     108            0 :         if (printSERDESCounters)
     109              :         {
     110            0 :                 std::cout << std::endl
     111            0 :                                   << std::endl;
     112            0 :                 std::cout << thisCFO->FormattedRegDump(cols, thisCFO->formattedCounterFunctions_) << std::endl;
     113              :         }
     114              : 
     115            0 :         delete thisCFO;
     116            0 :         return 0;
     117              : }
        

Generated by: LCOV version 2.0-1