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

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

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

revision 1.1 by kusanagi, Thu Jul 8 12:48:23 2004 UTC revision 2.1 by kusanagi, Sun Oct 17 12:28:41 2004 UTC
# Line 1  Line 1 
1  //If big-little endian problem: switch tmp1&0xFF00 + tmp2&0x00FF ->  /*****************************************************************
2  // tmp1&0x00FF + tmp2&0xFF00  Function to read AC physics 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 (BBAC|11DD)
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    ToDo: i)  do it endian-independent
15          ii) check for more events in the same file?
16    ******************************************************************/
17    
18  #include <stdio.h>  #include <stdio.h>
19  #include "ACphysics.h"  #include "AC.h"
20    int i,err,found,j;
21    
22  int ACphysics(unsigned short* datapointer,struct datastruct* physicspointer)  int ACphysics(int length,unsigned short* datapointer,struct physicsstruct* physicspointer)
23  {  {
24      int iter=2;
25    
26    *physicspointer=physicsdata;    *physicspointer=physicsdata;
27    
28    //look for header AC11, then cut out the event to a temp buffer    //look for header AC11, then cut out the event to a temp buffer
29    while(found==0)    while(found==0 && iter<length)
30      {      {
31        tmp1=*datapointer;        tmp1=*datapointer;
32        tmp2=*(datapointer+1);        tmp2=*(datapointer+1);
33    
34        if(tmp1==0x11AC)        if(tmp1==0x11AC)
35          //if(tmp1==0xAC11) //flipped
36          {          {
37            found=1;            found=1;
38            for(i=0;i<64;i++)            for(i=0;i<64;i++)
39              {              {
40                buffer[i]=*datapointer;                buffer[i]=flip(*datapointer);
41                datapointer++;                datapointer++;
42              }              }
43            tmp1=0x0000;            tmp1=0x0000;
44          }          }
45        if((tmp1&0xFF00) + (tmp2&0x00FF)==0xAC11)        else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0x11AC)
46            //else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xAC11) //flipped
47          {          {
48            found=1;            found=1;
49            for(i=0;i<64;i++)            for(i=0;i<64;i++)
50              {              {
51                buffer[i]=(tmp1&0xFF00) + (tmp2&0x00FF);                buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ));
52                  //buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); //flipped
53                datapointer++;                datapointer++;
54                tmp1=tmp2;                tmp1=tmp2;
55                tmp2=*(datapointer+1);                tmp2=*(datapointer+1);
56              }              }
57          }          }
58        datapointer++;        else{
59            datapointer++;
60            iter=iter+2;}
61      }      }
62      
63    //check header2    //check errors
64    if(buffer[1]==0xAC22)    if(found==0)
65        err=2;
66      else if(buffer[1]==0x22AC || buffer[1]==0xAC22)
67      err=0;      err=0;
68    else    else
69      err=1;      err=1;
# Line 56  int ACphysics(unsigned short* datapointe Line 81  int ACphysics(unsigned short* datapointe
81    for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i];    for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i];
82    for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i];    for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i];
83    physicsdata.CRC=buffer[63];    physicsdata.CRC=buffer[63];
84    
85    return err;    return err;
86    
87  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23