Skip to content

Commit bca0f51

Browse files
committed
handle write errors, added filtersacsicout, use clock_gettime
1 parent 2e3807c commit bca0f51

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.75
2+
- BUG: el tamano del paquete se tiene en cuenta en el
3+
calculo del CRC, deberia disminuir los falsos positivos.
4+
- SOPORTE: uso clock_gettime instead of gettimeofday.
5+
- ADD: añadida filtersicsacout
6+
17
0.74
28
- SOPORTE: añadido un conversor entre GPS y versión asterix
39
de ERA.

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ for destarch in $destarchs; do
113113
gcc $gccopts -o bin/client${destarch}${arch} src/client.c src/sacsic.c src/helpers.c src/startup.c $rnopts
114114
gcc $gccopts -o bin/cleanast${destarch}${arch} src/utils/cleanast.c $rnopts
115115
gcc $gccopts -o bin/filtersacsic${destarch}${arch} src/utils/filtersacsic.c $rnopts
116+
gcc $gccopts -o bin/filtersacsicout${destarch}${arch} src/utils/filtersacsicout.c $rnopts
116117
gcc $gccopts -o bin/filtercat${destarch}${arch} src/utils/filtercat.c $rnopts
117118
gcc $gccopts -o bin/filtercatout${destarch}${arch} src/utils/filtercatout.c $rnopts
118119
gcc $gccopts -o bin/joingps${destarch}${arch} src/utils/joingps.c $rnopts

include/defines.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ along with reader_network. If not, see <http://www.gnu.org/licenses/>.
2222
*/
2323

2424

25-
#define VERSION "0.74"
25+
#define VERSION "0.75"
2626
#define COPYRIGHT_NOTICE " v%s Copyright (C) 2002 - 2019 Diego Torres\n\n" \
2727
"This program comes with ABSOLUTELY NO WARRANTY.\n" \
2828
"This is free software, and you are welcome to redistribute it\n" \
@@ -55,7 +55,7 @@ along with reader_network. If not, see <http://www.gnu.org/licenses/>.
5555

5656
#define SELECT_TIMEOUT 10
5757

58-
#define SCRM_MAX_QUEUE_SIZE 5000
58+
#define SCRM_MAX_QUEUE_SIZE 2500
5959
#define SCRM_TIMEOUT 4
6060

6161
#define DEST_FILE_FORMAT_UNKNOWN 1

src/reader_network.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ char *dest_file_format_string = NULL;
399399
void setup_output_file(void) {
400400
char *gpsheader = NULL, *dest_file_region_parsed = NULL;
401401
struct timeval t;
402+
struct timespec ts;
402403
struct 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

781785
void setup_time(void) {
782-
struct timeval t;
786+
struct timeval tv;
783787
struct 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-

src/utils/filtercatout.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ int main(int argc, char *argv[]) {
7979
while( i<filesize ) {
8080
int oldi = i;
8181
int match = 0;
82-
83-
//int j;
82+
// int j = 0;
8483

8584
i += prebytes;
8685
lendb = (ptr[i+1]<<8) + ptr[i+2] + postbytes;
@@ -90,8 +89,8 @@ int main(int argc, char *argv[]) {
9089
match=1;
9190
}
9291

93-
//printf("cat(%02X) len(%d) pre(%d) post(%d)\n", ptr[i], lendb - prebytes - postbytes, prebytes,postbytes);
94-
//for(j=0;j<lendb+prebytes+postbytes;j++) printf("%02X ", ptr[i+j-prebytes]); printf("==\n\n");
92+
// printf("cat(%02X) len(%d) pre(%d) post(%d)\n", ptr[i], lendb - prebytes - postbytes, prebytes,postbytes);
93+
// for(j=0;j<lendb+prebytes+postbytes;j++) printf("%02X ", ptr[i+j-prebytes]); printf("==\n\n");
9594

9695
if (match) {
9796
if (write(fdout, ptr + oldi, lendb) != lendb) {

0 commit comments

Comments
 (0)