#include #include "ACcalib.h" int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer){ struct datastruct calibdata; //pointer to struct struct datastruct *calibpointer; int fd,i,j,err,found; unsigned short buffer[10000]; unsigned short tmp1,tmp2; int iter=2; //point struc-pointer to calibdata *calibpointer=calibdata; //look for header 0xACCA while(found==0 && iter=length) err=2; else if(buffer[8254]==0x22AC) err=0; else err=1; //Fill calibdata from buffer calibdata.header=buffer[0]; for(i=0;i<5;i++) calibdata.status[i]=buffer[1+i]; for(i=0;i<8;i++) calibdata.temp[i]=buffer[6+i]; for(i=0;i<16;i++) calibdata.DAC[i]=buffer[14+i]; for(i=0;i<6;i++) calibdata.regist[i]=buffer[30+i]; for(i=0;i<8;i++) calibdata.time[i]=buffer[36+i]; calibdata.n_tr=buffer[44]; for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buffer[45+i]; for(i=0;i<4096;i++) calibdata.curve1[i]=buffer[61+i]; for(i=0;i<4096;i++) calibdata.curve2[i]=buffer[4157+i]; calibdata.iCRC=buffer[8253]; calibdata.tail=buffer[8254]; calibdata.CRC=buffer[8255]; /* //debug printf("header: %hx\n",calibdata.header); printf("status: %hx\n",calibdata.status[0]); printf("temp: %hx\n",calibdata.temp[0]); printf("DAC: %hx\n",calibdata.DAC[0]); printf("regist: %hx\n",calibdata.regist[0]); printf("time: %hx\n",calibdata.time[0]); printf("n_tr: %hx\n",calibdata.n_tr); printf("hitmap_tr: %hx\n",calibdata.hitmap_tr[0]); printf("curve1: %hx\n",calibdata.curve1[0]); printf("curve2: %hx\n",calibdata.curve2[0]); printf("iCRC: %hx\n",calibdata.iCRC); printf("tail: %hx\n",calibdata.tail); printf("CRC: %hx\n",calibdata.CRC); printf("err: %d\n",err); */ return err; }