--- yoda/techmodel/forroutines/anticounter/ACphysics.c 2004/07/08 12:48:23 1.1 +++ yoda/techmodel/forroutines/anticounter/ACphysics.c 2004/10/17 12:28:41 2.1 @@ -1,44 +1,69 @@ -//If big-little endian problem: switch tmp1&0xFF00 + tmp2&0x00FF -> -// tmp1&0x00FF + tmp2&0xFF00 +/***************************************************************** +Function to read AC physics data v1.1 +Author: Petter Hofverberg, petter@particle.kth.se + +0408 v1.0 alive +0409 Added shifting operators to fix problem with odd data (BBAC|11DD) + ----- +Errors: (returned to the main program as the variable "err") +err= +0 - Ok +1 - Data found, but corrupt +2 - Data dont found in buffer + +ToDo: i) do it endian-independent + ii) check for more events in the same file? +******************************************************************/ + #include -#include "ACphysics.h" +#include "AC.h" +int i,err,found,j; -int ACphysics(unsigned short* datapointer,struct datastruct* physicspointer) +int ACphysics(int length,unsigned short* datapointer,struct physicsstruct* physicspointer) { + int iter=2; - *physicspointer=physicsdata; + *physicspointer=physicsdata; //look for header AC11, then cut out the event to a temp buffer - while(found==0) + while(found==0 && iter> 8 ) + ((tmp2&0x00FF) << 8 ) == 0x11AC) + //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xAC11) //flipped { found=1; for(i=0;i<64;i++) { - buffer[i]=(tmp1&0xFF00) + (tmp2&0x00FF); + buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 )); + //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); //flipped datapointer++; tmp1=tmp2; tmp2=*(datapointer+1); } } - datapointer++; + else{ + datapointer++; + iter=iter+2;} } - - //check header2 - if(buffer[1]==0xAC22) + + //check errors + if(found==0) + err=2; + else if(buffer[1]==0x22AC || buffer[1]==0xAC22) err=0; else err=1; @@ -56,7 +81,7 @@ for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i]; for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i]; physicsdata.CRC=buffer[63]; - + return err; }