-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyDecode.cpp
123 lines (94 loc) · 2.73 KB
/
myDecode.cpp
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
#include <cstdio>
#include <iostream>
#include "myDecode.h"
#include "myModules.h"
#include "myFIFO-IOp.h"
using namespace std;
#define ADDR_FADC (0x20000000)
#define ADDR_ADC5 (0x10000)
#define ADDR_ADC4 (0x20000)
#define ADDR_ADC3 (0x30000)
#define ADDR_ADC2 (0x40000)
#define ADDR_ADC1 (0x50000)
#define ADDR_ADC0 (0x60000)
#define ADDR_SCALER0 (0x200000)
#define ADDR_TDC0 (0x300000)
#define ADDR_TDC1 (0x7C000000)
int32_t verb;
static uint32_t _evsz_;
int32_t mySubEvent(uint32_t* buffer, int32_t frag){
SubEventHeader* head = (SubEventHeader*)buffer;
if(head->semk!=0xacabacab){
cout << "Cannot find the subevent marker. Something is wrong." << endl;
return 1;
}
if(verb){
cout << "\n---- SubEvent " << frag << " -----";
cout << "\nSubHeader size " << head->sevhsiz;
cout << "\nSubEvent size " << head->size;
cout << "\nModule ID 0x" << hex << head->id << dec << endl;
}
uint32_t result=0;
switch(head->id){
default:
cout << "Unknown module ID 0x" << hex
<< head->id << dec << endl;
result=1;
}
if(verb){
cout << "---- End of SubEvent " << frag << " ----" << endl;
}
return result;
}
int32_t myEvent(uint32_t* buffer, int32_t aVerb){
uint32_t i;
verb=aVerb;
EventHeader * head=(EventHeader *) buffer;
if(head->evmark!=0xCAFECAFE){
cout << "Cannot find the event marker. Something is wrong." << endl;
return 1;
}
if(verb){
cout << "\n##### Event " << head->evnum << " #####"
<< "\nHeader size " << head->evhsiz
<< "\nEvent size " << head->evsiz
<< "\nSpill " << head->spill
<< "\nTime " << head->tsec << " sec + "
<< head->tusec << " usec" << endl;
}
_evsz_ = *(buffer+2)/sizeof(uint32_t);
cout << hex << " " << *buffer << " evsz " << _evsz_
<< "\n##### FADC 7 " << *(buffer+_evsz_-105) << " #8 "
<< *(buffer+_evsz_-95) << dec << endl;
uint32_t evsizeword=head->evsiz/sizeof(uint32_t);
i=head->evhsiz/sizeof(uint32_t);
uint32_t frags=0;
while(i<evsizeword){
SubEventHeader* subhead;
uint32_t subsizeword;
uint32_t endpoint;
if(buffer[i]==0xACABACAB){
subhead=(SubEventHeader*)&buffer[i];
subsizeword=subhead->size/sizeof(uint32_t);
endpoint=i+subsizeword;
if(endpoint>evsizeword){
cout << "Subevent " << frags << " has a wrong size" << endl;
return 1;
}
if(mySubEvent(&buffer[i],frags)!=0){
cout << "Something is wrong in subevent " << frags
<< " stopping here" << endl;
return 1;
}
}else{
cout << "Cannot find the subevent marker. Something is wrong." << endl;
return 1;
}
frags++;
i=endpoint;
}
if(verb){
cout << "##### End of Event " << head->evnum << " #####" << endl;
}
return 0;
}