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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.2 by kusanagi, Fri Dec 3 22:08:07 2004 UTC revision 2.5 by kusanagi, Tue Dec 21 16:51:17 2004 UTC
# Line 1  Line 1 
1  /*******************************v1.0********************************  /*******************************v1.1********************************
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).
5  Author: Petter Hofverberg, petter@particle.kth.se  Author: Petter Hofverberg, petter@particle.kth.se
6    
7  0410 v1.0 alive  0410 v1.0 alive
8    0412 v1.1 fixed problem with found, and changed headers
9    
10  Errors: (returned to the main program as the variable "err")  Errors: (returned to the main program as the variable "err")
11  err=  err=
# Line 18  err= Line 19  err=
19  #include <stdio.h>  #include <stdio.h>
20  #include "AC.h"  #include "AC.h"
21    
22  int i,found,j;  int i,j,found;
23  unsigned short buffer[1000];  unsigned short buffer[1000];
24  unsigned short tmp1,tmp2;  unsigned short tmp1,tmp2;
25  unsigned char err;  unsigned char err;
# Line 29  struct physicsstruct *physicspointer; Line 30  struct physicsstruct *physicspointer;
30  struct calibstruct calibdata[2];  struct calibstruct calibdata[2];
31  struct calibstruct *calibpointer;  struct calibstruct *calibpointer;
32    
33    //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    void fillcalib(int k,unsigned short *buff)
53    {
54      for(i=0;i<2;i++) calibdata[k].header[i]=buff[i];
55      for(i=0;i<5;i++) calibdata[k].status[i]=buff[2+i];
56      for(i=0;i<8;i++) calibdata[k].temp[i]=buff[7+i];
57      for(i=0;i<8;i++) calibdata[k].DAC1[i]=buff[15+i];
58      for(i=0;i<8;i++) calibdata[k].DAC2[i]=buff[23+i];
59      for(i=0;i<6;i++) calibdata[k].regist[i]=buff[31+i];
60      for(i=0;i<8;i++) calibdata[k].time[i]=buff[37+i];
61      calibdata[k].n_tr=buff[45];
62      for(i=0;i<16;i++) calibdata[k].hitmap_tr[i]=buff[46+i];
63      for(i=0;i<4096;i++) calibdata[k].curve1[i]=buff[62+i];
64      for(i=0;i<4096;i++) calibdata[k].curve2[i]=buff[4158+i];
65      calibdata[k].iCRC=buff[8254];
66      calibdata[k].tail=buff[8255];
67      calibdata[k].CRC=buff[8256];
68      printf("tail:CRC > %hx:%hx\n",buff[8255],buff[8256]);
69    }
70    
71  unsigned char ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer)  unsigned char ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer)
72  {  {
73    
74   int iter=2;    err=0;
75    physicspointer[0]=physicsdata[0];    found=0;
76    physicspointer[1]=physicsdata[1];    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      
83    
84    //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
85    //AC11 for main, AC22 for extra    //AC11 for main, AC22 for extra
# Line 45  unsigned char ACphysics(int length,unsig Line 88  unsigned char ACphysics(int length,unsig
88        tmp1 = ((*datapointer) << 8) | *(datapointer+1);        tmp1 = ((*datapointer) << 8) | *(datapointer+1);
89        tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);        tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
90    
91        if(tmp1 == 0xAC11 && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0)))        if(tmp1 == 0xACAC && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0)))
92          {          {
           
93            for(i=0;i<64;i++)            for(i=0;i<64;i++)
94              {              {
95                buffer[i]=((*datapointer) << 8) | *(datapointer+1);                buffer[i]=((*datapointer) << 8) | *(datapointer+1);
# Line 69  unsigned char ACphysics(int length,unsig Line 111  unsigned char ACphysics(int length,unsig
111          datapointer++;          datapointer++;
112          iter=iter+1;}          iter=iter+1;}
113      }      }
114      physicspointer[0]=physicsdata[0];
115      physicspointer[1]=physicsdata[1];
116    return err;    return err;
117    
118  }  }
# Line 78  unsigned char ACphysics(int length,unsig Line 121  unsigned char ACphysics(int length,unsig
121  unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer)  unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer)
122  {  {
123    
124      err=0;
125      found=0;
126    int iter=2;    int iter=2;
127                  for(i=0;i<1000;i++)
128        buffer[i]=0;
129      fillcalib(0,&buffer[0]);
130      fillcalib(1,&buffer[0]);
131    
132    //point struct-pointer to calibdata    //point struct-pointer to calibdata
133    calibpointer[0]=calibdata[0];  //card1    
   calibpointer[1]=calibdata[1];  //card2  
134    
135    //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
136    //to each card depending on these.    //to each card depending on these.
# Line 91  unsigned char ACcalib(int length, unsign Line 139  unsigned char ACcalib(int length, unsign
139        tmp1 = ((*datapointer) << 8) | *(datapointer+1);        tmp1 = ((*datapointer) << 8) | *(datapointer+1);
140        tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);        tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
141    
142        if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0)))        if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xACA2 && (err&0x0F)==0x0)))
143          {          {
144            for(i=0;i<8256;i++)            for(i=0;i<8258;i++)
145              {              {
146                buffer[i]=((*datapointer) << 8) | *(datapointer+1);                buffer[i]=((*datapointer) << 8) | *(datapointer+1);
147                datapointer=datapointer+2;                datapointer=datapointer+2;
# Line 114  unsigned char ACcalib(int length, unsign Line 162  unsigned char ACcalib(int length, unsign
162          datapointer++;          datapointer++;
163          iter=iter+1;}          iter=iter+1;}
164      }      }
165      calibpointer[0]=calibdata[0];  //card1
166      calibpointer[1]=calibdata[1];  //card2
167    return err;    return err;
168  }  }
169    
 //Fill physicsdata from buffer  
 void fillphys(int k,unsigned short *buff)  
 {  
   for(i=0;i<2;i++) physicsdata[k].header[i]=buff[i];  
   physicsdata[k].status=buff[2];  
   physicsdata[k].hitmap=buff[3];  
   for(i=0;i<6;i++) physicsdata[k].regist[i]=buff[4+i];  
   for(i=0;i<16;i++) physicsdata[k].shift[i]=buff[10+i];  
   for(i=0;i<16;i++) physicsdata[k].counters[i]=buff[26+i];  
   for(i=0;i<8;i++) physicsdata[k].coinc[i]=buff[42+i];  
   physicsdata[k].trigg=buff[50];  
   for(i=0;i<2;i++) physicsdata[k].clock[i]=buff[51+i];  
   for(i=0;i<2;i++) physicsdata[k].temp[i]=buff[53+i];  
   for(i=0;i<8;i++) physicsdata[k].DAC[i]=buff[55+i];  
   physicsdata[k].CRC=buff[63];  
   
 }  
   
 //Fill calibdata from buffer  
 void fillcalib(int k,unsigned short *buff)  
 {  
   calibdata[k].header=buff[0];  
   for(i=0;i<5;i++) calibdata[k].status[i]=buff[1+i];  
   for(i=0;i<8;i++) calibdata[k].temp[i]=buff[6+i];  
   for(i=0;i<8;i++) calibdata[k].DAC1[i]=buff[14+i];  
   for(i=0;i<8;i++) calibdata[k].DAC2[i]=buff[22+i];  
   for(i=0;i<6;i++) calibdata[k].regist[i]=buff[30+i];  
   for(i=0;i<8;i++) calibdata[k].time[i]=buff[36+i];  
   calibdata[k].n_tr=buff[44];  
   for(i=0;i<16;i++) calibdata[k].hitmap_tr[i]=buff[45+i];  
   for(i=0;i<4096;i++) calibdata[k].curve1[i]=buff[61+i];  
   for(i=0;i<4096;i++) calibdata[k].curve2[i]=buff[4157+i];  
   calibdata[k].iCRC=buff[8253];  
   calibdata[k].tail=buff[8254];  
   calibdata[k].CRC=buff[8255];  
 }  

Legend:
Removed from v.2.2  
changed lines
  Added in v.2.5

  ViewVC Help
Powered by ViewVC 1.1.23