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

Annotation of /yoda/techmodel/forroutines/anticounter/AC.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.7 - (hide annotations) (download)
Sat Jan 29 00:26:59 2005 UTC (19 years, 10 months ago) by kusanagi
Branch: MAIN
Changes since 2.6: +13 -0 lines
File MIME type: text/plain
*** empty log message ***

1 kusanagi 2.5 /*******************************v1.1********************************
2 kusanagi 2.2
3     Functions to read AC physics data (ACphysics) and AC calibration
4     data (ACcalib).
5 kusanagi 2.1 Author: Petter Hofverberg, petter@particle.kth.se
6    
7 kusanagi 2.2 0410 v1.0 alive
8 kusanagi 2.5 0412 v1.1 fixed problem with found, and changed headers
9 kusanagi 2.2
10 kusanagi 2.1 Errors: (returned to the main program as the variable "err")
11     err=
12 kusanagi 2.2 0xFF - data (physics or calibration) from both cards found
13     0xF0 - only data from main card found
14     0x0F - only data from extra card found
15     0x00 - no data found
16 kusanagi 2.1
17     ******************************************************************/
18    
19     #include <stdio.h>
20     #include "AC.h"
21    
22 kusanagi 2.5 int i,j,found;
23 kusanagi 2.1 unsigned short buffer[1000];
24 kusanagi 2.2 unsigned short tmp1,tmp2;
25     unsigned char err;
26 kusanagi 2.1
27 kusanagi 2.2 struct physicsstruct physicsdata[2];
28 kusanagi 2.1 struct physicsstruct *physicspointer;
29    
30 kusanagi 2.6 struct calibstruct calibdata;
31 kusanagi 2.1 struct calibstruct *calibpointer;
32    
33 kusanagi 2.3 //Fill physicsdata from buffer
34     void fillphys(int k,unsigned short *buff)
35     {
36     for(i=0;i<2;i++) physicsdata[k].header[i]=buff[i];
37     physicsdata[k].status=buff[2];
38     physicsdata[k].hitmap=buff[3];
39     for(i=0;i<6;i++) physicsdata[k].regist[i]=buff[4+i];
40     for(i=0;i<16;i++) physicsdata[k].shift[i]=buff[10+i];
41     for(i=0;i<16;i++) physicsdata[k].counters[i]=buff[26+i];
42     for(i=0;i<8;i++) physicsdata[k].coinc[i]=buff[42+i];
43     physicsdata[k].trigg=buff[50];
44     for(i=0;i<2;i++) physicsdata[k].clock[i]=buff[51+i];
45     for(i=0;i<2;i++) physicsdata[k].temp[i]=buff[53+i];
46     for(i=0;i<8;i++) physicsdata[k].DAC[i]=buff[55+i];
47     physicsdata[k].CRC=buff[63];
48    
49     }
50    
51     //Fill calibdata from buffer
52 kusanagi 2.6 void fillcalib(unsigned short *buff)
53 kusanagi 2.3 {
54 kusanagi 2.6 for(i=0;i<2;i++) calibdata.header[i]=buff[i];
55     for(i=0;i<5;i++) calibdata.status[i]=buff[2+i];
56     for(i=0;i<8;i++) calibdata.temp[i]=buff[7+i];
57     for(i=0;i<8;i++) calibdata.DAC1[i]=buff[15+i];
58     for(i=0;i<8;i++) calibdata.DAC2[i]=buff[23+i];
59     for(i=0;i<6;i++) calibdata.regist[i]=buff[31+i];
60     for(i=0;i<8;i++) calibdata.time[i]=buff[37+i];
61     calibdata.n_tr=buff[45];
62     for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buff[46+i];
63     for(i=0;i<4096;i++) calibdata.curve1[i]=buff[62+i];
64     for(i=0;i<4096;i++) calibdata.curve2[i]=buff[4158+i];
65     calibdata.iCRC=buff[8254];
66     calibdata.tail=buff[8255];
67     calibdata.CRC=buff[8256];
68     //printf("tail:CRC > %hx:%hx\n",buff[8255],buff[8256]);
69 kusanagi 2.3 }
70 kusanagi 2.1
71 kusanagi 2.2 unsigned char ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer)
72 kusanagi 2.1 {
73    
74 kusanagi 2.5 err=0;
75     found=0;
76     int iter=2;
77     for(i=0;i<1000;i++)
78     buffer[i]=0;
79     fillphys(0,&buffer[0]);
80     fillphys(1,&buffer[0]);
81    
82 kusanagi 2.6 //point struct-pointer to physicsdata
83     //physicspointer[0]=physicsdata[0]; //card1
84     //physicspointer[1]=physicsdata[1]; //card2
85     //physicspointer=&physicsdata[0];
86 kusanagi 2.1
87 kusanagi 2.2 //look for top header ACAC, then unpack data to main card buffer or extra card buffer depending on the subheader
88     //AC11 for main, AC22 for extra
89     while(found<2 && iter<length)
90 kusanagi 2.1 {
91     tmp1 = ((*datapointer) << 8) | *(datapointer+1);
92 kusanagi 2.2 tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
93 kusanagi 2.4 if(tmp1 == 0xACAC && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0)))
94 kusanagi 2.1 {
95     for(i=0;i<64;i++)
96     {
97     buffer[i]=((*datapointer) << 8) | *(datapointer+1);
98     datapointer=datapointer+2;
99     }
100 kusanagi 2.2
101     if(tmp2==0xAC11){ //main card
102     fillphys(0,&buffer[0]);
103     err |= 0xF0;
104     }
105     else{ //extra card
106     fillphys(1,&buffer[0]);
107     err |= 0x0F;
108     }
109     tmp1=tmp2=0x0000;
110     found++;
111 kusanagi 2.1 }
112     else{
113     datapointer++;
114     iter=iter+1;}
115     }
116 kusanagi 2.6 //point struct-pointer to physicsdata
117     physicspointer[0]=physicsdata[0]; //card1
118     physicspointer[1]=physicsdata[1]; //card2
119    
120 kusanagi 2.1 return err;
121    
122     }
123    
124    
125 kusanagi 2.2 unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer)
126 kusanagi 2.1 {
127    
128 kusanagi 2.5 err=0;
129     found=0;
130 kusanagi 2.1 int iter=2;
131 kusanagi 2.5 for(i=0;i<1000;i++)
132     buffer[i]=0;
133 kusanagi 2.6 fillcalib(&buffer[0]);
134 kusanagi 2.5
135 kusanagi 2.1 //point struct-pointer to calibdata
136 kusanagi 2.6 //calibpointer[0]=calibdata[0]; //card1
137     //calibpointer[1]=calibdata[1]; //card2
138 kusanagi 2.1
139 kusanagi 2.2 //look for the top header 0xACCA, then the subheaders 0xAC11 and 0xAC22, and unpack the data
140     //to each card depending on these.
141 kusanagi 2.6 while(found<1 && iter<length)
142 kusanagi 2.1 {
143     tmp1 = ((*datapointer) << 8) | *(datapointer+1);
144 kusanagi 2.2 tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
145    
146 kusanagi 2.5 if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xACA2 && (err&0x0F)==0x0)))
147 kusanagi 2.1 {
148 kusanagi 2.3 for(i=0;i<8258;i++)
149 kusanagi 2.1 {
150     buffer[i]=((*datapointer) << 8) | *(datapointer+1);
151     datapointer=datapointer+2;
152     }
153 kusanagi 2.2
154     if(tmp2==0xAC11){ //main
155 kusanagi 2.6 fillcalib(&buffer[0]);
156 kusanagi 2.2 err |= 0xF0;
157     }
158     else{ //extra
159 kusanagi 2.6 fillcalib(&buffer[0]);
160 kusanagi 2.2 err |= 0x0F;
161     }
162     tmp1=tmp2=0x0000;
163     found++;
164 kusanagi 2.1 }
165     else{
166 kusanagi 2.2 datapointer++;
167     iter=iter+1;}
168 kusanagi 2.1 }
169 kusanagi 2.7 for (i = 0; i < 8200; i++){
170     printf("%i %x \n", i, datapointer[i]);
171     }
172     for (i = 0; i < 8200; i++){
173     printf("%i %x \n", i, buffer[i]);
174     }
175     for (i = 0; i < 8200; i++){
176     printf("%i %x \n", i, *(&calibdata + i));
177     }
178     for (i = 0; i < 8200; i++){
179     printf("%i %x \n", i, *(&calibdata + i));
180     }
181     //memcpy(calibpointer, &calibdata, sizeof(calibdata));
182 kusanagi 2.6 *calibpointer=calibdata; //card1
183    
184 kusanagi 2.1 return err;
185     }

  ViewVC Help
Powered by ViewVC 1.1.23