--- yoda/techmodel/forroutines/anticounter/AC.c 2004/12/16 17:32:59 2.3 +++ yoda/techmodel/forroutines/anticounter/AC.c 2005/01/03 14:20:11 2.6 @@ -1,10 +1,11 @@ -/*******************************v1.0******************************** +/*******************************v1.1******************************** Functions to read AC physics data (ACphysics) and AC calibration data (ACcalib). Author: Petter Hofverberg, petter@particle.kth.se 0410 v1.0 alive +0412 v1.1 fixed problem with found, and changed headers Errors: (returned to the main program as the variable "err") err= @@ -18,7 +19,7 @@ #include #include "AC.h" -int i,found,j; +int i,j,found; unsigned short buffer[1000]; unsigned short tmp1,tmp2; unsigned char err; @@ -26,7 +27,7 @@ struct physicsstruct physicsdata[2]; struct physicsstruct *physicspointer; -struct calibstruct calibdata[2]; +struct calibstruct calibdata; struct calibstruct *calibpointer; //Fill physicsdata from buffer @@ -48,32 +49,40 @@ } //Fill calibdata from buffer -void fillcalib(int k,unsigned short *buff) +void fillcalib(unsigned short *buff) { - for(i=0;i<2;i++) calibdata[k].header[i]=buff[i]; - for(i=0;i<5;i++) calibdata[k].status[i]=buff[2+i]; - for(i=0;i<8;i++) calibdata[k].temp[i]=buff[7+i]; - for(i=0;i<8;i++) calibdata[k].DAC1[i]=buff[15+i]; - for(i=0;i<8;i++) calibdata[k].DAC2[i]=buff[23+i]; - for(i=0;i<6;i++) calibdata[k].regist[i]=buff[31+i]; - for(i=0;i<8;i++) calibdata[k].time[i]=buff[37+i]; - calibdata[k].n_tr=buff[45]; - for(i=0;i<16;i++) calibdata[k].hitmap_tr[i]=buff[46+i]; - for(i=0;i<4096;i++) calibdata[k].curve1[i]=buff[62+i]; - for(i=0;i<4096;i++) calibdata[k].curve2[i]=buff[4158+i]; - calibdata[k].iCRC=buff[8254]; - calibdata[k].tail=buff[8255]; - calibdata[k].CRC=buff[8256]; - printf("tail:CRC > %hx:%hx\n",buff[8255],buff[8256]); + for(i=0;i<2;i++) calibdata.header[i]=buff[i]; + for(i=0;i<5;i++) calibdata.status[i]=buff[2+i]; + for(i=0;i<8;i++) calibdata.temp[i]=buff[7+i]; + for(i=0;i<8;i++) calibdata.DAC1[i]=buff[15+i]; + for(i=0;i<8;i++) calibdata.DAC2[i]=buff[23+i]; + for(i=0;i<6;i++) calibdata.regist[i]=buff[31+i]; + for(i=0;i<8;i++) calibdata.time[i]=buff[37+i]; + calibdata.n_tr=buff[45]; + for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buff[46+i]; + for(i=0;i<4096;i++) calibdata.curve1[i]=buff[62+i]; + for(i=0;i<4096;i++) calibdata.curve2[i]=buff[4158+i]; + calibdata.iCRC=buff[8254]; + calibdata.tail=buff[8255]; + calibdata.CRC=buff[8256]; + //printf("tail:CRC > %hx:%hx\n",buff[8255],buff[8256]); } - unsigned char ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer) { - int iter=2; - physicspointer[0]=physicsdata[0]; - physicspointer[1]=physicsdata[1]; + err=0; + found=0; + int iter=2; + for(i=0;i<1000;i++) + buffer[i]=0; + fillphys(0,&buffer[0]); + fillphys(1,&buffer[0]); + + //point struct-pointer to physicsdata + //physicspointer[0]=physicsdata[0]; //card1 + //physicspointer[1]=physicsdata[1]; //card2 + //physicspointer=&physicsdata[0]; //look for top header ACAC, then unpack data to main card buffer or extra card buffer depending on the subheader //AC11 for main, AC22 for extra @@ -81,10 +90,8 @@ { tmp1 = ((*datapointer) << 8) | *(datapointer+1); tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3); - - if(tmp1 == 0xAC11 && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0))) + if(tmp1 == 0xACAC && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0))) { - for(i=0;i<64;i++) { buffer[i]=((*datapointer) << 8) | *(datapointer+1); @@ -106,6 +113,9 @@ datapointer++; iter=iter+1;} } + //point struct-pointer to physicsdata + physicspointer[0]=physicsdata[0]; //card1 + physicspointer[1]=physicsdata[1]; //card2 return err; @@ -115,20 +125,25 @@ unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer) { + err=0; + found=0; int iter=2; - + for(i=0;i<1000;i++) + buffer[i]=0; + fillcalib(&buffer[0]); + //point struct-pointer to calibdata - calibpointer[0]=calibdata[0]; //card1 - calibpointer[1]=calibdata[1]; //card2 + //calibpointer[0]=calibdata[0]; //card1 + //calibpointer[1]=calibdata[1]; //card2 //look for the top header 0xACCA, then the subheaders 0xAC11 and 0xAC22, and unpack the data //to each card depending on these. - while(found<2 && iter