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

Contents of /rawreader/src/Read.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sun Dec 10 12:21:23 2006 UTC (18 years ago) by cafagna
Branch: MAIN
CVS Tags: v1r12
Changes since 1.1: +65 -265 lines
*** empty log message ***

1 #include "descript.h"
2 #include "flag.h"
3
4 void filename(char [], char [], char [], char[], int, char[]);
5 void FindRoute(int[], int*);
6 short int CRC(int []);
7 int restrict(int [], long long int[], int);
8
9 void read(char fni[], char fno[], char INF[],
10 char protocol[], char path[], char name[], char nnnnn_TMP[], float quality[], int real_route[], int &Rcount)
11 {
12 FILE *fo, *fout, *foRout, *foMiss, *fo_log_kadr, *fo_route;
13 ifstream fin;
14 ofstream fo_cln1, fokadr_cln1;
15
16 char buf[1024];
17 // char stop1;
18 char ch1,ch2,ch3, ch;
19 char file_route[80]; /*protocol binary filesm mmm_counter_nnnnn_cln1Er.log*/
20 char miss_file[80]; /*protocol files mmm_counter_nnnnn_mis_cln1.dat*/
21 char cln1_file[80]; /*route binary data files mmm_counter_nnnnn_cln1.pam*/
22 char cln1_kadr[80]; /*route binary data files mmm_counter_nnnnn_cln1.bin*/
23 char log_kadr[80]; /*log binary data files mmm_counter_nnnnn_cln1.log*/
24 char log_route[80]; /*log binary file for number of routes*/
25 char Short_Buf[8], Name_Buf[4];
26 short int CalcCheckSum;
27
28 int LenthBuf=1015, flag_help=0;
29 int i, j, k, file_length=0, Hex[3];
30 int N_er=0; /*Number of kadr with name error*/
31 int CRC0_er=0; /*Number of kadr with CRC0 error*/
32 int P_er=0; /*Number of kadr with packet error number*/
33 int M_er=0; /*Number of kadr with rout error number*/
34 int end=0; /*End of last pamela packet*/
35 // Buffers for Kadr analysis
36 int buffer1[1024], buffer2[1024], buffer3[1024];
37 int rr=0;
38
39 int header1, header2, header3, CRC_0[3], CRC_1[3];
40 long long int icount_int;
41 long long int icount_frac, tmpP, numP[3];
42 long int N1=0; /* Number of identified kadrs*/
43 long long int icount=0; /* Number of bytes in identified kadrs*/
44 long long int icount_total=0; /* Total number of bytes*/
45 long long int packet_first[100];/*First kadr number for each route*/
46 long long int packet_last[100]; /*Second kadr number for each route*/
47 long int count_missed[100]; /* Number of missed kadrs in each route*/
48 long int count_sec_missed[100];
49 unsigned long long int count_ident[100]; /* Number of good bytes in each rout*/
50 unsigned long long int count_tot[100]; /* Total number of bytes in each rout*/
51 int NumRout[1000]; /* Number of Route*/
52 long long int Num_kadrs[1000]; /* Number of identified kadrs in each rout*/
53 long int Num_good_kadrs[1000]; /* Number of normal kadrs in each rout*/
54 long long int Num_bad_kadrs[1000]; /* Bad kadrs number in each rout*/
55 // float quality[100]; /* File quality pointer*/
56 int counter=0; /* Last byte position in truncated kadr*/
57 int adr1=0; /* Initial byte of kadr in cln1.bin*/
58 int adr2=0; /* Last byte of kadr in cln2.bin*/
59 int tmp=0;
60 int numPack[4]; /* Number of kadr in given route*/
61 int good_pack=0;
62 int good_number=0;
63 int good_route=0;
64 int adress[4];
65 int R_er[100]; /* Rout errors number in given rout*/
66 int R_er_interf1[100]; /* Interface Rout error at begin of rout*/
67 int R_er_interf2[100]; /* Interface Rout error at end of rout*/
68 int Mis_group[1000]; /* Number of missed kadrs group
69 for each route*/
70 int Pack_Er[1000]; /* Number of packets with packet number
71 error for each route*/
72 int CRC_bad_kadr[3]; /* Current CRC bad kadr number*/
73 int flag_pack[3]; /* Flag for error in packet number*/
74 int flag_rout[3]; /* Flag for error in rout number*/
75 int flag_name[3]; /* Flag for name error*/
76 int flag_CRC0[3]; /* Flag for CRC0 error*/
77 int flag_CRC[3]; /* Flag for CRC error*/
78 int flag_CRC_cor[3]; /* Flag for CRC error correction*/
79 int flag_tr[3]; /* Truncate flag*/
80 short int flags; /* Number for all errors*/
81
82 for (j=0; j<4; j++) {adress[j]=0; numPack[j]=0;}
83 for (j=0; j<1024; j++)
84 {buffer1[j]=0; buffer2[j]=0; buffer3[j]=0;}
85 for (i=0; i<100; i++)
86 {Num_kadrs[i]=0;
87 NumRout[i]=0;
88 packet_first[i]=0;
89 packet_last[i]=0;
90 count_missed[i]=0;
91 count_sec_missed[i]=0;
92 count_ident[i]=0;
93 count_tot[i]=0;
94 R_er[i]=0;
95 R_er_interf1[i]=0;
96 Num_bad_kadrs[i]=0;
97 Num_good_kadrs[i]=0;
98 quality[i]=0; Mis_group[i]=0; Pack_Er[i]=0;
99 R_er_interf2[i]=0;}
100 for (i=0; i<3; i++)
101 {numP[i]=0; CRC_bad_kadr[i]=0; Hex[i]=0;
102 flag_pack[i]=0; flag_rout[i]=0;
103 flag_name[i]=0; flag_CRC0[i]=0; flag_tr[i]=0;
104 flag_CRC[i]=0; flag_CRC_cor[i]=0;}
105 // open input file "nnnnnmmm.pam"
106 fin.open(fni, ifstream::binary);
107 if(fin.good()==0) {cerr<<"can not open input file"; exit(0);}
108 //open output file "nnnnnmmm_work.dat"
109 fout=fopen(fno, "wb");
110 if(fout==0) {cerr<<"can not open outputfile"; exit(0);}
111 //open output file "nnnnnmmm_protocol.txt"
112 fo=fopen(protocol, "wb");
113 if(fo==0) {cerr<<"can not open protocol file"; exit(0);}
114 //open output file "nnnnnmmm_route.log"
115 strncpy(log_route,INF,strlen(INF)-9);
116 log_route[strlen(INF)-9]='\0';
117 strcat(log_route,"_route.log");
118 fo_route=fopen(log_route, "wb");
119 if(fo_route==0) {cerr<<"can not open file for routes number"; exit(0);}
120 /////////////////////////////////////////////////////////////////
121 // cin>>stop1;
122 k=0;
123 while(fin.eof()==0)
124 {
125 counter=0; //pounter for position of kadr truncation
126 N_er=0;
127 M_er=0;
128 P_er=0;
129 CRC0_er=0;
130 if (N1==0) Rcount=1;
131 /**********************data reading********************************/
132 fin.read(Name_Buf,3);
133 if (fin.eof()) break;
134 fin.read(Short_Buf,5);
135 if (fin.eof()) break;
136 ch1=Name_Buf[0];
137 ch2=Name_Buf[1];
138 ch3=Name_Buf[2];
139 tmpP=(long int)(unsigned char)(Short_Buf[1])+
140 256*(long int)(unsigned char)(Short_Buf[2])+
141 256*256*(long int)(unsigned char)(Short_Buf[3]);
142 icount+=8; icount_total+=8;
143 count_ident[Rcount-1]+=8; count_tot[Rcount-1]+=8;
144
145 while((ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&
146 (N1==0||buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])))
147 ||
148 (ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)&&(buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||(numP[2]+1)!=tmpP))
149 ||
150 (ch3!=(char)(CODE3)&&ch1!=(char)(CODE1)&&((numP[2]+1)!=tmpP||buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])))
151 ||
152 (ch1!=(char)(CODE1)&&
153 (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
154 ||
155 (ch2!=(char)(CODE2)&&
156 (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
157 ||
158 (ch3!=(char)(CODE3)&&
159 (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
160 ||
161 (ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)))
162 {fin.get(ch);
163 if (fin.eof()) {break;}
164 ch1=ch2; ch2=ch3; ch3=Short_Buf[0];
165 for (i=0;i<4;i++) Short_Buf[i]=Short_Buf[i+1]; Short_Buf[4]=ch;
166 icount_total+=1; count_tot[Rcount-1]+=1;
167 tmpP=(long int)(unsigned char)(Short_Buf[1])+
168 256*(long int)(unsigned char)(Short_Buf[2])+
169 256*256*(long int)(unsigned char)(Short_Buf[3]);
170 }
171 if ((fin.eof())&&(N1==0))
172 {
173 fclose(fout);
174 remove(fno);
175 fclose(fo);
176 remove(protocol);
177 remove(INF);
178 exit(0);
179 }
180
181 /*****************************************************************/
182 /*********************data reading********************************/
183 fin.read(buf,LenthBuf);
184 if (fin.eof()) break;
185 icount+=1015; icount_total+=1015;
186 count_ident[Rcount-1]+=1015; count_tot[Rcount-1]+=1015;
187 /****************************************************************/
188 /********************data reading********************************/
189 fin.get(ch);
190 icount+=1; icount_total+=1;
191 count_ident[Rcount-1]+=1; count_tot[Rcount-1]+=1;
192 if (fin.eof()) break;
193 /***************************************************************/
194 N1+=1; Num_kadrs[Rcount-1]+=1;
195
196 /**********************DATA ANALYSIS****************************/
197 /***************************************************************/
198 header1=(unsigned char)(ch1);
199 header2=(unsigned char)(ch2);
200 header3=(unsigned char)(ch3);
201 switch (N1)
202 {
203 case 1:{
204 buffer3[0]=(int)(unsigned char)(ch1);
205 buffer3[1]=(int)(unsigned char)(ch2);
206 buffer3[2]=(int)(unsigned char)(ch3);
207 buffer3[3]=(int)(unsigned char)(Short_Buf[0]);
208 buffer3[4]=(int)(unsigned char)(Short_Buf[1]);
209 buffer3[5]=(int)(unsigned char)(Short_Buf[2]);
210 buffer3[6]=(int)(unsigned char)(Short_Buf[3]);
211 buffer3[7]=(int)(unsigned char)(Short_Buf[4]);
212 for (i=0; i<1015; i++)
213 {buffer3[i+8]=(int)(unsigned char)(buf[i]);}
214 buffer3[1023]=(int)(unsigned char)(ch);
215 for (i=0; i<1024; i++)
216 {buffer1[i]=buffer3[i];buffer2[i]=buffer3[i];}
217
218 NumRout[Rcount-1]=1;
219 numP[2]=(long int)(unsigned char)(Short_Buf[1])+
220 256*(long int)(unsigned char)(Short_Buf[2])+
221 256*256*(long int)(unsigned char)(Short_Buf[3]);
222 CRC_bad_kadr[2]=0;
223 flag_pack[2]=0; flag_rout[2]=0;
224 flag_name[2]=0; flag_CRC0[2]=0; flag_tr[2]=0;
225 flag_CRC[2]=0; flag_CRC_cor[2]=0;
226 for (i=0; i<2; i++)
227 {numP[i]=numP[2];CRC_bad_kadr[i]=CRC_bad_kadr[2];
228 flag_pack[i]=flag_pack[2]; flag_rout[i]=flag_rout[2];
229 flag_name[i]=flag_name[2]; flag_CRC0[i]=flag_CRC0[2];
230 flag_CRC[i]=flag_CRC[2]; flag_tr[i]=flag_tr[2];
231 flag_CRC_cor[i]=flag_CRC_cor[2];}
232 CRC_0[2]=(int)(unsigned char)(Short_Buf[4]);
233 for (i=0; i<2; i++)
234 {CRC_0[i]=CRC_0[2];}
235 CRC_1[2]=(int)(unsigned char)(ch);
236 for (i=0; i<2; i++)
237 {CRC_1[i]=CRC_1[2];}
238 packet_first[Rcount-1]=numP[2];
239 break;
240 }
241 default:{
242 for (i=0; i<1024; i++)
243 {buffer1[i]=buffer2[i];buffer2[i]=buffer3[i];}
244 buffer3[0]=(int)(unsigned char)(ch1);
245 buffer3[1]=(int)(unsigned char)(ch2);
246 buffer3[2]=(int)(unsigned char)(ch3);
247 buffer3[3]=(int)(unsigned char)(Short_Buf[0]);
248 buffer3[4]=(int)(unsigned char)(Short_Buf[1]);
249 buffer3[5]=(int)(unsigned char)(Short_Buf[2]);
250 buffer3[6]=(int)(unsigned char)(Short_Buf[3]);
251 buffer3[7]=(int)(unsigned char)(Short_Buf[4]);
252 for (i=0; i<1015; i++)
253 {buffer3[i+8]=(int)(unsigned char)(buf[i]);}
254 buffer3[1023]=(int)(unsigned char)(ch);
255
256 for (i=0; i<2; i++)
257 {numP[i]=numP[i+1]; CRC_bad_kadr[i]=CRC_bad_kadr[i+1];
258 flag_pack[i]=flag_pack[i+1];
259 flag_rout[i]=flag_rout[i+1];
260 flag_name[i]=flag_name[i+1];
261 flag_CRC0[i]=flag_CRC0[i+1];
262 flag_tr[i]=flag_tr[i+1];
263 flag_CRC[i]=flag_CRC[i+1];
264 flag_CRC_cor[i]=flag_CRC_cor[i+1];}
265 numP[2]=(long int)(unsigned char)(Short_Buf[1])+
266 256*(long int)(unsigned char)(Short_Buf[2])+
267 256*256*(long int)(unsigned char)(Short_Buf[3]);
268 CRC_bad_kadr[2]=0;
269 flag_pack[2]=0; flag_rout[2]=0;
270 flag_name[2]=0; flag_CRC0[2]=0;
271 flag_CRC[2]=0; flag_CRC_cor[2]=0; flag_tr[2]=0;
272 for (i=0; i<2; i++) CRC_0[i]=CRC_0[i+1];
273 CRC_0[2]=(int)(unsigned char)(Short_Buf[4]);
274 for (i=0; i<2; i++) {CRC_1[i]=CRC_1[i+1];}
275 CRC_1[2]=(int)(unsigned char)(ch);
276 }
277 }
278 // if (fmod(N1,10000)==0.) cout<<N1<<"\n";
279
280 /******************CRC ERROR ANALYSIS***************************/
281 CalcCheckSum=CRC(buffer3);
282 if (CalcCheckSum!=(short int)(buffer3[1023]))
283 {
284 /*if (numP[2]==1026)
285 {for (i=0;i<8;i++) printf(" %x ",buffer3[i]); printf("\n");
286 for (i=8;i<16;i++) printf(" %x ",buffer3[i]); printf("\n");
287 for (i=1000;i<1008;i++) printf(" %x ",buffer3[i]); printf("\n");
288 printf("%x %x %x %x",buffer3[1020],buffer3[1021],buffer3[1022],buffer3[1023]);
289 cin>>i;}*/
290 fprintf(fout,"CRC = %x (%x) error in kadr %i\n", buffer3[1023],CalcCheckSum,numP[2]); //write in file nnnnn_work.dat
291
292 flag_CRC[2]=1;
293 Num_bad_kadrs[Rcount-1]+=1;
294 CRC_bad_kadr[2]=numP[2];
295 counter=restrict(buffer3,numP,buffer2[3]);
296 if (counter!=0)
297 {fprintf(fout," truncate byte=%i",counter);
298 // cout<<" truncate counter="<<counter<<" route="<<buffer2[3]<<" "<<buffer3[3]<<" kadr="<<numP[2]<<" "<<numP[1]<<" "<<numP[0]<<"\n";
299 fin.seekg(-(1024-counter),ios::cur);
300 icount-=1024;
301 count_ident[Rcount-1]-=1024;
302 count_tot[Rcount-1]-=1024-counter;
303 icount_total-=1024-counter;
304 N1-=1;
305 CRC_bad_kadr[2]=0;
306 flag_tr[2]=1;
307 Num_kadrs[Rcount-1]-=1;
308 Num_bad_kadrs[Rcount-1]-=1;}
309 }
310
311 /******************HEADER ANALYSIS*******************************/
312 if ((header1!=(int)(CODE1))||(header2!=(int)(CODE2))||(header3!=(int)(CODE3)))
313 {flag_name[2]=1; N_er=N1;}
314 /****************************************************************/
315
316 /******************CRC0 ANALYSIS*********************************/
317 if ((buffer2[7]!=buffer1[1023])&&
318 ((numP[1]==numP[0]+1)||(numP[1]==numP[2]-1))&&(flag_tr[1]!=1)&&(flag_tr[0]!=1)&&(N1>2))
319 {flag_CRC0[1]=1; CRC0_er=N1-1;}
320 /****************************************************************/
321
322 /******************KADR NUMBER ANALYSIS**************************/
323 if ((numP[1]!=(numP[0]+1))&&(numP[1]!=(numP[2]-1))&&(N1!=1)&&(CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
324 {P_er=N1-1; flag_pack[1]=1;
325 //Correct error packet number//
326 tmpP=numP[0]+1;
327 for (i=0;i<3;i++) Hex[i]=0;
328 for (i=0;i<3;i++)
329 {if (tmpP/(long int)(pow(256.,2-i))>=1)
330 {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
331 tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));}}
332 for (i=4;i<7;i++) (buffer2[i]=Hex[i-4]);
333 if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
334
335 tmpP=numP[2]-1;
336 for (i=0;i<3;i++) Hex[i]=0;
337 for (i=0;i<3;i++)
338 {if (tmpP/(long int)(pow(256.,2-i))>=1)
339 {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
340 tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));}}
341 for (i=4;i<7;i++) (buffer2[i]=Hex[i-4]);
342 if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
343 }
344 /////////////////////////////////////////////////////////////////////
345 if ((numP[2]!=(numP[1]+1))&&(N1!=1)&&(buffer3[3]==buffer2[3])&&(CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) flag_pack[2]=1;
346 if (flag_pack[2]!=1) packet_last[Rcount-1]=numP[2];
347 ////////Missing kadr analysis////////////////////////////////////
348 /**route number: 10 (10 19 10) 10 ******************************/
349 /**kadr number: 21 (22 17 18) 19 ******************************/
350 /**missed kadrs: 21 20 19 18 17 ******************************/
351 if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(buffer1[3]==buffer3[3])&&(flag_tr[1]==0)&&
352 (flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
353 {Mis_group[Rcount-1]+=1;
354 fprintf(foMiss,"secondary transmitted kadres may be %9i%9i\n",numP[1]+1,numP[0]-1);
355 count_sec_missed[Rcount-1]+=numP[0]-1-numP[1]-1;}
356 /**route number: 10 (10 19 10) 10 ******************************/
357 /**kadr number: 11 (12 15 20) 21 ******************************/
358 /**missed kadrs: 16 17 18 19 ******************************/
359 if ((numP[1]>numP[0]+1)&&(numP[1]<numP[2]-1)&&(buffer1[3]==buffer3[3])&&(flag_tr[1]==0)&&
360 (flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
361 {Mis_group[Rcount-1]+=1;
362 fprintf(foMiss,"%9i%9i\n",numP[1]+1,numP[2]-1);
363 count_missed[Rcount-1]+=numP[2]-numP[1]-1;}
364 /**route number: (10 10 10) 10 10 ******************************/
365 /**kadr number: (11 12 15) 20 21 ******************************/
366 /**missed kadrs: 13 14 ******************************/
367 else if ((numP[1]>=numP[0]+1)&&(numP[1]<numP[2]-1)&&
368 (buffer1[3]==buffer3[3])&&(buffer1[3]==buffer2[3])&&
369 (flag_tr[1]==0)&&(flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
370 {Mis_group[Rcount-1]+=1;
371 fprintf(foMiss,"%9i%9i\n",numP[0]+2,numP[2]-1);
372 count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}
373 /**route number: (10 10 10) 10 10 ******************************/
374 /**kadr number: (11 29 15) 14 15 ******************************/
375 /**number of missed kadrs:2 ******************************/
376 else if (((numP[1]<numP[0]+1)||(numP[1]>numP[2]-1))&&(numP[2]-numP[0]>2)&&
377 (buffer1[3]==buffer3[3])&&(buffer1[3]==buffer2[3])&&(flag_tr[1]==0)&&
378 (flag_pack[2]==0)&&(flag_pack[1]==1)&&(flag_pack[0]==0))
379 {Mis_group[Rcount-1]+=1;
380 fprintf(foMiss,"%9i%9i -1\n",numP[0]+1,numP[2]-1);
381 count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}
382 /**route number:10 (10 10 10) 10 10 ******************************/
383 /**kadr number: 1 (11 12 13) 14 15 ******************************/
384 /**number of missed kadrs: 10 ******************************/
385 else if ((N1>1)&&(abs(numP[2]-good_pack-2)>abs(Num_kadrs[Rcount-1]-good_number))&&
386 (buffer2[3]==good_route)&&(flag_tr[2]==0)&&(flag_pack[2]==0))
387 {Mis_group[Rcount-1]+=1;
388 fprintf(foMiss,"%9i%9i \n",good_pack+1,numP[2]-1);
389 count_missed[Rcount-1]+=numP[2]-good_pack-1;
390 }
391 //truncate kadr
392 /**route number: 10 (10 10 10) 10 ******************************/
393 /**kadr number: 11 (12 13 14) 15 ******************************/
394 /**missed truncate kadr:13 ******************************/
395 else if ((numP[0]<numP[2]-1)&&(buffer1[3]==buffer3[3])&&
396 (flag_tr[0]==0)&&(flag_tr[1]==1)&&(flag_tr[2]==0)&&
397 (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
398 {Mis_group[Rcount-1]+=1;
399 fprintf(foMiss,"%9i%9i\n",numP[0]+1,numP[2]-1);
400 count_missed[Rcount-1]+=numP[2]-numP[0]-1;}
401 /***************************************************************/
402
403 if (flag_CRC[2]!=1) {good_pack=numP[2]; good_route=buffer3[3]; good_number=Num_kadrs[Rcount-1];}
404
405 /******************ROUTE NUMBER ANALYSIS**************************/
406 if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&(buffer1[3]!=buffer3[3])&&
407 (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
408 {
409
410 }
411 /**************First route***************************************/
412 /**route number: (0 4) 4*****************************************/
413 /**kadr number: (0 1) 2*****************************************/
414 if (N1==2)
415 {packet_first[Rcount-1]=numP[1];
416 packet_last[Rcount-1]=numP[2];
417 NumRout[Rcount-1]=1;
418 // CREATE FILE NAMES
419 filename(file_route, miss_file, cln1_file, path,
420 NumRout[Rcount-1], name);
421 strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
422 cln1_kadr[strlen(cln1_file)-3]='\0';
423 strcat(cln1_kadr,"bin");
424 strncpy(log_kadr,file_route,strlen(file_route)-6);
425 log_kadr[strlen(file_route)-6]='\0';
426 strcat(log_kadr,"_bin.log");
427 //Open files for new route
428 foRout=fopen(file_route, "wb"); //xxx_mmm_nnnnn_cln1Er.log
429 foMiss=fopen(miss_file, "wb"); //xxx_mmm_nnnnn_mis_cln1.dat
430 fo_cln1.open(cln1_file, ios::binary); //xxx_mmm_nnnnn_cln1.pam
431 if (!fo_cln1) cout<<"can not open "<<cln1_file<<"\n";
432 fokadr_cln1.open(cln1_kadr,ios::binary); //xxx_mmm_nnnnn_cln1.bin
433 if (!fokadr_cln1) cout<<"can not open "<<cln1_kadr<<"\n";
434 fo_log_kadr=fopen(log_kadr,"wb"); //xxx_mmm_nnnnn_cln1_bin.log
435 }
436 /***************New route***************************************/
437 /**route number: 7 ( 7 0 8) 8*********************************/
438 /**kadr number: 199 (200 0 1) 2*********************************/
439 /**route number: 7 ( 7 8 8) 8*********************************/
440 /**kadr number: 199 (200 0 1) 2*********************************/
441 if ( ((buffer1[3]!=buffer3[3])&&(buffer2[3]==0)&&(N1>3)&&(numP[1]!=numP[0]+1)&&(numP[1]<10))||
442 ((buffer1[3]!=buffer2[3])&&(buffer2[3]==buffer3[3])&&(buffer1[3]!=0)&&(numP[1]!=numP[0]+1)&&(numP[1]<10))||
443 ((numP[2]==numP[1]+1)&&(numP[1]==0)&&(Num_kadrs[Rcount-1]>1000000)) )
444 {Rcount+=1;
445 packet_last[Rcount-2]=numP[0];
446 packet_first[Rcount-1]=numP[1];
447 NumRout[Rcount-1]=Rcount;
448 cout<<"New route="<<Rcount<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<"\n";
449 cout<<numP[0]<<" "<<numP[1]<<" "<<numP[2]<<"\n";
450 if (flag_tr[1]==0)
451 {Num_kadrs[Rcount-2]-=2;
452 Num_kadrs[Rcount-1]+=2;
453 count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;
454 count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;}
455 else
456 {Num_kadrs[Rcount-2]-=1;
457 Num_kadrs[Rcount-1]+=1;
458 count_ident[Rcount-1]+=1024; count_ident[Rcount-2]-=1024;
459 count_tot[Rcount-1]+=1024; count_tot[Rcount-2]-=1024;}
460 // CREATE FILE NAMES
461 filename(file_route, miss_file, cln1_file, path,
462 NumRout[Rcount-1], name);
463 strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
464 cln1_kadr[strlen(cln1_file)-3]='\0';
465 strcat(cln1_kadr,"bin");
466 strncpy(log_kadr,file_route,strlen(file_route)-6);
467 log_kadr[strlen(file_route)-6]='\0';
468 strcat(log_kadr,"_bin.log");
469 fclose(foRout); //Close files
470 fo_cln1.close(); //for old
471 fclose(foMiss); //route
472 fokadr_cln1.close();
473 fclose(fo_log_kadr);
474 //Open files for new route
475 foRout=fopen(file_route, "wb"); //xxx_mmm_nnnnn_cln1Er.log
476 foMiss=fopen(miss_file, "wb"); //xxx_mmm_nnnnn_mis_cln1.dat
477 fo_cln1.open(cln1_file, ios::binary); //xxx_mmm_nnnnn_cln1.pam
478 fokadr_cln1.open(cln1_kadr,ios::binary); //xxx_mmm_nnnnn_cln1.bin
479 fo_log_kadr=fopen(log_kadr,"wb"); //xxx_mmm_nnnnn_cln1_bin.log
480 if ((CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;}
481 if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
482 {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;
483 flags=(short int)(pow((float)(2*flag_name[1]),4)+
484 pow((float)(2*flag_rout[1]),1)+
485 pow((float)(2*flag_pack[1]),2)+
486 pow((float)(2*flag_CRC0[1]),3)+
487 pow((float)(2*flag_CRC[1]),5)+
488 pow((float)(2*flag_CRC_cor[1]),6));
489 fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
490 fprintf(fout,"%i New route %i\n",CRC_bad_kadr[1],flags);
491 CRC_bad_kadr[1]=-1;}
492 }
493
494 if (((numP[1]==0)&&(N1>1))||(N1==2))
495 {rr=0;
496 FindRoute(buffer2, &rr);
497 if (rr>0)
498 {
499 real_route[Rcount]=rr;
500 }
501 else
502 {
503 real_route[Rcount]=0;
504 }
505 }
506 /***************************************************************/
507 if (CRC_bad_kadr[1]==numP[1])
508 {
509 //Correct CRC0 error/////////////////////////////////////////////////
510 buffer2[7]=buffer1[1023];
511 if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
512 //Correct name error/////////////////////////////////////////////////
513 buffer2[0]=(int)(CODE1);
514 buffer2[1]=(int)(CODE2);
515 buffer2[2]=(int)(CODE3);
516 if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
517 }
518 ////////////////////////////////////////////////////////////////////
519 /*******************************************************************/
520 if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0)&&(N1>1))
521 {
522 flags=(short int)(pow((float)(2*flag_name[1]),4)+
523 pow((float)(2*flag_rout[1]),1)+
524 pow((float)(2*flag_pack[1]),2)+
525 pow((float)(2*flag_CRC0[1]),3)+
526 pow((float)(2*flag_CRC[1]),5)+
527 pow((float)(2*flag_CRC_cor[1]),6));
528 fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),
529 (char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
530 fprintf(fout,"%i flags=%i\n",CRC_bad_kadr[1],flags);}
531
532 /***************************************************************/
533 //*Packet analysis**********************************************
534 if (N_er!=0) fprintf(fout,"Name error %i in kadr %i\n",numP[2],N_er);
535 if (M_er!=0) fprintf(fout,"Root number error %i in kadr %i\n",numP[1],M_er);
536 if (P_er!=0) fprintf(fout,"Number packet error %i in kadr %i\n",numP[1], P_er);
537 if (CRC0_er!=0) fprintf(fout,"CRC0 error %i in kadr %i\n",numP[1], CRC0_er);
538
539 /***************PAMELA data extracting for each route***********/
540 // if (N1!=1&&(flag_CRC[1]==0||(flag_rout[1]==0&&flag_pack[1]==0)||
541 // (flag_CRC[1]!=0&&flag_CRC_cor[1]==1)))
542 if ((N1!=1)&&(flag_tr[1]==0))
543 {end=0;
544 if (buffer2[3]!=buffer1[3]||buffer2[3]!=buffer3[3])
545 {for (i=8;i<1020;i++)
546 {
547 // if (fmodf(float((Num_kadrs[Rcount-1]-1)*1015+i-8),float(64))==0.&&buffer2[i]==0&&buffer2[i+1]==0&&
548 // buffer2[i+2]==0&&buffer2[i+3]==0) end=1;
549 if (end!=1) fo_cln1<<(unsigned char)buffer2[i];
550 }
551 if (end!=1) for(i=1020;i<1023;i++) {fo_cln1<<(unsigned char)buffer2[i];}
552 }
553 else {for(i=8;i<1023;i++) fo_cln1<<(unsigned char)buffer2[i];}
554 for (i=0;i<1024;i++) {fokadr_cln1<<(unsigned char)buffer2[i];}
555 //Write in file mmm_counter_nnnnn_cln1_bin.log
556 tmp=numP[1];
557 for (k=0;k<4;k++) numPack[k]=0;
558 for (k=0;k<3;k++)
559 {if (tmp/(long int)(pow(256.,2-k))>=1)
560 {numPack[2-k]=(int)(tmp/(long int)(pow(256.,2-k)));
561 tmp=tmp-(long int)pow(256.,2-k)*(int)(tmp/(long int)(pow(256.,2-k)));}}
562 for (i=0;i<3;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
563 adr1=icount-1024*2;
564 for (k=0;k<4;k++) adress[k]=0;
565 for (k=0;k<4;k++)
566 {if (adr1/(long int)(pow(256.,3-k))>=1)
567 {adress[3-k]=(int)(adr1/(long int)(pow(256.,3-k)));
568 adr1=adr1-(long int)pow(256.,3-k)*
569 (int)(adr1/(long int)(pow(256.,3-k)));}}
570 for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
571 adr2=icount-1024;
572 for (k=0;k<4;k++) adress[k]=0;
573 for (k=0;k<4;k++)
574 {if (adr2/(long int)(pow(256.,3-k))>=1)
575 {adress[3-k]=(int)(adr2/(long int)(pow(256.,3-k)));
576 adr2=adr2-(long int)pow(256.,3-k)*
577 (int)(adr2/(long int)(pow(256.,3-k)));}}
578 for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
579 fputc(flags,fo_log_kadr);
580 }
581 }
582 /***************************************************************/
583 /***************************************************************/
584 if (flag_CRC[2]==0||(flag_rout[2]==0&&flag_pack[2]==0)||
585 (flag_CRC[2]!=0&&flag_CRC_cor[2]==1))
586 {end=0;
587 for (i=0;i<1024;i++) fokadr_cln1<<(unsigned char)buffer3[i];
588 //Write in file mmm_counter_nnnnn_cln1_bin.log
589 tmp=numP[2];
590 for (k=0;k<4;k++) numPack[k]=0;
591 for (k=0;k<3;k++)
592 {if (tmp/(long int)(pow(256.,2-k))>=1)
593 {numPack[2-k]=(int)(tmp/(long int)(pow(256.,2-k)));
594 tmp=tmp-(long int)pow(256.,2-k)*
595 (int)(tmp/(long int)(pow(256.,2-k)));}}
596 for (i=0;i<3;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
597 adr1=icount-1024;
598 for (k=0;k<4;k++) adress[k]=0;
599 for (k=0;k<4;k++)
600 {if (adr1/(long int)(pow(256.,3-k))>=1)
601 {adress[3-k]=(int)(adr1/(long int)(pow(256.,3-k)));
602 adr1=adr1-(long int)pow(256.,3-k)*
603 (int)(adr1/(long int)(pow(256.,3-k)));}}
604 for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
605 adr2=icount;
606 for (k=0;k<4;k++) adress[k]=0;
607 for (k=0;k<4;k++)
608 {if (adr2/(long int)(pow(256.,3-k))>=1)
609 {adress[3-k]=(int)(adr2/(long int)(pow(256.,3-k)));
610 adr2=adr2-(long int)pow(256.,3-k)*
611 (int)(adr2/(long int)(pow(256.,3-k)));}}
612 for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
613 fputc(flags,fo_log_kadr);
614
615 for (i=8;i<1019;i++)
616 {
617 // if (fmodf(float((Num_kadrs[Rcount-1]-1)*1015+i-8),
618 // float(64))==0.&&buffer3[i]==0&&buffer3[i+1]==0&&
619 // buffer3[i+2]==0&&buffer3[i+3]==0&&buffer3[i+4]==0) end=1;
620 if (end!=1) fo_cln1<<(unsigned char)buffer3[i];
621 }
622 if (end!=1) {for(i=1019;i<1023;i++) {fo_cln1<<(unsigned char)buffer3[i];}}
623 }
624
625 icount_int = (int)(icount/1024);
626 icount_frac= icount%1024;
627
628 //***protocol file***********************************************
629 file_length=(int)(strlen(name));
630 fprintf(fo,"file name=/home/ntsomz/downlinks/%s\n",name);
631 fprintf(fo,"file size= %i,%i kByte \n", icount_int, icount_frac);
632 fprintf(fo,"number identified cadres= %i\n", N1);
633 fprintf(fo,"number of routes= %i\n", Rcount);
634
635 for (i=0;i<Rcount;i++)
636 {
637 Num_good_kadrs[i]=Num_kadrs[i]-Num_bad_kadrs[i];
638 quality[i]=(float)(1.)-(float)(Num_bad_kadrs[i])/(float)(Num_kadrs[i]);
639 fprintf(fo,"\nRoute number=%i: number of normal cadres= %i: number of errors=%i; \n",NumRout[i],Num_good_kadrs[i],Num_bad_kadrs[i]);
640 fprintf(fo," size of identified cadres =%lli bytes;",count_ident[i]);
641 fprintf(fo," total size of route=%lli bytes;\n",count_tot[i]);
642 fprintf(fo," first cadre number= %lli:", packet_first[i]);
643 fprintf(fo," last cadre number= %lli:", packet_last[i]);
644 fprintf(fo," Number of missed cadres= %i:\n", count_missed[i]);
645 fprintf(fo,"number of identified cadres=%lli: quality index=%f\n", Num_kadrs[i], quality[i]);
646 }
647
648 //***route's number log file**************************************
649 for (i=0;i<Rcount;i++) {fprintf(fo_route,"%1c",(char)(NumRout[i]));}
650
651 //***************************************************************
652 fin.close();
653 fclose(fout);
654 fclose(fo);
655 fclose(foRout);
656 fclose(foMiss);
657 fo_cln1.close();
658 fclose(fo_log_kadr);
659 fokadr_cln1.close();
660 fclose(fo_route);
661 }
662

  ViewVC Help
Powered by ViewVC 1.1.23