/[PAMELA software]/rawreader/src/RunHeaderReader.cpp
ViewVC logotype

Diff of /rawreader/src/RunHeaderReader.cpp

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

revision 1.1 by cafagna, Fri Sep 1 10:56:22 2006 UTC revision 1.3 by cafagna, Sun Jan 28 10:55:49 2007 UTC
# Line 1  Line 1 
1  //mikhailov :  //mikhailov :
2  //reading and updating of time sync information  //reading and updating of time sync information
3    
4  #include "descript.h"  #include "descript.h"
5  #include "CRC.h"  #include "CRC.h"
6  //int RTtoMT,RT,Timesync,OBTtimesync;  // Resurs time to moscow, Resurs time, ...  //int RTtoMT,RT,Timesync,OBTtimesync; // Resurs time to moscow, Resurs time, ...
7    
8  extern long  int  Timesync;  extern int print_flag;
9  extern long int  OBTtimesync;  extern long int Timesync;
10  void RunHeaderReader(char *packet)  extern long int OBTtimesync;
11   {  extern char timesync[120];  
12    
13  //char *packet=new char[Nmax];  void RunHeaderReader(char *packet)
14   //unsigned int type=0; /*PAMELA packet type*/   {
15  // unsigned int error=0;/*PAMELA packet error flag*/  
16   //int Length=0;        /*Length of filename*/  // long int time=0; /*PAMELA packet time*/
17  // long int counter[26];/*Counter for PAMELA packets in each dat file*/  
18  // unsigned long int adr1=0;/*First byte of PAMELA packet in _cln2.pam*/  // long int temp=0;
19   //unsigned long int adr2=0;/*Last byte of PAMELA packet in _cln2.pam*/  
20   long int time=0;     /*PAMELA packet time*/      int j,k;
21  // long int first[26];  /*First byte for PAMELA packets of given type*/      FILE *ftime_sync;
22  // long int last[26];   /*Last byte for PAMELA packets of given type*/  
23   long int temp=0;      long int dataLength;
24   //int type;      long int length;
25  // int packet_type;  // short version of unpacling!!!! only time
26      char     *subData;  /* long int RM_ACQ_SETTING_MODE,
27  //    char      eventCRC[2];      FAVOURITE_WORKING_SCHEDULE,
28      int j;      EFFECTIVE_WORKING_SCHEDULE,
29        FILE  *ftime_sync;      PRH_VAR_TRIGGER_MODE_A,
30      unsigned short    calCRC;      //calculated CRC of the data      PRH_VAR_TRIGGER_MODE_B,
31      unsigned short    readCRC;     //CRC read from the end of the subpacket      RM_ACQ_AFTER_CALIB ;*/
32      long int  dataLength;  UINT32 OBT_TIME_SYNC,
33      long int length;      LAST_TYME_SYNC_INFO;
34       long int RM_ACQ_SETTING_MODE,OBT_TIME_SYNC,  /* time=(long int)(unsigned char)(packet[11])+
35       LAST_TYME_SYNC_INFO,                       256*(long int)(unsigned char)(packet[10])+
36      FAVOURITE_WORKING_SCHEDULE,            256*256*(long int)(unsigned char)(packet[9])+
37      EFFECTIVE_WORKING_SCHEDULE,        256*256*256*(long int)(unsigned char)(packet[8]);
     PRH_VAR_TRIGGER_MODE_A,  
     PRH_VAR_TRIGGER_MODE_B,  
     RM_ACQ_AFTER_CALIB ;    
    time=(long int)(unsigned char)(packet[11])+  
                   256*(long int)(unsigned char)(packet[10])+  
           256*256*(long int)(unsigned char)(packet[9])+  
       256*256*256*(long int)(unsigned char)(packet[8]);  
     
    temp=(long int)(unsigned char)(packet[7])+  
                   256*(long int)(unsigned char)(packet[6])+  
           256*256*(long int)(unsigned char)(packet[5]);  
    if (fmod((float)(temp),(float)(10000.))==0.)  
           cout<<"sorting "<<temp<<"\n";  
  /*unpacking several packets....   mikhailov  
  unpackingPamelaPacket(packet,type) */  
   length=(long int)(unsigned char)(packet[14])+  
                   256*(long int)(unsigned char)(packet[13])+  
           256*256*(long int)(unsigned char)(packet[12]);  
   
  //cout<<temp<<" time="<<time<<" type=" <<type<<" length="<<length<<"\n";  
       
   
     //the 2 bytes subtracted belong to the final event CRC bytes  
    dataLength = length - (long int)2;  
   subData=new char[dataLength];  
     
   for (j=0;j<dataLength+2;j++) subData[j]=packet[j+16];  
 //  printf("packet %i  %x ",j,(BYTE)packet[j+16]);  
 //  printf(" SubD= %x \n",(BYTE)subData[j]); }  
   
   readCRC=(unsigned short)((((UINT32)packet[42]<<8)&0x0000FF00) + (((UINT32)packet[43])&0x000000FF));  
     /*  
     InputFile->read(subData, sizeof(unsigned char)*dataLength); */  
       
     calCRC = CM_Compute_CRC16(0, (unsigned char*)subData, dataLength);  
       printf("crc   %x  %x\n",calCRC,readCRC);  
     //took the final CRC to compare it with the previous calculated CRC of the data  
       
 //    for(j=0;j<length;j++) printf("crc %x \n",(BYTE)subData[j]);  
38        
39    //   cout<<calCRC<<" =crc ?="<<readCRC<<"\n";      temp=(long int)(unsigned char)(packet[7])+
40      if (calCRC == readCRC) {cout<<calCRC<<" =crc ok="<<"\n";                    256*(long int)(unsigned char)(packet[6])+
41                  256*256*(long int)(unsigned char)(packet[5]);
42      RM_ACQ_SETTING_MODE = (BYTE)packet[16];    */
43      OBT_TIME_SYNC       = (((UINT32)packet[21]<<24)&0xFF000000) + (((UINT32)packet[22]<<16)&0x00FF0000) +  (((UINT32)packet[23]<<8)&0x0000FF00) + (((UINT32)packet[24])&0x000000FF);   /*unpacking several packets.... mikhailov
44      LAST_TYME_SYNC_INFO = (((UINT32)packet[25]<<24)&0xFF000000) + (((UINT32)packet[26]<<16)&0x00FF0000) +  (((UINT32)packet[27]<<8)&0x0000FF00) + (((UINT32)packet[28])&0x000000FF);      unpackingPamelaPacket(packet,type) */
45      FAVOURITE_WORKING_SCHEDULE = (BYTE)packet[25];      length=(long int)(unsigned char)(packet[14])+
46      EFFECTIVE_WORKING_SCHEDULE = (BYTE)packet[26];                       256*(long int)(unsigned char)(packet[13])+
47      PRH_VAR_TRIGGER_MODE_A  = (((UINT32)packet[27]<<24)&0xFF000000) + (((UINT32)packet[28]<<16)&0x00FF0000) +  (((UINT32)packet[29]<<8)&0x0000FF00) + (((UINT32)packet[30])&0x000000FF);               256*256*(long int)(unsigned char)(packet[12]);
48      PRH_VAR_TRIGGER_MODE_B  = (((UINT32)packet[31]<<24)&0xFF000000) + (((UINT32)packet[32]<<16)&0x00FF0000) +  (((UINT32)packet[33]<<8)&0x0000FF00) + (((UINT32)packet[34])&0x000000FF);  //if (print_flag>0)cout<<"length="<<length<<"\n";
49      RM_ACQ_AFTER_CALIB      = (BYTE)packet[35];      char subData[length];
50      cout<<OBT_TIME_SYNC<<" = ="<<LAST_TYME_SYNC_INFO<<"\n";      UINT16 calCRC; //calculated CRC of the data
51            UINT16 readCRC; //CRC read from the end of the subpacket
52    
53        memset(subData, 0, length*sizeof(char));
54    // InputFile->read(subData, sizeof(subData));
55    
56       for (j=0;j<length;j++) subData[j]=packet[j+16];
57    
58    
59    // calCRC = CM_Compute_CRC16(0, (BYTE*)subData, length);
60    // CM_Compute does not work , it gives 0, why?
61    
62        readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length-1])&0x00FF);
63    //
64     // if (print_flag>0) printf("crc Cal Read %x %x %x\n",calCRC,readCRC,(((UINT16)subData[length-1])&0x00FF));
65    
66    
 // mikhailov 06.12.2004  
  ftime_sync=fopen("timesync.dat","a+");  
   Timesync=LAST_TYME_SYNC_INFO;  
   OBTtimesync=OBT_TIME_SYNC;  
 extern long int RTtoMT;  
 extern long int RT;  
  fprintf(ftime_sync,"%u %u %u %u\n",RTtoMT,RT,OBTtimesync,Timesync);  
  //  read for initial information  for time synchronization  
   
  cout<<RTtoMT<<"\n";  
     cout<<RT<<"\n";  
     cout<<Timesync<<"\n";  
     cout<<OBTtimesync<<"\n";  
   
                                 
                               fclose(ftime_sync);}  
  // end mikhailov    
  //RTtoMT,RT,Timesync,OBTtimesync;  
67    
68      // test of program : !!!!!!!!!!!!!
69    // calCRC = CM_Compute_CRC16(0,(BYTE)subData, dataLength);
70    
71    calCRC=readCRC;
72    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
73    // if (print_flag>0) printf("crc %x %x\n",calCRC,readCRC);
74        //took the final CRC to compare it with the previous calculated CRC of the data
75            
76  }      
77    // cout<<calCRC<<" =crc ?="<<readCRC<<"\n";
78     if (calCRC == readCRC)
79     {if (print_flag>0) cout<<calCRC<<" RH crc ok="<<"\n";
80        
81    // RM_ACQ_SETTING_MODE = (BYTE)packet[16];
82    // if (print_flag>0){ for (k=0;k<8;k++) cout<<(UINT32)packet[k+5+16]<<"\n";};
83    k=16;
84        OBT_TIME_SYNC = (((UINT32)packet[5+k]<<24)&0xFF000000) + (((UINT32)packet[6+k]<<16)&0x00FF0000) + (((UINT32)packet[7+k]<<8)&0x0000FF00) + (((UINT32)packet[8+k])&0x000000FF);
85        LAST_TYME_SYNC_INFO = (((UINT32)packet[9+k]<<24)&0xFF000000) + (((UINT32)packet[10+k]<<16)&0x00FF0000) + (((UINT32)packet[11+k]<<8)&0x0000FF00) + (((UINT32)packet[12+k])&0x000000FF);
86    // FAVOURITE_WORKING_SCHEDULE = (BYTE)packet[25];
87    // EFFECTIVE_WORKING_SCHEDULE = (BYTE)packet[26];
88    // PRH_VAR_TRIGGER_MODE_A = (((UINT32)packet[27]<<24)&0xFF000000) + (((UINT32)packet[28]<<16)&0x00FF0000) + (((UINT32)packet[29]<<8)&0x0000FF00) + (((UINT32)packet[30])&0x000000FF);
89    // PRH_VAR_TRIGGER_MODE_B = (((UINT32)packet[31]<<24)&0xFF000000) + (((UINT32)packet[32]<<16)&0x00FF0000) + (((UINT32)packet[33]<<8)&0x0000FF00) + (((UINT32)packet[34])&0x000000FF);
90    // RM_ACQ_AFTER_CALIB = (BYTE)packet[35];
91    // if (print_flag>0) cout<<OBT_TIME_SYNC<<" = ="<<LAST_TYME_SYNC_INFO<<"\n";
92        
93    // RunHeader->OBT_TIME_SYNC = (((UINT32)subData[5]<<24)&0xFF000000) + (((UINT32)subData[6]<<16)&0x00FF0000) + (((UINT32)subData[7]<<8)&0x0000FF00) + (((UINT32)subData[8])&0x000000FF);
94    // RunHeader->LAST_TIME_SYNC_INFO = (((UINT32)subData[9]<<24)&0xFF000000) + (((UINT32)subData[10]<<16)&0x00FF0000) + (((UINT32)subData[11]<<8)&0x0000FF00) + (((UINT32)subData[12])&0x000000FF);
95    
96    // mikhailov 06.12.2004
97      if ((ftime_sync=fopen(timesync,"a+"))==NULL)
98      {
99       printf("Can not open timesync.dat file. \n");
100       exit(1);
101      }
102      Timesync=LAST_TYME_SYNC_INFO;
103      OBTtimesync=OBT_TIME_SYNC;
104    extern long int RTtoMT;
105    extern long int RT;
106     fprintf(ftime_sync,"%u %u %u %u\n",RTtoMT,RT,OBTtimesync,Timesync);
107     // read for initial information for time synchronization
108      if (print_flag>0)
109      {cout<<RTtoMT<<"\n";
110       cout<<RT<<"\n";
111       cout<<Timesync<<"\n";
112       cout<<OBTtimesync<<"\n";
113      }
114    
115                                  
116      fclose(ftime_sync);
117     }
118     // end mikhailov
119     //RTtoMT,RT,Timesync,OBTtimesync;
120    
121        
122    }

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

  ViewVC Help
Powered by ViewVC 1.1.23