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

Annotation of /rawreader/src/RunHeaderReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Dec 10 13:05:58 2006 UTC (18 years ago) by cafagna
Branch: MAIN
CVS Tags: v1r14
Changes since 1.1: +11 -10 lines
5th of December version

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

  ViewVC Help
Powered by ViewVC 1.1.23