1 |
cafagna |
1.1 |
///////////////PAMELA PACKETS READER/////////////////////////////////
|
2 |
|
|
#include "descript.h"
|
3 |
cafagna |
1.2 |
#include "flag.h"
|
4 |
cafagna |
1.1 |
|
5 |
|
|
#include "CRC.h"
|
6 |
|
|
|
7 |
|
|
short int CRC_H(char [], char []);
|
8 |
cafagna |
1.3 |
extern char MYSQL[80];
|
9 |
|
|
extern char database[80];
|
10 |
|
|
extern float YODA_flag;
|
11 |
|
|
extern float transmit_flag;
|
12 |
|
|
extern int print_flag;
|
13 |
cafagna |
1.1 |
|
14 |
|
|
void verify(char fni[], char inf[], char log[], char pam[],
|
15 |
|
|
char fno[], char path[], char name_ini[], char name_in[], int packet_type[],
|
16 |
cafagna |
1.2 |
float IndexQ, int r_counter, int real_route[])
|
17 |
cafagna |
1.1 |
{
|
18 |
cafagna |
1.3 |
FILE *fo_log, *fo_inf, *fo_miss, *fo_row;
|
19 |
cafagna |
1.1 |
|
20 |
|
|
time_t seconds;
|
21 |
cafagna |
1.2 |
|
22 |
cafagna |
1.1 |
struct tm *timeinfo;
|
23 |
|
|
char time_year[5], time_month[5], time_day[5];
|
24 |
|
|
char data_time[80];
|
25 |
|
|
char cirquit_no[10], route_no[80], name_path[80], name_cln2[80];
|
26 |
cafagna |
1.3 |
char connection[80];
|
27 |
cafagna |
1.1 |
bool file_ready, file_deleted, file_archived, file_proces;
|
28 |
cafagna |
1.2 |
int flag_to_transmit=0;
|
29 |
cafagna |
1.1 |
int flag_sec_trans=0; /*Second transmission flag*/
|
30 |
|
|
int num_rows=0;
|
31 |
|
|
int current_route=0;
|
32 |
|
|
|
33 |
|
|
char str_route[10];
|
34 |
|
|
char str_file[80];
|
35 |
|
|
|
36 |
cafagna |
1.3 |
char ch, ttt[80];
|
37 |
cafagna |
1.1 |
char miss_file[80];
|
38 |
|
|
char Name_Buf[9]; /*Name buffer*/
|
39 |
|
|
char Name_Buf_add[9]; /*Header buffer*/
|
40 |
|
|
char buff[16];
|
41 |
|
|
char Name_Buf_old[9]; /*Old name buffer*/
|
42 |
|
|
char Name_Buf_add_old[9]; /*Old header buffer*/
|
43 |
|
|
|
44 |
|
|
short int CalcCheckSum=0;
|
45 |
|
|
int num_type=0; /*Packet type number*/
|
46 |
|
|
int num_type1=0;
|
47 |
|
|
int num_type2=0;
|
48 |
|
|
int stop=0;
|
49 |
|
|
int Hex[3];
|
50 |
|
|
int Byte_adr1[4]; /*Bytes for Packet begin packing*/
|
51 |
|
|
int Byte_adr2[4]; /*Bytes for Packet end packing*/
|
52 |
|
|
int packet_counter[NumberPack+1]; /*Counter for each packet type*/
|
53 |
|
|
int count_name_cor=0; /*Counter for packet with corrected name*/
|
54 |
cafagna |
1.3 |
int er_pack_CRC=0; /*CRC error packet counter*/
|
55 |
|
|
int er_pack_Len=0; /*Length error packet counter*/
|
56 |
|
|
int er_pack_count=0; /*Errors counter*/
|
57 |
cafagna |
1.1 |
int count_miss=0; /*Missed packet counter*/
|
58 |
cafagna |
1.3 |
int count_sec_miss=0;
|
59 |
cafagna |
1.1 |
int P_er=0; /*Number of packet with counter error*/
|
60 |
|
|
int flag_CRC_H[3]; /*Flag for CRC header error*/
|
61 |
|
|
int flag_pack[3]; /*Flag for error in packet counter*/
|
62 |
|
|
int flag_len[3]; /*Flag for PAMELA packet length error*/
|
63 |
|
|
int flag_len_weak[3]; /*Suspicion flag for PAMELA packet length error*/
|
64 |
|
|
int flag_name[3]; /*Flag for name error*/
|
65 |
|
|
int flag_type[3]; /*Flag for packet type error*/
|
66 |
|
|
int flag_time[3]; /*Flag for time error*/
|
67 |
|
|
int flag_CRC_cor[3]; /*Flag for CRC error correction*/
|
68 |
|
|
int CRC_bad_pack[3]; /*Current header CRC bad packet number*/
|
69 |
|
|
int CRC_Header[3]; /*CRC in header for previous packets*/
|
70 |
|
|
int Mis_group=0; /*Number of missed packet group*/
|
71 |
|
|
short int flags=0; /*Number for all errors*/
|
72 |
|
|
long int tmpP=0; /*Temporary PAMELA packet number*/
|
73 |
|
|
long long int icount=0; /*Number of bytes in identified packets*/
|
74 |
|
|
long long int icount_total=0; /*Total number of bytes*/
|
75 |
|
|
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*/
|
77 |
|
|
long int N1=0; /*Number of identified PAMELA packets*/
|
78 |
|
|
long int numP[3]; /*Packet numbers for previous packets*/
|
79 |
|
|
long int LenP[3]; /*Packet length for previous packets*/
|
80 |
|
|
unsigned long int time_p[3]; /*Packet time*/
|
81 |
cafagna |
1.3 |
unsigned long int time_max=0;
|
82 |
|
|
unsigned long int time_min=0;
|
83 |
cafagna |
1.1 |
long int pack_length=0; /*PAMELA packet length*/
|
84 |
|
|
long long int adr_first[3]; /*Start displacement from file begin*/
|
85 |
|
|
long long int adr_last[3]; /*Finish displacement from file begin*/
|
86 |
|
|
long int temp[2];
|
87 |
|
|
char *buffer=new char[Nmax]; /*Buffer for PAMELA current packet*/
|
88 |
|
|
int FLAG_BIG=0; /*Flag for large packet*/
|
89 |
|
|
unsigned long int k=0, j=0;
|
90 |
|
|
int i;
|
91 |
|
|
//initialization , all =0
|
92 |
cafagna |
1.3 |
float ratioCln1Cln2;
|
93 |
cafagna |
1.2 |
int output;
|
94 |
|
|
char str[80];
|
95 |
|
|
|
96 |
cafagna |
1.1 |
stringstream oss, oss1;
|
97 |
|
|
|
98 |
cafagna |
1.3 |
strcpy(connection,MYSQL);
|
99 |
|
|
strcat(connection,database);
|
100 |
|
|
TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod");
|
101 |
cafagna |
1.1 |
|
102 |
|
|
oss.str("");
|
103 |
|
|
oss<<"select * from FILES1";
|
104 |
|
|
TSQLResult *res1=sqlServer->Query(oss.str().c_str());
|
105 |
|
|
num_rows=res1->GetRowCount();
|
106 |
|
|
if (num_rows>0)
|
107 |
|
|
{
|
108 |
|
|
oss.str("");
|
109 |
|
|
oss<<"select max(my_route) from FILES1";
|
110 |
|
|
TSQLResult *res2=sqlServer->Query(oss.str().c_str());
|
111 |
|
|
TSQLRow *row=res2->Next();
|
112 |
|
|
strcpy(str_route,row->GetField(0));
|
113 |
|
|
|
114 |
|
|
strcpy(str_file,inf);
|
115 |
|
|
str_file[strlen(inf)-9]='\0';
|
116 |
|
|
strcat(str_file,"_tmp.dat");
|
117 |
|
|
fo_row=fopen(str_file,"w+");
|
118 |
|
|
fprintf(fo_row,"%s",str_route);
|
119 |
|
|
fseek(fo_row,0,0);
|
120 |
|
|
fscanf(fo_row,"%i",¤t_route);
|
121 |
|
|
current_route+=1;
|
122 |
|
|
fclose(fo_row);
|
123 |
|
|
remove(str_file);
|
124 |
|
|
}
|
125 |
|
|
else
|
126 |
|
|
{
|
127 |
|
|
current_route=1;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
for (i=0; i<NumberPack+1; i++) packet_counter[i]=0;
|
131 |
|
|
for (i=0; i<3; i++)
|
132 |
|
|
{numP[i]=0; time_p[i]=0; CRC_Header[i]=0; CRC_bad_pack[i]=0;
|
133 |
|
|
flag_CRC_H[i]=0; flag_len[i]=0; flag_len_weak[i]=0; flag_pack[i]=0; flag_CRC_cor[i]=0;
|
134 |
|
|
flag_name[i]=0; flag_type[i]=0; flag_time[i]=0;
|
135 |
|
|
LenP[i]=0;
|
136 |
|
|
adr_first[i]=0; adr_last[i]=0;
|
137 |
|
|
Hex[i]=0;}
|
138 |
|
|
for (i=0; i<4; i++) {Byte_adr1[i]=0; Byte_adr2[i]=0;}
|
139 |
|
|
for (i=0; i<2; i++) temp[i]=0;
|
140 |
|
|
|
141 |
|
|
ifstream fin;
|
142 |
cafagna |
1.3 |
ofstream fo_pam, fo_work;
|
143 |
cafagna |
1.1 |
/**********************OPEN NECESSARY FILES************************/
|
144 |
|
|
/******************************************************************/
|
145 |
cafagna |
1.3 |
fin.open(fni, ios::binary); // open input file "nnnnn_mmm_xxx_cln1.pam"
|
146 |
cafagna |
1.2 |
if(fin.good()==0) {cerr<<"can not open input file "<<fni<<"\n"; exit(1);}
|
147 |
cafagna |
1.1 |
|
148 |
cafagna |
1.3 |
fo_work.open(fno, ios::out); //open output help file "work.dat"
|
149 |
|
|
if(!fo_work) {cerr<<"can not open outputfile"; exit(1);}
|
150 |
cafagna |
1.1 |
|
151 |
cafagna |
1.2 |
fo_log=fopen(log, "wb"); //open output file "xxx_mmm_nnnnn_cln2.log"
|
152 |
cafagna |
1.1 |
if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);}
|
153 |
|
|
|
154 |
cafagna |
1.2 |
fo_pam.open(pam, ios::binary); //open output file "xxx_mmm_nnnnn_cln2.pam"
|
155 |
cafagna |
1.1 |
if(fo_pam.good()==0) {cerr<<"can not open pam file"; exit(1);}
|
156 |
|
|
|
157 |
cafagna |
1.2 |
fo_inf=fopen(inf, "wb"); //open output file "xxx_mmm_nnnnn_cln2.inf"
|
158 |
cafagna |
1.1 |
if(fo_inf==NULL) {cerr<<"can not open inf file"; exit(1);}
|
159 |
|
|
|
160 |
|
|
strcpy(miss_file,path);
|
161 |
|
|
strncat(miss_file,name_in,strlen(name_in)-8);
|
162 |
|
|
fo_miss=fopen(strcat(miss_file,"mis_cln2.dat"), "wb");
|
163 |
cafagna |
1.2 |
//open output file "xxx_mmm_nnnnn_mis_cln2.dat"
|
164 |
cafagna |
1.1 |
if(fo_miss==NULL) {cerr<<"can not open miss file"; exit(1);}
|
165 |
|
|
/******************************************************************/
|
166 |
|
|
/******************************************************************/
|
167 |
|
|
|
168 |
|
|
//Write proccessed filename in help file
|
169 |
cafagna |
1.3 |
fo_work<<"initial file name : "<<name_in<<"\n";
|
170 |
cafagna |
1.2 |
|
171 |
cafagna |
1.1 |
/******************************************************************/
|
172 |
|
|
/******************MAIN READING CYCLE BEGIN************************/
|
173 |
|
|
/******************************************************************/
|
174 |
|
|
|
175 |
|
|
while(fin.eof()==0)
|
176 |
|
|
{
|
177 |
|
|
num_type=0; num_type1=0; num_type2=0;
|
178 |
|
|
|
179 |
|
|
/**********************data reading********************************/
|
180 |
|
|
if ((N1==0)&&(icount_total==0)) {fin.read(Name_Buf,8); icount_total+=8;}
|
181 |
|
|
|
182 |
|
|
/*******************temporary packet number************************/
|
183 |
|
|
tmpP=(long int)(unsigned char)(Name_Buf[7])+
|
184 |
cafagna |
1.2 |
256*(long int)(unsigned char)(Name_Buf[6])+
|
185 |
cafagna |
1.1 |
256*256*(long int)(unsigned char)(Name_Buf[5]);
|
186 |
|
|
|
187 |
|
|
if (N1==0) numP[2]=tmpP-1; //initial packet identification
|
188 |
|
|
|
189 |
|
|
/******************packet type identification**********************/
|
190 |
|
|
for (i=0;i<NumberPack;i++)
|
191 |
|
|
{if (packet_type[i]==(int)(unsigned char)(Name_Buf[3]))
|
192 |
|
|
num_type1=i+1;
|
193 |
|
|
if (packet_type[i]==(int)(unsigned char)(Name_Buf[4]))
|
194 |
|
|
num_type2=i+1;}
|
195 |
|
|
if ((num_type1==num_type2)&&(num_type1!=0)) num_type=num_type1;
|
196 |
|
|
if ((num_type1==0)&&(num_type2!=0)) num_type=num_type2;
|
197 |
|
|
if ((num_type1!=0)&&(num_type2==0)) num_type=num_type1;
|
198 |
|
|
|
199 |
|
|
///////////////////////////////////////////////////////////////////
|
200 |
|
|
////////////////// PAMELA PACKET IDENTIFICATION////////////////////
|
201 |
|
|
///////////////////////////////////////////////////////////////////
|
202 |
|
|
if (((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&
|
203 |
cafagna |
1.3 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
|
204 |
cafagna |
1.1 |
((int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&
|
205 |
cafagna |
1.3 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
|
206 |
cafagna |
1.1 |
((int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&
|
207 |
cafagna |
1.3 |
(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
|
208 |
cafagna |
1.1 |
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&
|
209 |
|
|
(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&
|
210 |
cafagna |
1.2 |
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&num_type1!=0&&num_type1==num_type2)||
|
211 |
cafagna |
1.1 |
((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&
|
212 |
|
|
(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&
|
213 |
|
|
(int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&
|
214 |
|
|
(tmpP==numP[2]+1)))
|
215 |
|
|
{if (N1==0) {for (i=0;i<8;i++) buffer[i]=Name_Buf[i]; }
|
216 |
|
|
N1+=1; FLAG_BIG=0;
|
217 |
|
|
if (N1==1) {icount+=8;}
|
218 |
|
|
packet_counter[num_type]+=1; //count packet number for each type
|
219 |
cafagna |
1.3 |
if ((print_flag>0) && (fmod((float)(tmpP),(float)(1000.))==0.)&&(tmpP!=0)) cout<<"verifying "<<tmpP<<"\n";
|
220 |
cafagna |
1.1 |
if (N1!=1)
|
221 |
|
|
{
|
222 |
|
|
/**************PAMELA PREVIOUS PACKET END DISPLACEMENT*************/
|
223 |
|
|
if ((icount-8-adr_first[2]+1-LenP[2]-16)<=Limit) {adr_last[2]=icount-8;} //end byte for previous packet
|
224 |
|
|
else if ((icount-8-adr_first[2]+1-LenP[2]-16)>Limit) {adr_last[2]=adr_first[2]+Limit;} //end byte for previous packet
|
225 |
|
|
/**************PAMELA PACKET LENGTH ERROR ANALYSIS*****************/
|
226 |
|
|
if ( (flag_CRC_H[2]==1)&&(GLOBAL_LEN_ER>0)&&
|
227 |
cafagna |
1.3 |
( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )
|
228 |
cafagna |
1.1 |
{flag_len[2]=1;
|
229 |
cafagna |
1.3 |
er_pack_Len+=1;
|
230 |
|
|
if (print_flag>0)
|
231 |
|
|
{cout<<"pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type="<<num_type<<"\n";}
|
232 |
|
|
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
|
233 |
|
|
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<<
|
234 |
|
|
packet_type[num_type]<<dec<<"\n";
|
235 |
cafagna |
1.2 |
}
|
236 |
cafagna |
1.1 |
if ( (flag_CRC_H[2]==0)&&(GLOBAL_LEN_ER>0)&&
|
237 |
|
|
( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )
|
238 |
|
|
{flag_len_weak[2]=1;
|
239 |
cafagna |
1.3 |
if (print_flag>0)
|
240 |
|
|
{cout<<"weak length error; pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16
|
241 |
|
|
<<" Type="<<num_type<<"\n";}
|
242 |
|
|
fo_work<<"Weak length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
|
243 |
|
|
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<num_type<<"\n";
|
244 |
cafagna |
1.2 |
}
|
245 |
cafagna |
1.1 |
|
246 |
|
|
if ((GLOBAL_LEN_ER>0)&&(flag_len[2]==1))
|
247 |
|
|
{
|
248 |
cafagna |
1.3 |
//Write data in file "nnnnn_mmm_xxx_cln2.pam"
|
249 |
cafagna |
1.1 |
for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
|
250 |
|
|
{fo_pam<< buffer[i];}
|
251 |
|
|
}
|
252 |
cafagna |
1.2 |
else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]!=1))
|
253 |
cafagna |
1.1 |
{
|
254 |
cafagna |
1.3 |
//Write data in file "nnnnn_mmm_xxx_cln2.pam"
|
255 |
cafagna |
1.1 |
for (i=0;i<LenP[2]+16;i++)
|
256 |
|
|
{fo_pam<< buffer[i];}
|
257 |
|
|
adr_last[2]=adr_first[2]+LenP[2]+15;
|
258 |
|
|
icount=adr_first[2]+15+LenP[2]+8;
|
259 |
|
|
}
|
260 |
cafagna |
1.2 |
else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]==1))
|
261 |
|
|
{
|
262 |
cafagna |
1.3 |
//Write data in file "nnnnn_mmm_xxx_cln2.pam"
|
263 |
cafagna |
1.2 |
for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
|
264 |
|
|
{fo_pam<< buffer[i];}
|
265 |
|
|
}
|
266 |
cafagna |
1.1 |
else if ((GLOBAL_LEN_ER==0)&&(adr_last[2]-adr_first[2]+1-LenP[2]-16>=0))
|
267 |
|
|
{
|
268 |
|
|
for (i=0;i<LenP[2]+16;i++)
|
269 |
|
|
{fo_pam<< buffer[i];}
|
270 |
|
|
adr_last[2]=adr_first[2]+LenP[2]+15;
|
271 |
|
|
icount=adr_first[2]+15+LenP[2]+8;
|
272 |
|
|
}
|
273 |
|
|
delete [] buffer;
|
274 |
|
|
buffer=new char[Nmax];
|
275 |
|
|
for (i=0;i<8;i++) buffer[i]=Name_Buf[i];
|
276 |
|
|
|
277 |
|
|
temp[1]=adr_last[2];
|
278 |
|
|
for (i=0;i<4;i++) Byte_adr2[i]=0;
|
279 |
|
|
for (i=0;i<4;i++)
|
280 |
|
|
{if (temp[1]/(long int)(pow(256.,3-i))>=1)
|
281 |
|
|
{Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));
|
282 |
|
|
temp[1]=temp[1]-(long int)pow(256.,3-i)*
|
283 |
|
|
(int)(temp[1]/(long int)(pow(256.,3-i)));}}
|
284 |
cafagna |
1.3 |
//Write previous packet end displacement in nnnnn_mmm_xxx_cln2.log file
|
285 |
cafagna |
1.1 |
for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));
|
286 |
|
|
}
|
287 |
|
|
/*********************reading remaining header********************/
|
288 |
|
|
fin.read(Name_Buf_add, 8);
|
289 |
|
|
if (fin.eof()) break;
|
290 |
|
|
icount+=8; icount_total+=8;
|
291 |
|
|
for (i=0;i<8;i++) buffer[i+8]=Name_Buf_add[i];
|
292 |
|
|
|
293 |
|
|
//packet length
|
294 |
|
|
pack_length=(long int)(unsigned char)(Name_Buf_add[6])+
|
295 |
|
|
256*(long int)(unsigned char)(Name_Buf_add[5])+
|
296 |
|
|
256*256*(long int)(unsigned char)(Name_Buf_add[4]);
|
297 |
|
|
/***********PACKET HEADER DATA ANALYSIS****************************/
|
298 |
|
|
switch (N1)
|
299 |
|
|
{
|
300 |
|
|
case 1:{
|
301 |
|
|
LenP[2]=pack_length;
|
302 |
|
|
numP[2]=(long int)(unsigned char)(Name_Buf[7])+
|
303 |
|
|
256*(long int)(unsigned char)(Name_Buf[6])+
|
304 |
cafagna |
1.3 |
256*256*(long int)(unsigned char)(Name_Buf[5]);
|
305 |
cafagna |
1.1 |
time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+
|
306 |
cafagna |
1.3 |
256*(long int)(unsigned char)(Name_Buf_add[2])+
|
307 |
|
|
256*256*(long int)(unsigned char)(Name_Buf_add[1])+
|
308 |
|
|
256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);
|
309 |
|
|
time_max=time_p[2];
|
310 |
|
|
time_min=time_p[2];
|
311 |
cafagna |
1.1 |
|
312 |
|
|
CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);
|
313 |
|
|
adr_first[2]=icount-15;
|
314 |
|
|
CRC_bad_pack[2]=0;
|
315 |
|
|
flag_CRC_H[2]=0;
|
316 |
|
|
flag_pack[2]=0;
|
317 |
|
|
flag_name[2]=0;
|
318 |
|
|
flag_type[2]=0;
|
319 |
|
|
flag_time[2]=0;
|
320 |
|
|
flag_CRC_cor[2]=0;
|
321 |
|
|
for (i=0; i<2; i++)
|
322 |
|
|
{numP[i]=numP[2]; time_p[i]=time_p[2];
|
323 |
|
|
CRC_Header[i]=CRC_Header[2];
|
324 |
|
|
LenP[i]=LenP[2];
|
325 |
|
|
adr_first[i]=adr_first[2];
|
326 |
|
|
CRC_bad_pack[i]=CRC_bad_pack[2];
|
327 |
|
|
flag_CRC_H[i]=flag_CRC_H[2];
|
328 |
|
|
flag_pack[i]=flag_pack[2];
|
329 |
|
|
flag_name[i]=flag_name[2];
|
330 |
|
|
flag_type[i]=flag_type[2];
|
331 |
|
|
flag_time[i]=flag_time[2];
|
332 |
|
|
flag_CRC_cor[i]=flag_CRC_cor[2];}
|
333 |
|
|
break;
|
334 |
|
|
}
|
335 |
|
|
default:{
|
336 |
|
|
for (i=0; i<2; i++)
|
337 |
|
|
{numP[i]=numP[i+1];
|
338 |
|
|
time_p[i]=time_p[i+1];
|
339 |
|
|
CRC_Header[i]=CRC_Header[i+1];
|
340 |
|
|
CRC_bad_pack[i]=CRC_bad_pack[i+1];
|
341 |
|
|
LenP[i]=LenP[i+1];
|
342 |
|
|
adr_first[i]=adr_first[i+1];
|
343 |
|
|
adr_last[i]=adr_last[i+1];
|
344 |
|
|
flag_CRC_H[i]=flag_CRC_H[i+1];
|
345 |
|
|
flag_len[i]=flag_len[i+1];
|
346 |
|
|
flag_len_weak[i]=flag_len_weak[i+1];
|
347 |
|
|
flag_pack[i]=flag_pack[i+1];
|
348 |
|
|
flag_name[i]=flag_name[i+1];
|
349 |
|
|
flag_type[i]=flag_type[i+1];
|
350 |
|
|
flag_time[i]=flag_time[i+1];
|
351 |
|
|
flag_CRC_cor[i]=flag_CRC_cor[i+1];}
|
352 |
|
|
numP[2]=(long int)(unsigned char)(Name_Buf[7])+
|
353 |
|
|
256*(long int)(unsigned char)(Name_Buf[6])+
|
354 |
|
|
256*256*(long int)(unsigned char)(Name_Buf[5]);
|
355 |
|
|
time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+
|
356 |
|
|
256*(long int)(unsigned char)(Name_Buf_add[2])+
|
357 |
|
|
256*256*(long int)(unsigned char)(Name_Buf_add[1])+
|
358 |
cafagna |
1.3 |
256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);
|
359 |
|
|
|
360 |
cafagna |
1.1 |
CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);
|
361 |
|
|
CRC_bad_pack[2]=0;
|
362 |
|
|
adr_first[2]=icount-15;
|
363 |
|
|
flag_CRC_H[2]=0;
|
364 |
|
|
flag_len[2]=0;
|
365 |
|
|
flag_len_weak[2]=0;
|
366 |
|
|
flag_pack[2]=0;
|
367 |
|
|
flag_name[2]=0;
|
368 |
|
|
flag_type[2]=0;
|
369 |
|
|
flag_time[2]=0;
|
370 |
|
|
flag_CRC_cor[2]=0;
|
371 |
|
|
LenP[2]=pack_length;
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
/********packet header CRC error analysis**************************/
|
375 |
|
|
// CalcCheckSum=CRC_H(Name_Buf, Name_Buf_add);
|
376 |
|
|
|
377 |
|
|
for (i=0; i<8; i++)
|
378 |
|
|
{buff[i]=Name_Buf[i];
|
379 |
|
|
buff[i+8]=Name_Buf_add[i];}
|
380 |
|
|
|
381 |
|
|
CalcCheckSum=(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15);
|
382 |
|
|
if (CalcCheckSum!=(short int)(unsigned char)(Name_Buf_add[7]))
|
383 |
cafagna |
1.3 |
{er_pack_CRC+=1;
|
384 |
|
|
CRC_bad_pack[2]=numP[2];
|
385 |
|
|
flag_CRC_H[2]=1;
|
386 |
|
|
fo_work<<"CRC error : PAMELA packet="<<numP[2]<<" : real CRC="<<bitset<8>(CRC_Header[2])<<"("<<CRC_Header[2]<<
|
387 |
|
|
") : calculated CRC="<<bitset<8>(CalcCheckSum)<<"("<<CalcCheckSum<<")\n";
|
388 |
|
|
}
|
389 |
|
|
if ((time_max<time_p[2])&&(flag_CRC_H[2]!=1)) time_max=time_p[2];
|
390 |
cafagna |
1.1 |
/*********packet counter error analysis****************************/
|
391 |
cafagna |
1.3 |
if ((numP[2]!=(numP[1]+1))&&(N1!=1)&&(flag_len[1]==0)&&(CRC_bad_pack[2]==numP[2]))
|
392 |
|
|
{
|
393 |
|
|
fo_work<<"Packet number error : packet="<<numP[2]<<" : previous="<<numP[1]<<" "<<numP[0]<<"\n";
|
394 |
|
|
flag_pack[2]=1;
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
if ((numP[1]!=(numP[0]+1))&&(numP[1]!=(numP[2]-1))&&(N1!=1)&&(CRC_bad_pack[1]==numP[1]))
|
398 |
|
|
{
|
399 |
|
|
fo_work<<"Packet number error : packet="<<numP[1]<<" : previous="<<numP[0]<<" : next="<<numP[2]<<"\n";
|
400 |
|
|
|
401 |
|
|
P_er=N1-1; flag_pack[1]=1;
|
402 |
cafagna |
1.1 |
|
403 |
|
|
//Correct error packet number//
|
404 |
|
|
tmpP=numP[0]+1;
|
405 |
|
|
for (i=0;i<3;i++) Hex[i]=0;
|
406 |
cafagna |
1.3 |
for (i=0;i<3;i++)
|
407 |
|
|
{if (tmpP/(long int) (pow(256.,2-i))>=1)
|
408 |
|
|
{Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
|
409 |
|
|
tmpP=tmpP-(long int)(pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)) ));
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
|
|
for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));
|
413 |
|
|
for (i=0; i<8; i++)
|
414 |
|
|
{buff[i]=Name_Buf_old[i];
|
415 |
|
|
buff[i+8]=Name_Buf_add_old[i];}
|
416 |
|
|
if (CRC_Header[1]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
|
417 |
|
|
{flag_CRC_cor[1]=1;}
|
418 |
|
|
//Correct error packet number//
|
419 |
cafagna |
1.1 |
tmpP=numP[2]-1;
|
420 |
|
|
for (i=0;i<3;i++) Hex[i]=0;
|
421 |
cafagna |
1.3 |
for (i=0;i<3;i++)
|
422 |
|
|
{if (tmpP/(long int)(pow(256.,2-i))>=1)
|
423 |
|
|
{Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
|
424 |
|
|
tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));
|
425 |
|
|
}
|
426 |
|
|
}
|
427 |
|
|
for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));
|
428 |
|
|
for (i=0; i<8; i++)
|
429 |
|
|
{buff[i]=Name_Buf_old[i];
|
430 |
|
|
buff[i+8]=Name_Buf_add_old[i];}
|
431 |
|
|
if (CRC_Header[1]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
|
432 |
|
|
{flag_CRC_cor[1]=1;}
|
433 |
cafagna |
1.1 |
}
|
434 |
|
|
/*********************Missing packet analysis**********************/
|
435 |
cafagna |
1.3 |
/**packet numbers: 21 (22 17 18) 19 ******************************/
|
436 |
|
|
/***missed packets: 21 20 19 18 17 ******************************/
|
437 |
|
|
if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
|
438 |
|
|
{Mis_group+=1;
|
439 |
|
|
count_sec_miss+=numP[0]-1-numP[1];
|
440 |
|
|
fprintf(fo_miss,"secondary transmitted packets may be %9i -%9i number of packets=%9i\n",
|
441 |
|
|
numP[1],numP[0],numP[0]-1-numP[1]);
|
442 |
|
|
}
|
443 |
cafagna |
1.1 |
/**packet numbers: 10 11 (12 15 19) 20 ****************************/
|
444 |
cafagna |
1.2 |
/***********missed packets: 16 17 18 ********************************/
|
445 |
cafagna |
1.3 |
else if ((numP[1]>numP[0]+1)&&(numP[1]<numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
|
446 |
cafagna |
1.1 |
{Mis_group+=1;
|
447 |
cafagna |
1.3 |
fprintf(fo_miss,"1) %9i%9i\n",numP[1]+1,numP[2]-1);
|
448 |
cafagna |
1.1 |
count_miss+=numP[2]-numP[1]-1;}
|
449 |
|
|
/**packet numbers: 10 (11 12 15) 19 20 ****************************/
|
450 |
cafagna |
1.2 |
/***********missed packets: 13 14 ***********************************/
|
451 |
cafagna |
1.3 |
else if ((numP[1]>=numP[0]+1)&&(numP[1]<numP[2]-1)&&(flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
|
452 |
cafagna |
1.1 |
{Mis_group+=1;
|
453 |
cafagna |
1.3 |
fprintf(fo_miss,"2) %9i%9i\n",numP[0]+2,numP[2]-1);
|
454 |
cafagna |
1.1 |
count_miss+=numP[2]-numP[1]-1;}
|
455 |
|
|
/**packet numbers: 10 (11 20 15) 16 17 ****************************/
|
456 |
cafagna |
1.2 |
/********missed packets number =2 ***********************************/
|
457 |
cafagna |
1.3 |
else if ((numP[0]<numP[2]-2)&&(flag_pack[2]==0)&&(flag_pack[1]==1)&&(flag_pack[0]==0))
|
458 |
cafagna |
1.1 |
{Mis_group+=1;
|
459 |
cafagna |
1.3 |
fprintf(fo_miss,"3) %9i%9i\n",numP[0]+1, numP[2]-1);
|
460 |
cafagna |
1.1 |
count_miss+=numP[2]-numP[0]-2;}
|
461 |
|
|
|
462 |
|
|
/**************Time error******************************************/
|
463 |
|
|
if ((numP[2]>=numP[0]+2)&&(flag_pack[2]==0)&&(flag_pack[0]==0)&&
|
464 |
|
|
(flag_time[0]==0)&&(time_p[2]>time_p[0])&&
|
465 |
|
|
((time_p[1]<time_p[0])||(time_p[1]>time_p[2])))
|
466 |
cafagna |
1.3 |
{flag_time[1]=1;
|
467 |
|
|
fo_work<<"Time error : PAMELA packet="<<numP[2]<<" : time="<<time_p[1]<<" : time previous="<<time_p[1]
|
468 |
|
|
<<" : time_next="<<time_p[2]<<"\n";
|
469 |
|
|
}
|
470 |
|
|
|
471 |
cafagna |
1.1 |
/**************Error number calculation****************************/
|
472 |
|
|
if (N1!=1)
|
473 |
|
|
{flags=(short int)((float)(flag_len_weak[1])+
|
474 |
|
|
pow((float)(2*flag_CRC_H[1]),1)+
|
475 |
cafagna |
1.3 |
pow((float)(2*flag_len[1]),2)+
|
476 |
cafagna |
1.1 |
pow((float)(2*flag_pack[1]),3)+
|
477 |
cafagna |
1.3 |
pow((float)(2*flag_name[1]),4)+
|
478 |
cafagna |
1.1 |
pow((float)(2*flag_type[1]),5)+
|
479 |
|
|
pow((float)(2*flag_time[1]),6)+
|
480 |
cafagna |
1.3 |
pow((float)(2*flag_CRC_cor[1]),7));
|
481 |
cafagna |
1.1 |
if (flags!=0) er_pack_count+=1;
|
482 |
cafagna |
1.3 |
//Write error number in log file
|
483 |
|
|
fprintf(fo_log,"%1c",char(flags));
|
484 |
|
|
//Write error number in work.dat file
|
485 |
|
|
if (flags!=0) fo_work<<"PAMELA packet="<<numP[1]<<" : error flag="<<flags<<"\n";
|
486 |
cafagna |
1.1 |
}
|
487 |
|
|
/***********************NAME ERROR*********************************/
|
488 |
|
|
if (((int)(unsigned char)Name_Buf[0]!=CODE_BYTE1)||
|
489 |
|
|
((int)(unsigned char)Name_Buf[1]!=CODE_BYTE2)||
|
490 |
|
|
((int)(unsigned char)Name_Buf[2]!=CODE_BYTE3))
|
491 |
|
|
{
|
492 |
cafagna |
1.3 |
fo_work<<"Name error : packet number="<<numP[2]<<" : ";
|
493 |
|
|
fo_work<<hex<<(int)(unsigned char)Name_Buf[0]<<" : "<<(int)(unsigned char)Name_Buf[1]
|
494 |
|
|
<<" : "<<(int)(unsigned char)Name_Buf[2]<<dec<<"\n";
|
495 |
cafagna |
1.1 |
Name_Buf[0]=(char)(CODE_BYTE1);
|
496 |
|
|
Name_Buf[1]=(char)(CODE_BYTE2);
|
497 |
|
|
Name_Buf[2]=(char)(CODE_BYTE3);
|
498 |
|
|
flag_name[2]=1;
|
499 |
cafagna |
1.3 |
|
500 |
|
|
for (i=0; i<8; i++)
|
501 |
|
|
{buff[i]=Name_Buf[i];
|
502 |
|
|
buff[i+8]=Name_Buf_add[i];}
|
503 |
|
|
if (CRC_Header[2]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
|
504 |
|
|
{
|
505 |
|
|
count_name_cor+=1;
|
506 |
|
|
buffer[0]=(char)(CODE_BYTE1);
|
507 |
|
|
buffer[1]=(char)(CODE_BYTE2);
|
508 |
|
|
buffer[2]=(char)(CODE_BYTE3);
|
509 |
|
|
flag_CRC_cor[2]=1;
|
510 |
|
|
}
|
511 |
cafagna |
1.1 |
}
|
512 |
|
|
|
513 |
|
|
/***********************PACKET TYPE ERROR**************************/
|
514 |
cafagna |
1.3 |
if ((num_type==0)||(num_type1==0)||(num_type2==0))
|
515 |
|
|
{
|
516 |
|
|
flag_type[2]=1;
|
517 |
|
|
fo_work<<"Packet type error : packet number="<<numP[2]<<" : packet type="<<hex<<packet_type[num_type]<<dec<<
|
518 |
|
|
" : "<<num_type<<" : "<<num_type1<<" : "<<num_type2<<"\n";
|
519 |
|
|
}
|
520 |
cafagna |
1.1 |
/******************PAMELA BEGIN PACKET DISPLACEMENT****************/
|
521 |
|
|
temp[0]=adr_first[2];
|
522 |
|
|
for (i=0;i<4;i++) Byte_adr1[i]=0;
|
523 |
|
|
for (i=0;i<4;i++)
|
524 |
|
|
{if (temp[0]/(long int)(pow(256.,3-i))>=1)
|
525 |
|
|
{Byte_adr1[3-i]=(int)(temp[0]/(long int)(pow(256.,3-i)));
|
526 |
|
|
temp[0]=temp[0]-(long int)pow(256.,3-i)*
|
527 |
|
|
(int)(temp[0]/(long int)(pow(256.,3-i)));}
|
528 |
|
|
}
|
529 |
|
|
|
530 |
cafagna |
1.3 |
//Write packet type and begin displacement in log file
|
531 |
cafagna |
1.1 |
fprintf(fo_log,"%1c",char(num_type));
|
532 |
|
|
for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr1[i]));
|
533 |
|
|
|
534 |
|
|
/**************PAMELA PACKET OLD BUFFER***************************/
|
535 |
|
|
for (i=0;i<8;i++)
|
536 |
cafagna |
1.3 |
{Name_Buf_old[i]=Name_Buf[i]; Name_Buf_add_old[i]=Name_Buf_add[i];}
|
537 |
cafagna |
1.1 |
|
538 |
|
|
/**********************data reading********************************/
|
539 |
|
|
fin.seekg(-1,ios::cur); icount-=1; icount_total-=1;
|
540 |
|
|
fin.read(Name_Buf,8);
|
541 |
|
|
if (fin.eof()) break;
|
542 |
|
|
icount+=8; icount_total+=8;
|
543 |
|
|
for (i=0;i<7;i++) buffer[i+16]=Name_Buf[i+1];
|
544 |
|
|
}
|
545 |
|
|
///////////////////////////////////////////////////////////////////
|
546 |
|
|
///////////////////////////////////////////////////////////////////
|
547 |
|
|
///////////////////////////////////////////////////////////////////
|
548 |
|
|
/**********************data reading********************************/
|
549 |
|
|
fin.get(ch);
|
550 |
|
|
if (fin.eof()) {break;}
|
551 |
|
|
icount_total+=1;
|
552 |
cafagna |
1.3 |
if ((print_flag>0) && fmod( double(icount_total), double(100000000.))==double(0.)) {cout<<"Mbytes="<<icount_total/1000000.<<"\n";}
|
553 |
cafagna |
1.1 |
if ((N1>0)&&(FLAG_BIG==0)) icount+=1;
|
554 |
|
|
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");*/
|
556 |
|
|
if ((icount-adr_first[2]-1)<Nmax)
|
557 |
|
|
{buffer[icount-adr_first[2]]=ch;}
|
558 |
|
|
else
|
559 |
|
|
{flag_len[2]=1;
|
560 |
cafagna |
1.3 |
er_pack_Len+=1;
|
561 |
|
|
fo_work<<"Length error (too long packet) : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
|
562 |
|
|
" : length (> Nmax="<<Nmax<<")="<<icount-adr_first[2]<<" : packet type="<<hex<<
|
563 |
|
|
packet_type[num_type]<<dec<<"\n";
|
564 |
|
|
if (print_flag>0 && FLAG_BIG==0) {cout<<"too long packet "<<numP[2]<<"\n";}
|
565 |
cafagna |
1.1 |
FLAG_BIG=1;
|
566 |
|
|
}
|
567 |
|
|
}
|
568 |
|
|
/******************************************************************/
|
569 |
|
|
/********************MAIN READING CYCLE END************************/
|
570 |
|
|
/******************************************************************/
|
571 |
|
|
|
572 |
|
|
/*************PAMELA LAST PACKET END DISPLACEMENT******************/
|
573 |
|
|
if (FLAG_BIG==0) {adr_last[2]=icount;}
|
574 |
|
|
else {adr_last[2]=adr_first[2]+Limit;}
|
575 |
cafagna |
1.3 |
if ((adr_last[2]-adr_first[2]+1-LenP[2]-16>64)||(adr_last[2]-adr_first[2]+1-LenP[2]-16<0))
|
576 |
|
|
{
|
577 |
|
|
flag_len[2]=1;
|
578 |
|
|
er_pack_Len+=1;
|
579 |
|
|
fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
|
580 |
|
|
" : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<<
|
581 |
|
|
packet_type[num_type]<<dec<<"\n";
|
582 |
|
|
}
|
583 |
cafagna |
1.1 |
if ( (flag_len[2]!=1)&&(flag_CRC_H[2]!=1) )
|
584 |
|
|
{adr_last[2]=adr_first[2]+LenP[2]+15;}
|
585 |
|
|
temp[1]=adr_last[2];
|
586 |
|
|
for (i=0;i<4;i++) Byte_adr2[i]=0;
|
587 |
|
|
for (i=0;i<4;i++)
|
588 |
|
|
{if (temp[1]/(long int)(pow(256.,3-i))>=1)
|
589 |
|
|
{Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));
|
590 |
|
|
temp[1]=temp[1]-(long int)pow(256.,3-i)*
|
591 |
|
|
(int)(temp[1]/(long int)(pow(256.,3-i)));}}
|
592 |
|
|
|
593 |
|
|
/*********PAMELA LAST PACKET LENGTH ERROR ANALYSIS*****************/
|
594 |
|
|
|
595 |
cafagna |
1.3 |
//Write last packet end displacement in log file
|
596 |
cafagna |
1.1 |
for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));
|
597 |
|
|
|
598 |
|
|
//Write error number in log and work.dat files
|
599 |
|
|
flags=(short int)(pow((float)(2*flag_CRC_H[2]),1)+
|
600 |
cafagna |
1.3 |
pow((float)(2*flag_len[2]),2)+
|
601 |
cafagna |
1.1 |
pow((float)(2*flag_pack[2]),3)+
|
602 |
|
|
pow((float)(2*flag_name[2]),4)+
|
603 |
cafagna |
1.3 |
pow((float)(2*flag_type[2]),5)+
|
604 |
cafagna |
1.1 |
pow((float)(2*flag_time[2]),6)+
|
605 |
|
|
pow((float)(2*flag_CRC_cor[2]),7));
|
606 |
|
|
if ((flags!=0)&&(N1>0)) er_pack_count+=1;
|
607 |
|
|
fprintf(fo_log,"%1c",char(flags));
|
608 |
cafagna |
1.3 |
//Write error number in work.dat file
|
609 |
|
|
if (flags!=0) fo_work<<"PAMELA packet="<<numP[2]<<" : error flag="<<flags<<"\n";
|
610 |
|
|
|
611 |
cafagna |
1.1 |
|
612 |
|
|
//Write inf file
|
613 |
cafagna |
1.3 |
fprintf(fo_inf,"%lli bytes in initial file %s\n", icount_total, name_in);
|
614 |
cafagna |
1.1 |
icount_int = (int)(icount_total/1024);
|
615 |
|
|
icount_frac= icount_total%1024;
|
616 |
cafagna |
1.3 |
fprintf(fo_inf,"file size= %i,%i kByte \n", icount_int, icount_frac);
|
617 |
|
|
strcpy(ttt,name_in);
|
618 |
|
|
ttt[17]='2';
|
619 |
|
|
fprintf(fo_inf,"%lli bytes in cln2 file %s\n", icount, ttt);
|
620 |
|
|
ratioCln1Cln2=(float)icount/icount_total;
|
621 |
|
|
fprintf(fo_inf,"ratio of sizes of Cln1 and Cln2 files %f\n", ratioCln1Cln2);
|
622 |
cafagna |
1.1 |
|
623 |
|
|
fprintf(fo_inf,"number of identified packets= %i\n", N1);
|
624 |
cafagna |
1.3 |
fprintf(fo_inf,"number of PAMELA missed packets= %i\n",count_miss);
|
625 |
|
|
fprintf(fo_inf,"number of PAMELA double transmitted packets = %i\n",count_sec_miss);
|
626 |
|
|
fprintf(fo_inf,"number of PAMELA packets with CRC error= %i\n",er_pack_CRC);
|
627 |
|
|
fprintf(fo_inf,"number of PAMELA packets with length error= %i\n",er_pack_Len);
|
628 |
|
|
fprintf(fo_inf,"Overall number of PAMELA packets with error= %i\n",er_pack_count);
|
629 |
|
|
fprintf(fo_inf,"number of PAMELA packets with corrected name= %i\n",count_name_cor);
|
630 |
|
|
fprintf(fo_inf,"number of PAMELA packets with non identified type =%i\n",packet_counter[0]);
|
631 |
cafagna |
1.1 |
|
632 |
|
|
for (i=1;i<NumberPack;i++)
|
633 |
|
|
{
|
634 |
|
|
fprintf(fo_inf,"Type %x number of PAMELA packets= %i\n",
|
635 |
|
|
packet_type[i-1], packet_counter[i]);
|
636 |
|
|
}
|
637 |
cafagna |
1.3 |
//Write data in file "nnnnn_mmm_xxx_cln2.pam"
|
638 |
cafagna |
1.1 |
for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
|
639 |
|
|
{fo_pam<<buffer[i];}
|
640 |
|
|
|
641 |
|
|
time(&seconds);
|
642 |
|
|
timeinfo=localtime(&seconds);
|
643 |
|
|
strftime(time_year,5,"%Y",timeinfo);
|
644 |
|
|
strftime(time_month,5,"%m",timeinfo);
|
645 |
|
|
strftime(time_day,5,"%d",timeinfo);
|
646 |
|
|
strcat( strcat(strcat(strcat(strcpy(data_time,time_year),"-"),time_month),"-"),time_day);
|
647 |
|
|
|
648 |
|
|
for (i=strlen(pam)-22;i<=strlen(pam);i++)
|
649 |
|
|
{name_cln2[i-(strlen(pam)-22)]=pam[i];}
|
650 |
|
|
for (i=0;i<strlen(pam)-22;i++)
|
651 |
|
|
{name_path[i]=pam[i];}
|
652 |
|
|
name_path[strlen(pam)-22]='\0';
|
653 |
cafagna |
1.2 |
for (i=0;i<5;i++)
|
654 |
|
|
{cirquit_no[i]=name_cln2[i];}
|
655 |
cafagna |
1.1 |
cirquit_no[5]='\0';
|
656 |
cafagna |
1.3 |
for (i=6;i<9;i++)
|
657 |
|
|
{route_no[i-6]=name_cln2[i];}
|
658 |
cafagna |
1.1 |
route_no[3]='\0';
|
659 |
|
|
file_ready=1;
|
660 |
|
|
file_deleted=0;
|
661 |
|
|
file_archived=0;
|
662 |
|
|
file_proces=0;
|
663 |
cafagna |
1.3 |
if (IndexQ>YODA_flag) file_proces=1;
|
664 |
cafagna |
1.1 |
|
665 |
cafagna |
1.3 |
if (IndexQ>transmit_flag) {flag_to_transmit=1;}
|
666 |
cafagna |
1.1 |
else {flag_to_transmit=0;}
|
667 |
|
|
oss.str("");
|
668 |
|
|
oss << "INSERT INTO FILES (cirquit_n, route_n, counter, qual_index, ready, deleted, date,"
|
669 |
|
|
<< " archived, path, cln2_name, proces_flag, transit_flag)"
|
670 |
|
|
<< " VALUES ('"<< cirquit_no << "','"<< route_no << "','"<<r_counter<<"','"<< IndexQ << "','"
|
671 |
|
|
<< file_ready << "','"<< file_deleted << "','"<< data_time << "','"<< file_archived << "','"
|
672 |
cafagna |
1.3 |
<< name_path << "', '" << name_cln2 << "','"<< file_proces << "','"
|
673 |
cafagna |
1.1 |
<< flag_to_transmit << "')";
|
674 |
cafagna |
1.3 |
if (print_flag>0) cout<<oss.str().c_str()<<" table FILES\n";
|
675 |
|
|
TSQLResult *res=sqlServer->Query(oss.str().c_str());
|
676 |
cafagna |
1.1 |
|
677 |
|
|
flag_sec_trans=0;
|
678 |
|
|
|
679 |
|
|
oss1.str("");
|
680 |
cafagna |
1.3 |
oss1 <<"INSERT INTO FILES1 (my_route, raw_filename, pam_size, ratioCln1Cln2, cirquit_n, route_n, route_real,"
|
681 |
|
|
<<" counter, board_time, Num_all, Num_macro, flag_twice, OBT_first, OBT_last)"
|
682 |
|
|
<<" VALUES ('"<<current_route<<"','"<<name_ini<<"','"<<icount<<"','"<<ratioCln1Cln2<<"','"<<cirquit_no<<"','"
|
683 |
cafagna |
1.1 |
<<route_no<<"','"<<real_route[r_counter]<<"','"<<r_counter
|
684 |
cafagna |
1.3 |
<<"','"<<time_p[2]<<"','"<<N1<<"','"<<packet_counter[28]<<"','"<<flag_sec_trans<<"','"<<time_min<<"','"<<time_max<<"')";
|
685 |
|
|
if (print_flag>0) cout<<oss1.str().c_str()<<" table FILES1\n";
|
686 |
cafagna |
1.1 |
TSQLResult *res3=sqlServer->Query(oss1.str().c_str());
|
687 |
|
|
|
688 |
|
|
// if (conn->Query(oss.str().c_str()) == 0)
|
689 |
|
|
// {
|
690 |
|
|
// printf("ERROR!!!");
|
691 |
|
|
// }
|
692 |
|
|
|
693 |
|
|
delete [] buffer;
|
694 |
|
|
|
695 |
|
|
/***************************************************************/
|
696 |
|
|
fin.close();
|
697 |
cafagna |
1.3 |
fo_work.close();
|
698 |
cafagna |
1.1 |
fclose(fo_log);
|
699 |
|
|
fclose(fo_inf);
|
700 |
|
|
fo_pam.close();
|
701 |
|
|
fclose(fo_miss);
|
702 |
|
|
}
|
703 |
|
|
|