/[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 2.1 - (show annotations) (download)
Sun Oct 17 12:28:41 2004 UTC (20 years, 2 months ago) by kusanagi
Branch: MAIN
CVS Tags: Rev041203
Changes since 2.0: +45 -27 lines
File MIME type: text/plain
*** empty log message ***

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 #include <stdio.h>
16 #include "AC.h"
17
18 int i,err,found,j;
19
20 int ACcalib(int length, unsigned short* datapointer, struct calibstruct* calibpointer)
21 {
22 int iter=2;
23
24 //point struct-pointer to calibdata
25 *calibpointer=calibdata;
26
27 //look for header 0xACCA
28 while(found==0 && iter<length)
29 {
30 tmp1=*datapointer;
31 tmp2=*(datapointer+1);
32
33 if(tmp1==0xCAAC)
34 {
35 found=1;
36 for(i=0;i<8256;i++)
37 {
38 buffer[i]=flip(*datapointer);
39 datapointer++;
40 }
41 tmp1=0x0000;
42 }
43 else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0xCAAC)
44 //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA)
45 {
46 found=1;
47 for(i=0;i<8256;i++)
48 {
49 buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8));
50 //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00);
51 datapointer++;
52 tmp1=tmp2;
53 tmp2=*(datapointer+1);
54 }
55 }
56 else{
57 datapointer++;
58 iter=iter+2;}
59 }
60
61 //check errors
62 if(found==0)
63 err=2;
64 else if(buffer[8254]==0xAC22)
65 err=0;
66 else
67 err=1;
68 printf("length: %d\n iter: %d\n",length,iter);
69
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 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 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
86 //debug
87 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 printf("err: %d\n",err);
105
106 return err;
107 }
108

  ViewVC Help
Powered by ViewVC 1.1.23