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 "dtcInterfaceLib/DTC_Registers.h"
11 :
12 0 : void printHelpMsg()
13 : {
14 0 : std::cout << "Usage: DTCRegDump [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 : << " -e: Print SERDES Error Counters" << std::endl
21 0 : << " -c: Print Mu2e protocol packet Counters" << std::endl
22 0 : << " -m: Use <file> as the emulated DTC memory area" << std::endl
23 0 : << " -d: DTC instance to use (defaults to DTCLIB_DTC if set, 0 otherwise)" << std::endl;
24 :
25 0 : exit(0);
26 : }
27 :
28 0 : int main(int argc, char* argv[])
29 : {
30 0 : auto printSERDESCounters = false;
31 0 : auto printRegisterDump = true;
32 0 : auto printSERDESErrors = false;
33 0 : auto printProtocolCounters = false;
34 0 : auto printPerformanceCounters = false;
35 0 : int dtc = -1;
36 0 : std::string memFileName = "mu2esim.bin";
37 :
38 0 : for (auto optind = 1; optind < argc; ++optind)
39 : {
40 0 : if (argv[optind][0] == '-')
41 : {
42 0 : switch (argv[optind][1])
43 : {
44 0 : case 's':
45 0 : printSERDESCounters = true;
46 0 : break;
47 0 : case 'R':
48 0 : printRegisterDump = false;
49 0 : break;
50 0 : case 'd':
51 0 : dtc = DTCLib::Utilities::getOptionValue(&optind, &argv);
52 0 : break;
53 0 : case 'm':
54 0 : memFileName = DTCLib::Utilities::getOptionString(&optind, &argv);
55 0 : break;
56 0 : case 'p':
57 0 : printPerformanceCounters = true;
58 0 : break;
59 0 : case 'e':
60 0 : printSERDESErrors = true;
61 0 : break;
62 0 : case 'c':
63 0 : printProtocolCounters = true;
64 0 : break;
65 0 : default:
66 0 : std::cout << "Unknown option: " << argv[optind] << std::endl;
67 0 : printHelpMsg();
68 0 : break;
69 0 : case 'h':
70 0 : printHelpMsg();
71 0 : break;
72 : }
73 : }
74 : }
75 :
76 0 : auto thisDTC = new DTCLib::DTC_Registers(DTCLib::DTC_SimMode_Disabled, dtc, memFileName, 0x1, "", true);
77 :
78 0 : auto cols = 80;
79 0 : auto lines = 24;
80 :
81 : #ifdef TIOCGSIZE
82 : struct ttysize ts;
83 : ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
84 : cols = ts.ts_cols;
85 : lines = ts.ts_lines;
86 : #elif defined(TIOCGWINSZ)
87 : struct winsize ts;
88 0 : ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
89 0 : cols = ts.ws_col;
90 0 : lines = ts.ws_row;
91 : #endif /* TIOCGSIZE */
92 :
93 0 : printf("Terminal is %dx%d\n", cols, lines);
94 :
95 0 : if (cols > 400)
96 : {
97 0 : cols = 120;
98 : }
99 :
100 0 : std::cout << "Driver Version: " << thisDTC->GetDevice()->get_driver_version() << std::endl;
101 :
102 0 : if (printRegisterDump)
103 : {
104 0 : std::cout << thisDTC->FormattedRegDump(cols, thisDTC->formattedDumpFunctions_) << std::endl;
105 : }
106 :
107 0 : if (printSERDESCounters)
108 : {
109 0 : std::cout << std::endl
110 0 : << std::endl;
111 0 : std::cout << "NOT IMPLEMENTED" << std::endl; // thisDTC->FormattedRegDump(cols, thisDTC->formattedSERDESCounterFunctions_) << std::endl;
112 : }
113 :
114 0 : if (printPerformanceCounters)
115 : {
116 0 : std::cout << std::endl
117 0 : << std::endl;
118 0 : std::cout << thisDTC->FormattedRegDump(cols, thisDTC->formattedPerformanceCounterFunctions_) << std::endl;
119 : }
120 :
121 0 : if (printSERDESErrors)
122 : {
123 0 : std::cout << std::endl
124 0 : << std::endl;
125 0 : std::cout << thisDTC->FormattedRegDump(cols, thisDTC->formattedSERDESErrorFunctions_) << std::endl;
126 : }
127 :
128 0 : if (printProtocolCounters)
129 : {
130 0 : std::cout << std::endl
131 0 : << std::endl;
132 0 : std::cout << thisDTC->FormattedRegDump(cols, thisDTC->formattedPacketCounterFunctions_) << std::endl;
133 : }
134 :
135 0 : delete thisDTC;
136 0 : return 0;
137 0 : }
|