From e6c2edb6064da2574f5553919144db61d1d99550 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sun, 15 Sep 2024 22:10:44 +0200 Subject: [PATCH] serial_debug --- net_io.c | 8 +++++++- readsb.c | 3 +++ readsb.h | 1 + sdr_beast.c | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/net_io.c b/net_io.c index 30e4fd81..cb53b650 100644 --- a/net_io.c +++ b/net_io.c @@ -4439,6 +4439,10 @@ static int readClient(struct client *c, int64_t now) { } else { // read instead of recv for modesbeast / gns-hulc .... nread = read(c->fd, c->buf + c->buflen, left); + if (Modes.debug_serial) { + fprintTimePrecise(stderr, now); + fprintf(stderr, " serial read return value: %d\n", nread); + } } int err = errno; @@ -5416,7 +5420,9 @@ void modesNetPeriodicWork(void) { Modes.services_in.event_progress = 0; Modes.services_out.event_progress = 0; - //fprintTimePrecise(stderr, now); fprintf(stderr, " event count %d wait_ms %d\n", Modes.net_event_count, (int) wait_ms); + if (Modes.debug_serial) { + fprintTimePrecise(stderr, now); fprintf(stderr, " event count %d wait_ms %d\n", Modes.net_event_count, (int) wait_ms); + } if (0 && Modes.net_event_count > 0) { fprintTimePrecise(stderr, now); fprintf(stderr, " event count %d wait_ms %d\n", Modes.net_event_count, (int) wait_ms); diff --git a/readsb.c b/readsb.c index 8292d919..4de6bafd 100644 --- a/readsb.c +++ b/readsb.c @@ -1972,6 +1972,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { if (strcasecmp(token[0], "debugGPS") == 0) { Modes.debug_gps = 1; } + if (strcasecmp(token[0], "debugSerial") == 0) { + Modes.debug_serial = 1; + } if (strcasecmp(token[0], "debugZstd") == 0) { Modes.debug_zstd = 1; } diff --git a/readsb.h b/readsb.h index 06064c11..533b59f1 100644 --- a/readsb.h +++ b/readsb.h @@ -639,6 +639,7 @@ struct _Modes int8_t mode_ac; // Enable decoding of SSR Modes A & C int8_t mode_ac_auto; // allow toggling of A/C by Beast commands int8_t debug_net; + int8_t debug_serial; int8_t debug_flush; int8_t debug_no_discard; int8_t debug_nextra; diff --git a/sdr_beast.c b/sdr_beast.c index d3e43056..ffd0ea22 100644 --- a/sdr_beast.c +++ b/sdr_beast.c @@ -136,7 +136,11 @@ bool beastOpen(void) { struct termios tios; speed_t baud = B3000000; - Modes.beast_fd = open(Modes.beast_serial, O_RDWR | O_NOCTTY); + int flags = O_RDWR | O_NOCTTY; + if (Modes.debug_serial) { + flags |= O_NONBLOCK; + } + Modes.beast_fd = open(Modes.beast_serial, flags); if (Modes.beast_fd < 0) { fprintf(stderr, "Failed to open serial device %s: %s\n", Modes.beast_serial, strerror(errno));