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

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

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

revision 1.2 by kusanagi, Sat Jul 17 20:03:42 2004 UTC revision 2.1 by kusanagi, Sun Oct 17 12:28:41 2004 UTC
# Line 1  Line 1 
1  #include <stdio.h>  /*****************************************************************
2  #include "ACcalib.h"  Program to read AC calibration data v1.1
3    author: Petter Hofverberg, petter@particle.kth.se
4    
5  int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer){  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  struct datastruct calibdata;  #include <stdio.h>
16    #include "AC.h"
 //pointer to struct  
 struct datastruct *calibpointer;  
17    
18  int fd,i,j,err,found;  int i,err,found,j;
 unsigned short buffer[10000];  
 unsigned short tmp1,tmp2;  
19    
20    int ACcalib(int length, unsigned short* datapointer, struct calibstruct* calibpointer)
21    {
22    int iter=2;    int iter=2;
23                
24    //point struc-pointer to calibdata    //point struct-pointer to calibdata
25    *calibpointer=calibdata;      *calibpointer=calibdata;  
26    
27    //look for header 0xACCA    //look for header 0xACCA
# Line 24  unsigned short tmp1,tmp2; Line 29  unsigned short tmp1,tmp2;
29      {      {
30        tmp1=*datapointer;        tmp1=*datapointer;
31        tmp2=*(datapointer+1);        tmp2=*(datapointer+1);
32          
33        if(tmp1==0xCAAC)        if(tmp1==0xCAAC)
34          {          {
35            found=1;            found=1;
36            for(i=0;i<8256;i++)            for(i=0;i<8256;i++)
37              {              {
38                buffer[i]=*datapointer;                buffer[i]=flip(*datapointer);
39                datapointer++;                datapointer++;
40              }              }
41            tmp1=0x0000;            tmp1=0x0000;
42          }          }
43        else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA)        else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0xCAAC)
44            //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xACCA)
45          {          {
46            found=1;            found=1;
47            for(i=0;i<8256;i++)            for(i=0;i<8256;i++)
48              {              {
49                buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00);                buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8));
50                  //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00);
51                datapointer++;                datapointer++;
52                tmp1=tmp2;                tmp1=tmp2;
53                tmp2=*(datapointer+1);                tmp2=*(datapointer+1);
# Line 48  unsigned short tmp1,tmp2; Line 56  unsigned short tmp1,tmp2;
56        else{        else{
57        datapointer++;        datapointer++;
58        iter=iter+2;}        iter=iter+2;}
   
59      }      }
60    
61    //check errors    //check errors
62    if(iter>=length)    if(found==0)
63      err=2;      err=2;
64    else if(buffer[8254]==0x22AC)    else if(buffer[8254]==0xAC22)
65      err=0;      err=0;
66    else    else
67      err=1;      err=1;
68      printf("length: %d\n iter: %d\n",length,iter);
69    
70    //Fill calibdata from buffer    //Fill calibdata from buffer
71    calibdata.header=buffer[0];    calibdata.header=buffer[0];
72    for(i=0;i<5;i++) calibdata.status[i]=buffer[1+i];    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];    for(i=0;i<8;i++) calibdata.temp[i]=buffer[6+i];
74    for(i=0;i<16;i++) calibdata.DAC[i]=buffer[14+i];    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];    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];    for(i=0;i<8;i++) calibdata.time[i]=buffer[36+i];
78    calibdata.n_tr=buffer[44];    calibdata.n_tr=buffer[44];
# Line 74  unsigned short tmp1,tmp2; Line 83  unsigned short tmp1,tmp2;
83    calibdata.tail=buffer[8254];    calibdata.tail=buffer[8254];
84    calibdata.CRC=buffer[8255];    calibdata.CRC=buffer[8255];
85        
   /*  
86    //debug    //debug
87    printf("header: %hx\n",calibdata.header);    if(err!=2)
88    printf("status: %hx\n",calibdata.status[0]);      {
89    printf("temp: %hx\n",calibdata.temp[0]);        printf("header.....   %hx\n",calibdata.header);
90    printf("DAC: %hx\n",calibdata.DAC[0]);        printf("status.....   %hx\n",calibdata.status[0]);
91    printf("regist: %hx\n",calibdata.regist[0]);        printf("temp.......   %hx\n",calibdata.temp[0]);
92    printf("time: %hx\n",calibdata.time[0]);        printf("DAC1.......   %hx\n",calibdata.DAC1[0]);
93    printf("n_tr: %hx\n",calibdata.n_tr);        printf("DAC2.......   %hx\n",calibdata.DAC2[0]);
94    printf("hitmap_tr: %hx\n",calibdata.hitmap_tr[0]);        printf("regist.....   %hx\n",calibdata.regist[0]);
95    printf("curve1: %hx\n",calibdata.curve1[0]);        printf("time.......   %hx\n",calibdata.time[0]);
96    printf("curve2: %hx\n",calibdata.curve2[0]);        printf("n_tr.......   %hx\n",calibdata.n_tr);
97    printf("iCRC: %hx\n",calibdata.iCRC);        printf("hitmap_tr..   %hx\n",calibdata.hitmap_tr[0]);
98    printf("tail: %hx\n",calibdata.tail);        printf("curve1.....   %hx\n",calibdata.curve1[0]);
99    printf("CRC: %hx\n",calibdata.CRC);        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);    printf("err: %d\n",err);
   */  
105    
106    return err;    return err;
107  }  }
108    

Legend:
Removed from v.1.2  
changed lines
  Added in v.2.1

  ViewVC Help
Powered by ViewVC 1.1.23