1 |
pam-fi |
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 |
|
|
extern long int Timesync; |
9 |
|
|
extern long int OBTtimesync; |
10 |
|
|
void RunHeaderReader(char *packet) |
11 |
|
|
{ |
12 |
|
|
|
13 |
|
|
//char *packet=new char[Nmax]; |
14 |
|
|
//unsigned int type=0; /*PAMELA packet type*/ |
15 |
|
|
// unsigned int error=0;/*PAMELA packet error flag*/ |
16 |
|
|
//int Length=0; /*Length of filename*/ |
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*/ |
19 |
|
|
//unsigned long int adr2=0;/*Last byte of PAMELA packet in _cln2.pam*/ |
20 |
|
|
long int time=0; /*PAMELA packet time*/ |
21 |
|
|
// long int first[26]; /*First byte for PAMELA packets of given type*/ |
22 |
|
|
// long int last[26]; /*Last byte for PAMELA packets of given type*/ |
23 |
|
|
long int temp=0; |
24 |
|
|
//int type; |
25 |
|
|
// int packet_type; |
26 |
|
|
char *subData; |
27 |
|
|
// char eventCRC[2]; |
28 |
|
|
int j; |
29 |
|
|
FILE *ftime_sync; |
30 |
|
|
unsigned short calCRC; //calculated CRC of the data |
31 |
|
|
unsigned short readCRC; //CRC read from the end of the subpacket |
32 |
|
|
long int dataLength; |
33 |
|
|
long int length; |
34 |
|
|
long int RM_ACQ_SETTING_MODE,OBT_TIME_SYNC, |
35 |
|
|
LAST_TYME_SYNC_INFO, |
36 |
|
|
FAVOURITE_WORKING_SCHEDULE, |
37 |
|
|
EFFECTIVE_WORKING_SCHEDULE, |
38 |
|
|
PRH_VAR_TRIGGER_MODE_A, |
39 |
|
|
PRH_VAR_TRIGGER_MODE_B, |
40 |
|
|
RM_ACQ_AFTER_CALIB ; |
41 |
|
|
time=(long int)(unsigned char)(packet[11])+ |
42 |
|
|
256*(long int)(unsigned char)(packet[10])+ |
43 |
|
|
256*256*(long int)(unsigned char)(packet[9])+ |
44 |
|
|
256*256*256*(long int)(unsigned char)(packet[8]); |
45 |
|
|
|
46 |
|
|
temp=(long int)(unsigned char)(packet[7])+ |
47 |
|
|
256*(long int)(unsigned char)(packet[6])+ |
48 |
|
|
256*256*(long int)(unsigned char)(packet[5]); |
49 |
|
|
if (fmod((float)(temp),(float)(10000.))==0.) |
50 |
|
|
cout<<"sorting "<<temp<<"\n"; |
51 |
|
|
/*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 |
|
|
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 |
|
|
// for(j=0;j<length;j++) printf("crc %x \n",(BYTE)subData[j]); |
77 |
|
|
|
78 |
|
|
// cout<<calCRC<<" =crc ?="<<readCRC<<"\n"; |
79 |
|
|
if (calCRC == readCRC) {cout<<calCRC<<" =crc ok="<<"\n"; |
80 |
|
|
|
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 |
|
|
cout<<OBT_TIME_SYNC<<" = ="<<LAST_TYME_SYNC_INFO<<"\n"; |
90 |
|
|
|
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 |
|
|
|
103 |
|
|
cout<<RTtoMT<<"\n"; |
104 |
|
|
cout<<RT<<"\n"; |
105 |
|
|
cout<<Timesync<<"\n"; |
106 |
|
|
cout<<OBTtimesync<<"\n"; |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
fclose(ftime_sync);} |
110 |
|
|
// end mikhailov |
111 |
|
|
//RTtoMT,RT,Timesync,OBTtimesync; |
112 |
|
|
|
113 |
|
|
|
114 |
|
|
} |