-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckrecbe.cxx
157 lines (129 loc) · 3.7 KB
/
checkrecbe.cxx
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
//
//
//
#include <iostream>
#include <iomanip>
#include <fstream>
//#include <cstdio>
//#include <csignal>
//#include <unistd.h>
//#include <time.h>
#include <arpa/inet.h>
#include "recbe.h"
#define uint32_t unsigned int
void ntoh_header(struct recbe_header *host, struct recbe_header *raw)
{
host->type = raw->type;
host->id = raw->id;
host->sent_num = ntohs(raw->sent_num);
host->time = ntohs(raw->time);
host->len = ntohs(raw->len);
host->trig_count = ntohl(raw->trig_count);
return;
}
int decode_tdc(unsigned int *data)
{
return 0;
}
int reading()
{
int nread = 0;
#if 0
while (! std::cin.eof()) {
uint32_t data;
std::cin.read(reinterpret_cast<char *>(&data), sizeof(data));
nread += std::cin.gcount();
int carry = 0;
int ch;
int tval;
std::cout << std::hex << std::setw(8) << data << " : ";
if ((data & 0xffffffff) == 0x12345678) {
std::cout << "Header" << std::endl;
} else
if ((data & 0xff0000ff) == 0xff0000aa) {
std::cout << "Gate Start" << std::endl;
} else
if ((data & 0xff0000ff) == 0xff000055) {
std::cout << "Gate End" << std::endl;
} else
if ((data & 0xff000000) == 0xff000000) {
carry = data & 0xff;
std::cout << "Carry : " << std::dec << carry << std::endl;
} else
if ((data & 0xc0000000) == 0xc0000000) {
ch = (data >> 24) & 0x1f;
tval = data & 0x00ffffff;
std::cout << "Ch: " << std::dec << std::setw(2) << ch
<< " Data : " << std::setw(8) << tval
<< " (0x" << std::hex << std::setw(6) << tval << ")"
<< std::dec << std::endl;
} else {
std::cout << "# BAD data : "
<< std::hex << data
<< std::dec << std::endl;
}
}
#endif
#if 0
uint32_t data;
std::cin.read(reinterpret_cast<char *>(&data), sizeof(uint32_t));
std::cout << "HEAD: " << std::hex << data << std::endl;
uint32_t prev_data = 0x00000000;
while (! std::cin.eof()) {
char *cdata = reinterpret_cast<char *>(&data);
std::cin.read(reinterpret_cast<char *>(&data), sizeof(uint32_t));
if (std::cin.eof()) break;
//if (std::cin.gcount() == 0) break;
nread += std::cin.gcount();
if (data == 0xffff5555) {
std::cout << "Gate end, Nread: " << std::dec << nread
<< ", GE: " << std::hex << data << std::endl;
time_t rectime;
std::cin.read(reinterpret_cast<char *>(&rectime), sizeof(time_t));
std::cout << ctime(&rectime);
} else if (
((cdata[1] - cdata[0]) != 1)
&& ((cdata[2] - cdata[1]) != 1)
&& ((cdata[3] - cdata[2]) != 1)) {
std::cout << "#E " << std::hex << data << std::endl;
if (prev_data != 0x00000000) {
int p = (prev_data >> 24) & 0xff;
int n = data & 0xff;
if ((n -p) != 1) {
std::cout << "#E " << std::hex
<< prev_data << " " << data
<< std::endl;
}
}
}
prev_data = data;
}
#endif
struct recbe_header header, header_raw;
unsigned short *body = new unsigned short [4000];
char *cheader = reinterpret_cast<char*>(&header_raw);
char *cbody = reinterpret_cast<char*>(body);
while (! std::cin.eof()) {
std::cin.read(cheader, sizeof(struct recbe_header));
nread += std::cin.gcount();
if (std::cin.eof()) break;
ntoh_header(&header, &header_raw);
nread += std::cin.gcount();
std::cin.read(cbody, header.len);
//std::vector<int> adc, tdc;
//decode_recbe(cbody, header.len, adc, tdc);
std::cout << "Type 0x:" << std::hex << std::setw(2) << static_cast<unsigned int>(header.type)
<< " id 0x:" << std::hex << std::setw(2) << static_cast<unsigned int>(header.id)
<< " Sent:" << std::dec << std::setw(6) << header.sent_num
<< " Time:" << std::setw(6) << header.time
<< " Len:" << std::setw(6) << header.len
<< " Trigger:" << std::setw(6) << header.trig_count
<< std::endl;
}
return 0;
}
int main(int argc, char* argv[])
{
reading();
return 0;
}