diff --git a/README.rst b/README.rst index e082a2d..cd780e8 100644 --- a/README.rst +++ b/README.rst @@ -40,7 +40,7 @@ New features in v2.0 --------------------- - New structure of the libraries - ADS-B and Comm-B data streaming -- Active aircraft viewing (terminal cursor) +- Active aircraft viewing (terminal curses) - Improved BDS identification - Optimizing decoding speed diff --git a/pyModeS/streamer/pmstream.py b/pyModeS/streamer/pmslive old mode 100644 new mode 100755 similarity index 89% rename from pyModeS/streamer/pmstream.py rename to pyModeS/streamer/pmslive index 8b7e14b..7221825 --- a/pyModeS/streamer/pmstream.py +++ b/pyModeS/streamer/pmslive @@ -1,103 +1,103 @@ -from __future__ import print_function, division -import os -import sys -import argparse -import curses -import numpy as np -import time -from threading import Lock -import pyModeS as pms -from pyModeS.extra.beastclient import BaseClient -from pyModeS.streamer.stream import Stream -from pyModeS.streamer.screen import Screen - -LOCK = Lock() -ADSB_MSG = [] -ADSB_TS = [] -COMMB_MSG = [] -COMMB_TS = [] - -parser = argparse.ArgumentParser() -parser.add_argument('--server', help='server address or IP', required=True) -parser.add_argument('--port', help='Raw beast port', required=True) -parser.add_argument('--lat0', help='Latitude of receiver', required=True) -parser.add_argument('--lon0', help='Longitude of receiver', required=True) -args = parser.parse_args() - -SERVER = args.server -PORT = int(args.port) -LAT0 = float(args.lat0) # 51.9899 for TU Delft -LON0 = float(args.lon0) # 4.3754 - -class ModesClient(BaseClient): - def __init__(self, host, port): - super(ModesClient, self).__init__(host, port) - - def handle_messages(self, messages): - local_buffer_adsb_msg = [] - local_buffer_adsb_ts = [] - local_buffer_ehs_msg = [] - local_buffer_ehs_ts = [] - - for msg, t in messages: - if len(msg) < 28: # only process long messages - continue - - df = pms.df(msg) - - if df == 17 or df == 18: - local_buffer_adsb_msg.append(msg) - local_buffer_adsb_ts.append(t) - elif df == 20 or df == 21: - local_buffer_ehs_msg.append(msg) - local_buffer_ehs_ts.append(t) - else: - continue - - - LOCK.acquire() - ADSB_MSG.extend(local_buffer_adsb_msg) - ADSB_TS.extend(local_buffer_adsb_ts) - COMMB_MSG.extend(local_buffer_ehs_msg) - COMMB_TS.extend(local_buffer_ehs_ts) - LOCK.release() - - -# redirect all stdout to null, avoiding messing up with the screen -sys.stdout = open(os.devnull, 'w') - -client = ModesClient(host=SERVER, port=PORT) -client.daemon = True -client.start() - -stream = Stream(lat0=LAT0, lon0=LON0) - -try: - screen = Screen() - screen.daemon = True - screen.start() - - while True: - if len(ADSB_MSG) > 200: - LOCK.acquire() - stream.process_raw(ADSB_TS, ADSB_MSG, COMMB_TS, COMMB_MSG) - ADSB_MSG = [] - ADSB_TS = [] - COMMB_MSG = [] - COMMB_TS = [] - LOCK.release() - - acs = stream.get_aircraft() - # try: - screen.update_data(acs) - screen.update() - # except KeyboardInterrupt: - # raise - # except: - # continue - -except KeyboardInterrupt: - sys.exit(0) - -finally: - curses.endwin() +#!/usr/bin/env python + +from __future__ import print_function, division +import os +import sys +import argparse +import curses +from threading import Lock +import pyModeS as pms +from pyModeS.extra.beastclient import BaseClient +from pyModeS.streamer.stream import Stream +from pyModeS.streamer.screen import Screen + +LOCK = Lock() +ADSB_MSG = [] +ADSB_TS = [] +COMMB_MSG = [] +COMMB_TS = [] + +parser = argparse.ArgumentParser() +parser.add_argument('--server', help='server address or IP', required=True) +parser.add_argument('--port', help='Raw beast port', required=True) +parser.add_argument('--lat0', help='Latitude of receiver', required=True) +parser.add_argument('--lon0', help='Longitude of receiver', required=True) +args = parser.parse_args() + +SERVER = args.server +PORT = int(args.port) +LAT0 = float(args.lat0) # 51.9899 for TU Delft +LON0 = float(args.lon0) # 4.3754 + +class ModesClient(BaseClient): + def __init__(self, host, port): + super(ModesClient, self).__init__(host, port) + + def handle_messages(self, messages): + local_buffer_adsb_msg = [] + local_buffer_adsb_ts = [] + local_buffer_ehs_msg = [] + local_buffer_ehs_ts = [] + + for msg, t in messages: + if len(msg) < 28: # only process long messages + continue + + df = pms.df(msg) + + if df == 17 or df == 18: + local_buffer_adsb_msg.append(msg) + local_buffer_adsb_ts.append(t) + elif df == 20 or df == 21: + local_buffer_ehs_msg.append(msg) + local_buffer_ehs_ts.append(t) + else: + continue + + + LOCK.acquire() + ADSB_MSG.extend(local_buffer_adsb_msg) + ADSB_TS.extend(local_buffer_adsb_ts) + COMMB_MSG.extend(local_buffer_ehs_msg) + COMMB_TS.extend(local_buffer_ehs_ts) + LOCK.release() + + +# redirect all stdout to null, avoiding messing up with the screen +sys.stdout = open(os.devnull, 'w') + +client = ModesClient(host=SERVER, port=PORT) +client.daemon = True +client.start() + +stream = Stream(lat0=LAT0, lon0=LON0) + +try: + screen = Screen() + screen.daemon = True + screen.start() + + while True: + if len(ADSB_MSG) > 200: + LOCK.acquire() + stream.process_raw(ADSB_TS, ADSB_MSG, COMMB_TS, COMMB_MSG) + ADSB_MSG = [] + ADSB_TS = [] + COMMB_MSG = [] + COMMB_TS = [] + LOCK.release() + + acs = stream.get_aircraft() + try: + screen.update_data(acs) + screen.update() + except KeyboardInterrupt: + raise + except: + continue + +except KeyboardInterrupt: + sys.exit(0) + +finally: + curses.endwin() diff --git a/pyModeS/streamer/screen.py b/pyModeS/streamer/screen.py index 2992425..4d601e4 100644 --- a/pyModeS/streamer/screen.py +++ b/pyModeS/streamer/screen.py @@ -28,6 +28,7 @@ class Screen(Thread): Thread.__init__(self) self.screen = curses.initscr() curses.noecho() + curses.mousemask(1) self.screen.keypad(True) self.y = 3 self.x = 1 diff --git a/setup.py b/setup.py index af6289c..6a53144 100644 --- a/setup.py +++ b/setup.py @@ -117,4 +117,6 @@ setup( # 'sample=sample:main', # ], # }, + + scripts=['pyModeS/streamer/pmslive'], )