Move output filtering down a level into the individual output functions.
This commit is contained in:
parent
54f2c54d8f
commit
dfc588335a
18
mode_s.c
18
mode_s.c
|
|
@ -2142,23 +2142,9 @@ void useModesMessage(struct modesMessage *mm) {
|
||||||
displayModesMessage(mm);
|
displayModesMessage(mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feed output clients.
|
// Feed output clients; modesQueueOutput appropriately filters messages to the different outputs.
|
||||||
// If in --net-verbatim mode, do this for all messages.
|
|
||||||
// Otherwise, apply a sanity-check filter and only
|
|
||||||
// forward messages when we have seen two of them.
|
|
||||||
|
|
||||||
if (Modes.net) {
|
if (Modes.net) {
|
||||||
if (Modes.net_verbatim || mm->msgtype == 32 || !a) {
|
modesQueueOutput(mm, a);
|
||||||
// Unconditionally send
|
|
||||||
modesQueueOutput(mm, a);
|
|
||||||
} else if (a->messages > 1) {
|
|
||||||
// Suppress the first message. When we receive a second message,
|
|
||||||
// emit the first two messages.
|
|
||||||
if (a->messages == 2) {
|
|
||||||
modesQueueOutput(&a->first_message, a);
|
|
||||||
}
|
|
||||||
modesQueueOutput(mm, a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
83
net_io.c
83
net_io.c
|
|
@ -376,7 +376,20 @@ static void completeWrite(struct net_writer *writer, void *endptr) {
|
||||||
//
|
//
|
||||||
// Write raw output in Beast Binary format with Timestamp to TCP clients
|
// Write raw output in Beast Binary format with Timestamp to TCP clients
|
||||||
//
|
//
|
||||||
static void modesSendBeastOutput(struct modesMessage *mm) {
|
static void modesSendBeastOutput(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 (!Modes.net_verbatim && mm->correctedbits >= 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't forward unreliable messages
|
||||||
|
if (!Modes.net_verbatim && (a && !a->reliable) && !mm->reliable)
|
||||||
|
return;
|
||||||
|
|
||||||
int msgLen = mm->msgbits / 8;
|
int msgLen = mm->msgbits / 8;
|
||||||
char *p = prepareWrite(&Modes.beast_out, 2 + 2 * (7 + msgLen));
|
char *p = prepareWrite(&Modes.beast_out, 2 + 2 * (7 + msgLen));
|
||||||
char ch;
|
char ch;
|
||||||
|
|
@ -448,12 +461,22 @@ static void send_beast_heartbeat(struct net_service *service)
|
||||||
//
|
//
|
||||||
// Write raw output to TCP clients
|
// Write raw output to TCP clients
|
||||||
//
|
//
|
||||||
static void modesSendRawOutput(struct modesMessage *mm) {
|
static void modesSendRawOutput(struct modesMessage *mm, struct aircraft *a) {
|
||||||
int msgLen = mm->msgbits / 8;
|
// Don't ever forward mlat messages via raw output.
|
||||||
char *p = prepareWrite(&Modes.raw_out, msgLen*2 + 15);
|
if (mm->source == SOURCE_MLAT)
|
||||||
int j;
|
return;
|
||||||
unsigned char *msg = (Modes.net_verbatim ? mm->verbatim : mm->msg);
|
|
||||||
|
|
||||||
|
// Filter some messages
|
||||||
|
// Don't forward 2-bit-corrected messages
|
||||||
|
if (mm->correctedbits >= 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't forward unreliable messages
|
||||||
|
if ((a && !a->reliable) && !mm->reliable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int msgLen = mm->msgbits / 8;
|
||||||
|
char *p = prepareWrite(&Modes.raw_out, msgLen*2 + 15);
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -465,7 +488,8 @@ static void modesSendRawOutput(struct modesMessage *mm) {
|
||||||
} else
|
} else
|
||||||
*p++ = '*';
|
*p++ = '*';
|
||||||
|
|
||||||
for (j = 0; j < msgLen; j++) {
|
unsigned char *msg = mm->msg;
|
||||||
|
for (int j = 0; j < msgLen; j++) {
|
||||||
sprintf(p, "%02X", msg[j]);
|
sprintf(p, "%02X", msg[j]);
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
|
|
@ -504,6 +528,22 @@ static void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a) {
|
||||||
struct tm stTime_receive, stTime_now;
|
struct tm stTime_receive, stTime_now;
|
||||||
int msgType;
|
int msgType;
|
||||||
|
|
||||||
|
// We require a tracked aircraft for SBS output
|
||||||
|
if (!a)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't ever forward 2-bit-corrected messages via SBS output.
|
||||||
|
if (mm->correctedbits >= 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't ever forward mlat messages via SBS output.
|
||||||
|
if (mm->source == SOURCE_MLAT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't ever send unreliable messages via SBS output
|
||||||
|
if (!mm->reliable && !a->reliable)
|
||||||
|
return;
|
||||||
|
|
||||||
// For now, suppress non-ICAO addresses
|
// For now, suppress non-ICAO addresses
|
||||||
if (mm->addr & MODES_NON_ICAO_ADDRESS)
|
if (mm->addr & MODES_NON_ICAO_ADDRESS)
|
||||||
return;
|
return;
|
||||||
|
|
@ -721,29 +761,12 @@ static void send_sbs_heartbeat(struct net_service *service)
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
//
|
//
|
||||||
void modesQueueOutput(struct modesMessage *mm, struct aircraft *a) {
|
void modesQueueOutput(struct modesMessage *mm, struct aircraft *a) {
|
||||||
int is_mlat = (mm->source == SOURCE_MLAT);
|
|
||||||
|
|
||||||
if (a && !is_mlat && mm->correctedbits < 2) {
|
// Delegate to the format-specific outputs, each of which makes its own decision about filtering messages
|
||||||
// Don't ever forward 2-bit-corrected messages via SBS output.
|
modesSendSBSOutput(mm, a);
|
||||||
// Don't ever forward mlat messages via SBS output.
|
modesSendRawOutput(mm, a);
|
||||||
modesSendSBSOutput(mm, a);
|
modesSendBeastOutput(mm, a);
|
||||||
}
|
writeFATSVEvent(mm, a);
|
||||||
|
|
||||||
if (!is_mlat && (Modes.net_verbatim || mm->correctedbits < 2)) {
|
|
||||||
// Forward 2-bit-corrected messages via raw output only if --net-verbatim is set
|
|
||||||
// Don't ever forward mlat messages via raw output.
|
|
||||||
modesSendRawOutput(mm);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!is_mlat || Modes.forward_mlat) && (Modes.net_verbatim || mm->correctedbits < 2)) {
|
|
||||||
// Forward 2-bit-corrected messages via beast output only if --net-verbatim is set
|
|
||||||
// Forward mlat messages via beast output only if --forward-mlat is set
|
|
||||||
modesSendBeastOutput(mm);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a && !is_mlat) {
|
|
||||||
writeFATSVEvent(mm, a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode a little-endian IEEE754 float (binary32)
|
// Decode a little-endian IEEE754 float (binary32)
|
||||||
|
|
@ -1950,7 +1973,7 @@ static void writeFATSVEvent(struct modesMessage *mm, struct aircraft *a)
|
||||||
return; // not enabled or no active connections
|
return; // not enabled or no active connections
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->messages < 2) // basic filter for bad decodes
|
if (!a || mm->source == SOURCE_MLAT || (!a->reliable && !mm->reliable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (mm->msgtype) {
|
switch (mm->msgtype) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue