More tweaking to A/C tracking.

This commit is contained in:
Oliver Jowett 2016-10-11 21:29:39 +01:00
parent f6b1b94c7d
commit 4cb17c194c
3 changed files with 46 additions and 15 deletions

View file

@ -178,7 +178,7 @@ void interactiveShowData(void) {
if (Modes.mode_ac) { if (Modes.mode_ac) {
for (unsigned i = 1; i < 4096 && row < rows; ++i) { 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; continue;
char strMode[5] = " A "; char strMode[5] = " A ";
@ -191,7 +191,7 @@ void interactiveShowData(void) {
} }
mvprintw(row, 0, 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 */ "", /* address */
strMode, /* mode */ strMode, /* mode */
modeA, /* squawk */ modeA, /* squawk */
@ -203,7 +203,7 @@ void interactiveShowData(void) {
"", /* lon */ "", /* lon */
"", /* signal */ "", /* signal */
modeAC_count[i], /* messages */ modeAC_count[i], /* messages */
""); /* seen */ modeAC_age[i]); /* age */
++row; ++row;
} }
} }

52
track.c
View file

@ -55,6 +55,7 @@
uint32_t modeAC_count[4096]; uint32_t modeAC_count[4096];
uint32_t modeAC_lastcount[4096]; uint32_t modeAC_lastcount[4096];
uint32_t modeAC_match[4096]; uint32_t modeAC_match[4096];
uint32_t modeAC_age[4096];
// //
// Return a new aircraft structure for the linked list of tracked // 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 // match on Mode A
if (trackDataValid(&a->squawk_valid)) { if (trackDataValid(&a->squawk_valid)) {
unsigned i = modeAToIndex(a->squawk); 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; a->modeA_hit = 1;
modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr); modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr);
} }
} }
// match on Mode C // match on Mode C (+/- 100ft)
if (trackDataValid(&a->altitude_valid)) { if (trackDataValid(&a->altitude_valid)) {
int modeC = (a->altitude + 49) / 100; int modeC = (a->altitude + 49) / 100;
unsigned modeA = modeCToModeA(modeC); unsigned modeA = modeCToModeA(modeC);
if (modeA) { unsigned i = modeAToIndex(modeA);
unsigned i = modeAToIndex(modeA); if (modeA && (modeAC_count[i] - modeAC_lastcount[i]) >= TRACK_MODEAC_MIN_MESSAGES) {
if ((modeAC_count[i] - modeAC_lastcount[i]) > TRACK_MODEAC_MIN_MESSAGES) { a->modeC_hit = 1;
a->modeC_hit = 1; modeAC_match[i] = (modeAC_match[i] ? 0xFFFFFFFF : a->addr);
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 // reset counts for next time
for (unsigned i = 0; i < 4096; ++i) { for (unsigned i = 0; i < 4096; ++i) {
if ((modeAC_count[i] - modeAC_lastcount[i]) <= TRACK_MODEAC_MIN_MESSAGES) { if (!modeAC_count[i])
modeAC_lastcount[i] = modeAC_count[i] = 0; 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 { } 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];
} }
} }

View file

@ -62,7 +62,7 @@
/* Minimum number of repeated Mode A/C replies with a particular Mode A code needed in a /* Minimum number of repeated Mode A/C replies with a particular Mode A code needed in a
* 1 second period before accepting that code. * 1 second period before accepting that code.
*/ */
#define TRACK_MODEAC_MIN_MESSAGES 3 #define TRACK_MODEAC_MIN_MESSAGES 4
typedef struct { typedef struct {
datasource_t source; /* where the data came from */ datasource_t source; /* where the data came from */
@ -168,6 +168,7 @@ struct aircraft {
*/ */
extern uint32_t modeAC_count[4096]; extern uint32_t modeAC_count[4096];
extern uint32_t modeAC_match[4096]; extern uint32_t modeAC_match[4096];
extern uint32_t modeAC_age[4096];
/* is this bit of data valid? */ /* is this bit of data valid? */
static inline int trackDataValid(const data_validity *v) static inline int trackDataValid(const data_validity *v)