@@ -399,6 +399,7 @@ char *dest_file_format_string = NULL;
399399void setup_output_file (void ) {
400400char * gpsheader = NULL , * dest_file_region_parsed = NULL ;
401401struct timeval t ;
402+ struct timespec ts ;
402403struct tm * t2 = NULL ;
403404
404405 gpsheader = (char * ) mem_alloc (2200 );
@@ -429,6 +430,9 @@ struct tm *t2 = NULL;
429430 if (gettimeofday (& t , NULL ) != 0 ) {
430431 log_printf (LOG_ERROR , "ERROR gettimeofday: %s\n" , strerror (errno )); exit (EXIT_FAILURE );
431432 }
433+ if (clock_gettime (CLOCK_REALTIME , & ts ) != 0 ) {
434+ log_printf (LOG_ERROR , "ERROR clock_gettime: %s\n" , strerror (errno )); exit (EXIT_FAILURE );
435+ }
432436 if ((t2 = gmtime (& t .tv_sec ))== NULL ) {
433437 log_printf (LOG_ERROR , "ERROR gmtime: %s\n" , strerror (errno )); exit (EXIT_FAILURE );
434438 }
@@ -779,14 +783,27 @@ void setup_input_network(void) {
779783}
780784
781785void setup_time (void ) {
782- struct timeval t ;
786+ struct timeval tv ;
783787struct tm * t2 ;
788+ struct timespec ts ;
789+ double tv_float = 0 , ts_float = 0 ;
790+ char precision [255 ];
784791
785- if (gettimeofday (& t , NULL )== -1 ) {
792+ if (gettimeofday (& tv , NULL )== -1 ) {
786793 log_printf (LOG_ERROR , "ERROR gettimeofday (setup_time): %s\n" , strerror (errno ));
787794 exit (EXIT_FAILURE );
788795 }
789- if ((t2 = gmtime (& t .tv_sec )) == NULL ) {
796+ if (clock_gettime (CLOCK_REALTIME , & ts ) != 0 ) {
797+ log_printf (LOG_ERROR , "ERROR clock_gettime (setup_time): %s\n" , strerror (errno ));
798+ exit (EXIT_FAILURE );
799+ }
800+
801+ tv_float = tv .tv_sec + (tv .tv_usec /1000000.0 );
802+ ts_float = ts .tv_sec + (ts .tv_nsec /1000000000.0 );
803+ snprintf (precision , 254 , "synchronization granularity of %dμs\n" , (int )floor (fabs (tv_float - ts_float )* 1000000.0 ));
804+ log_printf (LOG_VERBOSE , "%s" , precision );
805+
806+ if ((t2 = gmtime (& tv .tv_sec )) == NULL ) {
790807 log_printf (LOG_ERROR , "ERROR gmtime (setup_time): %s\n" , strerror (errno ));
791808 exit (EXIT_FAILURE );
792809 }
@@ -1048,33 +1065,33 @@ unsigned long count2_plot_filtered = 0;
10481065 count2_plot_filtered ++ ;
10491066 //ast_output_datablock(fs.ptr_raw, fs.size_datablock, count2_plot_processed, 0);
10501067 if ( fd_out_gps != -1 ) {
1051- if ( write (fd_out_gps , fs .ptr_raw , fs .size_datablock ) == -1 ) {
1068+ if ( write (fd_out_gps , fs .ptr_raw , fs .size_datablock ) != fs . size_datablock ) {
10521069 log_printf (LOG_ERROR , "ERROR writev1->fd_out_gps (fs): %s\n" , strerror (errno ));
10531070 }
10541071 // si el origen es gps, hay que escribir también el offset.
10551072 if ( offset != 0 ) {
1056- if ( write (fd_out_gps , ast_ptr_raw + ast_pos + ast_size_datablock , offset ) == -1 ) {
1073+ if ( write (fd_out_gps , ast_ptr_raw + ast_pos + ast_size_datablock , offset ) != offset ) {
10571074 log_printf (LOG_ERROR , "ERROR writev1->fd_out_gps (gps): %s\n" , strerror (errno ));
10581075 }
10591076 }
10601077 // nunca se puede dar la condición de que el original sea gps y el destino asterix.
10611078 }
10621079 if ( fd_out_ast != -1 ) {
10631080 // no hay offset que escribir, el origen es asterix, el destino debe ser asterix
1064- if ( write (fd_out_ast , fs .ptr_raw , fs .size_datablock ) == -1 ) {
1081+ if ( write (fd_out_ast , fs .ptr_raw , fs .size_datablock ) != fs . size_datablock ) {
10651082 log_printf (LOG_ERROR , "ERROR write (fs): %s\n" , strerror (errno ));
10661083 }
10671084 }
10681085 mem_free (fs .ptr_raw );
10691086 } else {
10701087 //ast_output_datablock(ast_ptr_raw + ast_pos, ast_size_datablock + offset, count2_plot_processed, 0);
10711088 if ( fd_out_gps != -1 ) {
1072- if ( write (fd_out_gps , ast_ptr_raw + ast_pos , ast_size_datablock + offset ) == -1 ) {
1089+ if ( write (fd_out_gps , ast_ptr_raw + ast_pos , ast_size_datablock + offset ) != ( ast_size_datablock + offset ) ) {
10731090 log_printf (LOG_ERROR , "ERROR writev2->fd_out_gps (ast_ptr_raw): %s\n" , strerror (errno ));
10741091 }
10751092 }
10761093 if ( fd_out_ast != -1 ) {
1077- if ( write (fd_out_ast , ast_ptr_raw + ast_pos , ast_size_datablock ) == -1 ) {
1094+ if ( write (fd_out_ast , ast_ptr_raw + ast_pos , ast_size_datablock ) != ast_size_datablock ) {
10781095 log_printf (LOG_ERROR , "ERROR writev2->fd_out_ast (ast_ptr_raw): %s\n" , strerror (errno ));
10791096 }
10801097 }
@@ -1335,10 +1352,8 @@ unsigned long count2_plot_filtered = 0;
13351352
13361353 if (mode_scrm || dest_screen_crc ) {
13371354 crc = crc32 (ast_ptr_raw_tmp , ast_size_datablock );
1338- if (dest_screen_crc ) {
1339- ast_output_datablock (ast_ptr_raw_tmp , ast_size_datablock , count2_plot_processed , 0 );
1340- log_printf (LOG_VERBOSE , "%3.4f [%08X]\n" , current_time_today , crc );
1341- }
1355+ // para incluir el tamaño en el cálculo del crc
1356+ crc = crc32_update (crc , (const unsigned char * )& ast_size_datablock ,sizeof (ast_size_datablock )) ^ 0xffffffff ;
13421357 }
13431358
13441359 if (mode_scrm ) {
@@ -1353,10 +1368,24 @@ unsigned long count2_plot_filtered = 0;
13531368 RBDelete (tree , node_old );
13541369 }
13551370 RBTreeInsert (tree , crc , current_timestamp );
1371+ if (dest_screen_crc ) {
1372+ int jj = 0 ;
1373+ printf ("+ %08X " , crc );
1374+ for (jj = 0 ; jj < udp_size ; jj ++ )
1375+ printf ("%02X" , ast_ptr_raw [jj ]);
1376+ printf (" (%3.4f)\n" , current_time_today );
1377+ }
13561378 } else {
13571379 node -> access ++ ;
13581380 record = false; // so dupes are ignored
13591381 count2_plot_duped ++ ;
1382+ if (dest_screen_crc ) {
1383+ int jj = 0 ;
1384+ printf ("- %08X " , crc );
1385+ for (jj = 0 ; jj < udp_size ; jj ++ )
1386+ printf ("%02X" , ast_ptr_raw [jj ]);
1387+ printf (" (%3.4f)\n" , current_time_today );
1388+ }
13601389 }
13611390 // RBTreePrint(tree);
13621391 }
@@ -1390,7 +1419,7 @@ unsigned long count2_plot_filtered = 0;
13901419 }
13911420 if (dest_file != NULL && record ) {
13921421 if ((dest_file_format & DEST_FILE_FORMAT_AST ) == DEST_FILE_FORMAT_AST ) {
1393- if ( (write (fd_out_ast , ast_ptr_raw_tmp , ast_size_datablock ) ) == -1 ) {
1422+ if ( (write (fd_out_ast , ast_ptr_raw_tmp , ast_size_datablock ) ) == ast_size_datablock ) {
13941423 log_printf (LOG_ERROR , "ERROR write_ast: %s (%d)\n" , strerror (errno ), fd_out_ast );
13951424 }
13961425 }
@@ -1536,4 +1565,3 @@ unsigned long count2_plot_filtered = 0;
15361565
15371566 return 0 ;
15381567}
1539-
0 commit comments