add script: pmslive
This commit is contained in:
parent
0ef64be934
commit
70b3af2c8b
@ -40,7 +40,7 @@ New features in v2.0
|
|||||||
---------------------
|
---------------------
|
||||||
- New structure of the libraries
|
- New structure of the libraries
|
||||||
- ADS-B and Comm-B data streaming
|
- ADS-B and Comm-B data streaming
|
||||||
- Active aircraft viewing (terminal cursor)
|
- Active aircraft viewing (terminal curses)
|
||||||
- Improved BDS identification
|
- Improved BDS identification
|
||||||
- Optimizing decoding speed
|
- Optimizing decoding speed
|
||||||
|
|
||||||
|
206
pyModeS/streamer/pmstream.py → pyModeS/streamer/pmslive
Normal file → Executable file
206
pyModeS/streamer/pmstream.py → pyModeS/streamer/pmslive
Normal file → Executable file
@ -1,103 +1,103 @@
|
|||||||
from __future__ import print_function, division
|
#!/usr/bin/env python
|
||||||
import os
|
|
||||||
import sys
|
from __future__ import print_function, division
|
||||||
import argparse
|
import os
|
||||||
import curses
|
import sys
|
||||||
import numpy as np
|
import argparse
|
||||||
import time
|
import curses
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
import pyModeS as pms
|
import pyModeS as pms
|
||||||
from pyModeS.extra.beastclient import BaseClient
|
from pyModeS.extra.beastclient import BaseClient
|
||||||
from pyModeS.streamer.stream import Stream
|
from pyModeS.streamer.stream import Stream
|
||||||
from pyModeS.streamer.screen import Screen
|
from pyModeS.streamer.screen import Screen
|
||||||
|
|
||||||
LOCK = Lock()
|
LOCK = Lock()
|
||||||
ADSB_MSG = []
|
ADSB_MSG = []
|
||||||
ADSB_TS = []
|
ADSB_TS = []
|
||||||
COMMB_MSG = []
|
COMMB_MSG = []
|
||||||
COMMB_TS = []
|
COMMB_TS = []
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--server', help='server address or IP', required=True)
|
parser.add_argument('--server', help='server address or IP', required=True)
|
||||||
parser.add_argument('--port', help='Raw beast port', 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('--lat0', help='Latitude of receiver', required=True)
|
||||||
parser.add_argument('--lon0', help='Longitude of receiver', required=True)
|
parser.add_argument('--lon0', help='Longitude of receiver', required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
SERVER = args.server
|
SERVER = args.server
|
||||||
PORT = int(args.port)
|
PORT = int(args.port)
|
||||||
LAT0 = float(args.lat0) # 51.9899 for TU Delft
|
LAT0 = float(args.lat0) # 51.9899 for TU Delft
|
||||||
LON0 = float(args.lon0) # 4.3754
|
LON0 = float(args.lon0) # 4.3754
|
||||||
|
|
||||||
class ModesClient(BaseClient):
|
class ModesClient(BaseClient):
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
super(ModesClient, self).__init__(host, port)
|
super(ModesClient, self).__init__(host, port)
|
||||||
|
|
||||||
def handle_messages(self, messages):
|
def handle_messages(self, messages):
|
||||||
local_buffer_adsb_msg = []
|
local_buffer_adsb_msg = []
|
||||||
local_buffer_adsb_ts = []
|
local_buffer_adsb_ts = []
|
||||||
local_buffer_ehs_msg = []
|
local_buffer_ehs_msg = []
|
||||||
local_buffer_ehs_ts = []
|
local_buffer_ehs_ts = []
|
||||||
|
|
||||||
for msg, t in messages:
|
for msg, t in messages:
|
||||||
if len(msg) < 28: # only process long messages
|
if len(msg) < 28: # only process long messages
|
||||||
continue
|
continue
|
||||||
|
|
||||||
df = pms.df(msg)
|
df = pms.df(msg)
|
||||||
|
|
||||||
if df == 17 or df == 18:
|
if df == 17 or df == 18:
|
||||||
local_buffer_adsb_msg.append(msg)
|
local_buffer_adsb_msg.append(msg)
|
||||||
local_buffer_adsb_ts.append(t)
|
local_buffer_adsb_ts.append(t)
|
||||||
elif df == 20 or df == 21:
|
elif df == 20 or df == 21:
|
||||||
local_buffer_ehs_msg.append(msg)
|
local_buffer_ehs_msg.append(msg)
|
||||||
local_buffer_ehs_ts.append(t)
|
local_buffer_ehs_ts.append(t)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
LOCK.acquire()
|
LOCK.acquire()
|
||||||
ADSB_MSG.extend(local_buffer_adsb_msg)
|
ADSB_MSG.extend(local_buffer_adsb_msg)
|
||||||
ADSB_TS.extend(local_buffer_adsb_ts)
|
ADSB_TS.extend(local_buffer_adsb_ts)
|
||||||
COMMB_MSG.extend(local_buffer_ehs_msg)
|
COMMB_MSG.extend(local_buffer_ehs_msg)
|
||||||
COMMB_TS.extend(local_buffer_ehs_ts)
|
COMMB_TS.extend(local_buffer_ehs_ts)
|
||||||
LOCK.release()
|
LOCK.release()
|
||||||
|
|
||||||
|
|
||||||
# redirect all stdout to null, avoiding messing up with the screen
|
# redirect all stdout to null, avoiding messing up with the screen
|
||||||
sys.stdout = open(os.devnull, 'w')
|
sys.stdout = open(os.devnull, 'w')
|
||||||
|
|
||||||
client = ModesClient(host=SERVER, port=PORT)
|
client = ModesClient(host=SERVER, port=PORT)
|
||||||
client.daemon = True
|
client.daemon = True
|
||||||
client.start()
|
client.start()
|
||||||
|
|
||||||
stream = Stream(lat0=LAT0, lon0=LON0)
|
stream = Stream(lat0=LAT0, lon0=LON0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
screen = Screen()
|
screen = Screen()
|
||||||
screen.daemon = True
|
screen.daemon = True
|
||||||
screen.start()
|
screen.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if len(ADSB_MSG) > 200:
|
if len(ADSB_MSG) > 200:
|
||||||
LOCK.acquire()
|
LOCK.acquire()
|
||||||
stream.process_raw(ADSB_TS, ADSB_MSG, COMMB_TS, COMMB_MSG)
|
stream.process_raw(ADSB_TS, ADSB_MSG, COMMB_TS, COMMB_MSG)
|
||||||
ADSB_MSG = []
|
ADSB_MSG = []
|
||||||
ADSB_TS = []
|
ADSB_TS = []
|
||||||
COMMB_MSG = []
|
COMMB_MSG = []
|
||||||
COMMB_TS = []
|
COMMB_TS = []
|
||||||
LOCK.release()
|
LOCK.release()
|
||||||
|
|
||||||
acs = stream.get_aircraft()
|
acs = stream.get_aircraft()
|
||||||
# try:
|
try:
|
||||||
screen.update_data(acs)
|
screen.update_data(acs)
|
||||||
screen.update()
|
screen.update()
|
||||||
# except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# raise
|
raise
|
||||||
# except:
|
except:
|
||||||
# continue
|
continue
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
curses.endwin()
|
curses.endwin()
|
@ -28,6 +28,7 @@ class Screen(Thread):
|
|||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.screen = curses.initscr()
|
self.screen = curses.initscr()
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
|
curses.mousemask(1)
|
||||||
self.screen.keypad(True)
|
self.screen.keypad(True)
|
||||||
self.y = 3
|
self.y = 3
|
||||||
self.x = 1
|
self.x = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user