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

Contents of /rawreader/src/RunHeaderReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sun Jan 28 10:55:49 2007 UTC (17 years, 10 months ago) by cafagna
Branch: MAIN
CVS Tags: v1r15, HEAD
Changes since 1.2: +116 -109 lines
Main two features of this version are:
1)  the estimation of absolute time is stored  in DB and in timesync.dat
file
2) There is CLN2_flag which gives possibility:
 a) to avoid creation of cln2 files Cln2_flag=0,
 b) if Cln2_flag=1 cln2 file is created with all data in raw file
 c) if Cln2_flag=2 cln2 file is created with only new data in raw file

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 extern int print_flag;
9 extern long int Timesync;
10 extern long int OBTtimesync;
11 extern char timesync[120];
12
13 void RunHeaderReader(char *packet)
14 {
15
16 // long int time=0; /*PAMELA packet time*/
17
18 // long int temp=0;
19
20 int j,k;
21 FILE *ftime_sync;
22
23 long int dataLength;
24 long int length;
25 // short version of unpacling!!!! only time
26 /* long int RM_ACQ_SETTING_MODE,
27 FAVOURITE_WORKING_SCHEDULE,
28 EFFECTIVE_WORKING_SCHEDULE,
29 PRH_VAR_TRIGGER_MODE_A,
30 PRH_VAR_TRIGGER_MODE_B,
31 RM_ACQ_AFTER_CALIB ;*/
32 UINT32 OBT_TIME_SYNC,
33 LAST_TYME_SYNC_INFO;
34 /* time=(long int)(unsigned char)(packet[11])+
35 256*(long int)(unsigned char)(packet[10])+
36 256*256*(long int)(unsigned char)(packet[9])+
37 256*256*256*(long int)(unsigned char)(packet[8]);
38
39 temp=(long int)(unsigned char)(packet[7])+
40 256*(long int)(unsigned char)(packet[6])+
41 256*256*(long int)(unsigned char)(packet[5]);
42 */
43 /*unpacking several packets.... mikhailov
44 unpackingPamelaPacket(packet,type) */
45 length=(long int)(unsigned char)(packet[14])+
46 256*(long int)(unsigned char)(packet[13])+
47 256*256*(long int)(unsigned char)(packet[12]);
48 //if (print_flag>0)cout<<"length="<<length<<"\n";
49 char subData[length];
50 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
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 }

  ViewVC Help
Powered by ViewVC 1.1.23