//If big-little endian problem: switch tmp1&0xFF00 + tmp2&0x00FF -> // tmp1&0x00FF + tmp2&0xFF00 #include #include "ACphysics.h" int ACphysics(unsigned short* datapointer,struct datastruct* physicspointer) { *physicspointer=physicsdata; //look for header AC11, then cut out the event to a temp buffer while(found==0) { tmp1=*datapointer; tmp2=*(datapointer+1); if(tmp1==0x11AC) { found=1; for(i=0;i<64;i++) { buffer[i]=*datapointer; datapointer++; } tmp1=0x0000; } if((tmp1&0xFF00) + (tmp2&0x00FF)==0xAC11) { found=1; for(i=0;i<64;i++) { buffer[i]=(tmp1&0xFF00) + (tmp2&0x00FF); datapointer++; tmp1=tmp2; tmp2=*(datapointer+1); } } datapointer++; } //check header2 if(buffer[1]==0xAC22) err=0; else err=1; //Fill physicsdata from buffer for(i=0;i<2;i++) physicsdata.header[i]=buffer[i]; physicsdata.status=buffer[2]; physicsdata.hitmap=buffer[3]; for(i=0;i<6;i++) physicsdata.regist[i]=buffer[4+i]; for(i=0;i<16;i++) physicsdata.shift[i]=buffer[10+i]; for(i=0;i<16;i++) physicsdata.counters[i]=buffer[26+i]; for(i=0;i<8;i++) physicsdata.coinc[i]=buffer[42+i]; physicsdata.trigg=buffer[50]; for(i=0;i<2;i++) physicsdata.clock[i]=buffer[51+i]; 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; }