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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.1 - (hide annotations) (download)
Sun Oct 17 12:28:41 2004 UTC (20 years, 1 month ago) by kusanagi
Branch: MAIN
CVS Tags: Rev041203
Changes since 2.0: +45 -27 lines
File MIME type: text/plain
*** empty log message ***

1 kusanagi 2.1 /*****************************************************************
2     Program to read AC calibration data v1.1
3     author: Petter Hofverberg, petter@particle.kth.se
4    
5     0408 v1.0 alive
6     0409 Added shifting operators to fix problem with odd data
7    
8     Errors: (returned to the main program as the variable "err")
9     err=
10     0 - Ok
11     1 - Data found, but corrupt
12     2 - Data dont found in buffer
13     ******************************************************************/
14    
15 kusanagi 1.1 #include <stdio.h>
16 kusanagi 2.1 #include "AC.h"
17 kusanagi 1.1
18 kusanagi 2.1 int i,err,found,j;
19 kusanagi 1.1
20 kusanagi 2.1 int ACcalib(int length, unsigned short* datapointer, struct calibstruct* calibpointer)
21 kusanagi 1.3 {
22 kusanagi 1.2 int iter=2;
23 kusanagi 2.1
24     //point struct-pointer to calibdata
25 kusanagi 1.1 *calibpointer=calibdata;
26    
27     //look for header 0xACCA
28 kusanagi 1.2 while(found==0 && iter<length)
29 kusanagi 1.1 {
30     tmp1=*datapointer;
31     tmp2=*(datapointer+1);
32 kusanagi 2.1
33 kusanagi 1.1 if(tmp1==0xCAAC)
34     {
35     found=1;
36     for(i=0;i<8256;i++)
37     {
38 kusanagi 2.1 buffer[i]=flip(*datapointer);
39 kusanagi 1.1 datapointer++;
40     }
41     tmp1=0x0000;
42     }
43 kusanagi 2.1 else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0xCAAC)
44     //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA)
45 kusanagi 1.1 {
46     found=1;
47     for(i=0;i<8256;i++)
48     {
49 kusanagi 2.1 buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8));
50     //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00);
51 kusanagi 1.1 datapointer++;
52     tmp1=tmp2;
53     tmp2=*(datapointer+1);
54     }
55     }
56 kusanagi 1.2 else{
57 kusanagi 1.1 datapointer++;
58 kusanagi 1.2 iter=iter+2;}
59 kusanagi 1.1 }
60    
61 kusanagi 1.2 //check errors
62 kusanagi 2.1 if(found==0)
63 kusanagi 1.2 err=2;
64 kusanagi 2.1 else if(buffer[8254]==0xAC22)
65 kusanagi 1.1 err=0;
66     else
67     err=1;
68 kusanagi 2.1 printf("length: %d\n iter: %d\n",length,iter);
69 kusanagi 1.1
70     //Fill calibdata from buffer
71     calibdata.header=buffer[0];
72     for(i=0;i<5;i++) calibdata.status[i]=buffer[1+i];
73     for(i=0;i<8;i++) calibdata.temp[i]=buffer[6+i];
74 kusanagi 1.3 for(i=0;i<8;i++) calibdata.DAC1[i]=buffer[14+i];
75     for(i=0;i<8;i++) calibdata.DAC2[i]=buffer[22+i];
76 kusanagi 1.1 for(i=0;i<6;i++) calibdata.regist[i]=buffer[30+i];
77     for(i=0;i<8;i++) calibdata.time[i]=buffer[36+i];
78     calibdata.n_tr=buffer[44];
79     for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buffer[45+i];
80     for(i=0;i<4096;i++) calibdata.curve1[i]=buffer[61+i];
81     for(i=0;i<4096;i++) calibdata.curve2[i]=buffer[4157+i];
82     calibdata.iCRC=buffer[8253];
83     calibdata.tail=buffer[8254];
84     calibdata.CRC=buffer[8255];
85 kusanagi 1.2
86 kusanagi 1.1 //debug
87 kusanagi 2.1 if(err!=2)
88     {
89     printf("header..... %hx\n",calibdata.header);
90     printf("status..... %hx\n",calibdata.status[0]);
91     printf("temp....... %hx\n",calibdata.temp[0]);
92     printf("DAC1....... %hx\n",calibdata.DAC1[0]);
93     printf("DAC2....... %hx\n",calibdata.DAC2[0]);
94     printf("regist..... %hx\n",calibdata.regist[0]);
95     printf("time....... %hx\n",calibdata.time[0]);
96     printf("n_tr....... %hx\n",calibdata.n_tr);
97     printf("hitmap_tr.. %hx\n",calibdata.hitmap_tr[0]);
98     printf("curve1..... %hx\n",calibdata.curve1[0]);
99     printf("curve2..... %hx\n",calibdata.curve2[0]);
100     printf("iCRC....... %hx\n",calibdata.iCRC);
101     printf("tail....... %hx\n",calibdata.tail);
102     printf("CRC........ %hx\n",calibdata.CRC);
103     }
104 kusanagi 1.1 printf("err: %d\n",err);
105    
106     return err;
107     }
108 kusanagi 1.3

  ViewVC Help
Powered by ViewVC 1.1.23