2 |
#include "ACcalib.h" |
#include "ACcalib.h" |
3 |
|
|
4 |
|
|
5 |
int ACcalib(unsigned short* datapointer, struct datastruct* calibpointer) |
int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer){ |
6 |
{ |
|
7 |
|
struct datastruct calibdata; |
8 |
|
|
9 |
|
//pointer to struct |
10 |
|
struct datastruct *calibpointer; |
11 |
|
|
12 |
|
int fd,i,j,err,found; |
13 |
|
unsigned short buffer[10000]; |
14 |
|
unsigned short tmp1,tmp2; |
15 |
|
|
16 |
|
|
17 |
|
int iter=2; |
18 |
|
|
19 |
//point struc-pointer to calibdata |
//point struc-pointer to calibdata |
20 |
*calibpointer=calibdata; |
*calibpointer=calibdata; |
21 |
|
|
22 |
//look for header 0xACCA |
//look for header 0xACCA |
23 |
while(found==0) |
while(found==0 && iter<length) |
24 |
{ |
{ |
25 |
tmp1=*datapointer; |
tmp1=*datapointer; |
26 |
tmp2=*(datapointer+1); |
tmp2=*(datapointer+1); |
34 |
} |
} |
35 |
tmp1=0x0000; |
tmp1=0x0000; |
36 |
} |
} |
37 |
if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA) |
else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA) |
38 |
{ |
{ |
39 |
found=1; |
found=1; |
40 |
for(i=0;i<8256;i++) |
for(i=0;i<8256;i++) |
45 |
tmp2=*(datapointer+1); |
tmp2=*(datapointer+1); |
46 |
} |
} |
47 |
} |
} |
48 |
|
else{ |
49 |
datapointer++; |
datapointer++; |
50 |
|
iter=iter+2;} |
51 |
|
|
52 |
} |
} |
53 |
|
|
54 |
//check tail. CHANGE! |
//check errors |
55 |
if(buffer[8253]==0xAC22) |
if(iter>=length) |
56 |
|
err=2; |
57 |
|
else if(buffer[8254]==0x22AC) |
58 |
err=0; |
err=0; |
59 |
else |
else |
60 |
err=1; |
err=1; |
73 |
calibdata.iCRC=buffer[8253]; |
calibdata.iCRC=buffer[8253]; |
74 |
calibdata.tail=buffer[8254]; |
calibdata.tail=buffer[8254]; |
75 |
calibdata.CRC=buffer[8255]; |
calibdata.CRC=buffer[8255]; |
76 |
|
|
77 |
/* |
/* |
78 |
//debug |
//debug |
79 |
printf("header: %hx\n",calibdata.header); |
printf("header: %hx\n",calibdata.header); |
94 |
|
|
95 |
return err; |
return err; |
96 |
} |
} |
|
|
|