forked from sPHENIX-Collaboration/srs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srs_control.cc
313 lines (241 loc) · 7.66 KB
/
srs_control.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using namespace std;
#include <iostream>
#include <iomanip>
#include <parseargument.h>
#include "srs_utils.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#define SRS_IP SRSIP
#ifndef SRS_IP
#define SRS_IP "10.0.0.3"
#endif
#define RECPORT 6007
void exithelp( const int ret =1)
{
cout << std::endl;
cout << " srs_control usage " << std::endl;
cout << " srs_control info show how we ae configured" << std::endl;
cout << " srs_control DAQ_IP <ip> set ip of DAQ stream" << std::endl;
cout << " srs_control BLCK_MODE val trigger mode" << std::endl;
cout << " srs_control BLCK_TRGBURST val number of time slots (<=9)" << std::endl;
cout << " srs_control BLCK_FREQ val dead time or frequency" << std::endl;
cout << " srs_control EVBLD_CHMASK val channel mask for hybrids" << std::endl;
cout << " srs_control EVBLD_DATALENGTH val length of capture window" << std::endl;
cout << " srs_control RO_ENABLE start acquisition" << std::endl;
cout << " srs_control RO_DISABLE stop acquisition" << std::endl;
cout << " srs_control readfpga read all fpga parameters" << std::endl;
cout << " srs_control readapv read all APV parameters" << std::endl;
cout << " srs_control readadccard read all ADC card parameters" << std::endl;
cout << " srs_control readhybrid read all APV Hybrid card parameters" << std::endl;
cout << " srs_control GETVALUE port adr sadr get a particular register" << std::endl;
cout << " srs_control SETVALUE port adr sadr val set a particular register" << std::endl;
cout << " " << std::endl;
exit(ret);
}
int main(int argc, char *argv[])
{
int reqport = 0;
int regcount =0;
if ( argc==1)
{
cout << "usage: " << argv[0] << " action " << endl;
exithelp();
}
std::string real_srs_ip;
if ( getenv("SRSIP") )
{
real_srs_ip = getenv("SRSIP");
}
else
{
real_srs_ip = SRS_IP;
}
returnstructure returnblock;
unsigned int val = 0;
unsigned int subaddress;
if ( argc > 2 )
{
int i;
if ( strcmp( argv[1], "readhybrid") == 0)
{
if ( argc < 4) exithelp();
val = get_uvalue( argv[2]);
if ( val >7) exithelp();
unsigned int reg = get_uvalue( argv[3]);
unsigned int s[] = { 0x800, 0x400, 0x200, 0x100, 0x8000, 0x4000, 0x2000, 0x1000};
subaddress = ( s[val] ) + 1; // we hardcode "Master APV" for now
reqport=6263;
cout << hex << "subaddress " << subaddress << endl;
int r = read_parameter ( real_srs_ip.c_str(), reqport, reg, &returnblock, subaddress);
cout << "received: " << r << " bytes" << endl;
if ( r>0)
{
cout << " Requestid: " << hex << ntohl(returnblock.RequestId) << dec << endl;
cout << " SubAdress: " << hex << ntohl(returnblock.SubAddress) << dec << endl;
cout << " CmdField1: " << hex << ntohl(returnblock.CmdField1) << dec << endl;
cout << " CmdField2: " << hex << ntohl(returnblock.CmdField2) << dec << endl;
int x = (r/4 -4)/2;
for ( int i = 0; i < x; i++)
{
cout << setw(3) << i << " " << setw(10) << hex << ntohl(returnblock.vp[i].value) <<dec << " ";
if ( returnblock.vp[i].errorcode)
{
cout << setw(10) << hex << ntohl(returnblock.vp[i].errorcode) <<dec;
}
else
{
cout << " ok";
}
cout << endl;
}
}
}
if ( strcmp( argv[1], "DAQ_IP") == 0)
{
val = get_uvalue( argv[2]);
i = set_value(real_srs_ip.c_str(), 10, 0, 6007, val);
}
else if ( strcmp( argv[1], "BLCK_MODE") == 0)
{
val = get_uvalue( argv[2]);
i = set_value( real_srs_ip.c_str(), 0, 0, 6039, val);
}
else if ( strcmp( argv[1], "BLCK_TRGBURST") == 0)
{
val = get_uvalue( argv[2]);
i = set_value( real_srs_ip.c_str(), 1, 0, 6039, val);
}
else if ( strcmp( argv[1], "BLCK_FREQ") == 0)
{
val = get_uvalue( argv[2]);
i = set_value( real_srs_ip.c_str(), 2, 0, 6039, val);
}
else if ( strcmp( argv[1], "EVBLD_CHMASK") == 0)
{
val = get_uvalue( argv[2]);
val &=0xffff;
i = set_value( real_srs_ip.c_str(), 8, 0, 6039, val);
}
else if ( strcmp( argv[1], "EVBLD_DATALENGTH") == 0)
{
val = get_uvalue( argv[2]);
val &=0xffff;
i = set_value( real_srs_ip.c_str(), 9, 0, 6039, val);
}
else if ( strcmp( argv[1], "HYBRID_APVLATENCY") == 0)
{
val = get_uvalue( argv[2]);
i = set_value( real_srs_ip.c_str(), 2, 0xff01, 6263, val);
}
else if ( strcmp( argv[1], "SETVALUE") == 0)
{
if ( argc < 6 ) exithelp(1);
int port = get_uvalue( argv[2]);
int adr = get_uvalue( argv[3]);
int sadr = get_uvalue( argv[4]);
val = get_uvalue( argv[5]);
i = set_value( real_srs_ip.c_str(), adr, sadr, port, val);
}
else if ( strcmp( argv[1], "GETVALUE") == 0)
{
if ( argc < 5 ) exithelp(1);
int port = get_uvalue( argv[2]);
int adr = get_uvalue( argv[3]);
int sadr = get_uvalue( argv[4]);
int r = read_parameter ( real_srs_ip.c_str(), port, adr, &returnblock, sadr);
cout << "received: " << r << " bytes" << endl;
if ( r>0)
{
cout << " Requestid: " << hex << ntohl(returnblock.RequestId) << dec << endl;
cout << " SubAdress: " << hex << ntohl(returnblock.SubAddress) << dec << endl;
cout << " CmdField1: " << hex << ntohl(returnblock.CmdField1) << dec << endl;
cout << " CmdField2: " << hex << ntohl(returnblock.CmdField2) << dec << endl;
int x = (r/4 -4)/2;
for ( int i = 0; i < x; i++)
{
cout << setw(3) << i << " " << setw(10) << hex << ntohl(returnblock.vp[i].value) <<dec << " ";
if ( returnblock.vp[i].errorcode)
{
cout << setw(10) << hex << ntohl(returnblock.vp[i].errorcode) <<dec;
}
else
{
cout << " ok";
}
cout << endl;
}
}
}
}
else
{
int i;
if ( strcmp( argv[1], "info") == 0)
{
cout << " Default SRS IP Address: " << real_srs_ip << endl;
}
else if ( strcmp( argv[1], "help") == 0)
{
exithelp(0);
}
else if ( strcmp( argv[1], "readfpga") == 0)
{
reqport = 6007;
regcount = 11;
}
else if ( strcmp( argv[1], "readapv") == 0)
{
reqport = 6039;
regcount = 21;
}
else if ( strcmp( argv[1], "readadccard") == 0)
{
reqport = 6519;
regcount = 6;
}
else if ( strcmp( argv[1], "RO_ENABLE") == 0)
{
val = 1;
i = set_value( real_srs_ip.c_str(), 0xF, 0, 6039, val);
}
else if ( strcmp( argv[1], "RO_DISABLE") == 0)
{
val = 0;
set_value( real_srs_ip.c_str(), 0xF, 0, 6039, val);
}
if ( reqport && regcount )
{
int r = read_params ( real_srs_ip.c_str(), reqport, regcount, &returnblock);
cout << "received: " << r << " bytes" << endl;
if ( r>0)
{
cout << " Requestid: " << hex << ntohl(returnblock.RequestId) << dec << endl;
cout << " SubAdress: " << hex << ntohl(returnblock.SubAddress) << dec << endl;
cout << " CmdField1: " << hex << ntohl(returnblock.CmdField1) << dec << endl;
cout << " CmdField2: " << hex << ntohl(returnblock.CmdField2) << dec << endl;
int x = (r/4 -4)/2;
for ( int i = 0; i < x; i++)
{
cout << setw(3) << i << " " << setw(10) << hex << ntohl(returnblock.vp[i].value) <<dec << " ";
if ( returnblock.vp[i].errorcode)
{
cout << setw(10) << hex << ntohl(returnblock.vp[i].errorcode) <<dec;
}
else
{
cout << " ok";
}
cout << endl;
}
}
}
}
return 0;
}