Track ADS-B version separately for direct ADS-B, TIS-B, ADS-R

(both because direct vs ground station might be different, and
to avoid characterizing ADS-R or TIS-B aircraft as being DO-260B
when they're not)
This commit is contained in:
Oliver Jowett 2019-12-12 09:21:26 -06:00
parent 886b0d3f81
commit d471249f17
2 changed files with 30 additions and 8 deletions

34
track.c
View File

@ -949,9 +949,28 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
if (mm->addrtype < a->addrtype) if (mm->addrtype < a->addrtype)
a->addrtype = mm->addrtype; a->addrtype = mm->addrtype;
// if we saw some direct ADS-B for the first time, assume version 0 // decide on where to stash the version
if (mm->source == SOURCE_ADSB && a->adsb_version < 0) int dummy_version = -1; // used for non-adsb/adsr/tisb messages
a->adsb_version = 0; int *message_version;
switch (mm->source) {
case SOURCE_ADSB:
message_version = &a->adsb_version;
break;
case SOURCE_TISB:
message_version = &a->tisb_version;
break;
case SOURCE_ADSR:
message_version = &a->adsr_version;
break;
default:
message_version = &dummy_version;
break;
}
// assume version 0 until we see something else
if (*message_version < 0)
*message_version = 0;
// category shouldn't change over time, don't bother with metadata // category shouldn't change over time, don't bother with metadata
if (mm->category_valid) { if (mm->category_valid) {
@ -961,7 +980,8 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
// operational status message // operational status message
// done early to update version / HRD / TAH // done early to update version / HRD / TAH
if (mm->opstatus.valid) { if (mm->opstatus.valid) {
a->adsb_version = mm->opstatus.version; *message_version = mm->opstatus.version;
if (mm->opstatus.hrd != HEADING_INVALID) { if (mm->opstatus.hrd != HEADING_INVALID) {
a->adsb_hrd = mm->opstatus.hrd; a->adsb_hrd = mm->opstatus.hrd;
} }
@ -971,7 +991,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
} }
// fill in ADS-B v0 NACp, SIL from position message type // fill in ADS-B v0 NACp, SIL from position message type
if (a->adsb_version == 0 && !mm->accuracy.nac_p_valid) { if (*message_version == 0 && !mm->accuracy.nac_p_valid) {
int computed_nacp = compute_v0_nacp(mm); int computed_nacp = compute_v0_nacp(mm);
if (computed_nacp != -1) { if (computed_nacp != -1) {
mm->accuracy.nac_p_valid = 1; mm->accuracy.nac_p_valid = 1;
@ -979,7 +999,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
} }
} }
if (a->adsb_version == 0 && mm->accuracy.sil_type == SIL_INVALID) { if (*message_version == 0 && mm->accuracy.sil_type == SIL_INVALID) {
int computed_sil = compute_v0_sil(mm); int computed_sil = compute_v0_sil(mm);
if (computed_sil != -1) { if (computed_sil != -1) {
mm->accuracy.sil_type = SIL_UNKNOWN; mm->accuracy.sil_type = SIL_UNKNOWN;
@ -1070,7 +1090,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
} }
if (mm->gs_valid) { if (mm->gs_valid) {
mm->gs.selected = (a->adsb_version == 2 ? mm->gs.v2 : mm->gs.v0); mm->gs.selected = (*message_version == 2 ? mm->gs.v2 : mm->gs.v0);
if (accept_data(&a->gs_valid, mm->source)) { if (accept_data(&a->gs_valid, mm->source)) {
a->gs = mm->gs.selected; a->gs = mm->gs.selected;
} }

View File

@ -195,12 +195,14 @@ struct aircraft {
unsigned cpr_even_rc; unsigned cpr_even_rc;
data_validity position_valid; data_validity position_valid;
double lat, lon; // Coordinated obtained from CPR encoded data double lat, lon; // Coordinates obtained from CPR encoded data
unsigned pos_nic; // NIC of last computed position unsigned pos_nic; // NIC of last computed position
unsigned pos_rc; // Rc of last computed position unsigned pos_rc; // Rc of last computed position
// data extracted from opstatus etc // data extracted from opstatus etc
int adsb_version; // ADS-B version (from ADS-B operational status); -1 means no ADS-B messages seen int adsb_version; // ADS-B version (from ADS-B operational status); -1 means no ADS-B messages seen
int adsr_version; // As above, for ADS-R messages
int tisb_version; // As above, for TIS-B messages
heading_type_t adsb_hrd; // Heading Reference Direction setting (from ADS-B operational status) heading_type_t adsb_hrd; // Heading Reference Direction setting (from ADS-B operational status)
heading_type_t adsb_tah; // Track Angle / Heading setting (from ADS-B operational status) heading_type_t adsb_tah; // Track Angle / Heading setting (from ADS-B operational status)