From 1a9811d2d5bd09c636eadbe79e0d087dacee5711 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Fri, 3 Oct 2014 02:50:28 +0000 Subject: [PATCH] faup1090 now exits if it loses its connection Before this if dump1090 restarted for some reason then faup1090 will sit there indefinitely "looking" stupid and passing no data to piaware, even after dump1090 comes back up. Much gratitude to Oliver Jowett (github user mutability) for the fix. --- dump1090.h | 1 + faup1090.c | 7 +++++++ net_io.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/dump1090.h b/dump1090.h index 8b9d564..50b7b15 100644 --- a/dump1090.h +++ b/dump1090.h @@ -362,6 +362,7 @@ struct { // Internal state unsigned int stat_fatsv_connections; unsigned int stat_raw_connections; unsigned int stat_beast_connections; + unsigned int stat_beast_connections_in; unsigned int stat_out_of_phase; unsigned int stat_ph_demodulated0; unsigned int stat_ph_demodulated1; diff --git a/faup1090.c b/faup1090.c index 21b336b..8b98d58 100644 --- a/faup1090.c +++ b/faup1090.c @@ -289,6 +289,12 @@ void backgroundTasks(void) { if (Modes.interactive) { interactiveShowData(); } + + // If we have lost our input connection, exit + if (Modes.stat_beast_connections_in == 0) { + fprintf(stderr, "Lost ADS-B data connection, exiting.\n"); + Modes.exit = 1; + } } // @@ -394,6 +400,7 @@ int main(int argc, char **argv) { c->service = Modes.bis = fd; Modes.clients = c; + Modes.stat_beast_connections_in = 1; while (Modes.net_only) { if (Modes.exit) exit(0); // If we exit net_only nothing further in main() diff --git a/net_io.c b/net_io.c index 7b06a8a..1c9f43f 100644 --- a/net_io.c +++ b/net_io.c @@ -131,6 +131,7 @@ struct client * modesAcceptClients(void) { if (*services[j].socket == Modes.sbsos) Modes.stat_sbs_connections++; if (*services[j].socket == Modes.ros) Modes.stat_raw_connections++; if (*services[j].socket == Modes.bos) Modes.stat_beast_connections++; + if (*services[j].socket == Modes.bis) Modes.stat_beast_connections_in++; if (*services[j].socket == Modes.fatsvos) Modes.stat_fatsv_connections++; j--; // Try again with the same listening port @@ -171,6 +172,8 @@ void modesFreeClient(struct client *c) { if (Modes.stat_raw_connections) Modes.stat_raw_connections--; } else if (c->service == Modes.bos) { if (Modes.stat_beast_connections) Modes.stat_beast_connections--; + } else if (c->service == Modes.bis) { + if (Modes.stat_beast_connections_in) Modes.stat_beast_connections_in--; } else if (c->service == Modes.fatsvos) { if (Modes.stat_fatsv_connections) Modes.stat_fatsv_connections--; }