| 3 |
#include <stdio.h> |
#include <stdio.h> |
| 4 |
#include "ACphysics.h" |
#include "ACphysics.h" |
| 5 |
|
|
| 6 |
int ACphysics(unsigned short* datapointer,struct datastruct* physicspointer) |
int ACphysics(int length,unsigned short* datapointer,struct datastruct* physicspointer){ |
|
{ |
|
| 7 |
|
|
| 8 |
*physicspointer=physicsdata; |
//physics structure |
| 9 |
|
struct datastruct physicsdata; |
| 10 |
|
|
| 11 |
|
//pointer to struct |
| 12 |
|
struct datastruct *physicspointer; |
| 13 |
|
|
| 14 |
|
//read variables |
| 15 |
|
int i,err,found; |
| 16 |
|
unsigned short buffer[100]; |
| 17 |
|
unsigned short tmp1,tmp2; |
| 18 |
|
|
| 19 |
|
int iter=2; |
| 20 |
|
|
| 21 |
|
*physicspointer=physicsdata; |
| 22 |
|
|
| 23 |
//look for header AC11, then cut out the event to a temp buffer |
//look for header AC11, then cut out the event to a temp buffer |
| 24 |
while(found==0) |
while(found==0 && iter<length) |
| 25 |
{ |
{ |
| 26 |
tmp1=*datapointer; |
tmp1=*datapointer; |
| 27 |
tmp2=*(datapointer+1); |
tmp2=*(datapointer+1); |
| 28 |
|
//printf("check: %hx\n",tmp1); |
| 29 |
if(tmp1==0x11AC) |
if(tmp1==0x11AC) |
| 30 |
{ |
{ |
| 31 |
found=1; |
found=1; |
| 36 |
} |
} |
| 37 |
tmp1=0x0000; |
tmp1=0x0000; |
| 38 |
} |
} |
| 39 |
if((tmp1&0xFF00) + (tmp2&0x00FF)==0xAC11) |
else if((tmp1&0xFF00) + (tmp2&0x00FF)==0xAC11) |
| 40 |
{ |
{ |
| 41 |
found=1; |
found=1; |
| 42 |
for(i=0;i<64;i++) |
for(i=0;i<64;i++) |
| 47 |
tmp2=*(datapointer+1); |
tmp2=*(datapointer+1); |
| 48 |
} |
} |
| 49 |
} |
} |
| 50 |
datapointer++; |
else{ |
| 51 |
|
datapointer++; |
| 52 |
|
iter=iter+2;} |
| 53 |
} |
} |
| 54 |
|
|
| 55 |
//check header2 |
//check errors |
| 56 |
if(buffer[1]==0xAC22) |
if(iter>=length) |
| 57 |
|
err=2; |
| 58 |
|
else if(buffer[1]==0xAC22) |
| 59 |
err=0; |
err=0; |
| 60 |
else |
else |
| 61 |
err=1; |
err=1; |
| 73 |
for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i]; |
for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i]; |
| 74 |
for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i]; |
for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i]; |
| 75 |
physicsdata.CRC=buffer[63]; |
physicsdata.CRC=buffer[63]; |
| 76 |
|
|
| 77 |
return err; |
return err; |
| 78 |
|
|
| 79 |
} |
} |