-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcaen_client.cc
473 lines (372 loc) · 12.6 KB
/
caen_client.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#include <iostream>
#include <sstream>
#include <parseargument.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "getopt.h"
//#include <CAENDigitizer.h>
//#include <CAENDigitizerType.h>
#include "caen_manager.h"
using namespace std;
int show_status( caen_manager *);
void exithelp( const int ret =1)
{
cout << std::endl;
cout << " caen_client usage " << std::endl;
cout << " -d link (optical fiber) number, default 0 " << std::endl;
cout << " -n node sub-module for daisy-chained setups, default 0 " << std::endl;
cout << " -v increase verbosity, multiple -v for more" << std::endl;
cout << std::endl;
cout << " caen_client status provide an overview of most registers" << std::endl;
cout << " caen_client identify identify the module" << std::endl;
cout << " caen_client init perform a standard initialization" << std::endl;
cout << " caen_client SetMaxNumEventsBLT set number of events" << endl;
cout << " caen_client SetExtTriggerInputMode set the trigger input mode (0-3)" << endl;
cout << " caen_client SetFastTriggerDigitizing 0/1" << endl;
cout << " caen_client SetFastTriggerMode 0/1 " << endl;
cout << " caen_client SetOutputSignalMode (0 -7) " << endl;
cout << " caen_client SetDRS4SamplingFrequency (0 - 5Gs, 1 - 2.5GS, 2 - 1GS)" << endl;
cout << " caen_client SetRecordLength set the number of samples" << endl;
cout << " caen_client SetPostTriggerSize set the number of samples past a trigger" << endl;
cout << " caen_client SetIOLevel 0 - NIM, 1 - TTL" << endl;
cout << " caen_client SetAcquisitionMode 0 - software, 1 - interrupt" << endl;
cout << " caen_client SetGroupEnableMask 0xff for all" << endl;
// cout << " caen_client LoadDRS4CorrectionData for 0 - 5Gs, 1 - 2.5GS, 2 - 1GS" << endl;
// cout << " caen_client SetDRS4Correction enable (1) or disable (0) the loaded correction data" << endl;
cout << " caen_client SetTriggerPolarity channel value set the trigger polarity for this channel (0/1)" << endl;
cout << " caen_client SetTriggerPolarity value set the trigger polarity for all channels (0/1)" << endl;
cout << " caen_client SetChannelDCOffset channel value set DAC offset for channel" << std::endl;
cout << " caen_client SetChannelDCOffset value set DAC offset for all channels" << std::endl;
cout << " caen_client PrintCalibrationData frequency chip print out the correction data for this frequency and chip" << std::endl;
cout << " caen_client WriteRegister address value low-level write to a register" << std::endl;
cout << " caen_client ReadRegister address low-level read from a register" << std::endl;
// cout << " caen_client reset full board reset" << std::endl;
cout << " " << std::endl;
exit(ret);
}
int main(int argc, char *argv[])
{
if ( argc==1)
{
exithelp(1);
}
int verbosity = 0;
int linknum = 0;
int node = 0;
int opt;
while ((opt = getopt(argc, argv, "hvd:n:")) != EOF)
{
switch (opt)
{
// the -d (which linknum) switch
case 'd':
if ( !sscanf(optarg, "%d", &linknum) ) exithelp();
if ( linknum < 0 || linknum > 15) exithelp();
break;
case 'n':
if ( !sscanf(optarg, "%d", &node) ) exithelp();
if ( node < 0 || node > 7) exithelp();
break;
case 'v':
verbosity++;
break;
case 'h':
exithelp(0);
break;
default:
break;
}
}
caen_manager * cm = new caen_manager(linknum, node);
if (cm->GetStatus())
{
cout << "Failure, Status = " << cm->GetStatus() << endl;
delete cm;
return 1;
}
unsigned short reg;
unsigned int val = 0;
unsigned int index = 0;
int i;
int status=-99;
if ( strcmp( argv[optind], "status") == 0)
{
cout << " Status" << endl;
show_status(cm);
delete cm;
return 0;
}
if ( argc > optind + 1 ) //we have 2+ parameters, say "level 16000"
{
if ( strcmp( argv[optind], "SetChannelDCOffset") == 0)
{
if ( argc > optind + 2 ) // "SetChannelDCOffset 10 16000"
{
index = get_uvalue( argv[optind+1]);
val = get_uvalue( argv[optind+2]);
//cout << " setting level " << index << " " << val << endl;
status = cm->SetChannelDCOffset(index, val);
}
else
{
val = get_uvalue( argv[optind+1]);
//cout << " setting all levels to " << val << endl;
status = cm->SetChannelDCOffset(val);
}
}
else if ( strcmp( argv[optind], "SetMaxNumEventsBLT") == 0)
{
val = get_uvalue( argv[optind+1]);
status = cm->SetMaxNumEventsBLT(val);
cout << __FILE__ << " " << __LINE__ << " value " << cm->ReadRegister(0xEF1C) << endl;
}
else if ( strcmp( argv[optind], "SetExtTriggerInputMode") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetExtTriggerInputMode(val);
}
else if ( strcmp( argv[optind], "SetTriggerPolarity") == 0)
{
if ( argc > optind + 2 )
{
index = get_uvalue( argv[optind+1]);
val = get_uvalue( argv[optind+2]);
status = cm->SetTriggerPolarity(index, val);
}
else
{
val = get_uvalue( argv[optind+1]);
// cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetTriggerPolarity(val);
}
}
else if ( strcmp( argv[optind], "SetFastTriggerDigitizing") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetFastTriggerDigitizing(val);
}
else if ( strcmp( argv[optind], "SetFastTriggerMode") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetFastTriggerMode(val);
}
else if ( strcmp( argv[optind], "SetOutputSignalMode") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetOutputSignalMode(val);
}
else if ( strcmp( argv[optind], "SetDRS4SamplingFrequency") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetDRS4SamplingFrequency(val);
}
else if ( strcmp( argv[optind], "SetRecordLength") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetRecordLength(val);
}
else if ( strcmp( argv[optind], "SetPostTriggerSize") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetPostTriggerSize(val);
}
else if ( strcmp( argv[optind], "SetIOLevel") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetIOLevel(val);
}
else if ( strcmp( argv[optind], "SetAcquisitionMode") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetAcquisitionMode(val);
}
else if ( strcmp( argv[optind], "SetGroupEnableMask") == 0)
{
val = get_uvalue( argv[optind+1]);
//cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
status = cm->SetGroupEnableMask(val);
}
// else if ( strcmp( argv[optind], "LoadDRS4CorrectionData") == 0)
// {
// val = get_uvalue( argv[optind+1]);
// //cout << __FILE__ << " " << __LINE__ << " setting to " << val << endl;
// status = cm->LoadDRS4CorrectionData(val);
// }
// else if ( strcmp( argv[optind], "SetDRS4Correction") == 0)
// {
// val = get_uvalue( argv[optind+1]);
// status = cm->EnableDRS4Correction(val);
// // cout << __FILE__ << " " << __LINE__ << " setting to " << val << " status " << status << endl;
// }
else if ( strcmp( argv[optind], "PrintCalibrationData") == 0)
{
val = get_uvalue( argv[optind+1]);
int chip = 0;
if ( argc > optind + 2 ) //we have a 3rd "chip" parameter
{
chip = get_uvalue( argv[optind+2]);
}
// cout << __FILE__ << " " << __LINE__ << " val " << val << " chip " << chip << endl;
status = cm->PrintCalibrationData(val, chip);
}
else if ( strcmp( argv[optind], "WriteRegister") == 0)
{
if ( argc > optind + 2 )
{
index = get_uvalue( argv[optind+1]);
val = get_uvalue( argv[optind+2]);
status = cm->WriteRegister(index, val);
}
else
{
status = -1;
}
}
else if ( strcmp( argv[optind], "ReadRegister") == 0)
{
index = get_uvalue( argv[optind+1]);
val = cm->ReadRegister(index);
cout << "Address 0x" << hex << index << ": 0x" << val << dec << endl;
status =0;
if ( val < 0) status = val;
}
}
else
{
if ( strcmp( argv[optind], "init") == 0)
{
//cout << " init " << val << endl;
status = cm->init();
}
else if ( strcmp( argv[optind], "identify") == 0)
{
cm->identify();
status = 0;
}
else if ( strcmp( argv[optind], "help") == 0)
{
delete cm;
exithelp(0);
}
}
if (status == -99)
{
cout << " function " << argv[optind] << " needs an argument " << endl;
return 1;
}
else if (status)
{
cout << "Failure, Status = " << status << " cm status = " << cm->GetStatus() << endl;
return 1;
}
return 0;
}
const char *getTriggerMnemomic(const int i)
{
switch (i)
{
case 0:
return "DISABLED";
break;
case 1:
return "EXTOUT_ONLY";
break;
case 2:
return "ACQ_ONLY";
break;
case 3:
return "ACQ_AND_EXTOUT";
break;
default:
return "unknown";
}
}
const char *getOutputSignalModeMnemonic(const int i)
{
switch ( i)
{
case 0:
return "TRIGGER";
break;
case 1:
return "FASTTRG_ALL";
break;
case 2:
return "FASTTRG_ACCEPTED";
break;
case 3:
return "BUSY";
break;
default:
return "unknown";
}
}
const char *GetDRS4SamplingFrequencyMnemonic(const int i)
{
switch ( i)
{
case 0:
return "DRS4_5GHz";
break;
case 1:
return "DRS4_2_5GHz";
break;
case 2:
return "DRS4_1GHz";
break;
default:
return "unknown";
}
}
int show_status( caen_manager *cm)
{
int i;
cout << "MaxNumEventsBLT: " << cm->GetMaxNumEventsBLT() << endl;
cout << "ExtTriggerInputMode: " << cm->GetExtTriggerInputMode() << " ("<< getTriggerMnemomic(cm->GetExtTriggerInputMode()) << ")" << endl;
cout << "FastTriggerDigitizing: " << cm->GetFastTriggerDigitizing();
if ( cm->GetFastTriggerDigitizing() ) cout << " (Enabled)";
else cout << " (Disabled)";
cout << endl;
cout << "FastTriggerMode: " << cm->GetFastTriggerMode();
if ( cm->GetFastTriggerMode() ) cout << " (Enabled)";
else cout << " (Disabled)";
cout << endl;
cout << "OutputSignalMode: " << cm->GetOutputSignalMode() << " (" << getOutputSignalModeMnemonic(cm->GetOutputSignalMode()) << ")" << endl;
cout << "Sampling Frequency: " << cm->GetDRS4SamplingFrequency() << " (" << GetDRS4SamplingFrequencyMnemonic(cm->GetDRS4SamplingFrequency()) << ")" << endl;
cout << "RecordLength: " << cm->GetRecordLength() << " samples" << endl;
cout << "PostTriggerSize: " << cm->GetPostTriggerSize() << endl;
cout << "IOLevel() " << cm->GetIOLevel();
if ( cm->GetIOLevel()) cout << " (TTL)" << endl;
else cout << " (NIM)" << endl;
cout << "AcquisitionMode " << cm->GetAcquisitionMode();
if ( cm->GetAcquisitionMode() ) cout << " (Interrrupt Controlled)" << endl;
else cout << " (software controlled)" << endl;
cout << "GroupEnableMask 0x" << hex << cm->GetGroupEnableMask() << dec << endl;
cout << "TriggerPolarity (F - falling edge / R - rising edge) :"<< endl;
cout << " ";
for ( i = 0; i < 32; i++)
{
if ( cm->GetTriggerPolarity(i)) cout << "F ";
else cout << "R ";
if ( (i+1)%8==0) cout << endl << " ";
}
cout << endl << "ChannelDCOffset:"<< endl;
cout << " ";
for ( i = 0; i < 32; i++)
{
cout << "0x" << hex << cm->GetChannelDCOffset(i) << dec << " ";
if ( (i+1)%8==0) cout << endl << " ";
}
cout << endl;
return 0;
}