Skip to content

Commit

Permalink
better ignore garbage DF17 so we do MLAT for them
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Mar 2, 2021
1 parent a3ffc10 commit fd54ec4
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions mlat/client/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def __init__(self, icao):
self.icao = icao
self.messages = 0
self.last_message_time = 0
self.last_position_time = 0
self.last_even_time = 0
self.last_odd_time = 0
self.adsb_good = False
self.even_message = None
self.odd_message = None
self.reported = False
Expand All @@ -51,7 +53,7 @@ class Coordinator:
report_interval = 30.0
stats_interval = 900.0
position_expiry_age = 30.0
expiry_age = 60.0
expiry_age = 120.0

def __init__(self, receiver, server, outputs, freq, allow_anon, allow_modeac):
self.receiver = receiver
Expand Down Expand Up @@ -81,7 +83,7 @@ def __init__(self, receiver, server, outputs, freq, allow_anon, allow_modeac):
_modes.DF_MODEAC: self.received_modeac
}
self.next_report = None
self.next_stats = monotonic_time() + self.stats_interval
self.next_stats = monotonic_time() + 60
self.next_profile = monotonic_time()
self.next_aircraft_update = self.last_aircraft_update = monotonic_time()
self.recent_jumps = 0
Expand Down Expand Up @@ -167,6 +169,11 @@ def update_aircraft(self, now):
ac.messages += 1
ac.last_message_time = now

if now - ac.last_even_time < self.position_expiry_age and now - ac.last_odd_time < self.position_expiry_age:
ac.adsb_good = True
else:
ac.adsb_good = False

# expire aircraft we have not seen for a while
for ac in list(self.aircraft.values()):
if (now - ac.last_message_time) > self.expiry_age:
Expand Down Expand Up @@ -211,7 +218,7 @@ def periodic_stats(self, now):
if ac.messages < 2:
continue

if now - ac.last_position_time < self.position_expiry_age:
if ac.adsb_good:
adsb_total += 1
if ac.requested:
adsb_req += 1
Expand Down Expand Up @@ -288,7 +295,7 @@ def update_receiver_filter(self):
mlat = set()
for icao in self.requested_traffic:
ac = self.aircraft.get(icao)
if not ac or (now - ac.last_position_time > self.position_expiry_age):
if not ac or not ac.adsb_good:
# requested, and we have not seen a recent ADS-B message from it
mlat.add(icao)

Expand Down Expand Up @@ -365,7 +372,7 @@ def received_df_misc(self, message, now):
return

# Candidate for MLAT
if now - ac.last_position_time < self.position_expiry_age:
if ac.adsb_good:
return # reported position recently, no need for mlat
self.server.send_mlat(message)

Expand All @@ -389,7 +396,7 @@ def received_df11(self, message, now):
return

# Candidate for MLAT
if now - ac.last_position_time < self.position_expiry_age:
if ac.adsb_good:
return # reported position recently, no need for mlat
self.server.send_mlat(message)

Expand All @@ -413,6 +420,10 @@ def received_df17(self, message, now):
# not a position message
return

if not message.valid:
# invalid message
return

if message.even_cpr:
ac.even_message = message
else:
Expand All @@ -426,13 +437,21 @@ def received_df17(self, message, now):
if message.altitude is None:
return # need an altitude

ac.last_position_time = now

if message.nuc < 6:
return # need NUCp >= 6

ac.recent_adsb_positions += 1

if message.even_cpr:
ac.last_even_time = now
else:
ac.last_odd_time = now

if now - ac.last_even_time < self.position_expiry_age and now - ac.last_odd_time < self.position_expiry_age:
ac.adsb_good = True
else:
ac.adsb_good = False

if not ac.requested:
return

Expand Down

0 comments on commit fd54ec4

Please sign in to comment.