-
Notifications
You must be signed in to change notification settings - Fork 0
/
adsb-targeted.py
executable file
·63 lines (46 loc) · 1.46 KB
/
adsb-targeted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python2
__author__ = 'Oliver Maskery'
import argparse
import datetime
import logging
import signal
import adsb
def main():
logging.basicConfig()
args = get_args()
client = Targeted(args.targets)
client.enable_rx_channel('adsb_decoded', 'fanout')
signal.signal(signal.SIGINT, client.handle_sigint)
client.consume()
print("exiting")
def get_args():
parser = argparse.ArgumentParser(
description='tool to display ADSB data from specific planes identified by ICAO'
)
parser.add_argument(
'targets', nargs='+', help='target ICAO numbers (in hex) to track'
)
return parser.parse_args()
class Targeted(adsb.Client):
def __init__(self, targets):
adsb.Client.__init__(self)
self._targets = [
int(target, 16)
for target in targets
]
self._last_hit = datetime.datetime.now()
def handle_received(self, message):
decoded = adsb.Message.from_json(message)
if decoded.icao in self._targets:
self._last_hit = datetime.datetime.now()
timestamp = self._last_hit.strftime(
'%d/%m/%Y %H:%M:%S'
)
print "[{}] icao {:06X} -> {}".format(
timestamp, decoded.icao, decoded.raw
)
else:
delta = datetime.datetime.now() - self._last_hit
print "{} since last hit\r".format(delta),
if __name__ == "__main__":
main()