diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..e275bff --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,69 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask instance folder +instance/ + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version diff --git a/python/adsblib.py b/python/adsblib.py new file mode 100644 index 0000000..81f72eb --- /dev/null +++ b/python/adsblib.py @@ -0,0 +1,9 @@ +import json +import socket + + +def GetEvents(host, port): + with socket.create_connection((host, port)) as sock: + fh = sock.makefile() + for line in fh: + yield json.loads(line) diff --git a/python/check_mhz.py b/python/check_mhz.py new file mode 100755 index 0000000..80596a1 --- /dev/null +++ b/python/check_mhz.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +import sys +import time + +import adsblib + + +if len(sys.argv) != 3: + print('Usage: %s ' % sys.argv[0]) + +advertised_mhz = None +start_time = None +start_timestamp = None +for i, event in enumerate(adsblib.GetEvents(sys.argv[1], sys.argv[2])): + advertised_mhz = event.get('mlat_timestamp_mhz', advertised_mhz) + + if 'mlat_timestamp' not in event: + continue + + if not start_time: + start_time = time.time() + start_timestamp = event['mlat_timestamp'] + + if i % 1000 == 0 and start_time and advertised_mhz: + time_diff = time.time() - start_time + value_diff = event['mlat_timestamp'] - start_timestamp + measured_mhz = value_diff / time_diff / 1000000 + print( + '\r%d samples, %d seconds, advertised: %d MHz, measured: %d MHz' % + (i, time_diff, advertised_mhz, measured_mhz), + end='', flush=True)