diff --git a/dump1090.h b/dump1090.h index 05648c725..1a90cd346 100644 --- a/dump1090.h +++ b/dump1090.h @@ -331,11 +331,13 @@ struct _Modes { // Internal state struct net_service *beast_verbatim_service; // Beast-format output service, verbatim mode struct net_service *beast_verbatim_local_service; // Beast-format output service, verbatim+local mode + struct net_service *beast_sys_time_service; // Beast-format output service, "cooked" mode, system timestamp struct net_service *beast_cooked_service; // Beast-format output service, "cooked" mode struct net_writer raw_out; // AVR-format output struct net_writer beast_verbatim_out; // Beast-format output, verbatim mode struct net_writer beast_verbatim_local_out; // Beast-format output, verbatim+local mode + struct net_writer beast_sys_time_out; // Beast-format output, "cooked" mode, system timestamp struct net_writer beast_cooked_out; // Beast-format output, "cooked" mode struct net_writer sbs_out; // SBS-format output struct net_writer stratux_out; // Stratux-format output diff --git a/net_io.c b/net_io.c index 21a0ae63f..cac7e59e6 100644 --- a/net_io.c +++ b/net_io.c @@ -272,6 +272,7 @@ void modesInitNet(void) { // we maintain three output services for the different option setting combinations we support // and switch clients between them if they request a change in mode Modes.beast_cooked_service = serviceInit("Beast TCP output (cooked mode)", &Modes.beast_cooked_out, send_beast_heartbeat, READ_MODE_BEAST_COMMAND, NULL, handleBeastCommand); + Modes.beast_sys_time_service = serviceInit("Beast TCP output (cooked mode, system timestamp)", &Modes.beast_sys_time_out, send_beast_heartbeat, READ_MODE_BEAST_COMMAND, NULL, handleBeastCommand); Modes.beast_verbatim_service = serviceInit("Beast TCP output (verbatim mode)", &Modes.beast_verbatim_out, send_beast_heartbeat, READ_MODE_BEAST_COMMAND, NULL, handleBeastCommand); Modes.beast_verbatim_local_service = serviceInit("Beast TCP output (verbatim+local mode)", &Modes.beast_verbatim_local_out, send_beast_heartbeat, READ_MODE_BEAST_COMMAND, NULL, handleBeastCommand); @@ -420,6 +421,23 @@ static void modesSendBeastVerbatimLocalOutput(struct modesMessage *mm) { writeBeastMessage(&Modes.beast_verbatim_local_out, mm->timestampMsg, mm->signalLevel, mm->verbatim, mm->msgbits / 8); } +static void modesSendBeastSysTimeOutput(struct modesMessage *mm, struct aircraft *a) { + // Don't forward mlat messages, unless --forward-mlat is set + if (mm->source == SOURCE_MLAT && !Modes.forward_mlat) + return; + + // Filter some messages from cooked output + // Don't forward 2-bit-corrected messages + if (mm->correctedbits >= 2) + return; + + // Don't forward unreliable messages + if ((a && !a->reliable) && !mm->reliable) + return; + + writeBeastMessage(&Modes.beast_sys_time_out, mm->sysTimestampMsg, mm->signalLevel, mm->msg, mm->msgbits / 8); +} + static void modesSendBeastCookedOutput(struct modesMessage *mm, struct aircraft *a) { // Don't forward mlat messages, unless --forward-mlat is set if (mm->source == SOURCE_MLAT && !Modes.forward_mlat) @@ -1019,6 +1037,7 @@ void modesQueueOutput(struct modesMessage *mm, struct aircraft *a) { modesSendRawOutput(mm, a); modesSendBeastVerbatimOutput(mm); modesSendBeastVerbatimLocalOutput(mm); + modesSendBeastSysTimeOutput(mm, a); modesSendBeastCookedOutput(mm, a); writeFATSVEvent(mm, a); } @@ -1181,6 +1200,8 @@ static void handleOptionsChange(struct client *c) { moveNetClient(c, Modes.beast_verbatim_local_service); else if (c->verbatim_requested) moveNetClient(c, Modes.beast_verbatim_service); + else if (c->sys_time_requested) + moveNetClient(c, Modes.beast_sys_time_service); else moveNetClient(c, Modes.beast_cooked_service); } @@ -1220,6 +1241,14 @@ static int handleBeastCommand(struct client *c, char *p) { c->local_requested = 1; handleOptionsChange(c); break; + case 't': + c->sys_time_requested = 0; + handleOptionsChange(c); + break; + case 'T': + c->sys_time_requested = 1; + handleOptionsChange(c); + break; } return 0; diff --git a/net_io.h b/net_io.h index bf24f1c1e..84c0e5887 100644 --- a/net_io.h +++ b/net_io.h @@ -62,6 +62,8 @@ struct client { int modeac_requested; // 1 if this Beast output connection has asked for A/C int verbatim_requested; // 1 if this Beast output connection has asked for verbatim mode int local_requested; // 1 if this Beast output connection has asked for local-only mode + int sys_time_requested; // 1 if this Beast output connection has asked for message timestamps + // to be from the system clock in milliseconds since epoch }; // Common writer state for all output sockets of one type