/[PAMELA software]/yoda/techmodel/forroutines/anticounter/ACcalib.c
ViewVC logotype

Contents of /yoda/techmodel/forroutines/anticounter/ACcalib.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sat Jul 17 20:03:42 2004 UTC (20 years, 4 months ago) by kusanagi
Branch: MAIN
CVS Tags: Rev040729
Changes since 1.1: +22 -8 lines
File MIME type: text/plain
*** empty log message ***

1 #include <stdio.h>
2 #include "ACcalib.h"
3
4
5 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
20 *calibpointer=calibdata;
21
22 //look for header 0xACCA
23 while(found==0 && iter<length)
24 {
25 tmp1=*datapointer;
26 tmp2=*(datapointer+1);
27 if(tmp1==0xCAAC)
28 {
29 found=1;
30 for(i=0;i<8256;i++)
31 {
32 buffer[i]=*datapointer;
33 datapointer++;
34 }
35 tmp1=0x0000;
36 }
37 else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA)
38 {
39 found=1;
40 for(i=0;i<8256;i++)
41 {
42 buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00);
43 datapointer++;
44 tmp1=tmp2;
45 tmp2=*(datapointer+1);
46 }
47 }
48 else{
49 datapointer++;
50 iter=iter+2;}
51
52 }
53
54 //check errors
55 if(iter>=length)
56 err=2;
57 else if(buffer[8254]==0x22AC)
58 err=0;
59 else
60 err=1;
61
62 //Fill calibdata from buffer
63 calibdata.header=buffer[0];
64 for(i=0;i<5;i++) calibdata.status[i]=buffer[1+i];
65 for(i=0;i<8;i++) calibdata.temp[i]=buffer[6+i];
66 for(i=0;i<16;i++) calibdata.DAC[i]=buffer[14+i];
67 for(i=0;i<6;i++) calibdata.regist[i]=buffer[30+i];
68 for(i=0;i<8;i++) calibdata.time[i]=buffer[36+i];
69 calibdata.n_tr=buffer[44];
70 for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buffer[45+i];
71 for(i=0;i<4096;i++) calibdata.curve1[i]=buffer[61+i];
72 for(i=0;i<4096;i++) calibdata.curve2[i]=buffer[4157+i];
73 calibdata.iCRC=buffer[8253];
74 calibdata.tail=buffer[8254];
75 calibdata.CRC=buffer[8255];
76
77 /*
78 //debug
79 printf("header: %hx\n",calibdata.header);
80 printf("status: %hx\n",calibdata.status[0]);
81 printf("temp: %hx\n",calibdata.temp[0]);
82 printf("DAC: %hx\n",calibdata.DAC[0]);
83 printf("regist: %hx\n",calibdata.regist[0]);
84 printf("time: %hx\n",calibdata.time[0]);
85 printf("n_tr: %hx\n",calibdata.n_tr);
86 printf("hitmap_tr: %hx\n",calibdata.hitmap_tr[0]);
87 printf("curve1: %hx\n",calibdata.curve1[0]);
88 printf("curve2: %hx\n",calibdata.curve2[0]);
89 printf("iCRC: %hx\n",calibdata.iCRC);
90 printf("tail: %hx\n",calibdata.tail);
91 printf("CRC: %hx\n",calibdata.CRC);
92 printf("err: %d\n",err);
93 */
94
95 return err;
96 }

  ViewVC Help
Powered by ViewVC 1.1.23