1 |
#include <stdio.h> |
2 |
#include "ACcalib.h" |
3 |
|
4 |
|
5 |
int ACcalib(unsigned short* datapointer, struct datastruct* calibpointer) |
6 |
{ |
7 |
|
8 |
//point struc-pointer to calibdata |
9 |
*calibpointer=calibdata; |
10 |
|
11 |
//look for header 0xACCA |
12 |
while(found==0) |
13 |
{ |
14 |
tmp1=*datapointer; |
15 |
tmp2=*(datapointer+1); |
16 |
if(tmp1==0xCAAC) |
17 |
{ |
18 |
found=1; |
19 |
for(i=0;i<8256;i++) |
20 |
{ |
21 |
buffer[i]=*datapointer; |
22 |
datapointer++; |
23 |
} |
24 |
tmp1=0x0000; |
25 |
} |
26 |
if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA) |
27 |
{ |
28 |
found=1; |
29 |
for(i=0;i<8256;i++) |
30 |
{ |
31 |
buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); |
32 |
datapointer++; |
33 |
tmp1=tmp2; |
34 |
tmp2=*(datapointer+1); |
35 |
} |
36 |
} |
37 |
datapointer++; |
38 |
|
39 |
} |
40 |
|
41 |
//check tail. CHANGE! |
42 |
if(buffer[8253]==0xAC22) |
43 |
err=0; |
44 |
else |
45 |
err=1; |
46 |
|
47 |
//Fill calibdata from buffer |
48 |
calibdata.header=buffer[0]; |
49 |
for(i=0;i<5;i++) calibdata.status[i]=buffer[1+i]; |
50 |
for(i=0;i<8;i++) calibdata.temp[i]=buffer[6+i]; |
51 |
for(i=0;i<16;i++) calibdata.DAC[i]=buffer[14+i]; |
52 |
for(i=0;i<6;i++) calibdata.regist[i]=buffer[30+i]; |
53 |
for(i=0;i<8;i++) calibdata.time[i]=buffer[36+i]; |
54 |
calibdata.n_tr=buffer[44]; |
55 |
for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buffer[45+i]; |
56 |
for(i=0;i<4096;i++) calibdata.curve1[i]=buffer[61+i]; |
57 |
for(i=0;i<4096;i++) calibdata.curve2[i]=buffer[4157+i]; |
58 |
calibdata.iCRC=buffer[8253]; |
59 |
calibdata.tail=buffer[8254]; |
60 |
calibdata.CRC=buffer[8255]; |
61 |
|
62 |
/* |
63 |
//debug |
64 |
printf("header: %hx\n",calibdata.header); |
65 |
printf("status: %hx\n",calibdata.status[0]); |
66 |
printf("temp: %hx\n",calibdata.temp[0]); |
67 |
printf("DAC: %hx\n",calibdata.DAC[0]); |
68 |
printf("regist: %hx\n",calibdata.regist[0]); |
69 |
printf("time: %hx\n",calibdata.time[0]); |
70 |
printf("n_tr: %hx\n",calibdata.n_tr); |
71 |
printf("hitmap_tr: %hx\n",calibdata.hitmap_tr[0]); |
72 |
printf("curve1: %hx\n",calibdata.curve1[0]); |
73 |
printf("curve2: %hx\n",calibdata.curve2[0]); |
74 |
printf("iCRC: %hx\n",calibdata.iCRC); |
75 |
printf("tail: %hx\n",calibdata.tail); |
76 |
printf("CRC: %hx\n",calibdata.CRC); |
77 |
printf("err: %d\n",err); |
78 |
*/ |
79 |
|
80 |
return err; |
81 |
} |
82 |
|