15 #define MEMZERO(array) memset((array),0,sizeof(array))
17 static uint8_t
getUint8(
const void* ptr,
int offset)
19 return *(uint8_t*)(((
char*)ptr)+offset);
22 static uint16_t
getUint16(
const void* ptr,
int offset)
24 uint8_t *ptr8 = (uint8_t*)(((
char*)ptr)+offset);
25 return ((ptr8[0]<<8) | ptr8[1]);
28 static uint32_t
getUint32(
const void* ptr,
int offset)
30 uint8_t *ptr8 = (uint8_t*)(((
char*)ptr)+offset);
31 return (ptr8[0]<<24) | (ptr8[1]<<16) | (ptr8[2]<<8) | ptr8[3];
35 static unsigned short crc16(
const unsigned char* data_p,
unsigned char length){
37 unsigned short crc = 0xFFFF;
40 x = crc >> 8 ^ *data_p++;
42 crc = (crc << 8) ^ ((
unsigned short)(x << 12)) ^ ((
unsigned short)(x <<5)) ^ ((
unsigned short)x);
159 printf(
"ALPHA16 data packet:\n");
164 printf(
" mod id: 0x%02x\n",
moduleId);
169 printf(
" nsamples: %d\n",
nsamples);
170 printf(
" checksum: 0x%04x, computed checksum 0x%04x\n",
checksum,
xcrc16);
178 this->reserve(nsamples);
182 for (
int i=0; i<nsamples; i++) {
212 printf(
"ALPHA16 event: %d, time %.0f (incr %.0f), channels: %d, error %d, complete %d\n",
eventNo,
eventTime,
eventTime -
prevEventTime,
numChan,
error,
complete);
234 const int modmap[][20] = {
235 { 269, 1, 2, 3, 4, 5, 6, 7, 8, 0 },
236 { 264, 1, 2, 3, 4, -5, -6, -7, -8, 0 },
237 { 257, 1, 2, 3, 4, -18, -6, -7, -8, 9, 10, 11, 12, 17, 14, 15, 16, 0 },
238 { 245, 1, 2, 3, 4, -19, -6, -7, -8, 9, 10, 11, 12, 18, 14, 15, 16, 0 },
239 { 238, 1, 2, 9, 4, -10, -6, -14, -19, 0 },
240 { 227, 14, 19, 9, 4, -10, -6, -7, -8, 0 },
241 { 220, 1, 2, 9, 4, -10, -6, -7, -8, 0 },
242 { 218, 1, 2, 8, 4, -9, -10, -11, -12, 0 },
243 { 194, 1, 2, 13, 4, -9, -10, -11, -12, 0 },
244 { 186, 1, 2, 12, 4, -10, -15, -17, -18, 0 },
245 { 184, -9, -12, -4, -11, -10, -15, -17, -18, 0 },
246 { 183, -9, -12, -4, -11, -14, -10, -15, -18, 0 },
247 { 180, -9, -12, -4, -7, -8, -10, -15, -16, 0 },
248 { 177, 9, 12, 4, 7, 8, 10, 15, 16, 0 },
249 { 173, 9, 12, 4, 6, 8, 10, 15, 16, 0 },
250 { 171, 9, 12, 4, 19, 8, 10, 15, 16, 0 },
251 { 158, 1, 2, 4, 7, -8, -10, -15, -16, 0 },
252 { 154, -1, -2, -4, -7, -8, -10, -15, -16, 0 },
253 { 151, 1, 2, 4, 7, 8, 10, 15, 16, 0 },
254 { 147, 1, 2, 3, 4, 6, 7, 8, 16, 0 },
255 { 140, 4, 10, 13, 15, 1, 16, 17, 2, 0 },
261 for (
int i=0; modmap[i][0] != 0; i++) {
262 assert(modmap[i][0] > modmap[i+1][0]);
267 for (
int i=0; modmap[i][0] != 0; i++) {
268 if (runno >= modmap[i][0]) {
276 printf(
"Alpha16EVB::Configure: for run %d found map index %d for run %d\n", runno, imap, modmap[imap][0]);
279 for (
int j=1; modmap[imap][j] != 0; j++) {
287 void Alpha16EVB::Print()
const
289 printf(
"EVB contents:\n");
290 for (
unsigned i=0; i<fEvents.size(); i++) {
291 printf(
"Entry %d: ", i);
298 bool Alpha16EVB::Match(
const Alpha16Event* e,
int imodule, uint32_t udpTs)
305 static const int chanmap_top[] = { 7, 15, 6, 14, 5, 13, 4, 12, 3, 11, 2, 10, 1, 9, 0, 8 };
306 static const int chanmap_bot[] = { 8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7 };
338 for (
int i=0; i<16; i++)
345 for (
int i=0; i<16; i++)
381 unsigned num_samples = 0;
386 if (num_samples == 0)
387 num_samples = e->
waveform[i].size();
388 if (e->
waveform[i].size() != num_samples) {
426 if (ts != ets && ts != ets+1 && ts+1 != ets) {
427 printf(
"ts mismatch %d: 0x%08x vs 0x%08x diff %d\n", i, ts, ets, ts-ets);
439 Alpha16Event* Alpha16EVB::FindEvent(
int imodule, uint32_t udpTs)
443 for (
unsigned i=0; i<fEvents.size(); i++) {
444 if (Match(fEvents[i], imodule, udpTs)) {
464 fEvents.push_front(e);
473 if (fEvents.size() < 1)
478 if (e->
complete || fEvents.size() > 10) {
static uint8_t getUint8(const void *ptr, int offset)
static uint16_t getUint16(const void *ptr, int offset)
static unsigned short crc16(const unsigned char *data_p, unsigned char length)
static uint32_t getUint32(const void *ptr, int offset)
static const int chanmap_bot[]
static const int chanmap_top[]
void CheckEvent(Alpha16Event *e)
Alpha16Event * NewEvent()
void Configure(int runno)
uint32_t fFirstEventTs[MAX_ALPHA16 *NUM_CHAN_ALPHA16]
void AddBank(Alpha16Event *e, int imodule, const void *bkptr, int bklen)
std::vector< int > fConfModMap
uint32_t udpEventTs[MAX_ALPHA16 *NUM_CHAN_ALPHA16]
bool udpPresent[MAX_ALPHA16 *NUM_CHAN_ALPHA16]
Alpha16Packet udpPacket[MAX_ALPHA16 *NUM_CHAN_ALPHA16]
Alpha16Waveform waveform[MAX_ALPHA16 *NUM_CHAN_ALPHA16]
static int PacketVersion(const void *ptr, int bklen8)
static int PacketChannel(const void *ptr, int bklen8)
static uint32_t PacketTimestamp(const void *ptr, int bklen8)
void Unpack(const void *bkptr, int bklen8)
static int PacketType(const void *ptr, int bklen8)