1 |
/*******************************v1.3******************************** |
/*******************************v1.2******************************** |
2 |
|
|
3 |
Functions to read AC physics data (ACphysics) and AC calibration |
Functions to read AC physics data (ACphysics) and AC calibration |
4 |
data (ACcalib). |
data (ACcalib). |
7 |
0410 v1.0 alive |
0410 v1.0 alive |
8 |
0412 v1.1 fixed problem with found, and changed headers |
0412 v1.1 fixed problem with found, and changed headers |
9 |
0502 v1.2 added a crc check |
0502 v1.2 added a crc check |
|
0502 v1.3 increased buffer size |
|
10 |
|
|
11 |
Errors: (returned to the main program as the variable "err") |
Errors: (returned to the main program as the variable "err") |
12 |
err= |
err= |
24 |
#define FALSE 0 |
#define FALSE 0 |
25 |
|
|
26 |
int i,j,found; |
int i,j,found; |
27 |
unsigned short buffer[8300]; |
unsigned short buffer[1000]; |
28 |
unsigned short tmp1,tmp2,check; |
unsigned short tmp1,tmp2,check; |
29 |
unsigned char err; |
unsigned char err; |
30 |
|
|
177 |
found=0; |
found=0; |
178 |
check=0; |
check=0; |
179 |
int iter=2; |
int iter=2; |
180 |
for(i=0;i<8300;i++) |
for(i=0;i<1000;i++) |
181 |
buffer[i]=0; |
buffer[i]=0; |
182 |
fillphys(0,&buffer[0]); |
fillphys(0,&buffer[0]); |
183 |
fillphys(1,&buffer[0]); |
fillphys(1,&buffer[0]); |
184 |
|
|
185 |
|
//point struct-pointer to physicsdata |
186 |
|
//physicspointer[0]=physicsdata[0]; //card1 |
187 |
|
//physicspointer[1]=physicsdata[1]; //card2 |
188 |
|
//physicspointer=&physicsdata[0]; |
189 |
|
|
190 |
//look for top header ACAC, then unpack data to main card buffer or extra card buffer depending on the subheader |
//look for top header ACAC, then unpack data to main card buffer or extra card buffer depending on the subheader |
191 |
//AC11 for main, AC22 for extra |
//AC11 for main, AC22 for extra |
192 |
while(found<2 && iter<length) |
while(found<2 && iter<length) |
227 |
} |
} |
228 |
|
|
229 |
|
|
230 |
unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer) |
unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct *calibpointer) |
231 |
{ |
{ |
232 |
|
|
233 |
err=0; |
err=0; |
234 |
found=0; |
found=0; |
235 |
check=0; |
check=0; |
236 |
int iter=2; |
int iter=2; |
237 |
for(i=0;i<8300;i++) |
for(i=0;i<1000;i++) |
238 |
buffer[i]=0; |
buffer[i]=0; |
239 |
fillcalib(&buffer[0]); |
fillcalib(&buffer[0]); |
240 |
|
|
241 |
|
//point struct-pointer to calibdata |
242 |
|
//calibpointer[0]=calibdata[0]; //card1 |
243 |
|
//calibpointer[1]=calibdata[1]; //card2 |
244 |
|
|
245 |
//look for the top header 0xACCA, then the subheaders 0xAC11 and 0xAC22, and unpack the data |
//look for the top header 0xACCA, then the subheaders 0xAC11 and 0xAC22, and unpack the data |
246 |
//to each card depending on these. |
//to each card depending on these. |
247 |
while(found<1 && iter<length) |
while(found<1 && iter<length) |
251 |
|
|
252 |
if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xACA2 && (err&0x0F)==0x0))) |
if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xACA2 && (err&0x0F)==0x0))) |
253 |
{ |
{ |
254 |
for(i=0;i<8257;i++) |
for(i=0;i<8258;i++) |
255 |
{ |
{ |
256 |
buffer[i]=((*datapointer) << 8) | *(datapointer+1); |
buffer[i]=((*datapointer) << 8) | *(datapointer+1); |
257 |
if(i<8256) //8257 |
if(i<8257) |
258 |
check=crc(check,buffer[i]); |
check=crc(check,buffer[i]); |
259 |
datapointer=datapointer+2; |
datapointer=datapointer+2; |
260 |
} |
} |
274 |
datapointer++; |
datapointer++; |
275 |
iter=iter+1;} |
iter=iter+1;} |
276 |
} |
} |
277 |
memcpy(calibpointer,&calibdata,sizeof(calibdata)); |
memcpy(calibpointer, &calibdata, sizeof(calibdata)); |
278 |
|
|
279 |
return err; |
return err; |
280 |
} |
} |
281 |
|
|