#include #include #define N_DATALENGTH 16384 // in units of words (ie 4096 => 16 Kbyte) #include /* getenv, exit */ #include #include #include #include void checkDATAbuffer(char*, int); void printbufferL(char*, int); void byteswop32(char*, int); void byteswop316(char*, int); FILE * InStream; char *FileName= (char*)"AIDA.dat"; unsigned int DataBuffer[N_DATALENGTH]; size_t count = N_DATALENGTH*4; int GoodItems = 0; int AllItems = 0; char MessageBuffer[132]; void Usage(char *progname) { fprintf(stderr,"Usage\n%s -f [file path name]\n",progname); fprintf(stderr,"\tfile path name is file name used to read data\n"); exit(1); } int main(int argc, char *argv[], char *envp[]) { int i; ssize_t bytes; char fname[32]; int blocks = 0; // command line arguments if (argc >1) { for(i=1;i "); for (i = 0; i < 32; i++) { printf("0x%08lx ", eventbuffer[i]); } printf("\n"); } len = l/4; /* len in units of int */ eventbuffer = (unsigned int *)p; if(trace) printf("Block received length %d\n", len ); while (len >= 2) { data = *eventbuffer++; len--; timestamp = *eventbuffer++; len--; Code = -1; Info = 0; if (data == 0xffffffff) break; /* end of buffer */ AllItems++; switch ((data >> 30 ) & 3) { case 3: /* ADC data word */ range = (data >> 28) & 1; module = (data >> 22) & 63; channel = (data >> 16) & 63; adc = (unsigned short) (data & 0x0000ffff); timeL = timestamp; timeH = SYNC100 >> 28; if (timeL >= 0 && timeL <= 0xa0) { timestampf = ((unsigned long long) (timeH + 1) << 28) + (unsigned long long) timeL; } else { timestampf = ((unsigned long long) timeH << 28) + (unsigned long long) timeL; } if (trace_adc) printf("adc data: 0x%04x range=%d module=%d channel=%d: H=0x%08lx L=0x%08lx: TS=0x%012llx\n", adc, range, module, channel, data, timestamp, timestampf); Code = 16; Time = timestampf; break; case 2: /* information data word */ icode = (data >> 20) & 0x0f; /* information code */ ifield = data & 0x000fffff; /* information field */ module = (data >> 24) & 0x3f; switch (icode) { case 2: /* PAUSE timestamp */ timestampf = ((unsigned long long) ifield << 28) | (unsigned long long) timestamp; if (trace_pause ) printf("received PAUSE: m=%d, ifield=0x%05x: H=0x%08lx L=0x%08lx: TS=0x%012llx\n", module, ifield, data, timestamp, timestampf); Code = 2; Time = timestampf; LinkState = 1; break; case 3: /* RESUME timestamp */ timestampf = ((unsigned long long) ifield << 28) | (unsigned long long) timestamp; if (trace_resume) printf("received RESUME: m=%d, ifield=0x%05x: H=0x%08lx L=0x%08lx: TS=0x%012llx\n", module, ifield, data, timestamp, timestampf); Code = 3; Time = timestampf; if ((timestampf & 0xfffffffffffc0000ull) == (SYNC100 & 0xfffffffffffc0000ull)) { LinkState = 2; } else { LinkState = 1; } break; case 4: /* SYNC100 timestamp / WR timestamp L */ timestampf = ((unsigned long long) ifield << 28) | (unsigned long long) timestamp; WRTime0019 = timestamp; WRTime2847 = (ifield << 28); if (trace_sync) printf("received SYNC100 TS: m=%d, ifield=0x%05x: H=0x%08lx L=0x%08lx: TS=0x%012llx\n", module, ifield, data, timestamp, timestampf); Code = 4; Time = timestampf; if (LinkState != 2) { printf("received SYNC100 TS -> GOING: 0x%012llx\n",timestampf); LinkState = 2; } else { if (timestampf < SYNC100) { printf("received SYNC100 TS with timewarp: 0x%012llx 0x%012llx\n",timestampf,SYNC100); } if (((unsigned int)(timestampf - SYNC100)) != SYNC_STEP) { printf("received SYNC100 TS with unexpected value: 0x%012llx 0x%012llx 0x%08lx\n",timestampf,SYNC100,((unsigned int)(timestampf - SYNC100)) ); } } SYNC100 = timestampf; break; case 5: /* WR timestamp H */ timestampf = ((unsigned long long) ifield << 28) | (unsigned long long) timestamp; WRTime0019 = timestamp; WRTime4863 = (ifield << 28); WRTimeF = ((unsigned long long) WRTime4863 << 48) | ((unsigned long long) WRTime2847 << 28) | (unsigned long long) WRTime0019; if (trace_wr) printf("received WR High TS: m=%d, ifield=0x%05x: H=0x%08lx L=0x%08lx: WR=0x%012llx\n", module, ifield, data, timestamp, WRTimeF); Code = 5; Time = WRTimeF; break; case 6: /* FEE64 discriminator data */ timeL = timestamp; timeH = SYNC100 >> 28; if (timeL >= 0 && timeL <= 0xa0) { timestampf = ((unsigned long long) (timeH + 1) << 28) + (unsigned long long) timeL; } else { timestampf = ((unsigned long long) timeH << 28) + (unsigned long long) timeL; } if (trace_disc) printf("received AIDA Disc: m=%d, 0x%05x: H=0x%08lx L=0x%08lx: TS=0x%012llx\n", module, ifield, data, timestamp, timestampf); Code = 6; Time = timestampf; break; default: /* undefined code */ printf("received undefined information code: %d\n", icode); break; } break; case 1: /* wave form data */ timeL = timestamp; timeH = SYNC100 >> 28; if (timeL >= 0 && timeL <= 0xa0) { timestampf = ((unsigned long long) (timeH + 1) << 28) + (unsigned long long) timeL; } else { timestampf = ((unsigned long long) timeH << 28) + (unsigned long long) timeL; } module = (data >> 22) & 63; channel = (data >> 16) & 63; samples = (data >> 18) & 0x00003fff; /* in units of 4 samples (64 bits) */ while (samples > 0) {samples--; eventbuffer++; len--; eventbuffer++; len--;} if (trace_wave) printf("received waveform: module=%d channel=%d samples=%d H=0x%08lx L=0x%08lx: TS=0x%012llx\n", module, channel, samples*4, data, timestamp, timestampf); Code = 32; Time = timestampf; break; case 0: /* bad format */ default: printf("bad event data (%d %d) - (0x%08lx 0x%08lx)\n", l/4, len, data, timestamp); len = 0; break; } } /* end of while */ } void printbufferL(char* p, int l) { int len; int i, j; unsigned int * eventbuffer; len = l/4; /* len in units of int */ eventbuffer = (unsigned int *)p; printf("buffer len=%d bytes\n",l); printf(">\n"); for (j=0;j<16;j++) { for (i=0;i<8;i++) {printf("0x%08lx ", *eventbuffer++);} printf("\n"); } } void byteswop32(char* p, int l) { int len; char *ps; char *pd; char b0, b1, b2, b3; len = l/4; ps = p; pd = p; while (len > 0) { b0 = *ps++; b1 = *ps++; b2 = *ps++; b3 = *ps++; *pd++ = b3; *pd++ = b2; *pd++ = b1; *pd++ = b0; len--; } } void byteswop16(char* p, int l) { int len; char *ps; char *pd; char b0, b1; len = l/2; ps = p; pd = p; while (len > 0) { b0 = *ps++; b1 = *ps++; *pd++ = b1; *pd++ = b0; len--; } }