7 #include <rtsSystems.h>
8 #include <daqFormats.h>
12 int fpd_reader(
char *m,
struct fpd_t *fpd, u_int driver)
30 fpd->max_channels = 1 ;
33 if(datap == NULL)
return 0 ;
35 len = ntohl(datap->det[FPD_ID].len) * 4 ;
36 if(len == 0)
return 0 ;
38 off = ntohl(datap->det[FPD_ID].off) ;
39 if(off == 0)
return 0 ;
42 fpdp = (
struct FPDP *)((u_int *)m + off) ;
44 if(checkBank(fpdp->bh.bank_type,
"FPDP") < 0) {
48 memset(&fpd,0,
sizeof(fpd)) ;
50 fpd->max_channels = 256 ;
54 banks = (l2h32(fpdp->bh.length) - 10)/2 ;
56 for(type=0;type<banks;type++) {
57 if(fpdp->type[type].len == 0) {
58 LOG(DBG,
"FPD bank %d not present (len==0)",type,0,0,0,0) ;
62 LOG(DBG,
"FPD bank %d found: len %d qw, off %d qw (%d %d)",type,
63 l2h32(fpdp->type[type].len),l2h32(fpdp->type[type].off),fpdp->type[type].len,fpdp->type[type].off) ;
69 adcd = (
struct FPDADCD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
71 if(checkBank(adcd->bh.bank_type,CHAR_FPDADCD) < 0) {
76 ch = (l2h32(adcd->bh.length) - 10)*2 ;
79 if(ch > (
int)(
sizeof(fpd->adc)/
sizeof(fpd->adc[0]))) {
80 LOG(ERR,
"Counter overflow in FPDADCD! ch == %d",ch,0,0,0,0) ;
85 fpd->adc[i] = l2h16(adcd->data[i]) ;
91 tdcd = (
struct FPDTDCD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
92 if(checkBank(tdcd->bh.bank_type,CHAR_FPDTDCD) < 0) {
98 fpd->tdc[i] = l2h16(tdcd->data[i]) ;
104 regd = (
struct FPDREGD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
105 if(checkBank(regd->bh.bank_type,CHAR_FPDREGD) < 0) {
111 fpd->reg[i] = l2h16(regd->data[i]) ;
117 pedr = (
struct FPDPEDR *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
118 if(checkBank(pedr->bh.bank_type,CHAR_FPDPEDR) < 0) {
124 fpd->ped[i] = l2h16(pedr->ped[i]) ;
127 fpd->rms[i] = l2h16(pedr->rms[i]) ;
132 scl = (
struct FPDSCL *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
133 if(checkBank(scl->bh.bank_type,CHAR_FPDSCL) < 0) {
139 bbcdat = (
struct BBCDAT *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
140 if(checkBank(bbcdat->bh.bank_type,CHAR_BBCDAT) < 0) {
146 fpd->bbc.pulse[i] = l2h16(bbcdat->pulse[i]) ;
149 fpd->bbc.time[i] = l2h16(bbcdat->time[i]) ;
152 fpd->bbc.proof[i] = l2h16(bbcdat->proof[i]) ;
155 fpd->bbc.spare[i] = l2h16(bbcdat->spare[i]) ;
161 bbcped = (
struct BBCPED *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
162 if(checkBank(bbcped->bh.bank_type,CHAR_BBCPED) < 0) {
167 fpd->bbc.ped[i] = l2h16(bbcped->ped[i]) ;
170 fpd->bbc.rms[i] = l2h16(bbcped->rms[i]) ;
173 fpd->bbc.peaks[i] = l2h16(bbcped->peaks[i]) ;
178 bbcscl = (
struct BBCSCL *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
179 if(checkBank(bbcscl->bh.bank_type,CHAR_BBCSCL) < 0) {
184 fpd->bbc.scl[i] = l2h16(bbcscl->scl[i]) ;
191 LOG(ERR,
"Unknown bank id %d in FPDP?",type,0,0,0,0) ;