From 4cb17c194c72f04c8f4e27b2433d4a1a519f4622 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Tue, 11 Oct 2016 21:29:39 +0100 Subject: [PATCH] More tweaking to A/C tracking. --- interactive.c | 6 +++--- track.c | 52 ++++++++++++++++++++++++++++++++++++++++----------- track.h | 3 ++- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/interactive.c b/interactive.c index c26800b..7be904a 100644 --- a/interactive.c +++ b/interactive.c @@ -178,7 +178,7 @@ void interactiveShowData(void) { if (Modes.mode_ac) { for (unsigned i = 1; i < 4096 && row < rows; ++i) { - if (modeAC_match[i] || modeAC_count[i] < 100) + if (modeAC_match[i] || modeAC_count[i] < 50 || modeAC_age[i] > 5) continue; char strMode[5] = " A "; @@ -191,7 +191,7 @@ void interactiveShowData(void) { } mvprintw(row, 0, - "%7s %-4s %04x %-8s %6s %3s %3s %7s %8s %5s %5d %2s\n", + "%7s %-4s %04x %-8s %6s %3s %3s %7s %8s %5s %5d %2d\n", "", /* address */ strMode, /* mode */ modeA, /* squawk */ @@ -203,7 +203,7 @@ void interactiveShowData(void) { "", /* lon */ "", /* signal */ modeAC_count[i], /* messages */ - ""); /* seen */ + modeAC_age[i]); /* age */ ++row; } } diff --git a/track.c b/track.c index 12e1c61..1aded30 100644 --- a/track.c +++ b/track.c @@ -55,6 +55,7 @@ uint32_t modeAC_count[4096]; uint32_t modeAC_lastcount[4096]; uint32_t modeAC_match[4096]; +uint32_t modeAC_age[4096]; // // Return a new aircraft structure for the linked list of tracked @@ -661,33 +662,62 @@ static void trackMatchAC(uint64_t now) // match on Mode A if (trackDataValid(&a->squawk_valid)) { unsigned i = modeAToIndex(a->squawk); - if ((modeAC_count[i] - modeAC_lastcount[i]) > TRACK_MODEAC_MIN_MESSAGES) { + if ((modeAC_count[i] - modeAC_lastcount[i]) >= TRACK_MODEAC_MIN_MESSAGES) { a->modeA_hit = 1; modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); } } - // match on Mode C + // match on Mode C (+/- 100ft) if (trackDataValid(&a->altitude_valid)) { int modeC = (a->altitude + 49) / 100; + unsigned modeA = modeCToModeA(modeC); - if (modeA) { - unsigned i = modeAToIndex(modeA); - if ((modeAC_count[i] - modeAC_lastcount[i]) > TRACK_MODEAC_MIN_MESSAGES) { - a->modeC_hit = 1; - modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); - } + unsigned i = modeAToIndex(modeA); + if (modeA && (modeAC_count[i] - modeAC_lastcount[i]) >= TRACK_MODEAC_MIN_MESSAGES) { + a->modeC_hit = 1; + modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); + } + + modeA = modeCToModeA(modeC + 1); + i = modeAToIndex(modeA); + if (modeA && (modeAC_count[i] - modeAC_lastcount[i]) >= TRACK_MODEAC_MIN_MESSAGES) { + a->modeC_hit = 1; + modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); + } + + modeA = modeCToModeA(modeC - 1); + i = modeAToIndex(modeA); + if (modeA && (modeAC_count[i] - modeAC_lastcount[i]) >= TRACK_MODEAC_MIN_MESSAGES) { + a->modeC_hit = 1; + modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); } } } // reset counts for next time for (unsigned i = 0; i < 4096; ++i) { - if ((modeAC_count[i] - modeAC_lastcount[i]) <= TRACK_MODEAC_MIN_MESSAGES) { - modeAC_lastcount[i] = modeAC_count[i] = 0; + if (!modeAC_count[i]) + continue; + + if ((modeAC_count[i] - modeAC_lastcount[i]) < TRACK_MODEAC_MIN_MESSAGES) { + if (++modeAC_age[i] > 15) { + // not heard from for a while, clear it out + modeAC_lastcount[i] = modeAC_count[i] = modeAC_age[i] = 0; + } } else { - modeAC_lastcount[i] = modeAC_count[i]; + // this one is live + // set a high initial age for matches, so they age out rapidly + // and don't show up on the interactive display when the matching + // mode S data goes away or changes + if (modeAC_match[i]) { + modeAC_age[i] = 10; + } else { + modeAC_age[i] = 0; + } } + + modeAC_lastcount[i] = modeAC_count[i]; } } diff --git a/track.h b/track.h index 1ce3ae4..de26f68 100644 --- a/track.h +++ b/track.h @@ -62,7 +62,7 @@ /* Minimum number of repeated Mode A/C replies with a particular Mode A code needed in a * 1 second period before accepting that code. */ -#define TRACK_MODEAC_MIN_MESSAGES 3 +#define TRACK_MODEAC_MIN_MESSAGES 4 typedef struct { datasource_t source; /* where the data came from */ @@ -168,6 +168,7 @@ struct aircraft { */ extern uint32_t modeAC_count[4096]; extern uint32_t modeAC_match[4096]; +extern uint32_t modeAC_age[4096]; /* is this bit of data valid? */ static inline int trackDataValid(const data_validity *v)