--- yoda/techmodel/forroutines/anticounter/ACphysics.c 2004/09/21 20:51:02 2.0 +++ yoda/techmodel/forroutines/anticounter/ACphysics.c 2004/10/17 12:28:41 2.1 @@ -1,47 +1,55 @@ -//If big-little endian problem: switch tmp1&0xFF00 + tmp2&0x00FF -> -// tmp1&0x00FF + tmp2&0xFF00 -#include -#include "ACphysics.h" - -int ACphysics(int length,unsigned short* datapointer,struct datastruct* physicspointer){ - -//physics structure -struct datastruct physicsdata; - -//pointer to struct -struct datastruct *physicspointer; +/***************************************************************** +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? +******************************************************************/ -//read variables -int i,err,found; -unsigned short buffer[100]; -unsigned short tmp1,tmp2; +#include +#include "AC.h" +int i,err,found,j; - int iter=2; +int ACphysics(int length,unsigned short* datapointer,struct physicsstruct* physicspointer) +{ + int iter=2; *physicspointer=physicsdata; - + //look for header AC11, then cut out the event to a temp buffer 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); @@ -53,9 +61,9 @@ } //check errors - if(iter>=length) + if(found==0) err=2; - else if(buffer[1]==0xAC22) + else if(buffer[1]==0x22AC || buffer[1]==0xAC22) err=0; else err=1;