diff --git a/pyModeS/decoder/adsb.py b/pyModeS/decoder/adsb.py index 5a72a35..3230706 100644 --- a/pyModeS/decoder/adsb.py +++ b/pyModeS/decoder/adsb.py @@ -176,14 +176,25 @@ def oe_flag(msg): msgbin = common.hex2bin(msg) return int(msgbin[53]) -# Uncertainty & accuracy -def nic(msg, *argv): - if len(argv) == 1: - # assume ads-b v1, only one supplement bit - return nic_v1(msg, *argv) - elif len(argv) == 3: - # assume ads-b v2, three supplement bits - return nic_v2(msg, *argv) + +def version(msg): + """ADS-B Version + + Args: + msg (string): 28 bytes hexadecimal message string, TC = 31 + + Returns: + int: version number + """ + tc = typecode(msg) + + if tc != 31: + raise RuntimeError("%s: Not a status operation message, expecting TC = 31" % msg) + + msgbin = common.hex2bin(msg) + version = common.bin2int(msgbin[72:75]) + + return version def nic_v1(msg, nic_sup_b): @@ -461,23 +472,3 @@ def sil(msg, version): sil_sup = common.bin2int(msgbin[86]) return sil, sil_sup - - -def version(msg): - """ADS-B Version - - Args: - msg (string): 28 bytes hexadecimal message string, TC = 31 - - Returns: - int: version number - """ - tc = typecode(msg) - - if tc != 31: - raise RuntimeError("%s: Not a status operation message, expecting TC = 31" % msg) - - msgbin = common.hex2bin(msg) - version = common.bin2int(msgbin[72:75]) - - return version diff --git a/pyModeS/streamer/screen.py b/pyModeS/streamer/screen.py index 4d601e4..1e9494d 100644 --- a/pyModeS/streamer/screen.py +++ b/pyModeS/streamer/screen.py @@ -1,4 +1,5 @@ from __future__ import print_function, division +import os import curses import numpy as np import time @@ -20,7 +21,7 @@ COLUMNS = [ ('NACv', 5), ('NACp', 5), ('SIL', 5), - ('updated', 12), + ('live', 6), ] class Screen(Thread): @@ -45,7 +46,7 @@ class Screen(Thread): def draw_frame(self): self.screen.border(0) - self.screen.addstr(0, 2, "Online aircraft ('crtl+c' to exit, 'enter' to select)") + self.screen.addstr(0, 2, "Online aircraft ('ESC' to exit, 'Enter' to lock one)") def update(self): if len(self.acs) == 0: @@ -64,12 +65,15 @@ class Screen(Thread): header = ' icao' for c, cw in COLUMNS: - c = 'updated' if c=='t' else c header += (cw-len(c))*' ' + c + # fill end with spaces + header += (self.scr_w - 2 - len(header)) * ' ' + if len(header) > self.scr_w - 2: header = header[:self.scr_w-3] + '>' + self.screen.addstr(row, 1, header) row +=1 @@ -93,10 +97,18 @@ class Screen(Thread): line += icao for c, cw in COLUMNS: - val = '' if ac[c] is None else ac[c] + if c=='live': + val = int(time.time() - ac[c]) + elif ac[c] is None: + val = '' + else: + val = ac[c] val_str = str(val) line += (cw-len(val_str))*' ' + val_str + # fill end with spaces + line += (self.scr_w - 2 - len(line)) * ' ' + if len(line) > self.scr_w - 2: line = line[:self.scr_w-3] + '>' @@ -122,7 +134,10 @@ class Screen(Thread): while True: c = self.screen.getch() - if c == curses.KEY_HOME: + if c == 27: + curses.endwin() + os._exit(1) + elif c == curses.KEY_HOME: self.x = 1 self.y = 1 elif c == curses.KEY_NPAGE: @@ -145,3 +160,6 @@ class Screen(Thread): self.y = y_intent elif c == curses.KEY_ENTER or c == 10 or c == 13: self.lock_icao = (self.screen.instr(self.y, 1, 6)).decode() + elif c == curses.KEY_F5: + self.screen.refresh() + self.draw_frame() diff --git a/pyModeS/streamer/stream.py b/pyModeS/streamer/stream.py index 728815d..25013e9 100644 --- a/pyModeS/streamer/stream.py +++ b/pyModeS/streamer/stream.py @@ -36,7 +36,7 @@ class Stream(): if icao not in self.acs: self.acs[icao] = { - 'updated': None, + 'live': None, 'lat': None, 'lon': None, 'alt': None, @@ -54,7 +54,7 @@ class Stream(): 'SIL' : None } - self.acs[icao]['updated'] = int(t) + self.acs[icao]['live'] = int(t) if 1 <= tc <= 4: self.acs[icao]['callsign'] = pms.adsb.callsign(msg) @@ -110,34 +110,19 @@ class Stream(): local_updated_acs_buffer.append(icao) # Uncertainty & accuracy - if (5 <= tc <= 8): - if self.acs[icao]['ver'] == 1: - if self.acs[icao]['nic_s'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v1(msg, self.acs[icao]['nic_s']) - elif self.acs[icao]['ver'] == 2: - if self.acs[icao]['nic_a'] != None and self.acs[icao]['nic_b'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v2(msg, self.acs[icao]['nic_a'], self.acs[icao]['nic_b'], self.acs[icao]['nic_c']) - if (9 <= tc <= 18): - if self.acs[icao]['ver'] == 1: - if self.acs[icao]['nic_s'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v1(msg, self.acs[icao]['nic_s']) - elif self.acs[icao]['ver'] == 2: - self.acs[icao]['nic_b'] = pms.adsb.nic_b(msg) - if self.acs[icao]['nic_a'] != None and self.acs[icao]['nic_b'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v2(msg, self.acs[icao]['nic_a'], self.acs[icao]['nic_b'], self.acs[icao]['nic_c']) + ac = self.acs[icao] + + if (5 <= tc <= 8) or (9 <= tc <= 18) or (20 <= tc <= 22): + if (ac['ver'] == 1) and ('nic_s' in ac.keys()): + self.acs[icao]['NIC'] = pms.adsb.nic_v1(msg, ac['nic_s']) + elif (ac['ver'] == 2) and ('nic_a' in ac.keys()) and ('nic_b' in ac.keys()): + self.acs[icao]['NIC'] = pms.adsb.nic_v2(msg, ac['nic_a'], ac['nic_b'], ac['nic_c']) if tc == 19: - if self.acs[icao]['ver'] in [1, 2]: + if ac['ver'] in [1, 2]: self.acs[icao]['NACv'] = pms.adsb.nac_v(msg) - if (20 <= tc <= 22): - if self.acs[icao]['ver'] == 1: - if self.acs[icao]['nic_s'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v1(msg, self.acs[icao]['nic_s']) - elif self.acs[icao]['ver'] == 2: - if self.acs[icao]['nic_a'] != None and self.acs[icao]['nic_b'] != None: - self.acs[icao]['NIC'] = pms.adsb.nic_v2(msg, self.acs[icao]['nic_a'], self.acs[icao]['nic_b'], self.acs[icao]['nic_c']) if tc == 29: - if self.acs[icao]['ver'] != None: - self.acs[icao]['SIL'], self.acs[icao]['sil_s'] = pms.adsb.sil(msg, self.acs[icao]['ver']) + if ac['ver'] != None: + self.acs[icao]['SIL'], self.acs[icao]['sil_s'] = pms.adsb.sil(msg, ac['ver']) self.acs[icao]['NACp'] = pms.adsb.nac_p(msg) if tc == 31: self.acs[icao]['ver'] = pms.adsb.version(msg) @@ -149,8 +134,6 @@ class Stream(): self.acs[icao]['nic_a'], self.acs[icao]['nic_c'] = pms.adsb.nic_a_c(msg) - - # process commb message for t, msg in zip(commb_ts, commb_msgs): icao = pms.icao(msg) @@ -183,7 +166,7 @@ class Stream(): # clear up old data for icao in list(self.acs.keys()): - if self.t - self.acs[icao]['updated'] > self.cache_timeout: + if self.t - self.acs[icao]['live'] > self.cache_timeout: del self.acs[icao] continue