diff --git a/dump1090.c b/dump1090.c index 699693d..8fc6f28 100644 --- a/dump1090.c +++ b/dump1090.c @@ -514,6 +514,7 @@ void showHelp(void) { "--net-ro-interval TCP output memory flush rate in seconds (default: 0)\n" "--net-heartbeat TCP heartbeat rate in seconds (default: 60 sec; 0 to disable)\n" "--net-buffer TCP buffer size 64Kb * (2^n) (default: n=0, 64Kb)\n" +"--net-verbatim Do not apply CRC corrections to messages we forward; send unchanged\n" "--lat Reference/receiver latitude for surface posn (opt)\n" "--lon Reference/receiver longitude for surface posn (opt)\n" "--max-range Absolute maximum range for position decoding (in nm, default: 300)\n" @@ -826,6 +827,8 @@ int main(int argc, char **argv) { Modes.net_output_sbs_port = atoi(argv[++j]); } else if (!strcmp(argv[j],"--net-buffer") && more) { Modes.net_sndbuf_size = atoi(argv[++j]); + } else if (!strcmp(argv[j],"--net-verbatim")) { + Modes.net_verbatim = 1; } else if (!strcmp(argv[j],"--onlyaddr")) { Modes.onlyaddr = 1; } else if (!strcmp(argv[j],"--metric")) { diff --git a/dump1090.h b/dump1090.h index f757a1b..55fcf8e 100644 --- a/dump1090.h +++ b/dump1090.h @@ -349,6 +349,7 @@ struct { // Internal state int net_http_port; // HTTP port int net_fatsv_port; // FlightAware TSV port int net_sndbuf_size; // TCP output buffer size (64Kb * 2^n) + int net_verbatim; // if true, send the original message, not the CRC-corrected one int quiet; // Suppress stdout int interactive; // Interactive mode int interactive_rows; // Interactive mode: max number of rows @@ -394,6 +395,7 @@ struct { // Internal state struct modesMessage { // Generic fields unsigned char msg[MODES_LONG_MSG_BYTES]; // Binary message. + unsigned char verbatim[MODES_LONG_MSG_BYTES]; // Binary message, as originally received before correction int msgbits; // Number of bits in message int msgtype; // Downlink format # uint32_t crc; // Message CRC diff --git a/mode_s.c b/mode_s.c index f6c3d91..9344e10 100644 --- a/mode_s.c +++ b/mode_s.c @@ -417,8 +417,12 @@ static char *ais_charset = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./01 int decodeModesMessage(struct modesMessage *mm, unsigned char *msg) { - // Work on our local copy + // Work on our local copy. memcpy(mm->msg, msg, MODES_LONG_MSG_BYTES); + if (Modes.net_verbatim) { + // Preserve the original uncorrected copy for later forwarding + memcpy(mm->verbatim, msg, MODES_LONG_MSG_BYTES); + } msg = mm->msg; // Get the message type ASAP as other operations depend on this diff --git a/net_io.c b/net_io.c index ca6bb18..33b2399 100644 --- a/net_io.c +++ b/net_io.c @@ -273,6 +273,7 @@ void modesSendBeastOutput(struct modesMessage *mm) { char * pTimeStamp; char ch; int j; + unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg); if (!p) return; @@ -297,7 +298,7 @@ void modesSendBeastOutput(struct modesMessage *mm) { if (0x1A == ch) {*p++ = ch; } for (j = 0; j < msgLen; j++) { - *p++ = (ch = mm->msg[j]); + *p++ = (ch = msg[j]); if (0x1A == ch) {*p++ = ch; } } @@ -314,6 +315,7 @@ void modesSendRawOutput(struct modesMessage *mm) { char *p = prepareWrite(&Modes.raw_out, msgLen*2 + 15); int j; unsigned char * pTimeStamp; + unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg); if (!p) return; @@ -329,7 +331,7 @@ void modesSendRawOutput(struct modesMessage *mm) { *p++ = '*'; for (j = 0; j < msgLen; j++) { - sprintf(p, "%02X", mm->msg[j]); + sprintf(p, "%02X", msg[j]); p += 2; }