-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecode.py
49 lines (37 loc) · 1.53 KB
/
decode.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
import logging
import signal
import sys
import time
import traceback
import pyModeS as pms
from transformers import Transformers
class Decode:
def __init__(self, transformers: Transformers, reference_position: dict) -> None:
self.transformers = transformers
self.reference_position = reference_position
def stop(self, signal: int, frame):
logging.debug('Stopping decode process')
sys.exit(0)
def process_raw(self, msg):
icao = pms.icao(msg)
tc = pms.adsb.typecode(msg)
data = {
"icao": icao,
"type_code": tc,
"call_sign": pms.adsb.callsign(msg) if 1 <= tc <= 4 else None,
"velocity": pms.adsb.velocity(msg) if (5 <= tc <= 8) or (tc == 19) else None,
"altitude": pms.adsb.altitude(msg) if (not (tc < 5 or tc == 19 or tc > 22)) else None,
"position": pms.adsb.position_with_ref(msg, self.reference_position['latitude'],
self.reference_position['longitude']) if (5 <= tc <= 8) or (
9 <= tc <= 18 or 20 <= tc <= 22) else None,
}
return self.transformers.transform(data)
def run(self, raw_pipe_out, ac_pipe_in):
logging.debug('Start decode process')
signal.signal(signal.SIGTERM, self.stop)
while True:
while raw_pipe_out.poll():
data = raw_pipe_out.recv()
decoded = self.process_raw(data)
ac_pipe_in.send(decoded)
time.sleep(0.001)