/[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 2.0 by kusanagi, Tue Sep 21 20:51:02 2004 UTC revision 2.1 by kusanagi, Sun Oct 17 12:28:41 2004 UTC
# Line 1  Line 1 
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>  #include <stdio.h>
16  #include "ACcalib.h"  #include "AC.h"
17    
18  // Program to read AC calibration data  int i,err,found,j;
 // 0408 Petter Hofverberg, petter@particle.kth.se  
19    
20  int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer)  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 16  int ACcalib(int length, unsigned short* Line 29  int ACcalib(int length, unsigned short*
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 43  int ACcalib(int length, unsigned short* Line 59  int ACcalib(int length, unsigned short*
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];
# Line 66  int ACcalib(int length, unsigned short* Line 83  int ACcalib(int length, unsigned short*
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("DAC1: %hx\n",calibdata.DAC1[0]);        printf("status.....   %hx\n",calibdata.status[0]);
91    printf("DAC2: %hx\n",calibdata.DAC2[0]);        printf("temp.......   %hx\n",calibdata.temp[0]);
92    printf("regist: %hx\n",calibdata.regist[0]);        printf("DAC1.......   %hx\n",calibdata.DAC1[0]);
93    printf("time: %hx\n",calibdata.time[0]);        printf("DAC2.......   %hx\n",calibdata.DAC2[0]);
94    printf("n_tr: %hx\n",calibdata.n_tr);        printf("regist.....   %hx\n",calibdata.regist[0]);
95    printf("hitmap_tr: %hx\n",calibdata.hitmap_tr[0]);        printf("time.......   %hx\n",calibdata.time[0]);
96    printf("curve1: %hx\n",calibdata.curve1[0]);        printf("n_tr.......   %hx\n",calibdata.n_tr);
97    printf("curve2: %hx\n",calibdata.curve2[0]);        printf("hitmap_tr..   %hx\n",calibdata.hitmap_tr[0]);
98    printf("iCRC: %hx\n",calibdata.iCRC);        printf("curve1.....   %hx\n",calibdata.curve1[0]);
99    printf("tail: %hx\n",calibdata.tail);        printf("curve2.....   %hx\n",calibdata.curve2[0]);
100    printf("CRC: %hx\n",calibdata.CRC);        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  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23