From ada188a1c8f16a22955653217006e3cd95ffe3c0 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Thu, 22 Jan 2015 12:30:12 +0000 Subject: [PATCH] Changed my mind, put the non-ICAO flag bit in the address itself since we have 8 bits spare, so there's no chance of confusing it with an ICAO address, and we can safely use the filter table to match future messages without also matching equivalent ICAO addresses. --- dump1090.h | 3 ++- interactive.c | 8 ++++---- mode_ac.c | 6 ++---- mode_s.c | 5 +++-- net_io.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dump1090.h b/dump1090.h index 5f8ce7f..659c081 100644 --- a/dump1090.h +++ b/dump1090.h @@ -164,12 +164,13 @@ #define MODES_ACFLAGS_NSEWSPD_VALID (1<<14) // Aircraft EW and NS Speed is known #define MODES_ACFLAGS_LATLON_REL_OK (1<<15) // Indicates it's OK to do a relative CPR #define MODES_ACFLAGS_REL_CPR_USED (1<<16) // Lat/lon derived from relative CPR -#define MODES_ACFLAGS_NON_ICAO (1<<17) // Address is not ICAO-format #define MODES_ACFLAGS_LLEITHER_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID) #define MODES_ACFLAGS_LLBOTH_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID) #define MODES_ACFLAGS_AOG_GROUND (MODES_ACFLAGS_AOG_VALID | MODES_ACFLAGS_AOG) +#define MODES_NON_ICAO_ADDRESS (1<<24) // Set on addresses to indicate they are not ICAO addresses + #define MODES_DEBUG_DEMOD (1<<0) #define MODES_DEBUG_DEMODERR (1<<1) #define MODES_DEBUG_BADCRC (1<<2) diff --git a/interactive.c b/interactive.c index fc44b38..0dcb227 100644 --- a/interactive.c +++ b/interactive.c @@ -523,10 +523,10 @@ void interactiveShowData(void) { if (Modes.interactive_rtl1090 == 0) { printf ( -"Hex Mode Sqwk Flight Alt Spd Hdg Lat Long RSSI Msgs Ti%c\n", progress); +" Hex Mode Sqwk Flight Alt Spd Hdg Lat Long RSSI Msgs Ti%c\n", progress); } else { printf ( -"Hex Flight Alt V/S GS TT SSR G*456^ Msgs Seen %c\n", progress); +" Hex Flight Alt V/S GS TT SSR G*456^ Msgs Seen %c\n", progress); } printf( "-------------------------------------------------------------------------------\n"); @@ -601,8 +601,8 @@ void interactiveShowData(void) { snprintf(strFl, 6, "%5d", altitude); } - printf("%06X%s %-4s %-4s %-8s %5s %3s %3s %7s %8s %5.1f %5d %2d\n", - a->addr, (a->bFlags & MODES_ACFLAGS_NON_ICAO) ? "~" : " ", + printf("%s%06X %-4s %-4s %-8s %5s %3s %3s %7s %8s %5.1f %5d %2d\n", + (a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : " ", (a->addr & 0xffffff), strMode, strSquawk, a->flight, strFl, strGs, strTt, strLat, strLon, 10 * log10(signalAverage), msgs, (int)(now - a->seen)); } diff --git a/mode_ac.c b/mode_ac.c index 04e522d..b4ecd11 100644 --- a/mode_ac.c +++ b/mode_ac.c @@ -364,14 +364,12 @@ void decodeModeAMessage(struct modesMessage *mm, int ModeA) mm->msg[0] = (ModeA >> 8); mm->msg[1] = (ModeA); - // Fudge an ICAO address based on Mode A (remove the Ident bit) - // Use an upper address byte of FF, since this is ICAO unallocated - mm->addr = 0x00FF0000 | (ModeA & 0x0000FF7F); + // Fudge an address based on Mode A (remove the Ident bit) + mm->addr = (ModeA & 0x0000FF7F) | MODES_NON_ICAO_ADDRESS; // Set the Identity field to ModeA mm->modeA = ModeA & 0x7777; mm->bFlags |= MODES_ACFLAGS_SQUAWK_VALID; - mm->bFlags |= MODES_ACFLAGS_NON_ICAO; // Flag ident in flight status mm->fs = ModeA & 0x0080; diff --git a/mode_s.c b/mode_s.c index 0df3d4a..042dfe1 100644 --- a/mode_s.c +++ b/mode_s.c @@ -545,8 +545,9 @@ int decodeModesMessage(struct modesMessage *mm, unsigned char *msg) mm->addr = (msg[1] << 16) | (msg[2] << 8) | (msg[3]); if (mm->msgtype == 18 && (mm->cf != 0 && mm->cf != 6)) - mm->bFlags |= MODES_ACFLAGS_NON_ICAO; // DF 18 message not using ICAO addressing - else if (!mm->correctedbits && (mm->msgtype != 11 || mm->iid == 0)) { + mm->addr |= MODES_NON_ICAO_ADDRESS; // don't confuse this with any ICAO address + + if (!mm->correctedbits && (mm->msgtype != 11 || mm->iid == 0)) { // No CRC errors seen, and either it was an DF17/18 extended squitter // or a DF11 acquisition squitter with II = 0. We probably have the right address. diff --git a/net_io.c b/net_io.c index 1a7dda5..ba71b59 100644 --- a/net_io.c +++ b/net_io.c @@ -749,7 +749,7 @@ char *generateAircraftJson(const char *url_path, int *len) { else *p++ = ','; - p += snprintf(p, end-p, "\n {\"hex\":\"%06x%s\"", a->addr, (a->bFlags & MODES_ACFLAGS_NON_ICAO) ? "~" : ""); + p += snprintf(p, end-p, "\n {\"hex\":\"%s%06x\"", (a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : "", a->addr & 0xFFFFFF); if (a->bFlags & MODES_ACFLAGS_SQUAWK_VALID) p += snprintf(p, end-p, ",\"squawk\":\"%04x\"", a->modeA); if (a->bFlags & MODES_ACFLAGS_CALLSIGN_VALID) @@ -1311,14 +1311,14 @@ static void writeFATSV() { char *p, *end; // skip non-ICAO - if (a->bFlags & MODES_ACFLAGS_NON_ICAO) + if (a->addr & MODES_NON_ICAO_ADDRESS) continue; // don't emit if it hasn't updated since last time if (a->seen < a->fatsv_last_emitted) { continue; } - + emittedSecondsAgo = (int)(now - a->fatsv_last_emitted); // don't emit more than once every five seconds