--- yoda/techmodel/forroutines/anticounter/ACcalib.c 2004/09/21 20:51:02 2.0 +++ yoda/techmodel/forroutines/anticounter/ACcalib.c 2004/10/17 12:28:41 2.1 @@ -1,14 +1,27 @@ +/***************************************************************** +Program to read AC calibration data v1.1 +author: Petter Hofverberg, petter@particle.kth.se + +0408 v1.0 alive +0409 Added shifting operators to fix problem with odd data + +Errors: (returned to the main program as the variable "err") +err= +0 - Ok +1 - Data found, but corrupt +2 - Data dont found in buffer +******************************************************************/ + #include -#include "ACcalib.h" +#include "AC.h" -// Program to read AC calibration data -// 0408 Petter Hofverberg, petter@particle.kth.se +int i,err,found,j; -int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer) +int ACcalib(int length, unsigned short* datapointer, struct calibstruct* calibpointer) { int iter=2; - - //point struc-pointer to calibdata + + //point struct-pointer to calibdata *calibpointer=calibdata; //look for header 0xACCA @@ -16,22 +29,25 @@ { tmp1=*datapointer; tmp2=*(datapointer+1); + if(tmp1==0xCAAC) { found=1; for(i=0;i<8256;i++) { - buffer[i]=*datapointer; + buffer[i]=flip(*datapointer); datapointer++; } tmp1=0x0000; } - else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA) + else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0xCAAC) + //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA) { found=1; for(i=0;i<8256;i++) { - buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); + buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8)); + //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); datapointer++; tmp1=tmp2; tmp2=*(datapointer+1); @@ -43,12 +59,13 @@ } //check errors - if(iter>=length) + if(found==0) err=2; - else if(buffer[8254]==0x22AC) + else if(buffer[8254]==0xAC22) err=0; else err=1; + printf("length: %d\n iter: %d\n",length,iter); //Fill calibdata from buffer calibdata.header=buffer[0]; @@ -66,24 +83,25 @@ 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("DAC1: %hx\n",calibdata.DAC1[0]); - printf("DAC2: %hx\n",calibdata.DAC2[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); + if(err!=2) + { + printf("header..... %hx\n",calibdata.header); + printf("status..... %hx\n",calibdata.status[0]); + printf("temp....... %hx\n",calibdata.temp[0]); + printf("DAC1....... %hx\n",calibdata.DAC1[0]); + printf("DAC2....... %hx\n",calibdata.DAC2[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; }