5 |
#include "CRC.h" |
#include "CRC.h" |
6 |
|
|
7 |
short int CRC_H(char [], char []); |
short int CRC_H(char [], char []); |
8 |
extern char MYSQL[80]; |
extern char MYSQL[120]; |
9 |
extern char database[80]; |
extern char database[120]; |
10 |
extern float YODA_flag; |
extern float YODA_flag; |
11 |
extern float transmit_flag; |
extern float transmit_flag; |
12 |
extern int print_flag; |
extern int print_flag; |
75 |
long int icount_int=0; /*Entire part of total file size in Kbytes*/ |
long int icount_int=0; /*Entire part of total file size in Kbytes*/ |
76 |
long int icount_frac=0; /*Fractional part of total file size*/ |
long int icount_frac=0; /*Fractional part of total file size*/ |
77 |
long int N1=0; /*Number of identified PAMELA packets*/ |
long int N1=0; /*Number of identified PAMELA packets*/ |
78 |
long int numP[3]; /*Packet numbers for previous packets*/ |
long int numP[3]; /*Packet numbers for previous packets*/ |
79 |
|
long int PackType[3]; /*Packet type for previous packets*/ |
80 |
long int LenP[3]; /*Packet length for previous packets*/ |
long int LenP[3]; /*Packet length for previous packets*/ |
81 |
unsigned long int time_p[3]; /*Packet time*/ |
unsigned long int time_p[3]; /*Packet time*/ |
82 |
unsigned long int time_max=0; |
unsigned long int time_max=0; |
99 |
strcpy(connection,MYSQL); |
strcpy(connection,MYSQL); |
100 |
strcat(connection,database); |
strcat(connection,database); |
101 |
TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod"); |
TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod"); |
102 |
|
if (sqlServer==0) {cerr<<"can not connect with MYSQL server\n"; exit(1);} |
103 |
oss.str(""); |
oss.str(""); |
104 |
oss<<"select * from FILES1"; |
oss<<"select * from FILES1"; |
105 |
TSQLResult *res1=sqlServer->Query(oss.str().c_str()); |
TSQLResult *res1=sqlServer->Query(oss.str().c_str()); |
133 |
{numP[i]=0; time_p[i]=0; CRC_Header[i]=0; CRC_bad_pack[i]=0; |
{numP[i]=0; time_p[i]=0; CRC_Header[i]=0; CRC_bad_pack[i]=0; |
134 |
flag_CRC_H[i]=0; flag_len[i]=0; flag_len_weak[i]=0; flag_pack[i]=0; flag_CRC_cor[i]=0; |
flag_CRC_H[i]=0; flag_len[i]=0; flag_len_weak[i]=0; flag_pack[i]=0; flag_CRC_cor[i]=0; |
135 |
flag_name[i]=0; flag_type[i]=0; flag_time[i]=0; |
flag_name[i]=0; flag_type[i]=0; flag_time[i]=0; |
136 |
LenP[i]=0; |
LenP[i]=0; PackType[i]=0; |
137 |
adr_first[i]=0; adr_last[i]=0; |
adr_first[i]=0; adr_last[i]=0; |
138 |
Hex[i]=0;} |
Hex[i]=0;} |
139 |
for (i=0; i<4; i++) {Byte_adr1[i]=0; Byte_adr2[i]=0;} |
for (i=0; i<4; i++) {Byte_adr1[i]=0; Byte_adr2[i]=0;} |
140 |
for (i=0; i<2; i++) temp[i]=0; |
for (i=0; i<2; i++) temp[i]=0; |
141 |
|
|
142 |
ifstream fin; |
ifstream fin; |
143 |
ofstream fo_pam, fo_work; |
ofstream fo_pam, fo_work; |
144 |
/**********************OPEN NECESSARY FILES************************/ |
/**********************OPEN NECESSARY FILES************************/ |
145 |
/******************************************************************/ |
/******************************************************************/ |
146 |
fin.open(fni, ios::binary); // open input file "nnnnn_mmm_xxx_cln1.pam" |
fin.open(fni, ios::binary); // open input file "nnnnn_mmm_xxx_cln1.pam" |
147 |
if(fin.good()==0) {cerr<<"can not open input file "<<fni<<"\n"; exit(1);} |
if(fin.good()==0) {cerr<<"can not open input file (Verify.cpp) "<<fni<<"\n"; exit(1);} |
148 |
|
|
149 |
fo_work.open(fno, ios::out); //open output help file "work.dat" |
fo_work.open(fno, ios::out); //open output help file "work.dat" |
150 |
if(!fo_work) {cerr<<"can not open outputfile"; exit(1);} |
if(!fo_work) {cerr<<"can not open outputfile"; exit(1);} |
185 |
256*(long int)(unsigned char)(Name_Buf[6])+ |
256*(long int)(unsigned char)(Name_Buf[6])+ |
186 |
256*256*(long int)(unsigned char)(Name_Buf[5]); |
256*256*(long int)(unsigned char)(Name_Buf[5]); |
187 |
|
|
|
if (N1==0) numP[2]=tmpP-1; //initial packet identification |
|
188 |
|
|
189 |
/******************packet type identification**********************/ |
/******************packet type identification**********************/ |
190 |
for (i=0;i<NumberPack;i++) |
for (i=0;i<NumberPack;i++) |
196 |
if ((num_type1==0)&&(num_type2!=0)) num_type=num_type2; |
if ((num_type1==0)&&(num_type2!=0)) num_type=num_type2; |
197 |
if ((num_type1!=0)&&(num_type2==0)) num_type=num_type1; |
if ((num_type1!=0)&&(num_type2==0)) num_type=num_type1; |
198 |
|
|
199 |
|
if (N1==0) |
200 |
|
{numP[2]=tmpP-1; //initial packet identification |
201 |
|
PackType[2]=num_type-1;} //initial packet type identification |
202 |
/////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////// |
203 |
////////////////// PAMELA PACKET IDENTIFICATION//////////////////// |
////////////////// PAMELA PACKET IDENTIFICATION//////////////////// |
204 |
/////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////// |
205 |
if (((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&& |
if (((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
206 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
((int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
207 |
((int)(unsigned char)Name_Buf[1]==CODE_BYTE2&& |
((int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
208 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&& |
209 |
((int)(unsigned char)Name_Buf[2]==CODE_BYTE3&& |
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&num_type1!=0&&num_type1==num_type2)|| |
210 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)|| |
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&& |
211 |
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&& |
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&(tmpP==numP[2]+1))) |
|
(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&& |
|
|
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&num_type1!=0&&num_type1==num_type2)|| |
|
|
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&& |
|
|
(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&& |
|
|
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&& |
|
|
(tmpP==numP[2]+1))) |
|
212 |
{if (N1==0) {for (i=0;i<8;i++) buffer[i]=Name_Buf[i]; } |
{if (N1==0) {for (i=0;i<8;i++) buffer[i]=Name_Buf[i]; } |
213 |
N1+=1; FLAG_BIG=0; |
N1+=1; FLAG_BIG=0; |
214 |
if (N1==1) {icount+=8;} |
if (N1==1) {icount+=8;} |
215 |
|
|
216 |
packet_counter[num_type]+=1; //count packet number for each type |
packet_counter[num_type]+=1; //count packet number for each type |
217 |
if ((print_flag>0) && (fmod((float)(tmpP),(float)(1000.))==0.)&&(tmpP!=0)) cout<<"verifying "<<tmpP<<"\n"; |
if ((print_flag>0) && (fmod((float)(tmpP),(float)(1000.))==0.)&&(tmpP!=0)) cout<<"verifying "<<tmpP<<"\n"; |
218 |
if (N1!=1) |
if (N1!=1) |
226 |
{flag_len[2]=1; |
{flag_len[2]=1; |
227 |
er_pack_Len+=1; |
er_pack_Len+=1; |
228 |
if (print_flag>0) |
if (print_flag>0) |
229 |
{cout<<"pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type="<<num_type<<"\n";} |
{cout<<"pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type=" |
230 |
|
<<packet_type[PackType[2]]<<"\n";} |
231 |
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
232 |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<< |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<< |
233 |
packet_type[num_type]<<dec<<"\n"; |
packet_type[PackType[2]]<<dec<<"\n"; |
234 |
} |
} |
235 |
if ( (flag_CRC_H[2]==0)&&(GLOBAL_LEN_ER>0)&& |
if ( (flag_CRC_H[2]==0)&&(GLOBAL_LEN_ER>0)&& |
236 |
( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) ) |
( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) ) |
237 |
{flag_len_weak[2]=1; |
{flag_len_weak[2]=1; |
238 |
if (print_flag>0) |
if (print_flag>0) |
239 |
{cout<<"weak length error; pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16 |
{cout<<"weak length error; pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16 |
240 |
<<" Type="<<num_type<<"\n";} |
<<" Type="<<hex<<packet_type[PackType[2]]<<dec<<"\n";} |
241 |
fo_work<<"Weak length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
fo_work<<"Weak length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
242 |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<num_type<<"\n"; |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<< |
243 |
|
packet_type[PackType[2]]<<dec<<"\n"; |
244 |
} |
} |
245 |
|
|
246 |
if ((GLOBAL_LEN_ER>0)&&(flag_len[2]==1)) |
if ((GLOBAL_LEN_ER>0)&&(flag_len[2]==1)) |
319 |
flag_time[2]=0; |
flag_time[2]=0; |
320 |
flag_CRC_cor[2]=0; |
flag_CRC_cor[2]=0; |
321 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
322 |
{numP[i]=numP[2]; time_p[i]=time_p[2]; |
{numP[i]=numP[2]; PackType[i]=PackType[2]; time_p[i]=time_p[2]; |
323 |
CRC_Header[i]=CRC_Header[2]; |
CRC_Header[i]=CRC_Header[2]; |
324 |
LenP[i]=LenP[2]; |
LenP[i]=LenP[2]; |
325 |
adr_first[i]=adr_first[2]; |
adr_first[i]=adr_first[2]; |
334 |
} |
} |
335 |
default:{ |
default:{ |
336 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
337 |
{numP[i]=numP[i+1]; |
{numP[i]=numP[i+1]; PackType[i]=PackType[i+1]; |
338 |
time_p[i]=time_p[i+1]; |
time_p[i]=time_p[i+1]; |
339 |
CRC_Header[i]=CRC_Header[i+1]; |
CRC_Header[i]=CRC_Header[i+1]; |
340 |
CRC_bad_pack[i]=CRC_bad_pack[i+1]; |
CRC_bad_pack[i]=CRC_bad_pack[i+1]; |
352 |
numP[2]=(long int)(unsigned char)(Name_Buf[7])+ |
numP[2]=(long int)(unsigned char)(Name_Buf[7])+ |
353 |
256*(long int)(unsigned char)(Name_Buf[6])+ |
256*(long int)(unsigned char)(Name_Buf[6])+ |
354 |
256*256*(long int)(unsigned char)(Name_Buf[5]); |
256*256*(long int)(unsigned char)(Name_Buf[5]); |
355 |
|
PackType[2]=num_type-1; |
356 |
time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+ |
time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+ |
357 |
256*(long int)(unsigned char)(Name_Buf_add[2])+ |
256*(long int)(unsigned char)(Name_Buf_add[2])+ |
358 |
256*256*(long int)(unsigned char)(Name_Buf_add[1])+ |
256*256*(long int)(unsigned char)(Name_Buf_add[1])+ |
437 |
/***missed packets: 21 20 19 18 17 ******************************/ |
/***missed packets: 21 20 19 18 17 ******************************/ |
438 |
if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0)) |
if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0)) |
439 |
{Mis_group+=1; |
{Mis_group+=1; |
440 |
count_sec_miss+=numP[0]-1-numP[1]; |
count_sec_miss+=numP[0]-numP[1]; |
441 |
fprintf(fo_miss,"secondary transmitted packets may be %9i -%9i number of packets=%9i\n", |
fprintf(fo_miss,"secondary transmitted packets may be %9i -%9i number of packets=%9i\n", |
442 |
numP[1],numP[0],numP[0]-1-numP[1]); |
numP[1],numP[0],numP[0]-numP[1]); |
443 |
} |
} |
444 |
/**packet numbers: 10 11 (12 15 19) 20 ****************************/ |
/**packet numbers: 10 11 (12 15 19) 20 ****************************/ |
445 |
/***********missed packets: 16 17 18 ********************************/ |
/***********missed packets: 16 17 18 ********************************/ |
523 |
for (i=0;i<4;i++) Byte_adr1[i]=0; |
for (i=0;i<4;i++) Byte_adr1[i]=0; |
524 |
for (i=0;i<4;i++) |
for (i=0;i<4;i++) |
525 |
{if (temp[0]/(long int)(pow(256.,3-i))>=1) |
{if (temp[0]/(long int)(pow(256.,3-i))>=1) |
526 |
{Byte_adr1[3-i]=(int)(temp[0]/(long int)(pow(256.,3-i))); |
{Byte_adr1[3-i]=(int)(temp[0]/(long int)(pow(256.,3-i))); |
527 |
temp[0]=temp[0]-(long int)pow(256.,3-i)* |
temp[0]=temp[0]-(long int)pow(256.,3-i)*(int)(temp[0]/(long int)(pow(256.,3-i)));} |
|
(int)(temp[0]/(long int)(pow(256.,3-i)));} |
|
528 |
} |
} |
529 |
|
|
530 |
//Write packet type and begin displacement in log file |
//Write packet type and begin displacement in log file |
552 |
if ((print_flag>0) && fmod( double(icount_total), double(100000000.))==double(0.)) {cout<<"Mbytes="<<icount_total/1000000.<<"\n";} |
if ((print_flag>0) && fmod( double(icount_total), double(100000000.))==double(0.)) {cout<<"Mbytes="<<icount_total/1000000.<<"\n";} |
553 |
if ((N1>0)&&(FLAG_BIG==0)) icount+=1; |
if ((N1>0)&&(FLAG_BIG==0)) icount+=1; |
554 |
for (i=0;i<7;i++) Name_Buf[i]=Name_Buf[i+1]; |
for (i=0;i<7;i++) Name_Buf[i]=Name_Buf[i+1]; |
555 |
Name_Buf[7]=ch; /*for(i=0;i<8;i++) printf("%x",(int)(unsigned char)Name_Buf[i]); printf("\n");*/ |
Name_Buf[7]=ch; |
556 |
if ((icount-adr_first[2]-1)<Nmax) |
if ((icount-adr_first[2]-1)<Nmax) |
557 |
{buffer[icount-adr_first[2]]=ch;} |
{buffer[icount-adr_first[2]]=ch;} |
558 |
else |
else |
559 |
{flag_len[2]=1; |
{if (FLAG_BIG==0) |
560 |
er_pack_Len+=1; |
{flag_len[2]=1; |
561 |
fo_work<<"Length error (too long packet) : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
er_pack_Len+=1; |
562 |
" : length (> Nmax="<<Nmax<<")="<<icount-adr_first[2]<<" : packet type="<<hex<< |
fo_work<<"Length error (too long packet) : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
563 |
packet_type[num_type]<<dec<<"\n"; |
" : length (> Nmax="<<Nmax<<")="<<icount-adr_first[2]<<" : packet type="<<hex<< |
564 |
if (print_flag>0 && FLAG_BIG==0) {cout<<"too long packet "<<numP[2]<<"\n";} |
packet_type[PackType[2]]<<dec<<"\n"; |
565 |
FLAG_BIG=1; |
if (print_flag>0) {cout<<"too long packet "<<numP[2]<<"\n";} |
566 |
|
FLAG_BIG=1; |
567 |
|
} |
568 |
} |
} |
569 |
} |
} |
570 |
/******************************************************************/ |
/******************************************************************/ |
572 |
/******************************************************************/ |
/******************************************************************/ |
573 |
|
|
574 |
/*************PAMELA LAST PACKET END DISPLACEMENT******************/ |
/*************PAMELA LAST PACKET END DISPLACEMENT******************/ |
575 |
if (FLAG_BIG==0) {adr_last[2]=icount;} |
if ((icount-adr_first[2]+1-LenP[2]-16)<=Limit) {adr_last[2]=icount;} //end byte for previous packet |
576 |
else {adr_last[2]=adr_first[2]+Limit;} |
else if ((icount-adr_first[2]+1-LenP[2]-16)>Limit) {adr_last[2]=adr_first[2]+Limit;} //end byte for previous packet |
577 |
|
|
578 |
if ((adr_last[2]-adr_first[2]+1-LenP[2]-16>64)||(adr_last[2]-adr_first[2]+1-LenP[2]-16<0)) |
if ((adr_last[2]-adr_first[2]+1-LenP[2]-16>64)||(adr_last[2]-adr_first[2]+1-LenP[2]-16<0)) |
579 |
{ |
{ |
580 |
flag_len[2]=1; |
flag_len[2]=1; |
581 |
er_pack_Len+=1; |
er_pack_Len+=1; |
582 |
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<< |
583 |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<< |
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<< |
584 |
packet_type[num_type]<<dec<<"\n"; |
packet_type[PackType[2]]<<dec<<"\n"; |
585 |
} |
} |
586 |
if ( (flag_len[2]!=1)&&(flag_CRC_H[2]!=1) ) |
if ( (flag_len[2]!=1)&&(flag_CRC_H[2]!=1) ) |
587 |
{adr_last[2]=adr_first[2]+LenP[2]+15;} |
{adr_last[2]=adr_first[2]+LenP[2]+15;} |
591 |
{if (temp[1]/(long int)(pow(256.,3-i))>=1) |
{if (temp[1]/(long int)(pow(256.,3-i))>=1) |
592 |
{Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i))); |
{Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i))); |
593 |
temp[1]=temp[1]-(long int)pow(256.,3-i)* |
temp[1]=temp[1]-(long int)pow(256.,3-i)* |
594 |
(int)(temp[1]/(long int)(pow(256.,3-i)));}} |
(int)(temp[1]/(long int)(pow(256.,3-i)));}} |
|
|
|
|
/*********PAMELA LAST PACKET LENGTH ERROR ANALYSIS*****************/ |
|
595 |
|
|
596 |
//Write last packet end displacement in log file |
//Write last packet end displacement in log file |
597 |
for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i])); |
for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i])); |
609 |
//Write error number in work.dat file |
//Write error number in work.dat file |
610 |
if (flags!=0) fo_work<<"PAMELA packet="<<numP[2]<<" : error flag="<<flags<<"\n"; |
if (flags!=0) fo_work<<"PAMELA packet="<<numP[2]<<" : error flag="<<flags<<"\n"; |
611 |
|
|
|
|
|
612 |
//Write inf file |
//Write inf file |
613 |
fprintf(fo_inf,"%lli bytes in initial file %s\n", icount_total, name_in); |
fprintf(fo_inf,"%lli bytes in initial file %s\n", icount_total, name_in); |
614 |
icount_int = (int)(icount_total/1024); |
icount_int = (int)(icount_total/1024); |
691 |
// } |
// } |
692 |
|
|
693 |
delete [] buffer; |
delete [] buffer; |
|
|
|
694 |
/***************************************************************/ |
/***************************************************************/ |
695 |
fin.close(); |
fin.close(); |
696 |
fo_work.close(); |
fo_work.close(); |