Compare commits
130 Commits
v2.4
...
pr_demod24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c62b3b48fc | ||
|
|
ae01f95ff5 | ||
|
|
c3839d861c | ||
|
|
a8f3b9c811 | ||
|
|
8f098671a0 | ||
|
|
4cf99e8927 | ||
|
|
5a703a0d3c | ||
|
|
90f35a8f29 | ||
|
|
87e6f50486 | ||
|
|
0667c1b3c3 | ||
|
|
9d82f9b9c9 | ||
|
|
51222372b1 | ||
|
|
d3607a16c1 | ||
|
|
6a427c08b5 | ||
|
|
afd53af87b | ||
|
|
6b4a5bdaf3 | ||
|
|
3e0d7ceec5 | ||
|
|
130491e641 | ||
|
|
1f620d6534 | ||
|
|
b4d4ef8f1f | ||
|
|
bb8f83e832 | ||
|
|
b90932e51d | ||
|
|
b36540e2a1 | ||
|
|
c02414417d | ||
|
|
13f4fe77bb | ||
|
|
401f3f5e95 | ||
|
|
73c3a75234 | ||
|
|
06941bac2e | ||
|
|
6e33ac0288 | ||
|
|
65ce1a62c4 | ||
|
|
5dc74a5548 | ||
|
|
e7edba9e25 | ||
|
|
ce5adbafe5 | ||
|
|
b52431ca51 | ||
|
|
00f04a8886 | ||
|
|
0eb2d1f6a2 | ||
|
|
26ef5d3ad9 | ||
|
|
b90c2e740d | ||
|
|
e39baf38ed | ||
|
|
b9471d7fcb | ||
|
|
a350050e6e | ||
|
|
01574a9f01 | ||
|
|
cdb7aef82e | ||
|
|
a0a8c9b2f7 | ||
|
|
0b2648bfe0 | ||
|
|
69ce39ab39 | ||
|
|
83e22892ba | ||
|
|
7434fc9ed3 | ||
|
|
7260bff7e9 | ||
|
|
dd1fd596f8 | ||
|
|
b9089d55d2 | ||
|
|
6ab147bffe | ||
|
|
a308b9a7e0 | ||
|
|
96f49a00e4 | ||
|
|
b8f8f4dbc0 | ||
|
|
a4ce3bfaf1 | ||
|
|
3bb8c361e9 | ||
|
|
89e67fae31 | ||
|
|
50cef7d424 | ||
|
|
20801883d5 | ||
|
|
56d70b03d2 | ||
|
|
47de4d1163 | ||
|
|
2978329d03 | ||
|
|
4471c836d9 | ||
|
|
d16484bf72 | ||
|
|
436e9ce2c8 | ||
|
|
4a6341bcc0 | ||
|
|
90e60a74b5 | ||
|
|
f65ffd13f7 | ||
|
|
a3e5e7e141 | ||
|
|
668d6580d0 | ||
|
|
eacc828b75 | ||
|
|
4ba900f500 | ||
|
|
35c0bfa513 | ||
|
|
beb50fc788 | ||
|
|
fc135eacef | ||
|
|
84c6255567 | ||
|
|
224a0b8a67 | ||
|
|
c3976f1ca3 | ||
|
|
dd3a869c08 | ||
|
|
7e966090ab | ||
|
|
7a4c465f7d | ||
|
|
0ced97e3eb | ||
|
|
2bdd638cef | ||
|
|
93fc536926 | ||
|
|
1f15a953e3 | ||
|
|
0d7f628f3c | ||
|
|
7348a10f1b | ||
|
|
c9d2c4c6bc | ||
|
|
0c5539be3a | ||
|
|
1cf4d37e56 | ||
|
|
2fc376abae | ||
|
|
9c660578ad | ||
|
|
ba84cd7c39 | ||
|
|
2085a2c432 | ||
|
|
4126dedd19 | ||
|
|
7892aac4de | ||
|
|
7dcff01910 | ||
|
|
228306dd5f | ||
|
|
1c6b39322f | ||
|
|
9dde1b63d6 | ||
|
|
560b737739 | ||
|
|
d50f05d00d | ||
|
|
11a560dbb5 | ||
|
|
b51facbdc6 | ||
|
|
d77d1f7f6b | ||
|
|
5286355bf6 | ||
|
|
fe9e033a64 | ||
|
|
57307109e6 | ||
|
|
dc8f194e6e | ||
|
|
6571fe6fc0 | ||
|
|
aa64d4e7a9 | ||
|
|
db57d7419f | ||
|
|
ed18352c0c | ||
|
|
a75d6fd050 | ||
|
|
0ff628bb8e | ||
|
|
ea7653ef79 | ||
|
|
2046b1de07 | ||
|
|
768b80df8e | ||
|
|
e52d43f963 | ||
|
|
b60b31d4fb | ||
|
|
cb67c63326 | ||
|
|
bddaf9aec6 | ||
|
|
00fc1475ff | ||
|
|
489c405de0 | ||
|
|
ec2721cfdc | ||
|
|
2f13524a7c | ||
|
|
fb24d4f25c | ||
|
|
9ad535dc93 | ||
|
|
9a89766766 |
12
.coveragerc
Normal file
12
.coveragerc
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
include = */pyModeS/*
|
||||||
|
omit = *tests*
|
||||||
|
|
||||||
|
[report]
|
||||||
|
exclude_lines =
|
||||||
|
coverage: ignore
|
||||||
|
raise NotImplementedError
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
|
||||||
|
ignore_errors = True
|
||||||
3
.flake8
Normal file
3
.flake8
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[flake8]
|
||||||
|
max-line-length = 80
|
||||||
|
extend-ignore = E203, E302
|
||||||
29
.github/workflows/pypi-publish.yml
vendored
Normal file
29
.github/workflows/pypi-publish.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# This workflows will upload a Python Package using Twine when a release is created
|
||||||
|
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
|
||||||
|
|
||||||
|
name: PyPI Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: "3.x"
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install setuptools wheel twine
|
||||||
|
- name: Build and publish
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
||||||
|
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
python setup.py sdist bdist_wheel
|
||||||
|
twine upload dist/*
|
||||||
74
.github/workflows/run-tests.yml
vendored
Normal file
74
.github/workflows/run-tests.yml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request_target:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
POETRY_VERSION: "1.3.1"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
||||||
|
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
# Poetry cache depends on OS, Python version and Poetry version.
|
||||||
|
- name: Cache Poetry cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pypoetry
|
||||||
|
key: poetry-cache-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ env.POETRY_VERSION }}
|
||||||
|
|
||||||
|
# virtualenv cache should depends on OS, Python version and `poetry.lock` (and optionally workflow files).
|
||||||
|
- name: Cache Packages
|
||||||
|
uses: actions/cache@v3
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
|
with:
|
||||||
|
path: ~/.local
|
||||||
|
key: poetry-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
|
||||||
|
|
||||||
|
- name: Add poetry to windows path
|
||||||
|
if: "startsWith(runner.os, 'windows')"
|
||||||
|
run: |
|
||||||
|
echo "C:\Users\runneradmin\.local\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
|
||||||
|
- name: Install and configure Poetry
|
||||||
|
uses: snok/install-poetry@v1.3.3
|
||||||
|
with:
|
||||||
|
version: ${{ env.POETRY_VERSION }}
|
||||||
|
virtualenvs-create: true
|
||||||
|
virtualenvs-in-project: true
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
poetry install
|
||||||
|
|
||||||
|
- name: Type checking
|
||||||
|
if: ${{ env.PYTHON_VERSION != '3.7' }}
|
||||||
|
run: |
|
||||||
|
poetry run mypy pyModeS
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
poetry run pytest tests --cov --cov-report term-missing
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
if: ${{ github.event_name != 'pull_request_target' && env.PYTHON_VERSION == '3.10' }}
|
||||||
|
uses: codecov/codecov-action@v2
|
||||||
|
with:
|
||||||
|
env_vars: PYTHON_VERSION
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -5,6 +5,11 @@ __pycache__/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Cython
|
||||||
|
pyModeS/decoder/flarm/decode.c
|
||||||
|
pyModeS/extra/demod2400/core.c
|
||||||
|
pyModeS/c_common.c
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
||||||
@@ -64,3 +69,4 @@ target/
|
|||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
|
|
||||||
|
|||||||
26
Makefile
Normal file
26
Makefile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
install:
|
||||||
|
pip install . --upgrade
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
pip uninstall pyModeS -y
|
||||||
|
|
||||||
|
ext:
|
||||||
|
python setup.py build_ext --inplace
|
||||||
|
|
||||||
|
test:
|
||||||
|
make clean
|
||||||
|
@echo ""
|
||||||
|
@echo "[Test with py_common]"
|
||||||
|
python -m pytest tests
|
||||||
|
@echo ""
|
||||||
|
@echo "[Test with c_common]"
|
||||||
|
python setup.py build_ext --inplace
|
||||||
|
python -m pytest tests
|
||||||
|
|
||||||
|
clean:
|
||||||
|
find pyModeS -type f -name '*.c' -delete
|
||||||
|
find pyModeS -type f -name '*.so' -delete
|
||||||
|
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
|
||||||
|
rm -rf *.egg-info
|
||||||
|
rm -rf .pytest_cache
|
||||||
|
rm -rf build/*
|
||||||
155
README.rst
155
README.rst
@@ -1,6 +1,42 @@
|
|||||||
The Python ADS-B/Mode-S Decoder
|
The Python ADS-B/Mode-S Decoder
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
|
PyModeS is a Python library designed to decode Mode-S (including ADS-B) messages. It can be imported to your python project or used as a standalone tool to view and save live traffic data.
|
||||||
|
|
||||||
|
This is a project created by Junzi Sun, who works at `TU Delft <https://www.tudelft.nl/en/>`_, `Aerospace Engineering Faculty <https://www.tudelft.nl/en/ae/>`_, `CNS/ATM research group <http://cs.lr.tudelft.nl/atm/>`_. It is supported by many `contributors <https://github.com/junzis/pyModeS/graphs/contributors>`_ from different institutions.
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
------------
|
||||||
|
|
||||||
|
pyModeS supports the decoding of following types of messages:
|
||||||
|
|
||||||
|
- DF4 / DF20: Altitude code
|
||||||
|
- DF5 / DF21: Identity code (squawk code)
|
||||||
|
|
||||||
|
- DF17 / DF18: Automatic Dependent Surveillance-Broadcast (ADS-B)
|
||||||
|
|
||||||
|
- TC=1-4 / BDS 0,8: Aircraft identification and category
|
||||||
|
- TC=5-8 / BDS 0,6: Surface position
|
||||||
|
- TC=9-18 / BDS 0,5: Airborne position
|
||||||
|
- TC=19 / BDS 0,9: Airborne velocity
|
||||||
|
- TC=28 / BDS 6,1: Airborne status [to be implemented]
|
||||||
|
- TC=29 / BDS 6,2: Target state and status information [to be implemented]
|
||||||
|
- TC=31 / BDS 6,5: Aircraft operational status [to be implemented]
|
||||||
|
|
||||||
|
- DF20 / DF21: Mode-S Comm-B messages
|
||||||
|
|
||||||
|
- BDS 1,0: Data link capability report
|
||||||
|
- BDS 1,7: Common usage GICB capability report
|
||||||
|
- BDS 2,0: Aircraft identification
|
||||||
|
- BDS 3,0: ACAS active resolution advisory
|
||||||
|
- BDS 4,0: Selected vertical intention
|
||||||
|
- BDS 4,4: Meteorological routine air report (experimental)
|
||||||
|
- BDS 4,5: Meteorological hazard report (experimental)
|
||||||
|
- BDS 5,0: Track and turn report
|
||||||
|
- BDS 6,0: Heading and speed report
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
If you find this project useful for your research, please considering cite this tool as::
|
If you find this project useful for your research, please considering cite this tool as::
|
||||||
|
|
||||||
@article{sun2019pymodes,
|
@article{sun2019pymodes,
|
||||||
@@ -14,40 +50,6 @@ If you find this project useful for your research, please considering cite this
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Introduction
|
|
||||||
---------------------
|
|
||||||
PyModeS is a Python library designed to decode Mode-S (including ADS-B) message. It can be imported to your python project or be used as a standalone tool to view and save live traffic data.
|
|
||||||
|
|
||||||
Messages with following Downlink Formats (DF) are supported:
|
|
||||||
|
|
||||||
**DF17 / DF18: Automatic Dependent Surveillance-Broadcast (ADS-B)**
|
|
||||||
|
|
||||||
- TC=1-4 / BDS 0,8: Aircraft identification and category
|
|
||||||
- TC=5-8 / BDS 0,6: Surface position
|
|
||||||
- TC=9-18 / BDS 0,5: Airborne position
|
|
||||||
- TC=19 / BDS 0,9: Airborne velocity
|
|
||||||
- TC=28 / BDS 6,1: Airborne status [to be implemented]
|
|
||||||
- TC=29 / BDS 6,2: Target state and status information [to be implemented]
|
|
||||||
- TC=31 / BDS 6,5: Aircraft operational status [to be implemented]
|
|
||||||
|
|
||||||
|
|
||||||
**DF20 / DF21: Mode-S Comm-B replies**
|
|
||||||
|
|
||||||
- BDS 1,0: Data link capability report
|
|
||||||
- BDS 1,7: Common usage GICB capability report
|
|
||||||
- BDS 2,0: Aircraft identification
|
|
||||||
- BDS 3,0: ACAS active resolution advisory
|
|
||||||
- BDS 4,0: Selected vertical intention
|
|
||||||
- BDS 4,4: Meteorological routine air report (experimental)
|
|
||||||
- BDS 4,5: Meteorological hazard report (experimental)
|
|
||||||
- BDS 5,0: Track and turn report
|
|
||||||
- BDS 6,0: Heading and speed report
|
|
||||||
|
|
||||||
|
|
||||||
**DF4 / DF20: Altitude code**
|
|
||||||
|
|
||||||
**DF5 / DF21: Identity code (squawk code)**
|
|
||||||
|
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
-----------
|
-----------
|
||||||
@@ -55,32 +57,50 @@ Check out and contribute to this open-source project at:
|
|||||||
https://github.com/junzis/pyModeS
|
https://github.com/junzis/pyModeS
|
||||||
|
|
||||||
Detailed manual on Mode-S decoding is published at:
|
Detailed manual on Mode-S decoding is published at:
|
||||||
https://mode-s.org/decode.
|
https://mode-s.org/decode
|
||||||
|
|
||||||
The API documentation of pyModeS is at:
|
The API documentation of pyModeS is at:
|
||||||
http://pymodes.readthedocs.io
|
https://mode-s.org/api
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Install
|
Basic installation
|
||||||
-------
|
-------------------
|
||||||
|
|
||||||
The pyModeS can be installed with extra option ``[all]`` in order to install dependencies ``pyzmq`` and ``pyrtlsdr`` automatically.
|
|
||||||
|
|
||||||
Installation examples::
|
Installation examples::
|
||||||
|
|
||||||
# stable version, basic
|
# stable version
|
||||||
pip install pyModeS
|
pip install pyModeS
|
||||||
|
|
||||||
# stable version, including dependencies for streamer and rtlsdr
|
# conda (compiled) version
|
||||||
pip install pyModeS[all]
|
conda install -c conda-forge pymodes
|
||||||
|
|
||||||
# development version, basic
|
# development version
|
||||||
pip install git+https://github.com/junzis/pyModeS
|
pip install git+https://github.com/junzis/pyModeS
|
||||||
|
|
||||||
# development version, including dependencies for streamer and rtlsdr
|
|
||||||
pip install git+https://github.com/junzis/pyModeS#egg=pyModeS[all]
|
|
||||||
|
|
||||||
|
Dependencies ``numpy``, and ``pyzmq`` are installed automatically during previous installations processes.
|
||||||
|
|
||||||
|
If you need to connect pyModeS to a RTL-SDR receiver, ``pyrtlsdr`` need to be installed manually::
|
||||||
|
|
||||||
|
pip install pyrtlsdr
|
||||||
|
|
||||||
|
|
||||||
|
Advanced installation (using c modules)
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
If you want to make use of the (faster) c module, install ``pyModeS`` as follows::
|
||||||
|
|
||||||
|
# conda (compiled) version
|
||||||
|
conda install -c conda-forge pymodes
|
||||||
|
|
||||||
|
# stable version
|
||||||
|
pip install pyModeS
|
||||||
|
|
||||||
|
# development version
|
||||||
|
git clone https://github.com/junzis/pyModeS
|
||||||
|
cd pyModeS
|
||||||
|
poetry install -E rtlsdr
|
||||||
|
|
||||||
|
|
||||||
View live traffic (modeslive)
|
View live traffic (modeslive)
|
||||||
@@ -106,7 +126,7 @@ General usage::
|
|||||||
Live with RTL-SDR
|
Live with RTL-SDR
|
||||||
*******************
|
*******************
|
||||||
|
|
||||||
If you have an RTL-SDR receiver plugged to the computer, you can connect it with ``rtlsdr`` source switch, shown as follows::
|
If you have an RTL-SDR receiver connected to your computer, you can use the ``rtlsdr`` source switch (require ``pyrtlsdr`` package), with command::
|
||||||
|
|
||||||
$ modeslive --source rtlsdr
|
$ modeslive --source rtlsdr
|
||||||
|
|
||||||
@@ -147,7 +167,7 @@ Common functions
|
|||||||
pms.hex2bin(str) # Convert hexadecimal string to binary string
|
pms.hex2bin(str) # Convert hexadecimal string to binary string
|
||||||
pms.bin2int(str) # Convert binary string to integer
|
pms.bin2int(str) # Convert binary string to integer
|
||||||
pms.hex2int(str) # Convert hexadecimal string to integer
|
pms.hex2int(str) # Convert hexadecimal string to integer
|
||||||
pms.gray2int(str) # Convert grey code to interger
|
pms.gray2int(str) # Convert grey code to integer
|
||||||
|
|
||||||
|
|
||||||
Core functions for ADS-B decoding
|
Core functions for ADS-B decoding
|
||||||
@@ -161,7 +181,7 @@ Core functions for ADS-B decoding
|
|||||||
# Typecode 1-4
|
# Typecode 1-4
|
||||||
pms.adsb.callsign(msg)
|
pms.adsb.callsign(msg)
|
||||||
|
|
||||||
# Typecode 5-8 (surface), 9-18 (airborne, barometric height), and 9-18 (airborne, GNSS height)
|
# Typecode 5-8 (surface), 9-18 (airborne, barometric height), and 20-22 (airborne, GNSS height)
|
||||||
pms.adsb.position(msg_even, msg_odd, t_even, t_odd, lat_ref=None, lon_ref=None)
|
pms.adsb.position(msg_even, msg_odd, t_even, t_odd, lat_ref=None, lon_ref=None)
|
||||||
pms.adsb.airborne_position(msg_even, msg_odd, t_even, t_odd)
|
pms.adsb.airborne_position(msg_even, msg_odd, t_even, t_odd)
|
||||||
pms.adsb.surface_position(msg_even, msg_odd, t_even, t_odd, lat_ref, lon_ref)
|
pms.adsb.surface_position(msg_even, msg_odd, t_even, t_odd, lat_ref, lon_ref)
|
||||||
@@ -255,8 +275,20 @@ Mode-S Enhanced Surveillance (EHS)
|
|||||||
pms.commb.vr60ins(msg) # Inertial vertical speed (ft/min)
|
pms.commb.vr60ins(msg) # Inertial vertical speed (ft/min)
|
||||||
|
|
||||||
|
|
||||||
Meteorological routine air report (MRAR) [Experimental]
|
Meteorological reports [Experimental]
|
||||||
********************************************************
|
**************************************
|
||||||
|
|
||||||
|
To identify BDS 4,4 and 4,5 codes, you must set ``mrar`` argument to ``True`` in the ``infer()`` function:
|
||||||
|
|
||||||
|
.. code:: python
|
||||||
|
|
||||||
|
pms.bds.infer(msg. mrar=True)
|
||||||
|
|
||||||
|
Once the correct MRAR and MHR messages are identified, decode them as follows:
|
||||||
|
|
||||||
|
|
||||||
|
Meteorological routine air report (MRAR)
|
||||||
|
+++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
@@ -267,8 +299,8 @@ Meteorological routine air report (MRAR) [Experimental]
|
|||||||
pms.commb.hum44(msg) # Humidity (%)
|
pms.commb.hum44(msg) # Humidity (%)
|
||||||
|
|
||||||
|
|
||||||
Meteorological hazard air report (MHR) [Experimental]
|
Meteorological hazard air report (MHR)
|
||||||
*******************************************************
|
+++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
@@ -327,8 +359,19 @@ Here is an example:
|
|||||||
|
|
||||||
Unit test
|
Unit test
|
||||||
---------
|
---------
|
||||||
To perform unit tests. First, install ``tox`` through pip. Then, run the following commands:
|
To perform unit tests, ``pytest`` must be install first.
|
||||||
|
|
||||||
.. code:: bash
|
Build Cython extensions
|
||||||
|
::
|
||||||
|
|
||||||
$ tox
|
$ make ext
|
||||||
|
|
||||||
|
Run unit tests
|
||||||
|
::
|
||||||
|
|
||||||
|
$ make test
|
||||||
|
|
||||||
|
Clean build files
|
||||||
|
::
|
||||||
|
|
||||||
|
$ make clean
|
||||||
|
|||||||
77
build.py
Normal file
77
build.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
from distutils.core import Distribution, Extension
|
||||||
|
from distutils.command import build_ext
|
||||||
|
|
||||||
|
from Cython.Build import cythonize
|
||||||
|
|
||||||
|
|
||||||
|
def build() -> None:
|
||||||
|
compile_args = []
|
||||||
|
|
||||||
|
if sys.platform == "linux":
|
||||||
|
compile_args += [
|
||||||
|
"-march=native",
|
||||||
|
"-O3",
|
||||||
|
"-msse",
|
||||||
|
"-msse2",
|
||||||
|
"-mfma",
|
||||||
|
"-mfpmath=sse",
|
||||||
|
"-Wno-pointer-sign",
|
||||||
|
"-Wno-unused-variable",
|
||||||
|
]
|
||||||
|
|
||||||
|
extensions = [
|
||||||
|
Extension(
|
||||||
|
"pyModeS.c_common",
|
||||||
|
["pyModeS/c_common.pyx"],
|
||||||
|
extra_compile_args=compile_args,
|
||||||
|
),
|
||||||
|
Extension(
|
||||||
|
"pyModeS.decoder.flarm.decode",
|
||||||
|
[
|
||||||
|
"pyModeS/decoder/flarm/decode.pyx",
|
||||||
|
"pyModeS/decoder/flarm/core.c",
|
||||||
|
],
|
||||||
|
extra_compile_args=compile_args,
|
||||||
|
include_dirs=["pyModeS/decoder/flarm"],
|
||||||
|
),
|
||||||
|
Extension(
|
||||||
|
"pyModeS.extra.demod2400.core",
|
||||||
|
[
|
||||||
|
"pyModeS/extra/demod2400/core.pyx",
|
||||||
|
"pyModeS/extra/demod2400/demod2400.c",
|
||||||
|
],
|
||||||
|
extra_compile_args=compile_args,
|
||||||
|
include_dirs=["pyModeS/extra/demod2400"],
|
||||||
|
libraries=["m"],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
ext_modules = cythonize(
|
||||||
|
extensions,
|
||||||
|
compiler_directives={"binding": True, "language_level": 3},
|
||||||
|
)
|
||||||
|
|
||||||
|
distribution = Distribution(
|
||||||
|
{"name": "extended", "ext_modules": ext_modules}
|
||||||
|
)
|
||||||
|
distribution.package_dir = "extended" # type: ignore
|
||||||
|
|
||||||
|
cmd = build_ext.build_ext(distribution)
|
||||||
|
cmd.verbose = True # type: ignore
|
||||||
|
cmd.ensure_finalized() # type: ignore
|
||||||
|
cmd.run()
|
||||||
|
|
||||||
|
# Copy built extensions back to the project
|
||||||
|
for output in cmd.get_outputs():
|
||||||
|
relative_extension = os.path.relpath(output, cmd.build_lib)
|
||||||
|
shutil.copyfile(output, relative_extension)
|
||||||
|
mode = os.stat(relative_extension).st_mode
|
||||||
|
mode |= (mode & 0o444) >> 2
|
||||||
|
os.chmod(relative_extension, mode)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
build()
|
||||||
@@ -17,5 +17,5 @@ help:
|
|||||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
%: Makefile
|
%: Makefile
|
||||||
rm -f source/pyModeS*.rst source/modules.rst
|
rm -f source/pyModeS*.rst source/modules.rst
|
||||||
sphinx-apidoc -f -e -M -o source/ ../pyModeS
|
sphinx-apidoc -f -e -M -o source/ ../pyModeS ../pyModeS/decoder/ehs.py ../pyModeS/decoder/els.py ../pyModeS/streamer ../pyModeS/extra
|
||||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|||||||
17
doc/source/_templates/layout.html
Normal file
17
doc/source/_templates/layout.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{% extends "!layout.html" %}
|
||||||
|
|
||||||
|
{% block footer %}
|
||||||
|
{{ super() }}
|
||||||
|
|
||||||
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-74700456-1"></script>
|
||||||
|
<script>
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
|
||||||
|
gtag('config', 'UA-74700456-1');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -14,19 +14,20 @@
|
|||||||
#
|
#
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, os.path.abspath('../..'))
|
|
||||||
|
sys.path.insert(0, os.path.abspath("../.."))
|
||||||
|
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = 'pyModeS'
|
project = "pyModeS"
|
||||||
copyright = '2019, Junzi Sun'
|
copyright = "2019, Junzi Sun"
|
||||||
author = 'Junzi Sun'
|
author = "Junzi Sun"
|
||||||
|
|
||||||
# The short X.Y version
|
# The short X.Y version
|
||||||
version = ''
|
version = ""
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
release = ''
|
release = ""
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
@@ -39,26 +40,24 @@ release = ''
|
|||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||||
# ones.
|
# ones.
|
||||||
extensions = [
|
extensions = [
|
||||||
'sphinx.ext.autodoc',
|
"sphinx.ext.autodoc",
|
||||||
'sphinx.ext.todo',
|
"sphinx.ext.mathjax",
|
||||||
'sphinx.ext.coverage',
|
"sphinx.ext.viewcode",
|
||||||
'sphinx.ext.mathjax',
|
"sphinx.ext.githubpages",
|
||||||
'sphinx.ext.viewcode',
|
"sphinx.ext.napoleon",
|
||||||
'sphinx.ext.githubpages',
|
|
||||||
'sphinx.ext.napoleon',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
# templates_path = ['']
|
templates_path = ["_templates"]
|
||||||
|
|
||||||
# The suffix(es) of source filenames.
|
# The suffix(es) of source filenames.
|
||||||
# You can specify multiple suffix as a list of string:
|
# You can specify multiple suffix as a list of string:
|
||||||
#
|
#
|
||||||
# source_suffix = ['.rst', '.md']
|
# source_suffix = ['.rst', '.md']
|
||||||
source_suffix = '.rst'
|
source_suffix = ".rst"
|
||||||
|
|
||||||
# The master toctree document.
|
# The master toctree document.
|
||||||
master_doc = 'index'
|
master_doc = "index"
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
@@ -82,6 +81,10 @@ pygments_style = None
|
|||||||
# a list of builtin themes.
|
# a list of builtin themes.
|
||||||
#
|
#
|
||||||
# html_theme = 'alabaster'
|
# html_theme = 'alabaster'
|
||||||
|
html_theme = "neo_rtd_theme"
|
||||||
|
import sphinx_theme
|
||||||
|
|
||||||
|
html_theme_path = [sphinx_theme.get_html_theme_path()]
|
||||||
|
|
||||||
# Theme options are theme-specific and customize the look and feel of a theme
|
# Theme options are theme-specific and customize the look and feel of a theme
|
||||||
# further. For a list of options available for each theme, see the
|
# further. For a list of options available for each theme, see the
|
||||||
@@ -108,7 +111,7 @@ pygments_style = None
|
|||||||
# -- Options for HTMLHelp output ---------------------------------------------
|
# -- Options for HTMLHelp output ---------------------------------------------
|
||||||
|
|
||||||
# Output file base name for HTML help builder.
|
# Output file base name for HTML help builder.
|
||||||
htmlhelp_basename = 'pyModeSdoc'
|
htmlhelp_basename = "pyModeSdoc"
|
||||||
|
|
||||||
|
|
||||||
# -- Options for LaTeX output ------------------------------------------------
|
# -- Options for LaTeX output ------------------------------------------------
|
||||||
@@ -117,15 +120,12 @@ latex_elements = {
|
|||||||
# The paper size ('letterpaper' or 'a4paper').
|
# The paper size ('letterpaper' or 'a4paper').
|
||||||
#
|
#
|
||||||
# 'papersize': 'letterpaper',
|
# 'papersize': 'letterpaper',
|
||||||
|
|
||||||
# The font size ('10pt', '11pt' or '12pt').
|
# The font size ('10pt', '11pt' or '12pt').
|
||||||
#
|
#
|
||||||
# 'pointsize': '10pt',
|
# 'pointsize': '10pt',
|
||||||
|
|
||||||
# Additional stuff for the LaTeX preamble.
|
# Additional stuff for the LaTeX preamble.
|
||||||
#
|
#
|
||||||
# 'preamble': '',
|
# 'preamble': '',
|
||||||
|
|
||||||
# Latex figure (float) alignment
|
# Latex figure (float) alignment
|
||||||
#
|
#
|
||||||
# 'figure_align': 'htbp',
|
# 'figure_align': 'htbp',
|
||||||
@@ -135,8 +135,7 @@ latex_elements = {
|
|||||||
# (source start file, target name, title,
|
# (source start file, target name, title,
|
||||||
# author, documentclass [howto, manual, or own class]).
|
# author, documentclass [howto, manual, or own class]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
(master_doc, 'pyModeS.tex', 'pyModeS Documentation',
|
(master_doc, "pyModeS.tex", "pyModeS Documentation", "Junzi Sun", "manual")
|
||||||
'Junzi Sun', 'manual'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -144,10 +143,7 @@ latex_documents = [
|
|||||||
|
|
||||||
# One entry per manual page. List of tuples
|
# One entry per manual page. List of tuples
|
||||||
# (source start file, name, description, authors, manual section).
|
# (source start file, name, description, authors, manual section).
|
||||||
man_pages = [
|
man_pages = [(master_doc, "pymodes", "pyModeS Documentation", [author], 1)]
|
||||||
(master_doc, 'pymodes', 'pyModeS Documentation',
|
|
||||||
[author], 1)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for Texinfo output ----------------------------------------------
|
# -- Options for Texinfo output ----------------------------------------------
|
||||||
@@ -156,9 +152,15 @@ man_pages = [
|
|||||||
# (source start file, target name, title, author,
|
# (source start file, target name, title, author,
|
||||||
# dir menu entry, description, category)
|
# dir menu entry, description, category)
|
||||||
texinfo_documents = [
|
texinfo_documents = [
|
||||||
(master_doc, 'pyModeS', 'pyModeS Documentation',
|
(
|
||||||
author, 'pyModeS', 'One line description of project.',
|
master_doc,
|
||||||
'Miscellaneous'),
|
"pyModeS",
|
||||||
|
"pyModeS Documentation",
|
||||||
|
author,
|
||||||
|
"pyModeS",
|
||||||
|
"One line description of project.",
|
||||||
|
"Miscellaneous",
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +179,7 @@ epub_title = project
|
|||||||
# epub_uid = ''
|
# epub_uid = ''
|
||||||
|
|
||||||
# A list of files that should not be packed into the epub file.
|
# A list of files that should not be packed into the epub file.
|
||||||
epub_exclude_files = ['search.html']
|
epub_exclude_files = ["search.html"]
|
||||||
|
|
||||||
|
|
||||||
# -- Extension configuration -------------------------------------------------
|
# -- Extension configuration -------------------------------------------------
|
||||||
|
|||||||
@@ -9,11 +9,49 @@ Welcome to pyModeS documentation!
|
|||||||
The source code can be found at: https://github.com/junzis/pyModeS
|
The source code can be found at: https://github.com/junzis/pyModeS
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 3
|
:caption: Core modules
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
pyModeS.decoder.adsb
|
||||||
|
pyModeS.decoder.commb
|
||||||
|
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:caption: ADS-B messages
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
pyModeS.decoder.bds.bds05
|
||||||
|
pyModeS.decoder.bds.bds06
|
||||||
|
pyModeS.decoder.bds.bds08
|
||||||
|
pyModeS.decoder.bds.bds09
|
||||||
|
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:caption: ELS - elementary surveillance
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
pyModeS.decoder.bds.bds10
|
||||||
|
pyModeS.decoder.bds.bds17
|
||||||
|
pyModeS.decoder.bds.bds20
|
||||||
|
pyModeS.decoder.bds.bds30
|
||||||
|
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:caption: EHS - enhanced surveillance
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
pyModeS.decoder.bds.bds40
|
||||||
|
pyModeS.decoder.bds.bds50
|
||||||
|
pyModeS.decoder.bds.bds60
|
||||||
|
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:caption: MRAR / MHR
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
pyModeS.decoder.bds.bds44
|
||||||
|
pyModeS.decoder.bds.bds45
|
||||||
|
|
||||||
pyModeS.decoder
|
|
||||||
pyModeS.streamer
|
|
||||||
pyModeS.extra
|
|
||||||
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
|
|
||||||
pushd %~dp0
|
|
||||||
|
|
||||||
REM Command file for Sphinx documentation
|
|
||||||
|
|
||||||
if "%SPHINXBUILD%" == "" (
|
|
||||||
set SPHINXBUILD=sphinx-build
|
|
||||||
)
|
|
||||||
set SOURCEDIR=.
|
|
||||||
set BUILDDIR=_build
|
|
||||||
|
|
||||||
if "%1" == "" goto help
|
|
||||||
|
|
||||||
%SPHINXBUILD% >NUL 2>NUL
|
|
||||||
if errorlevel 9009 (
|
|
||||||
echo.
|
|
||||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
|
||||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
|
||||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
|
||||||
echo.may add the Sphinx directory to PATH.
|
|
||||||
echo.
|
|
||||||
echo.If you don't have Sphinx installed, grab it from
|
|
||||||
echo.http://sphinx-doc.org/
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
||||||
goto end
|
|
||||||
|
|
||||||
:help
|
|
||||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
||||||
|
|
||||||
:end
|
|
||||||
popd
|
|
||||||
7
doc/source/pyModeS.c_common.rst
Normal file
7
doc/source/pyModeS.c_common.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
pyModeS.c\_common module
|
||||||
|
========================
|
||||||
|
|
||||||
|
.. automodule:: pyModeS.c_common
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
doc/source/pyModeS.common.rst
Normal file
7
doc/source/pyModeS.common.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
pyModeS.common module
|
||||||
|
=====================
|
||||||
|
|
||||||
|
.. automodule:: pyModeS.common
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.acas module
|
|||||||
===========================
|
===========================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.acas
|
.. automodule:: pyModeS.decoder.acas
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.adsb module
|
|||||||
===========================
|
===========================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.adsb
|
.. automodule:: pyModeS.decoder.adsb
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.allcall module
|
|||||||
==============================
|
==============================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.allcall
|
.. automodule:: pyModeS.decoder.allcall
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds05 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds05
|
.. automodule:: pyModeS.decoder.bds.bds05
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds06 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds06
|
.. automodule:: pyModeS.decoder.bds.bds06
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds08 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds08
|
.. automodule:: pyModeS.decoder.bds.bds08
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds09 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds09
|
.. automodule:: pyModeS.decoder.bds.bds09
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds10 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds10
|
.. automodule:: pyModeS.decoder.bds.bds10
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds17 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds17
|
.. automodule:: pyModeS.decoder.bds.bds17
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds20 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds20
|
.. automodule:: pyModeS.decoder.bds.bds20
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds30 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds30
|
.. automodule:: pyModeS.decoder.bds.bds30
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds40 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds40
|
.. automodule:: pyModeS.decoder.bds.bds40
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds44 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds44
|
.. automodule:: pyModeS.decoder.bds.bds44
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds45 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds45
|
.. automodule:: pyModeS.decoder.bds.bds45
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds50 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds50
|
.. automodule:: pyModeS.decoder.bds.bds50
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds53 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds53
|
.. automodule:: pyModeS.decoder.bds.bds53
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.bds.bds60 module
|
|||||||
================================
|
================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds.bds60
|
.. automodule:: pyModeS.decoder.bds.bds60
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ pyModeS.decoder.bds package
|
|||||||
===========================
|
===========================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.bds
|
.. automodule:: pyModeS.decoder.bds
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
pyModeS.decoder.bds.bds05
|
pyModeS.decoder.bds.bds05
|
||||||
pyModeS.decoder.bds.bds06
|
pyModeS.decoder.bds.bds06
|
||||||
@@ -25,4 +26,3 @@ Submodules
|
|||||||
pyModeS.decoder.bds.bds50
|
pyModeS.decoder.bds.bds50
|
||||||
pyModeS.decoder.bds.bds53
|
pyModeS.decoder.bds.bds53
|
||||||
pyModeS.decoder.bds.bds60
|
pyModeS.decoder.bds.bds60
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.commb module
|
|||||||
============================
|
============================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.commb
|
.. automodule:: pyModeS.decoder.commb
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.decoder.common module
|
|
||||||
=============================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.common
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.decoder.ehs module
|
|
||||||
==========================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.ehs
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.decoder.els module
|
|
||||||
==========================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.els
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -2,29 +2,28 @@ pyModeS.decoder package
|
|||||||
=======================
|
=======================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder
|
.. automodule:: pyModeS.decoder
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
Subpackages
|
Subpackages
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
pyModeS.decoder.bds
|
pyModeS.decoder.bds
|
||||||
|
|
||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
pyModeS.decoder.acas
|
pyModeS.decoder.acas
|
||||||
pyModeS.decoder.adsb
|
pyModeS.decoder.adsb
|
||||||
pyModeS.decoder.allcall
|
pyModeS.decoder.allcall
|
||||||
pyModeS.decoder.commb
|
pyModeS.decoder.commb
|
||||||
pyModeS.decoder.common
|
|
||||||
pyModeS.decoder.ehs
|
|
||||||
pyModeS.decoder.els
|
|
||||||
pyModeS.decoder.surv
|
pyModeS.decoder.surv
|
||||||
pyModeS.decoder.uncertainty
|
pyModeS.decoder.uncertainty
|
||||||
|
pyModeS.decoder.uplink
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.surv module
|
|||||||
===========================
|
===========================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.surv
|
.. automodule:: pyModeS.decoder.surv
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ pyModeS.decoder.uncertainty module
|
|||||||
==================================
|
==================================
|
||||||
|
|
||||||
.. automodule:: pyModeS.decoder.uncertainty
|
.. automodule:: pyModeS.decoder.uncertainty
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|||||||
7
doc/source/pyModeS.decoder.uplink.rst
Normal file
7
doc/source/pyModeS.decoder.uplink.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
pyModeS.decoder.uplink module
|
||||||
|
=============================
|
||||||
|
|
||||||
|
.. automodule:: pyModeS.decoder.uplink
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.extra.aero module
|
|
||||||
=========================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.extra.aero
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
pyModeS.extra package
|
|
||||||
=====================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.extra
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Submodules
|
|
||||||
----------
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
|
|
||||||
pyModeS.extra.aero
|
|
||||||
pyModeS.extra.tcpclient
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.extra.tcpclient module
|
|
||||||
==============================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.extra.tcpclient
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -2,16 +2,23 @@ pyModeS package
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
.. automodule:: pyModeS
|
.. automodule:: pyModeS
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
Subpackages
|
Subpackages
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
pyModeS.decoder
|
pyModeS.decoder
|
||||||
pyModeS.extra
|
|
||||||
pyModeS.streamer
|
|
||||||
|
|
||||||
|
Submodules
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
|
pyModeS.c_common
|
||||||
|
pyModeS.common
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
pyModeS.streamer package
|
|
||||||
========================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.streamer
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Submodules
|
|
||||||
----------
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
|
|
||||||
pyModeS.streamer.screen
|
|
||||||
pyModeS.streamer.stream
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.streamer.screen module
|
|
||||||
==============================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.streamer.screen
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pyModeS.streamer.stream module
|
|
||||||
==============================
|
|
||||||
|
|
||||||
.. automodule:: pyModeS.streamer.stream
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
0
doc/warnings
Normal file
0
doc/warnings
Normal file
1364
poetry.lock
generated
Normal file
1364
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,35 @@
|
|||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from .decoder.common import *
|
try:
|
||||||
|
from . import c_common as common
|
||||||
|
from .c_common import *
|
||||||
|
except Exception:
|
||||||
|
from . import py_common as common # type: ignore
|
||||||
|
from .py_common import * # type: ignore
|
||||||
|
|
||||||
from .decoder import tell
|
from .decoder import tell
|
||||||
from .decoder import adsb
|
from .decoder import adsb
|
||||||
from .decoder import commb
|
from .decoder import commb
|
||||||
from .decoder import common
|
from .decoder import allcall
|
||||||
|
from .decoder import surv
|
||||||
from .decoder import bds
|
from .decoder import bds
|
||||||
from .extra import aero
|
from .extra import aero
|
||||||
from .extra import tcpclient
|
from .extra import tcpclient
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"common",
|
||||||
|
"tell",
|
||||||
|
"adsb",
|
||||||
|
"commb",
|
||||||
|
"allcall",
|
||||||
|
"surv",
|
||||||
|
"bds",
|
||||||
|
"aero",
|
||||||
|
"tcpclient",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
warnings.simplefilter("once", DeprecationWarning)
|
warnings.simplefilter("once", DeprecationWarning)
|
||||||
|
|
||||||
dirpath = os.path.dirname(os.path.realpath(__file__))
|
dirpath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|||||||
28
pyModeS/c_common.pxd
Normal file
28
pyModeS/c_common.pxd
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# cython: language_level=3
|
||||||
|
|
||||||
|
cdef int char_to_int(unsigned char binstr)
|
||||||
|
cdef unsigned char int_to_char(unsigned char i)
|
||||||
|
|
||||||
|
cpdef str hex2bin(str hexstr)
|
||||||
|
cpdef long bin2int(str binstr)
|
||||||
|
cpdef long hex2int(str hexstr)
|
||||||
|
cpdef str bin2hex(str binstr)
|
||||||
|
|
||||||
|
cpdef unsigned char df(str msg)
|
||||||
|
cpdef long crc(str msg, bint encode=*)
|
||||||
|
|
||||||
|
cpdef long floor(double x)
|
||||||
|
cpdef str icao(str msg)
|
||||||
|
cpdef bint is_icao_assigned(str icao)
|
||||||
|
|
||||||
|
cpdef int typecode(str msg)
|
||||||
|
cpdef int cprNL(double lat)
|
||||||
|
|
||||||
|
cpdef str idcode(str msg)
|
||||||
|
cpdef str squawk(str binstr)
|
||||||
|
|
||||||
|
cpdef int altcode(str msg)
|
||||||
|
cpdef int altitude(str binstr)
|
||||||
|
|
||||||
|
cpdef str data(str msg)
|
||||||
|
cpdef bint allzeros(str msg)
|
||||||
18
pyModeS/c_common.pyi
Normal file
18
pyModeS/c_common.pyi
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
def hex2bin(hexstr: str) -> str: ...
|
||||||
|
def bin2int(binstr: str) -> int: ...
|
||||||
|
def hex2int(hexstr: str) -> int: ...
|
||||||
|
def bin2hex(binstr: str) -> str: ...
|
||||||
|
def df(msg: str) -> int: ...
|
||||||
|
def crc(msg: str, encode: bool = False) -> int: ...
|
||||||
|
def floor(x: float) -> float: ...
|
||||||
|
def icao(msg: str) -> str: ...
|
||||||
|
def is_icao_assigned(icao: str) -> bool: ...
|
||||||
|
def typecode(msg: str) -> int: ...
|
||||||
|
def cprNL(lat: float) -> int: ...
|
||||||
|
def idcode(msg: str) -> str: ...
|
||||||
|
def squawk(binstr: str) -> str: ...
|
||||||
|
def altcode(msg: str) -> int: ...
|
||||||
|
def altitude(binstr: str) -> int: ...
|
||||||
|
def data(msg: str) -> str: ...
|
||||||
|
def allzeros(msg: str) -> bool: ...
|
||||||
|
def wrongstatus(data: str, sb: int, msb: int, lsb: int) -> bool: ...
|
||||||
405
pyModeS/c_common.pyx
Normal file
405
pyModeS/c_common.pyx
Normal file
@@ -0,0 +1,405 @@
|
|||||||
|
# cython: language_level=3
|
||||||
|
|
||||||
|
cimport cython
|
||||||
|
from cpython cimport array
|
||||||
|
from cpython.bytes cimport PyBytes_GET_SIZE
|
||||||
|
from cpython.bytearray cimport PyByteArray_GET_SIZE
|
||||||
|
|
||||||
|
from libc.math cimport abs, cos, acos, fabs, M_PI as pi, floor as c_floor
|
||||||
|
|
||||||
|
|
||||||
|
cdef int char_to_int(unsigned char binstr):
|
||||||
|
if 48 <= binstr <= 57: # 0 to 9
|
||||||
|
return binstr - 48
|
||||||
|
if 97 <= binstr <= 102: # a to f
|
||||||
|
return binstr - 97 + 10
|
||||||
|
if 65 <= binstr <= 70: # A to F
|
||||||
|
return binstr - 65 + 10
|
||||||
|
return 0
|
||||||
|
|
||||||
|
cdef unsigned char int_to_char(unsigned char i):
|
||||||
|
if i < 10:
|
||||||
|
return 48 + i # "0" + i
|
||||||
|
return 97 - 10 + i # "a" - 10 + i
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.overflowcheck(False)
|
||||||
|
cpdef str hex2bin(str hexstr):
|
||||||
|
"""Convert a hexadecimal string to binary string, with zero fillings."""
|
||||||
|
# num_of_bits = len(hexstr) * 4
|
||||||
|
cdef hexbytes = bytes(hexstr.encode())
|
||||||
|
cdef Py_ssize_t len_hexstr = PyBytes_GET_SIZE(hexbytes)
|
||||||
|
# binstr = bin(int(hexbytes, 16))[2:].zfill(int(num_of_bits))
|
||||||
|
cdef bytearray _binstr = bytearray(4 * len_hexstr)
|
||||||
|
cdef unsigned char[:] binstr = _binstr
|
||||||
|
cdef unsigned char int_
|
||||||
|
cdef Py_ssize_t i
|
||||||
|
for i in range(len_hexstr):
|
||||||
|
int_ = char_to_int(hexbytes[i])
|
||||||
|
binstr[4*i] = int_to_char((int_ >> 3) & 1)
|
||||||
|
binstr[4*i+1] = int_to_char((int_ >> 2) & 1)
|
||||||
|
binstr[4*i+2] = int_to_char((int_ >> 1) & 1)
|
||||||
|
binstr[4*i+3] = int_to_char((int_) & 1)
|
||||||
|
return _binstr.decode()
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
cpdef long bin2int(str binstr):
|
||||||
|
"""Convert a binary string to integer."""
|
||||||
|
# return int(binstr, 2)
|
||||||
|
cdef bytearray binbytes = bytearray(binstr.encode())
|
||||||
|
cdef Py_ssize_t len_ = PyByteArray_GET_SIZE(binbytes)
|
||||||
|
cdef long cumul = 0
|
||||||
|
cdef unsigned char[:] v_binstr = binbytes
|
||||||
|
for i in range(len_):
|
||||||
|
cumul = 2*cumul + char_to_int(v_binstr[i])
|
||||||
|
return cumul
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
cpdef long hex2int(str hexstr):
|
||||||
|
"""Convert a binary string to integer."""
|
||||||
|
# return int(hexstr, 2)
|
||||||
|
cdef bytearray binbytes = bytearray(hexstr.encode())
|
||||||
|
cdef Py_ssize_t len_ = PyByteArray_GET_SIZE(binbytes)
|
||||||
|
cdef long cumul = 0
|
||||||
|
cdef unsigned char[:] v_hexstr = binbytes
|
||||||
|
for i in range(len_):
|
||||||
|
cumul = 16*cumul + char_to_int(v_hexstr[i])
|
||||||
|
return cumul
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
cpdef str bin2hex(str binstr):
|
||||||
|
return "{0:X}".format(int(binstr, 2))
|
||||||
|
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
cpdef unsigned char df(str msg):
|
||||||
|
"""Decode Downlink Format value, bits 1 to 5."""
|
||||||
|
cdef str dfbin = hex2bin(msg[:2])
|
||||||
|
# return min(bin2int(dfbin[0:5]), 24)
|
||||||
|
cdef long df = bin2int(dfbin[0:5])
|
||||||
|
if df > 24:
|
||||||
|
return 24
|
||||||
|
return df
|
||||||
|
|
||||||
|
# the CRC generator
|
||||||
|
# G = [int("11111111", 2), int("11111010", 2), int("00000100", 2), int("10000000", 2)]
|
||||||
|
cdef array.array _G = array.array('l', [0b11111111, 0b11111010, 0b00000100, 0b10000000])
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef long crc(str msg, bint encode=False):
|
||||||
|
"""Mode-S Cyclic Redundancy Check.
|
||||||
|
|
||||||
|
Detect if bit error occurs in the Mode-S message. When encode option is on,
|
||||||
|
the checksum is generated.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (string): 28 bytes hexadecimal message string
|
||||||
|
encode (bool): True to encode the date only and return the checksum
|
||||||
|
Returns:
|
||||||
|
int: message checksum, or partity bits (encoder)
|
||||||
|
|
||||||
|
"""
|
||||||
|
# the CRC generator
|
||||||
|
# G = [int("11111111", 2), int("11111010", 2), int("00000100", 2), int("10000000", 2)]
|
||||||
|
# cdef array.array _G = array.array('l', [0b11111111, 0b11111010, 0b00000100, 0b10000000])
|
||||||
|
cdef long[4] G = _G
|
||||||
|
|
||||||
|
# msgbin_split = wrap(msgbin, 8)
|
||||||
|
# mbytes = list(map(bin2int, msgbin_split))
|
||||||
|
cdef bytearray _msgbin = bytearray(hex2bin(msg).encode())
|
||||||
|
cdef unsigned char[:] msgbin = _msgbin
|
||||||
|
|
||||||
|
cdef Py_ssize_t len_msgbin = PyByteArray_GET_SIZE(_msgbin)
|
||||||
|
cdef Py_ssize_t len_mbytes = len_msgbin // 8
|
||||||
|
cdef Py_ssize_t i
|
||||||
|
|
||||||
|
if encode:
|
||||||
|
for i in range(len_msgbin - 24, len_msgbin):
|
||||||
|
msgbin[i] = 0
|
||||||
|
|
||||||
|
cdef array.array _mbytes = array.array(
|
||||||
|
'l', [bin2int(_msgbin[8*i:8*i+8].decode()) for i in range(len_mbytes)]
|
||||||
|
)
|
||||||
|
|
||||||
|
cdef long[:] mbytes = _mbytes
|
||||||
|
|
||||||
|
cdef long bits, mask
|
||||||
|
cdef Py_ssize_t ibyte, ibit
|
||||||
|
|
||||||
|
for ibyte in range(len_mbytes - 3):
|
||||||
|
for ibit in range(8):
|
||||||
|
mask = 0x80 >> ibit
|
||||||
|
bits = mbytes[ibyte] & mask
|
||||||
|
|
||||||
|
if bits > 0:
|
||||||
|
mbytes[ibyte] = mbytes[ibyte] ^ (G[0] >> ibit)
|
||||||
|
mbytes[ibyte + 1] = mbytes[ibyte + 1] ^ (
|
||||||
|
0xFF & ((G[0] << 8 - ibit) | (G[1] >> ibit))
|
||||||
|
)
|
||||||
|
mbytes[ibyte + 2] = mbytes[ibyte + 2] ^ (
|
||||||
|
0xFF & ((G[1] << 8 - ibit) | (G[2] >> ibit))
|
||||||
|
)
|
||||||
|
mbytes[ibyte + 3] = mbytes[ibyte + 3] ^ (
|
||||||
|
0xFF & ((G[2] << 8 - ibit) | (G[3] >> ibit))
|
||||||
|
)
|
||||||
|
|
||||||
|
cdef long result = (mbytes[len_mbytes-3] << 16) | (mbytes[len_mbytes-2] << 8) | mbytes[len_mbytes-1]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cpdef long floor(double x):
|
||||||
|
"""Mode-S floor function.
|
||||||
|
|
||||||
|
Defined as the greatest integer value k, such that k <= x
|
||||||
|
For example: floor(3.6) = 3 and floor(-3.6) = -4
|
||||||
|
|
||||||
|
"""
|
||||||
|
return <long> c_floor(x)
|
||||||
|
|
||||||
|
cpdef str icao(str msg):
|
||||||
|
"""Calculate the ICAO address from an Mode-S message."""
|
||||||
|
cdef unsigned char DF = df(msg)
|
||||||
|
cdef long c0, c1
|
||||||
|
|
||||||
|
if DF in (11, 17, 18):
|
||||||
|
addr = msg[2:8]
|
||||||
|
elif DF in (0, 4, 5, 16, 20, 21):
|
||||||
|
c0 = crc(msg, encode=True)
|
||||||
|
c1 = hex2int(msg[-6:])
|
||||||
|
addr = "%06X" % (c0 ^ c1)
|
||||||
|
else:
|
||||||
|
addr = None
|
||||||
|
|
||||||
|
return addr
|
||||||
|
|
||||||
|
|
||||||
|
cpdef bint is_icao_assigned(str icao):
|
||||||
|
"""Check whether the ICAO address is assigned (Annex 10, Vol 3)."""
|
||||||
|
if (icao is None) or (not isinstance(icao, str)) or (len(icao) != 6):
|
||||||
|
return False
|
||||||
|
|
||||||
|
cdef long icaoint = hex2int(icao)
|
||||||
|
|
||||||
|
if 0x200000 < icaoint < 0x27FFFF:
|
||||||
|
return False # AFI
|
||||||
|
if 0x280000 < icaoint < 0x28FFFF:
|
||||||
|
return False # SAM
|
||||||
|
if 0x500000 < icaoint < 0x5FFFFF:
|
||||||
|
return False # EUR, NAT
|
||||||
|
if 0x600000 < icaoint < 0x67FFFF:
|
||||||
|
return False # MID
|
||||||
|
if 0x680000 < icaoint < 0x6F0000:
|
||||||
|
return False # ASIA
|
||||||
|
if 0x900000 < icaoint < 0x9FFFFF:
|
||||||
|
return False # NAM, PAC
|
||||||
|
if 0xB00000 < icaoint < 0xBFFFFF:
|
||||||
|
return False # CAR
|
||||||
|
if 0xD00000 < icaoint < 0xDFFFFF:
|
||||||
|
return False # future
|
||||||
|
if 0xF00000 < icaoint < 0xFFFFFF:
|
||||||
|
return False # future
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef int typecode(str msg):
|
||||||
|
"""Type code of ADS-B message"""
|
||||||
|
if df(msg) not in (17, 18):
|
||||||
|
return -1
|
||||||
|
# return None
|
||||||
|
|
||||||
|
cdef str tcbin = hex2bin(msg[8:10])
|
||||||
|
return bin2int(tcbin[0:5])
|
||||||
|
|
||||||
|
@cython.cdivision(True)
|
||||||
|
cpdef int cprNL(double lat):
|
||||||
|
"""NL() function in CPR decoding."""
|
||||||
|
|
||||||
|
if abs(lat) <= 1e-08:
|
||||||
|
return 59
|
||||||
|
elif abs(abs(lat) - 87) <= 1e-08 + 1e-05 * 87:
|
||||||
|
return 2
|
||||||
|
elif lat > 87 or lat < -87:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
cdef int nz = 15
|
||||||
|
cdef double a = 1 - cos(pi / (2 * nz))
|
||||||
|
cdef double b = cos(pi / 180 * fabs(lat)) ** 2
|
||||||
|
cdef double nl = 2 * pi / (acos(1 - a / b))
|
||||||
|
NL = floor(nl)
|
||||||
|
return NL
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef str idcode(str msg):
|
||||||
|
"""Compute identity (squawk code)."""
|
||||||
|
if df(msg) not in [5, 21]:
|
||||||
|
raise RuntimeError("Message must be Downlink Format 5 or 21.")
|
||||||
|
|
||||||
|
squawk_code = squawk(hex2bin(msg)[19:32])
|
||||||
|
return squawk_code
|
||||||
|
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef str squawk(str binstr):
|
||||||
|
"""Compute identity (squawk code)."""
|
||||||
|
|
||||||
|
if len(binstr) != 13 or set(binstr) != set('01'):
|
||||||
|
raise RuntimeError("Input must be 13 bits binary string")
|
||||||
|
|
||||||
|
cdef bytearray _mbin = bytearray(binstr.encode())
|
||||||
|
cdef unsigned char[:] mbin = _mbin
|
||||||
|
|
||||||
|
cdef bytearray _idcode = bytearray(4)
|
||||||
|
cdef unsigned char[:] idcode = _idcode
|
||||||
|
|
||||||
|
cdef unsigned char C1 = mbin[0]
|
||||||
|
cdef unsigned char A1 = mbin[1]
|
||||||
|
cdef unsigned char C2 = mbin[2]
|
||||||
|
cdef unsigned char A2 = mbin[3]
|
||||||
|
cdef unsigned char C4 = mbin[4]
|
||||||
|
cdef unsigned char A4 = mbin[5]
|
||||||
|
# X = mbin[6]
|
||||||
|
cdef unsigned char B1 = mbin[7]
|
||||||
|
cdef unsigned char D1 = mbin[8]
|
||||||
|
cdef unsigned char B2 = mbin[9]
|
||||||
|
cdef unsigned char D2 = mbin[10]
|
||||||
|
cdef unsigned char B4 = mbin[11]
|
||||||
|
cdef unsigned char D4 = mbin[12]
|
||||||
|
|
||||||
|
idcode[0] = int_to_char((char_to_int(A4)*2 + char_to_int(A2))*2 + char_to_int(A1))
|
||||||
|
idcode[1] = int_to_char((char_to_int(B4)*2 + char_to_int(B2))*2 + char_to_int(B1))
|
||||||
|
idcode[2] = int_to_char((char_to_int(C4)*2 + char_to_int(C2))*2 + char_to_int(C1))
|
||||||
|
idcode[3] = int_to_char((char_to_int(D4)*2 + char_to_int(D2))*2 + char_to_int(D1))
|
||||||
|
|
||||||
|
return _idcode.decode()
|
||||||
|
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef int altcode(str msg):
|
||||||
|
"""Compute the altitude."""
|
||||||
|
if df(msg) not in [0, 4, 16, 20]:
|
||||||
|
raise RuntimeError("Message must be Downlink Format 0, 4, 16, or 20.")
|
||||||
|
|
||||||
|
alt = altitude(hex2bin(msg)[19:32])
|
||||||
|
return alt
|
||||||
|
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
@cython.wraparound(False)
|
||||||
|
cpdef int altitude(str binstr):
|
||||||
|
|
||||||
|
if len(binstr) != 13 or not set(binstr).issubset(set("01")):
|
||||||
|
raise RuntimeError("Input must be 13 bits binary string")
|
||||||
|
|
||||||
|
cdef bytearray _mbin = bytearray(binstr.encode())
|
||||||
|
cdef unsigned char[:] mbin = _mbin
|
||||||
|
|
||||||
|
cdef char Mbit = binstr[6]
|
||||||
|
cdef char Qbit = binstr[8]
|
||||||
|
|
||||||
|
cdef int alt = 0
|
||||||
|
cdef bytearray vbin
|
||||||
|
cdef bytearray _graybytes = bytearray(11)
|
||||||
|
cdef unsigned char[:] graybytes = _graybytes
|
||||||
|
|
||||||
|
if bin2int(binstr) == 0:
|
||||||
|
# altitude unknown or invalid
|
||||||
|
alt = -9999
|
||||||
|
|
||||||
|
elif Mbit == 48: # unit in ft, "0" -> 48
|
||||||
|
if Qbit == 49: # 25ft interval, "1" -> 49
|
||||||
|
vbin = _mbin[:6] + _mbin[7:8] + _mbin[9:]
|
||||||
|
alt = bin2int(vbin.decode()) * 25 - 1000
|
||||||
|
if Qbit == 48: # 100ft interval, above 50175ft, "0" -> 48
|
||||||
|
graybytes[8] = mbin[0]
|
||||||
|
graybytes[2] = mbin[1]
|
||||||
|
graybytes[9] = mbin[2]
|
||||||
|
graybytes[3] = mbin[3]
|
||||||
|
graybytes[10] = mbin[4]
|
||||||
|
graybytes[4] = mbin[5]
|
||||||
|
# M = mbin[6]
|
||||||
|
graybytes[5] = mbin[7]
|
||||||
|
# Q = mbin[8]
|
||||||
|
graybytes[6] = mbin[9]
|
||||||
|
graybytes[0] = mbin[10]
|
||||||
|
graybytes[7] = mbin[11]
|
||||||
|
graybytes[1] = mbin[12]
|
||||||
|
|
||||||
|
alt = gray2alt(_graybytes.decode())
|
||||||
|
|
||||||
|
elif Mbit == 49: # unit in meter, "1" -> 49
|
||||||
|
vbin = _mbin[:6] + _mbin[7:]
|
||||||
|
alt = int(bin2int(vbin.decode()) * 3.28084) # convert to ft
|
||||||
|
|
||||||
|
return alt
|
||||||
|
|
||||||
|
|
||||||
|
cpdef int gray2alt(str codestr):
|
||||||
|
cdef str gc500 = codestr[:8]
|
||||||
|
cdef int n500 = gray2int(gc500)
|
||||||
|
|
||||||
|
# in 100-ft step must be converted first
|
||||||
|
cdef str gc100 = codestr[8:]
|
||||||
|
cdef int n100 = gray2int(gc100)
|
||||||
|
|
||||||
|
if n100 in [0, 5, 6]:
|
||||||
|
return -1
|
||||||
|
#return None
|
||||||
|
|
||||||
|
if n100 == 7:
|
||||||
|
n100 = 5
|
||||||
|
|
||||||
|
if n500 % 2:
|
||||||
|
n100 = 6 - n100
|
||||||
|
|
||||||
|
alt = (n500 * 500 + n100 * 100) - 1300
|
||||||
|
return alt
|
||||||
|
|
||||||
|
|
||||||
|
cdef int gray2int(str graystr):
|
||||||
|
"""Convert greycode to binary."""
|
||||||
|
cdef int num = bin2int(graystr)
|
||||||
|
num ^= num >> 8
|
||||||
|
num ^= num >> 4
|
||||||
|
num ^= num >> 2
|
||||||
|
num ^= num >> 1
|
||||||
|
return num
|
||||||
|
|
||||||
|
|
||||||
|
cpdef str data(str msg):
|
||||||
|
"""Return the data frame in the message, bytes 9 to 22."""
|
||||||
|
return msg[8:-6]
|
||||||
|
|
||||||
|
|
||||||
|
cpdef bint allzeros(str msg):
|
||||||
|
"""Check if the data bits are all zeros."""
|
||||||
|
d = hex2bin(data(msg))
|
||||||
|
|
||||||
|
if bin2int(d) > 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def wrongstatus(data, sb, msb, lsb):
|
||||||
|
"""Check if the status bit and field bits are consistency.
|
||||||
|
|
||||||
|
This Function is used for checking BDS code versions.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# status bit, most significant bit, least significant bit
|
||||||
|
status = int(data[sb - 1])
|
||||||
|
value = bin2int(data[msb - 1 : lsb])
|
||||||
|
|
||||||
|
if not status:
|
||||||
|
if value != 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
22
pyModeS/common.pyi
Normal file
22
pyModeS/common.pyi
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
def hex2bin(hexstr: str) -> str: ...
|
||||||
|
def bin2int(binstr: str) -> int: ...
|
||||||
|
def hex2int(hexstr: str) -> int: ...
|
||||||
|
def bin2hex(binstr: str) -> str: ...
|
||||||
|
def df(msg: str) -> int: ...
|
||||||
|
def crc(msg: str, encode: bool = False) -> int: ...
|
||||||
|
def floor(x: float) -> float: ...
|
||||||
|
def icao(msg: str) -> Optional[str]: ...
|
||||||
|
def is_icao_assigned(icao: str) -> bool: ...
|
||||||
|
def typecode(msg: str) -> Optional[int]: ...
|
||||||
|
def cprNL(lat: float) -> int: ...
|
||||||
|
def idcode(msg: str) -> str: ...
|
||||||
|
def squawk(binstr: str) -> str: ...
|
||||||
|
def altcode(msg: str) -> Optional[int]: ...
|
||||||
|
def altitude(binstr: str) -> Optional[int]: ...
|
||||||
|
def gray2alt(binstr: str) -> Optional[int]: ...
|
||||||
|
def gray2int(binstr: str) -> int: ...
|
||||||
|
def data(msg: str) -> str: ...
|
||||||
|
def allzeros(msg: str) -> bool: ...
|
||||||
|
def wrongstatus(data: str, sb: int, msb: int, lsb: int) -> bool: ...
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
from __future__ import absolute_import, print_function, division
|
def tell(msg: str) -> None:
|
||||||
|
from .. import common, adsb, commb, bds
|
||||||
|
|
||||||
from pyModeS.decoder import adsb, commb, common, bds
|
|
||||||
|
|
||||||
|
|
||||||
def tell(msg):
|
|
||||||
def _print(label, value, unit=None):
|
def _print(label, value, unit=None):
|
||||||
print("%20s: " % label, end="")
|
print("%28s: " % label, end="")
|
||||||
print("%s " % value, end="")
|
print("%s " % value, end="")
|
||||||
if unit:
|
if unit:
|
||||||
print(unit)
|
print(unit)
|
||||||
@@ -20,16 +17,21 @@ def tell(msg):
|
|||||||
_print("Downlink Format", df)
|
_print("Downlink Format", df)
|
||||||
|
|
||||||
if df == 17:
|
if df == 17:
|
||||||
_print("Protocal", "Mode-S Extended Squitter (ADS-B)")
|
_print("Protocol", "Mode-S Extended Squitter (ADS-B)")
|
||||||
|
|
||||||
tc = common.typecode(msg)
|
tc = common.typecode(msg)
|
||||||
|
|
||||||
|
if tc is None:
|
||||||
|
_print("ERROR", "Unknown typecode")
|
||||||
|
return
|
||||||
|
|
||||||
if 1 <= tc <= 4: # callsign
|
if 1 <= tc <= 4: # callsign
|
||||||
callsign = adsb.callsign(msg)
|
callsign = adsb.callsign(msg)
|
||||||
_print("Type", "Identitification and category")
|
_print("Type", "Identification and category")
|
||||||
_print("Callsign:", callsign)
|
_print("Callsign:", callsign)
|
||||||
|
|
||||||
if 5 <= tc <= 8: # surface position
|
if 5 <= tc <= 8: # surface position
|
||||||
_print("Type", "Surface postition")
|
_print("Type", "Surface position")
|
||||||
oe = adsb.oe_flag(msg)
|
oe = adsb.oe_flag(msg)
|
||||||
msgbin = common.hex2bin(msg)
|
msgbin = common.hex2bin(msg)
|
||||||
cprlat = common.bin2int(msgbin[54:71]) / 131072.0
|
cprlat = common.bin2int(msgbin[54:71]) / 131072.0
|
||||||
@@ -55,12 +57,14 @@ def tell(msg):
|
|||||||
|
|
||||||
if tc == 19:
|
if tc == 19:
|
||||||
_print("Type", "Airborne velocity")
|
_print("Type", "Airborne velocity")
|
||||||
spd, trk, vr, t = adsb.velocity(msg)
|
velocity = adsb.velocity(msg)
|
||||||
types = {"GS": "Ground speed", "TAS": "True airspeed"}
|
if velocity is not None:
|
||||||
_print("Speed", spd, "knots")
|
spd, trk, vr, t = velocity
|
||||||
_print("Track", trk, "degrees")
|
types = {"GS": "Ground speed", "TAS": "True airspeed"}
|
||||||
_print("Vertical rate", vr, "feet/minute")
|
_print("Speed", spd, "knots")
|
||||||
_print("Type", types[t])
|
_print("Track", trk, "degrees")
|
||||||
|
_print("Vertical rate", vr, "feet/minute")
|
||||||
|
_print("Type", types[t])
|
||||||
|
|
||||||
if 20 <= tc <= 22: # airborne position
|
if 20 <= tc <= 22: # airborne position
|
||||||
_print("Type", "Airborne position (with GNSS altitude)")
|
_print("Type", "Airborne position (with GNSS altitude)")
|
||||||
@@ -74,12 +78,100 @@ def tell(msg):
|
|||||||
_print("CPR Longitude", cprlon)
|
_print("CPR Longitude", cprlon)
|
||||||
_print("Altitude", alt, "feet")
|
_print("Altitude", alt, "feet")
|
||||||
|
|
||||||
|
if tc == 29: # target state and status
|
||||||
|
_print("Type", "Target State and Status")
|
||||||
|
subtype = common.bin2int((common.hex2bin(msg)[32:])[5:7])
|
||||||
|
_print("Subtype", subtype)
|
||||||
|
tcas_operational = adsb.tcas_operational(msg)
|
||||||
|
types_29 = {0: "Not Engaged", 1: "Engaged"}
|
||||||
|
tcas_operational_types = {0: "Not Operational", 1: "Operational"}
|
||||||
|
if subtype == 0:
|
||||||
|
emergency_types = {
|
||||||
|
0: "No emergency",
|
||||||
|
1: "General emergency",
|
||||||
|
2: "Lifeguard/medical emergency",
|
||||||
|
3: "Minimum fuel",
|
||||||
|
4: "No communications",
|
||||||
|
5: "Unlawful interference",
|
||||||
|
6: "Downed aircraft",
|
||||||
|
7: "Reserved",
|
||||||
|
}
|
||||||
|
vertical_horizontal_types = {
|
||||||
|
1: "Acquiring mode",
|
||||||
|
2: "Capturing/Maintaining mode",
|
||||||
|
}
|
||||||
|
tcas_ra_types = {0: "Not active", 1: "Active"}
|
||||||
|
alt, alt_source, alt_ref = adsb.target_altitude(msg)
|
||||||
|
angle, angle_type, angle_source = adsb.target_angle(msg)
|
||||||
|
vertical_mode = adsb.vertical_mode(msg)
|
||||||
|
horizontal_mode = adsb.horizontal_mode(msg)
|
||||||
|
tcas_ra = adsb.tcas_ra(msg)
|
||||||
|
emergency_status = adsb.emergency_status(msg)
|
||||||
|
_print("Target altitude", alt, "feet")
|
||||||
|
_print("Altitude source", alt_source)
|
||||||
|
_print("Altitude reference", alt_ref)
|
||||||
|
_print("Angle", angle, "°")
|
||||||
|
_print("Angle Type", angle_type)
|
||||||
|
_print("Angle Source", angle_source)
|
||||||
|
if vertical_mode is not None:
|
||||||
|
_print(
|
||||||
|
"Vertical mode",
|
||||||
|
vertical_horizontal_types[vertical_mode],
|
||||||
|
)
|
||||||
|
if horizontal_mode is not None:
|
||||||
|
_print(
|
||||||
|
"Horizontal mode",
|
||||||
|
vertical_horizontal_types[horizontal_mode],
|
||||||
|
)
|
||||||
|
_print(
|
||||||
|
"TCAS/ACAS",
|
||||||
|
tcas_operational_types[tcas_operational]
|
||||||
|
if tcas_operational
|
||||||
|
else None,
|
||||||
|
)
|
||||||
|
_print("TCAS/ACAS RA", tcas_ra_types[tcas_ra])
|
||||||
|
_print("Emergency status", emergency_types[emergency_status])
|
||||||
|
else:
|
||||||
|
alt, alt_source = adsb.selected_altitude(msg) # type: ignore
|
||||||
|
baro = adsb.baro_pressure_setting(msg)
|
||||||
|
hdg = adsb.selected_heading(msg)
|
||||||
|
autopilot = adsb.autopilot(msg)
|
||||||
|
vnav = adsb.vnav_mode(msg)
|
||||||
|
alt_hold = adsb.altitude_hold_mode(msg)
|
||||||
|
app = adsb.approach_mode(msg)
|
||||||
|
lnav = adsb.lnav_mode(msg)
|
||||||
|
_print("Selected altitude", alt, "feet")
|
||||||
|
_print("Altitude source", alt_source)
|
||||||
|
_print(
|
||||||
|
"Barometric pressure setting",
|
||||||
|
baro,
|
||||||
|
"" if baro is None else "millibars",
|
||||||
|
)
|
||||||
|
_print("Selected Heading", hdg, "°")
|
||||||
|
if not (common.bin2int((common.hex2bin(msg)[32:])[46]) == 0):
|
||||||
|
_print(
|
||||||
|
"Autopilot", types_29[autopilot] if autopilot else None
|
||||||
|
)
|
||||||
|
_print("VNAV mode", types_29[vnav] if vnav else None)
|
||||||
|
_print(
|
||||||
|
"Altitude hold mode",
|
||||||
|
types_29[alt_hold] if alt_hold else None,
|
||||||
|
)
|
||||||
|
_print("Approach mode", types_29[app] if app else None)
|
||||||
|
_print(
|
||||||
|
"TCAS/ACAS",
|
||||||
|
tcas_operational_types[tcas_operational]
|
||||||
|
if tcas_operational
|
||||||
|
else None,
|
||||||
|
)
|
||||||
|
_print("LNAV mode", types_29[lnav] if lnav else None)
|
||||||
|
|
||||||
if df == 20:
|
if df == 20:
|
||||||
_print("Protocal", "Mode-S Comm-B altitude reply")
|
_print("Protocol", "Mode-S Comm-B altitude reply")
|
||||||
_print("Altitude", common.altcode(msg), "feet")
|
_print("Altitude", common.altcode(msg), "feet")
|
||||||
|
|
||||||
if df == 21:
|
if df == 21:
|
||||||
_print("Protocal", "Mode-S Comm-B identity reply")
|
_print("Protocol", "Mode-S Comm-B identity reply")
|
||||||
_print("Squawk code", common.idcode(msg))
|
_print("Squawk code", common.idcode(msg))
|
||||||
|
|
||||||
if df == 20 or df == 21:
|
if df == 20 or df == 21:
|
||||||
@@ -97,7 +189,7 @@ def tell(msg):
|
|||||||
}
|
}
|
||||||
|
|
||||||
BDS = bds.infer(msg, mrar=True)
|
BDS = bds.infer(msg, mrar=True)
|
||||||
if BDS in labels.keys():
|
if BDS is not None and BDS in labels.keys():
|
||||||
_print("BDS", "%s (%s)" % (BDS, labels[BDS]))
|
_print("BDS", "%s (%s)" % (BDS, labels[BDS]))
|
||||||
else:
|
else:
|
||||||
_print("BDS", BDS)
|
_print("BDS", BDS)
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Decoding Air-Air Surveillance (ACAS) DF=0/16
|
Decoding Air-Air Surveillance (ACAS) DF=0/16
|
||||||
|
|
||||||
[To be implemented]
|
[To be implemented]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
from pyModeS.decoder import common
|
|
||||||
|
|||||||
@@ -1,88 +1,150 @@
|
|||||||
# Copyright (C) 2015 Junzi Sun (TU Delft)
|
"""ADS-B module.
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
The ADS-B module also imports functions from the following modules:
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
- bds05: ``airborne_position()``, ``airborne_position_with_ref()``,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
``altitude()``
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
- bds06: ``surface_position()``, ``surface_position_with_ref()``,
|
||||||
# GNU General Public License for more details.
|
``surface_velocity()``
|
||||||
|
- bds08: ``category()``, ``callsign()``
|
||||||
# You should have received a copy of the GNU General Public License
|
- bds09: ``airborne_velocity()``, ``altitude_diff()``
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""ADS-B Wrapper.
|
|
||||||
|
|
||||||
The ADS-B wrapper also imports functions from the following modules:
|
|
||||||
|
|
||||||
- pyModeS.decoder.bds.bds05
|
|
||||||
Functions: ``airborne_position``, ``airborne_position_with_ref``, ``altitude``
|
|
||||||
- pyModeS.decoder.bds.bds06
|
|
||||||
Functions: ``surface_position``, ``surface_position_with_ref``, ``surface_velocity``
|
|
||||||
- pyModeS.decoder.bds.bds08
|
|
||||||
Functions: ``category``, ``callsign``
|
|
||||||
- pyModeS.decoder.bds.bds09
|
|
||||||
Functions: ``airborne_velocity``, ``altitude_diff``
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from __future__ import annotations
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import pyModeS as pms
|
from .. import common
|
||||||
from pyModeS.decoder import common
|
from . import uncertainty
|
||||||
from pyModeS.decoder import uncertainty
|
from .bds.bds05 import airborne_position, airborne_position_with_ref
|
||||||
|
from .bds.bds05 import altitude as altitude05
|
||||||
# from pyModeS.decoder.bds import bds05, bds06, bds09
|
from .bds.bds06 import (
|
||||||
from pyModeS.decoder.bds.bds05 import (
|
|
||||||
airborne_position,
|
|
||||||
airborne_position_with_ref,
|
|
||||||
altitude,
|
|
||||||
)
|
|
||||||
from pyModeS.decoder.bds.bds06 import (
|
|
||||||
surface_position,
|
surface_position,
|
||||||
surface_position_with_ref,
|
surface_position_with_ref,
|
||||||
surface_velocity,
|
surface_velocity,
|
||||||
)
|
)
|
||||||
from pyModeS.decoder.bds.bds08 import category, callsign
|
from .bds.bds08 import callsign, category
|
||||||
from pyModeS.decoder.bds.bds09 import airborne_velocity, altitude_diff
|
from .bds.bds09 import airborne_velocity, altitude_diff
|
||||||
|
from .bds.bds61 import emergency_squawk, emergency_state, is_emergency
|
||||||
|
from .bds.bds62 import (
|
||||||
|
altitude_hold_mode,
|
||||||
|
approach_mode,
|
||||||
|
autopilot,
|
||||||
|
baro_pressure_setting,
|
||||||
|
emergency_status,
|
||||||
|
horizontal_mode,
|
||||||
|
lnav_mode,
|
||||||
|
selected_altitude,
|
||||||
|
selected_heading,
|
||||||
|
target_altitude,
|
||||||
|
target_angle,
|
||||||
|
tcas_operational,
|
||||||
|
tcas_ra,
|
||||||
|
vertical_mode,
|
||||||
|
vnav_mode,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"airborne_position",
|
||||||
|
"airborne_position_with_ref",
|
||||||
|
"altitude05",
|
||||||
|
"surface_position",
|
||||||
|
"surface_position_with_ref",
|
||||||
|
"surface_velocity",
|
||||||
|
"callsign",
|
||||||
|
"category",
|
||||||
|
"airborne_velocity",
|
||||||
|
"altitude_diff",
|
||||||
|
"emergency_squawk",
|
||||||
|
"emergency_state",
|
||||||
|
"is_emergency",
|
||||||
|
"df",
|
||||||
|
"icao",
|
||||||
|
"typecode",
|
||||||
|
"position",
|
||||||
|
"position_with_ref",
|
||||||
|
"altitude",
|
||||||
|
"velocity",
|
||||||
|
"speed_heading",
|
||||||
|
"oe_flag",
|
||||||
|
"version",
|
||||||
|
"nuc_p",
|
||||||
|
"nuc_v",
|
||||||
|
"nic_v1",
|
||||||
|
"nic_v2",
|
||||||
|
"nic_s",
|
||||||
|
"nic_a_c",
|
||||||
|
"nic_b",
|
||||||
|
"nac_p",
|
||||||
|
"nac_v",
|
||||||
|
"sil",
|
||||||
|
"selected_altitude",
|
||||||
|
"target_altitude",
|
||||||
|
"vertical_mode",
|
||||||
|
"horizontal_mode",
|
||||||
|
"selected_heading",
|
||||||
|
"target_angle",
|
||||||
|
"baro_pressure_setting",
|
||||||
|
"autopilot",
|
||||||
|
"vnav_mode",
|
||||||
|
"altitude_hold_mode",
|
||||||
|
"approach_mode",
|
||||||
|
"lnav_mode",
|
||||||
|
"tcas_operational",
|
||||||
|
"tcas_ra",
|
||||||
|
"emergency_status",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def df(msg):
|
def df(msg: str) -> int:
|
||||||
return common.df(msg)
|
return common.df(msg)
|
||||||
|
|
||||||
|
|
||||||
def icao(msg):
|
def icao(msg: str) -> None | str:
|
||||||
return common.icao(msg)
|
return common.icao(msg)
|
||||||
|
|
||||||
|
|
||||||
def typecode(msg):
|
def typecode(msg: str) -> None | int:
|
||||||
return common.typecode(msg)
|
return common.typecode(msg)
|
||||||
|
|
||||||
|
|
||||||
def position(msg0, msg1, t0, t1, lat_ref=None, lon_ref=None):
|
def position(
|
||||||
"""Decode position from a pair of even and odd position message
|
msg0: str,
|
||||||
(works with both airborne and surface position messages)
|
msg1: str,
|
||||||
|
t0: int | datetime,
|
||||||
|
t1: int | datetime,
|
||||||
|
lat_ref: None | float = None,
|
||||||
|
lon_ref: None | float = None,
|
||||||
|
) -> None | tuple[float, float]:
|
||||||
|
"""Decode surface or airborne position from a pair of even and odd
|
||||||
|
position messages.
|
||||||
|
|
||||||
|
Note, that to decode surface position using the position message pair,
|
||||||
|
the reference position has to be provided.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg0 (string): even message (28 bytes hexadecimal string)
|
msg0 (string): even message (28 hexdigits)
|
||||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
msg1 (string): odd message (28 hexdigits)
|
||||||
t0 (int): timestamps for the even message
|
t0 (int): timestamps for the even message
|
||||||
t1 (int): timestamps for the odd message
|
t1 (int): timestamps for the odd message
|
||||||
|
lat_ref (float): latitude of reference position
|
||||||
|
lon_ref (float): longitude of reference position
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(float, float): (latitude, longitude) of the aircraft
|
(float, float): (latitude, longitude) of the aircraft
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tc0 = typecode(msg0)
|
tc0 = typecode(msg0)
|
||||||
tc1 = typecode(msg1)
|
tc1 = typecode(msg1)
|
||||||
|
|
||||||
|
if tc0 is None or tc1 is None:
|
||||||
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|
||||||
if 5 <= tc0 <= 8 and 5 <= tc1 <= 8:
|
if 5 <= tc0 <= 8 and 5 <= tc1 <= 8:
|
||||||
if (not lat_ref) or (not lon_ref):
|
if lat_ref is None or lon_ref is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Surface position encountered, a reference \
|
"Surface position encountered, a reference position"
|
||||||
position lat/lon required. Location of \
|
" lat/lon required. Location of receiver can be used."
|
||||||
receiver can be used."
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref)
|
return surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref)
|
||||||
@@ -96,19 +158,22 @@ def position(msg0, msg1, t0, t1, lat_ref=None, lon_ref=None):
|
|||||||
return airborne_position(msg0, msg1, t0, t1)
|
return airborne_position(msg0, msg1, t0, t1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("incorrect or inconsistant message types")
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|
||||||
|
|
||||||
def position_with_ref(msg, lat_ref, lon_ref):
|
def position_with_ref(
|
||||||
"""Decode position with only one message,
|
msg: str, lat_ref: float, lon_ref: float
|
||||||
knowing reference nearby location, such as previously
|
) -> tuple[float, float]:
|
||||||
calculated location, ground station, or airport location, etc.
|
"""Decode position with only one message.
|
||||||
Works with both airborne and surface position messages.
|
|
||||||
The reference position shall be with in 180NM (airborne) or 45NM (surface)
|
A reference position is required, which can be previously
|
||||||
|
calculated location, ground station, or airport location.
|
||||||
|
The function works with both airborne and surface position messages.
|
||||||
|
The reference position shall be within 180NM (airborne) or 45NM (surface)
|
||||||
of the true position.
|
of the true position.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): even message (28 bytes hexadecimal string)
|
msg (str): even message (28 hexdigits)
|
||||||
lat_ref: previous known latitude
|
lat_ref: previous known latitude
|
||||||
lon_ref: previous known longitude
|
lon_ref: previous known longitude
|
||||||
|
|
||||||
@@ -118,6 +183,9 @@ def position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
|
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
|
if tc is None:
|
||||||
|
raise RuntimeError("incorrect or inconsistent message types")
|
||||||
|
|
||||||
if 5 <= tc <= 8:
|
if 5 <= tc <= 8:
|
||||||
return surface_position_with_ref(msg, lat_ref, lon_ref)
|
return surface_position_with_ref(msg, lat_ref, lon_ref)
|
||||||
|
|
||||||
@@ -125,93 +193,94 @@ def position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
return airborne_position_with_ref(msg, lat_ref, lon_ref)
|
return airborne_position_with_ref(msg, lat_ref, lon_ref)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("incorrect or inconsistant message types")
|
raise RuntimeError("incorrect or inconsistent message types")
|
||||||
|
|
||||||
|
|
||||||
def altitude(msg):
|
def altitude(msg: str) -> None | float:
|
||||||
"""Decode aircraft altitude
|
"""Decode aircraft altitude.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: altitude in feet
|
int: altitude in feet
|
||||||
"""
|
|
||||||
|
|
||||||
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
if tc < 5 or tc == 19 or tc > 22:
|
if tc is None or tc < 5 or tc == 19 or tc > 22:
|
||||||
raise RuntimeError("%s: Not a position message" % msg)
|
raise RuntimeError("%s: Not a position message" % msg)
|
||||||
|
|
||||||
if tc >= 5 and tc <= 8:
|
elif tc >= 5 and tc <= 8:
|
||||||
# surface position, altitude 0
|
# surface position, altitude 0
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
msgbin = common.hex2bin(msg)
|
|
||||||
q = msgbin[47]
|
|
||||||
if q:
|
|
||||||
n = common.bin2int(msgbin[40:47] + msgbin[48:52])
|
|
||||||
alt = n * 25 - 1000
|
|
||||||
return alt
|
|
||||||
else:
|
else:
|
||||||
return None
|
# airborn position
|
||||||
|
return altitude05(msg)
|
||||||
|
|
||||||
|
|
||||||
def velocity(msg, rtn_sources=False):
|
def velocity(
|
||||||
|
msg: str, source: bool = False
|
||||||
|
) -> None | tuple[None | float, None | float, None | int, str]:
|
||||||
"""Calculate the speed, heading, and vertical rate
|
"""Calculate the speed, heading, and vertical rate
|
||||||
(handles both airborne or surface message)
|
(handles both airborne or surface message).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
rtn_source (boolean): If the function will return
|
source (boolean): Include direction and vertical rate sources in return.
|
||||||
the sources for direction of travel and vertical
|
Default to False.
|
||||||
rate. This will change the return value from a four
|
If set to True, the function will return six value instead of four.
|
||||||
element array to a six element array.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, float, int, string, string, string): speed (kt),
|
int, float, int, string, [string], [string]:
|
||||||
ground track or heading (degree),
|
- Speed (kt)
|
||||||
rate of climb/descent (ft/min), speed type
|
- Angle (degree), either ground track or heading
|
||||||
('GS' for ground speed, 'AS' for airspeed),
|
- Vertical rate (ft/min)
|
||||||
direction source ('true_north' for ground track / true north
|
- Speed type ('GS' for ground speed, 'AS' for airspeed)
|
||||||
as refrence, 'mag_north' for magnetic north as reference),
|
- [Optional] Direction source ('TRUE_NORTH' or 'MAGNETIC_NORTH')
|
||||||
rate of climb/descent source ('Baro' for barometer, 'GNSS'
|
- [Optional] Vertical rate source ('BARO' or 'GNSS')
|
||||||
for GNSS constellation).
|
|
||||||
|
For surface messages, vertical rate and its respective sources are set
|
||||||
In the case of surface messages, None will be put in place
|
to None.
|
||||||
for vertical rate and its respective sources.
|
|
||||||
"""
|
"""
|
||||||
|
tc = typecode(msg)
|
||||||
|
error = "incorrect or inconsistent message types, expecting 4<TC<9 or TC=19"
|
||||||
|
if tc is None:
|
||||||
|
raise RuntimeError(error)
|
||||||
|
|
||||||
if 5 <= typecode(msg) <= 8:
|
if 5 <= tc <= 8:
|
||||||
return surface_velocity(msg, rtn_sources)
|
return surface_velocity(msg, source)
|
||||||
|
|
||||||
elif typecode(msg) == 19:
|
elif tc == 19:
|
||||||
return airborne_velocity(msg, rtn_sources)
|
return airborne_velocity(msg, source)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(error)
|
||||||
"incorrect or inconsistant message types, expecting 4<TC<9 or TC=19"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def speed_heading(msg):
|
def speed_heading(msg: str) -> None | tuple[None | float, None | float]:
|
||||||
"""Get speed and ground track (or heading) from the velocity message
|
"""Get speed and ground track (or heading) from the velocity message
|
||||||
(handles both airborne or surface message)
|
(handles both airborne or surface message)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, float): speed (kt), ground track or heading (degree)
|
(int, float): speed (kt), ground track or heading (degree)
|
||||||
"""
|
"""
|
||||||
spd, trk_or_hdg, rocd, tag = velocity(msg)
|
decoded = velocity(msg)
|
||||||
|
if decoded is None:
|
||||||
|
return None
|
||||||
|
spd, trk_or_hdg, rocd, tag = decoded
|
||||||
return spd, trk_or_hdg
|
return spd, trk_or_hdg
|
||||||
|
|
||||||
|
|
||||||
def oe_flag(msg):
|
def oe_flag(msg: str) -> int:
|
||||||
"""Check the odd/even flag. Bit 54, 0 for even, 1 for odd.
|
"""Check the odd/even flag. Bit 54, 0 for even, 1 for odd.
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
Returns:
|
Returns:
|
||||||
int: 0 or 1, for even or odd frame
|
int: 0 or 1, for even or odd frame
|
||||||
"""
|
"""
|
||||||
@@ -219,11 +288,11 @@ def oe_flag(msg):
|
|||||||
return int(msgbin[53])
|
return int(msgbin[53])
|
||||||
|
|
||||||
|
|
||||||
def version(msg):
|
def version(msg: str) -> int:
|
||||||
"""ADS-B Version
|
"""ADS-B Version
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string, TC = 31
|
msg (str): 28 hexdigits string, TC = 31
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: version number
|
int: version number
|
||||||
@@ -241,13 +310,15 @@ def version(msg):
|
|||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def nuc_p(msg):
|
def nuc_p(msg: str) -> tuple[int, None | float, None | int, None | int]:
|
||||||
"""Calculate NUCp, Navigation Uncertainty Category - Position (ADS-B version 1)
|
"""Calculate NUCp, Navigation Uncertainty Category - Position
|
||||||
|
(ADS-B version 1)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string,
|
msg (str): 28 hexdigits string,
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
int: NUCp, Navigation Uncertainty Category (position)
|
||||||
int: Horizontal Protection Limit
|
int: Horizontal Protection Limit
|
||||||
int: 95% Containment Radius - Horizontal (meters)
|
int: 95% Containment Radius - Horizontal (meters)
|
||||||
int: 95% Containment Radius - Vertical (meters)
|
int: 95% Containment Radius - Vertical (meters)
|
||||||
@@ -255,7 +326,7 @@ def nuc_p(msg):
|
|||||||
"""
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
if typecode(msg) < 5 or typecode(msg) > 22:
|
if tc is None or tc < 5 or tc is None or tc > 22:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s: Not a surface position message (5<TC<8), \
|
"%s: Not a surface position message (5<TC<8), \
|
||||||
airborne position message (8<TC<19), \
|
airborne position message (8<TC<19), \
|
||||||
@@ -263,27 +334,36 @@ def nuc_p(msg):
|
|||||||
% msg
|
% msg
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
NUCp = uncertainty.TC_NUCp_lookup[tc]
|
||||||
NUCp = uncertainty.TC_NUCp_lookup[tc]
|
index = uncertainty.NUCp.get(NUCp, None)
|
||||||
HPL = uncertainty.NUCp[NUCp]["HPL"]
|
|
||||||
RCu = uncertainty.NUCp[NUCp]["RCu"]
|
if index is not None:
|
||||||
RCv = uncertainty.NUCp[NUCp]["RCv"]
|
HPL = index["HPL"]
|
||||||
except KeyError:
|
RCu = index["RCu"]
|
||||||
|
RCv = index["RCv"]
|
||||||
|
else:
|
||||||
HPL, RCu, RCv = uncertainty.NA, uncertainty.NA, uncertainty.NA
|
HPL, RCu, RCv = uncertainty.NA, uncertainty.NA, uncertainty.NA
|
||||||
|
|
||||||
if tc in [20, 21]:
|
RCv = uncertainty.NA
|
||||||
RCv = uncertainty.NA
|
|
||||||
|
|
||||||
return HPL, RCu, RCv
|
# RCv only available for GNSS height
|
||||||
|
if tc == 20:
|
||||||
|
RCv = 4
|
||||||
|
elif tc == 21:
|
||||||
|
RCv = 15
|
||||||
|
|
||||||
|
return NUCp, HPL, RCu, RCv
|
||||||
|
|
||||||
|
|
||||||
def nuc_v(msg):
|
def nuc_v(msg: str) -> tuple[int, None | float, None | float]:
|
||||||
"""Calculate NUCv, Navigation Uncertainty Category - Velocity (ADS-B version 1)
|
"""Calculate NUCv, Navigation Uncertainty Category - Velocity
|
||||||
|
(ADS-B version 1)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string,
|
msg (str): 28 hexdigits string,
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
int: NUCv, Navigation Uncertainty Category (velocity)
|
||||||
int or string: 95% Horizontal Velocity Error
|
int or string: 95% Horizontal Velocity Error
|
||||||
int or string: 95% Vertical Velocity Error
|
int or string: 95% Vertical Velocity Error
|
||||||
"""
|
"""
|
||||||
@@ -296,28 +376,31 @@ def nuc_v(msg):
|
|||||||
|
|
||||||
msgbin = common.hex2bin(msg)
|
msgbin = common.hex2bin(msg)
|
||||||
NUCv = common.bin2int(msgbin[42:45])
|
NUCv = common.bin2int(msgbin[42:45])
|
||||||
|
index = uncertainty.NUCv.get(NUCv, None)
|
||||||
|
|
||||||
try:
|
if index is not None:
|
||||||
HVE = uncertainty.NUCv[NUCv]["HVE"]
|
HVE = index["HVE"]
|
||||||
VVE = uncertainty.NUCv[NUCv]["VVE"]
|
VVE = index["VVE"]
|
||||||
except KeyError:
|
else:
|
||||||
HVE, VVE = uncertainty.NA, uncertainty.NA
|
HVE, VVE = uncertainty.NA, uncertainty.NA
|
||||||
|
|
||||||
return HVE, VVE
|
return NUCv, HVE, VVE
|
||||||
|
|
||||||
|
|
||||||
def nic_v1(msg, NICs):
|
def nic_v1(msg: str, NICs: int) -> tuple[int, None | float, None | float]:
|
||||||
"""Calculate NIC, navigation integrity category, for ADS-B version 1
|
"""Calculate NIC, navigation integrity category, for ADS-B version 1
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
NICs (int or string): NIC supplement
|
NICs (int or string): NIC supplement
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
int: NIC, Navigation Integrity Category
|
||||||
int or string: Horizontal Radius of Containment
|
int or string: Horizontal Radius of Containment
|
||||||
int or string: Vertical Protection Limit
|
int or string: Vertical Protection Limit
|
||||||
"""
|
"""
|
||||||
if typecode(msg) < 5 or typecode(msg) > 22:
|
tc = typecode(msg)
|
||||||
|
if tc is None or tc < 5 or tc > 22:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s: Not a surface position message (5<TC<8), \
|
"%s: Not a surface position message (5<TC<8), \
|
||||||
airborne position message (8<TC<19), \
|
airborne position message (8<TC<19), \
|
||||||
@@ -325,33 +408,37 @@ def nic_v1(msg, NICs):
|
|||||||
% msg
|
% msg
|
||||||
)
|
)
|
||||||
|
|
||||||
tc = typecode(msg)
|
|
||||||
NIC = uncertainty.TC_NICv1_lookup[tc]
|
NIC = uncertainty.TC_NICv1_lookup[tc]
|
||||||
|
|
||||||
if isinstance(NIC, dict):
|
if isinstance(NIC, dict):
|
||||||
NIC = NIC[NICs]
|
NIC = NIC[NICs]
|
||||||
|
|
||||||
try:
|
d_index = uncertainty.NICv1.get(NIC, None)
|
||||||
Rc = uncertainty.NICv1[NIC][NICs]["Rc"]
|
Rc, VPL = uncertainty.NA, uncertainty.NA
|
||||||
VPL = uncertainty.NICv1[NIC][NICs]["VPL"]
|
|
||||||
except KeyError:
|
|
||||||
Rc, VPL = uncertainty.NA, uncertainty.NA
|
|
||||||
|
|
||||||
return Rc, VPL
|
if d_index is not None:
|
||||||
|
index = d_index.get(NICs, None)
|
||||||
|
if index is not None:
|
||||||
|
Rc = index["Rc"]
|
||||||
|
VPL = index["VPL"]
|
||||||
|
|
||||||
|
return NIC, Rc, VPL
|
||||||
|
|
||||||
|
|
||||||
def nic_v2(msg, NICa, NICbc):
|
def nic_v2(msg: str, NICa: int, NICbc: int) -> tuple[int, int]:
|
||||||
"""Calculate NIC, navigation integrity category, for ADS-B version 2
|
"""Calculate NIC, navigation integrity category, for ADS-B version 2
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
NICa (int or string): NIC supplement - A
|
NICa (int or string): NIC supplement - A
|
||||||
NICbc (int or srting): NIC supplement - B or C
|
NICbc (int or string): NIC supplement - B or C
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
int: NIC, Navigation Integrity Category
|
||||||
int or string: Horizontal Radius of Containment
|
int or string: Horizontal Radius of Containment
|
||||||
"""
|
"""
|
||||||
if typecode(msg) < 5 or typecode(msg) > 22:
|
tc = typecode(msg)
|
||||||
|
if tc is None or tc < 5 or tc > 22:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s: Not a surface position message (5<TC<8), \
|
"%s: Not a surface position message (5<TC<8), \
|
||||||
airborne position message (8<TC<19), \
|
airborne position message (8<TC<19), \
|
||||||
@@ -359,7 +446,6 @@ def nic_v2(msg, NICa, NICbc):
|
|||||||
% msg
|
% msg
|
||||||
)
|
)
|
||||||
|
|
||||||
tc = typecode(msg)
|
|
||||||
NIC = uncertainty.TC_NICv2_lookup[tc]
|
NIC = uncertainty.TC_NICv2_lookup[tc]
|
||||||
|
|
||||||
if 20 <= tc <= 22:
|
if 20 <= tc <= 22:
|
||||||
@@ -375,14 +461,14 @@ def nic_v2(msg, NICa, NICbc):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
Rc = uncertainty.NA
|
Rc = uncertainty.NA
|
||||||
|
|
||||||
return Rc
|
return NIC, Rc # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def nic_s(msg):
|
def nic_s(msg: str) -> int:
|
||||||
"""Obtain NIC supplement bit, TC=31 message
|
"""Obtain NIC supplement bit, TC=31 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: NICs number (0 or 1)
|
int: NICs number (0 or 1)
|
||||||
@@ -400,11 +486,11 @@ def nic_s(msg):
|
|||||||
return nic_s
|
return nic_s
|
||||||
|
|
||||||
|
|
||||||
def nic_a_c(msg):
|
def nic_a_c(msg: str) -> tuple[int, int]:
|
||||||
"""Obtain NICa/c, navigation integrity category supplements a and c
|
"""Obtain NICa/c, navigation integrity category supplements a and c
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, int): NICa and NICc number (0 or 1)
|
(int, int): NICa and NICc number (0 or 1)
|
||||||
@@ -423,18 +509,18 @@ def nic_a_c(msg):
|
|||||||
return nic_a, nic_c
|
return nic_a, nic_c
|
||||||
|
|
||||||
|
|
||||||
def nic_b(msg):
|
def nic_b(msg: str) -> int:
|
||||||
"""Obtain NICb, navigation integrity category supplement-b
|
"""Obtain NICb, navigation integrity category supplement-b
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: NICb number (0 or 1)
|
int: NICb number (0 or 1)
|
||||||
"""
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
if tc < 9 or tc > 18:
|
if tc is None or tc < 9 or tc > 18:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s: Not a airborne position message, expecting 8<TC<19" % msg
|
"%s: Not a airborne position message, expecting 8<TC<19" % msg
|
||||||
)
|
)
|
||||||
@@ -445,15 +531,18 @@ def nic_b(msg):
|
|||||||
return nic_b
|
return nic_b
|
||||||
|
|
||||||
|
|
||||||
def nac_p(msg):
|
def nac_p(msg: str) -> tuple[int, int | None, int | None]:
|
||||||
"""Calculate NACp, Navigation Accuracy Category - Position
|
"""Calculate NACp, Navigation Accuracy Category - Position
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string, TC = 29 or 31
|
msg (str): 28 hexdigits string, TC = 29 or 31
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int or string: 95% horizontal accuracy bounds, Estimated Position Uncertainty
|
int: NACp, Navigation Accuracy Category (position)
|
||||||
int or string: 95% vertical accuracy bounds, Vertical Estimated Position Uncertainty
|
int or string: 95% horizontal accuracy bounds,
|
||||||
|
Estimated Position Uncertainty
|
||||||
|
int or string: 95% vertical accuracy bounds,
|
||||||
|
Vertical Estimated Position Uncertainty
|
||||||
"""
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
@@ -477,18 +566,21 @@ def nac_p(msg):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
EPU, VEPU = uncertainty.NA, uncertainty.NA
|
EPU, VEPU = uncertainty.NA, uncertainty.NA
|
||||||
|
|
||||||
return EPU, VEPU
|
return NACp, EPU, VEPU
|
||||||
|
|
||||||
|
|
||||||
def nac_v(msg):
|
def nac_v(msg: str) -> tuple[int, float | None, float | None]:
|
||||||
"""Calculate NACv, Navigation Accuracy Category - Velocity
|
"""Calculate NACv, Navigation Accuracy Category - Velocity
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string, TC = 19
|
msg (str): 28 hexdigits string, TC = 19
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int or string: 95% horizontal accuracy bounds for velocity, Horizontal Figure of Merit
|
int: NACv, Navigation Accuracy Category (velocity)
|
||||||
int or string: 95% vertical accuracy bounds for velocity, Vertical Figure of Merit
|
int or string: 95% horizontal accuracy bounds for velocity,
|
||||||
|
Horizontal Figure of Merit
|
||||||
|
int or string: 95% vertical accuracy bounds for velocity,
|
||||||
|
Vertical Figure of Merit
|
||||||
"""
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
@@ -506,25 +598,30 @@ def nac_v(msg):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
HFOMr, VFOMr = uncertainty.NA, uncertainty.NA
|
HFOMr, VFOMr = uncertainty.NA, uncertainty.NA
|
||||||
|
|
||||||
return HFOMr, VFOMr
|
return NACv, HFOMr, VFOMr
|
||||||
|
|
||||||
|
|
||||||
def sil(msg, version):
|
def sil(
|
||||||
|
msg: str,
|
||||||
|
version: None | int,
|
||||||
|
) -> tuple[float | None, float | None, str]:
|
||||||
"""Calculate SIL, Surveillance Integrity Level
|
"""Calculate SIL, Surveillance Integrity Level
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string with TC = 29, 31
|
msg (str): 28 hexdigits string with TC = 29, 31
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int or string: Probability of exceeding Horizontal Radius of Containment RCu
|
int or string:
|
||||||
int or string: Probability of exceeding Vertical Integrity Containment Region VPL
|
Probability of exceeding Horizontal Radius of Containment RCu
|
||||||
|
int or string:
|
||||||
|
Probability of exceeding Vertical Integrity Containment Region VPL
|
||||||
string: SIL supplement based on per "hour" or "sample", or 'unknown'
|
string: SIL supplement based on per "hour" or "sample", or 'unknown'
|
||||||
"""
|
"""
|
||||||
tc = typecode(msg)
|
tc = typecode(msg)
|
||||||
|
|
||||||
if tc not in [29, 31]:
|
if tc not in [29, 31]:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s: Not a target state and status messag, \
|
"%s: Not a target state and status message, \
|
||||||
or operation status message, expecting TC = 29 or 31"
|
or operation status message, expecting TC = 29 or 31"
|
||||||
% msg
|
% msg
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,23 +1,98 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Decoding all call replies DF=11
|
Decode all-call reply messages, with downlink format 11
|
||||||
|
|
||||||
[To be implemented]
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
from pyModeS.decoder import common
|
from __future__ import annotations
|
||||||
|
from typing import Callable, TypeVar
|
||||||
|
|
||||||
|
from .. import common
|
||||||
|
|
||||||
|
T = TypeVar("T")
|
||||||
|
F = Callable[[str], T]
|
||||||
|
|
||||||
|
|
||||||
|
def _checkdf(func: F[T]) -> F[T]:
|
||||||
|
|
||||||
|
"""Ensure downlink format is 11."""
|
||||||
|
|
||||||
|
def wrapper(msg: str) -> T:
|
||||||
|
df = common.df(msg)
|
||||||
|
if df != 11:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Incorrect downlink format, expect 11, got {}".format(df)
|
||||||
|
)
|
||||||
|
return func(msg)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def icao(msg: str) -> None | str:
|
||||||
|
"""Decode transponder code (ICAO address).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
string: ICAO address
|
||||||
|
|
||||||
|
"""
|
||||||
|
return common.icao(msg)
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def interrogator(msg: str) -> str:
|
||||||
|
"""Decode interrogator identifier code.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int: interrogator identifier code
|
||||||
|
|
||||||
|
"""
|
||||||
|
# the CRC remainder contains the CL and IC field.
|
||||||
|
# the top three bits are CL field and last four bits are IC field.
|
||||||
|
remainder = common.crc(msg)
|
||||||
|
if remainder > 79:
|
||||||
|
IC = "corrupt IC"
|
||||||
|
elif remainder < 16:
|
||||||
|
IC = "II" + str(remainder)
|
||||||
|
else:
|
||||||
|
IC = "SI" + str(remainder - 16)
|
||||||
|
return IC
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def capability(msg: str) -> tuple[int, None | str]:
|
||||||
|
"""Decode transponder capability.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: transponder capability, description
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
ca = common.bin2int(msgbin[5:8])
|
||||||
|
|
||||||
|
if ca == 0:
|
||||||
|
text = "level 1 transponder"
|
||||||
|
elif ca == 4:
|
||||||
|
text = "level 2 transponder, ability to set CA to 7, on ground"
|
||||||
|
elif ca == 5:
|
||||||
|
text = "level 2 transponder, ability to set CA to 7, airborne"
|
||||||
|
elif ca == 6:
|
||||||
|
text = (
|
||||||
|
"evel 2 transponder, ability to set CA to 7, "
|
||||||
|
"either airborne or ground"
|
||||||
|
)
|
||||||
|
elif ca == 7:
|
||||||
|
text = (
|
||||||
|
"Downlink Request value is 0, "
|
||||||
|
"or the Flight Status is 2, 3, 4 or 5, "
|
||||||
|
"either airborne or on the ground"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
text = None
|
||||||
|
|
||||||
|
return ca, text
|
||||||
|
|||||||
@@ -18,16 +18,13 @@
|
|||||||
Common functions for Mode-S decoding
|
Common functions for Mode-S decoding
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from pyModeS.extra import aero
|
from ... import common
|
||||||
from pyModeS.decoder import common
|
from ...extra import aero
|
||||||
from pyModeS.decoder.bds import (
|
from . import ( # noqa: F401
|
||||||
bds05,
|
|
||||||
bds06,
|
|
||||||
bds08,
|
|
||||||
bds09,
|
|
||||||
bds10,
|
bds10,
|
||||||
bds17,
|
bds17,
|
||||||
bds20,
|
bds20,
|
||||||
@@ -36,22 +33,26 @@ from pyModeS.decoder.bds import (
|
|||||||
bds44,
|
bds44,
|
||||||
bds45,
|
bds45,
|
||||||
bds50,
|
bds50,
|
||||||
bds53,
|
|
||||||
bds60,
|
bds60,
|
||||||
|
bds61,
|
||||||
|
bds62,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def is50or60(msg, spd_ref, trk_ref, alt_ref):
|
def is50or60(
|
||||||
|
msg: str, spd_ref: float, trk_ref: float, alt_ref: float
|
||||||
|
) -> Optional[str]:
|
||||||
"""Use reference ground speed and trk to determine BDS50 and DBS60.
|
"""Use reference ground speed and trk to determine BDS50 and DBS60.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
spd_ref (float): reference speed (ADS-B ground speed), kts
|
spd_ref (float): reference speed (ADS-B ground speed), kts
|
||||||
trk_ref (float): reference track (ADS-B track angle), deg
|
trk_ref (float): reference track (ADS-B track angle), deg
|
||||||
alt_ref (float): reference altitude (ADS-B altitude), ft
|
alt_ref (float): reference altitude (ADS-B altitude), ft
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
String or None: BDS version, or possible versions, or None if nothing matches.
|
String or None: BDS version, or possible versions,
|
||||||
|
or None if nothing matches.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -60,25 +61,34 @@ def is50or60(msg, spd_ref, trk_ref, alt_ref):
|
|||||||
vy = v * np.cos(np.radians(angle))
|
vy = v * np.cos(np.radians(angle))
|
||||||
return vx, vy
|
return vx, vy
|
||||||
|
|
||||||
|
# message must be both BDS 50 and 60 before processing
|
||||||
if not (bds50.is50(msg) and bds60.is60(msg)):
|
if not (bds50.is50(msg) and bds60.is60(msg)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
h50 = bds50.trk50(msg)
|
# --- assuming BDS60 ---
|
||||||
v50 = bds50.gs50(msg)
|
|
||||||
|
|
||||||
if h50 is None or v50 is None:
|
|
||||||
return "BDS50,BDS60"
|
|
||||||
|
|
||||||
h60 = bds60.hdg60(msg)
|
h60 = bds60.hdg60(msg)
|
||||||
m60 = bds60.mach60(msg)
|
m60 = bds60.mach60(msg)
|
||||||
i60 = bds60.ias60(msg)
|
i60 = bds60.ias60(msg)
|
||||||
|
|
||||||
|
# additional check now knowing the altitude
|
||||||
|
if (m60 is not None) and (i60 is not None):
|
||||||
|
ias_ = aero.mach2cas(m60, alt_ref * aero.ft) / aero.kts
|
||||||
|
if abs(i60 - ias_) > 20:
|
||||||
|
return "BDS50"
|
||||||
|
|
||||||
if h60 is None or (m60 is None and i60 is None):
|
if h60 is None or (m60 is None and i60 is None):
|
||||||
return "BDS50,BDS60"
|
return "BDS50,BDS60"
|
||||||
|
|
||||||
m60 = np.nan if m60 is None else m60
|
m60 = np.nan if m60 is None else m60
|
||||||
i60 = np.nan if i60 is None else i60
|
i60 = np.nan if i60 is None else i60
|
||||||
|
|
||||||
|
# --- assuming BDS50 ---
|
||||||
|
h50 = bds50.trk50(msg)
|
||||||
|
v50 = bds50.gs50(msg)
|
||||||
|
|
||||||
|
if h50 is None or v50 is None:
|
||||||
|
return "BDS50,BDS60"
|
||||||
|
|
||||||
XY5 = vxy(v50 * aero.kts, h50)
|
XY5 = vxy(v50 * aero.kts, h50)
|
||||||
XY6m = vxy(aero.mach2tas(m60, alt_ref * aero.ft), h60)
|
XY6m = vxy(aero.mach2tas(m60, alt_ref * aero.ft), h60)
|
||||||
XY6i = vxy(aero.cas2tas(i60 * aero.kts, alt_ref * aero.ft), h60)
|
XY6i = vxy(aero.cas2tas(i60 * aero.kts, alt_ref * aero.ft), h60)
|
||||||
@@ -104,15 +114,17 @@ def is50or60(msg, spd_ref, trk_ref, alt_ref):
|
|||||||
return BDS
|
return BDS
|
||||||
|
|
||||||
|
|
||||||
def infer(msg, mrar=False):
|
def infer(msg: str, mrar: bool = False) -> Optional[str]:
|
||||||
"""Estimate the most likely BDS code of an message.
|
"""Estimate the most likely BDS code of an message.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
mrar (bool): Also infer MRAR (BDS 44) and MHR (BDS 45). Defaults to False.
|
mrar (bool): Also infer MRAR (BDS 44) and MHR (BDS 45).
|
||||||
|
Defaults to False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
String or None: BDS version, or possible versions, or None if nothing matches.
|
String or None: BDS version, or possible versions,
|
||||||
|
or None if nothing matches.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
df = common.df(msg)
|
df = common.df(msg)
|
||||||
@@ -123,9 +135,11 @@ def infer(msg, mrar=False):
|
|||||||
# For ADS-B / Mode-S extended squitter
|
# For ADS-B / Mode-S extended squitter
|
||||||
if df == 17:
|
if df == 17:
|
||||||
tc = common.typecode(msg)
|
tc = common.typecode(msg)
|
||||||
|
if tc is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if 1 <= tc <= 4:
|
if 1 <= tc <= 4:
|
||||||
return "BDS08" # indentification and category
|
return "BDS08" # identification and category
|
||||||
if 5 <= tc <= 8:
|
if 5 <= tc <= 8:
|
||||||
return "BDS06" # surface movement
|
return "BDS06" # surface movement
|
||||||
if 9 <= tc <= 18:
|
if 9 <= tc <= 18:
|
||||||
|
|||||||
@@ -1,36 +1,24 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 0,5
|
# BDS 0,5
|
||||||
# ADS-B TC=9-18
|
# ADS-B TC=9-18
|
||||||
# Airborn position
|
# Airborne position
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from datetime import datetime
|
||||||
from pyModeS.decoder import common
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def airborne_position(msg0, msg1, t0, t1):
|
def airborne_position(
|
||||||
"""Decode airborn position from a pair of even and odd position message
|
msg0: str, msg1: str, t0: int | datetime, t1: int | datetime
|
||||||
|
) -> None | tuple[float, float]:
|
||||||
|
"""Decode airborne position from a pair of even and odd position message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg0 (string): even message (28 bytes hexadecimal string)
|
msg0 (string): even message (28 hexdigits)
|
||||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
msg1 (string): odd message (28 hexdigits)
|
||||||
t0 (int): timestamps for the even message
|
t0 (int): timestamps for the even message
|
||||||
t1 (int): timestamps for the odd message
|
t1 (int): timestamps for the odd message
|
||||||
|
|
||||||
@@ -52,13 +40,13 @@ def airborne_position(msg0, msg1, t0, t1):
|
|||||||
raise RuntimeError("Both even and odd CPR frames are required.")
|
raise RuntimeError("Both even and odd CPR frames are required.")
|
||||||
|
|
||||||
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
||||||
cprlat_even = common.bin2int(mb0[22:39]) / 131072.0
|
cprlat_even = common.bin2int(mb0[22:39]) / 131072
|
||||||
cprlon_even = common.bin2int(mb0[39:56]) / 131072.0
|
cprlon_even = common.bin2int(mb0[39:56]) / 131072
|
||||||
cprlat_odd = common.bin2int(mb1[22:39]) / 131072.0
|
cprlat_odd = common.bin2int(mb1[22:39]) / 131072
|
||||||
cprlon_odd = common.bin2int(mb1[39:56]) / 131072.0
|
cprlon_odd = common.bin2int(mb1[39:56]) / 131072
|
||||||
|
|
||||||
air_d_lat_even = 360.0 / 60
|
air_d_lat_even = 360 / 60
|
||||||
air_d_lat_odd = 360.0 / 59
|
air_d_lat_odd = 360 / 59
|
||||||
|
|
||||||
# compute latitude index 'j'
|
# compute latitude index 'j'
|
||||||
j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
||||||
@@ -77,18 +65,19 @@ def airborne_position(msg0, msg1, t0, t1):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# compute ni, longitude index m, and longitude
|
# compute ni, longitude index m, and longitude
|
||||||
if t0 > t1:
|
# (people pass int+int or datetime+datetime)
|
||||||
|
if t0 > t1: # type: ignore
|
||||||
lat = lat_even
|
lat = lat_even
|
||||||
nl = common.cprNL(lat)
|
nl = common.cprNL(lat)
|
||||||
ni = max(common.cprNL(lat) - 0, 1)
|
ni = max(common.cprNL(lat) - 0, 1)
|
||||||
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
||||||
lon = (360.0 / ni) * (m % ni + cprlon_even)
|
lon = (360 / ni) * (m % ni + cprlon_even)
|
||||||
else:
|
else:
|
||||||
lat = lat_odd
|
lat = lat_odd
|
||||||
nl = common.cprNL(lat)
|
nl = common.cprNL(lat)
|
||||||
ni = max(common.cprNL(lat) - 1, 1)
|
ni = max(common.cprNL(lat) - 1, 1)
|
||||||
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
||||||
lon = (360.0 / ni) * (m % ni + cprlon_odd)
|
lon = (360 / ni) * (m % ni + cprlon_odd)
|
||||||
|
|
||||||
if lon > 180:
|
if lon > 180:
|
||||||
lon = lon - 360
|
lon = lon - 360
|
||||||
@@ -96,14 +85,16 @@ def airborne_position(msg0, msg1, t0, t1):
|
|||||||
return round(lat, 5), round(lon, 5)
|
return round(lat, 5), round(lon, 5)
|
||||||
|
|
||||||
|
|
||||||
def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
def airborne_position_with_ref(
|
||||||
|
msg: str, lat_ref: float, lon_ref: float
|
||||||
|
) -> tuple[float, float]:
|
||||||
"""Decode airborne position with only one message,
|
"""Decode airborne position with only one message,
|
||||||
knowing reference nearby location, such as previously calculated location,
|
knowing reference nearby location, such as previously calculated location,
|
||||||
ground station, or airport location, etc. The reference position shall
|
ground station, or airport location, etc. The reference position shall
|
||||||
be with in 180NM of the true position.
|
be within 180NM of the true position.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): even message (28 bytes hexadecimal string)
|
msg (str): even message (28 hexdigits)
|
||||||
lat_ref: previous known latitude
|
lat_ref: previous known latitude
|
||||||
lon_ref: previous known longitude
|
lon_ref: previous known longitude
|
||||||
|
|
||||||
@@ -113,11 +104,11 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
|
|
||||||
mb = common.hex2bin(msg)[32:]
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
cprlat = common.bin2int(mb[22:39]) / 131072.0
|
cprlat = common.bin2int(mb[22:39]) / 131072
|
||||||
cprlon = common.bin2int(mb[39:56]) / 131072.0
|
cprlon = common.bin2int(mb[39:56]) / 131072
|
||||||
|
|
||||||
i = int(mb[21])
|
i = int(mb[21])
|
||||||
d_lat = 360.0 / 59 if i else 360.0 / 60
|
d_lat = 360 / 59 if i else 360 / 60
|
||||||
|
|
||||||
j = common.floor(lat_ref / d_lat) + common.floor(
|
j = common.floor(lat_ref / d_lat) + common.floor(
|
||||||
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
|
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
|
||||||
@@ -128,9 +119,9 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
ni = common.cprNL(lat) - i
|
ni = common.cprNL(lat) - i
|
||||||
|
|
||||||
if ni > 0:
|
if ni > 0:
|
||||||
d_lon = 360.0 / ni
|
d_lon = 360 / ni
|
||||||
else:
|
else:
|
||||||
d_lon = 360.0
|
d_lon = 360
|
||||||
|
|
||||||
m = common.floor(lon_ref / d_lon) + common.floor(
|
m = common.floor(lon_ref / d_lon) + common.floor(
|
||||||
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
|
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
|
||||||
@@ -141,11 +132,11 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
return round(lat, 5), round(lon, 5)
|
return round(lat, 5), round(lon, 5)
|
||||||
|
|
||||||
|
|
||||||
def altitude(msg):
|
def altitude(msg: str) -> None | int:
|
||||||
"""Decode aircraft altitude
|
"""Decode aircraft altitude
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: altitude in feet
|
int: altitude in feet
|
||||||
@@ -153,21 +144,14 @@ def altitude(msg):
|
|||||||
|
|
||||||
tc = common.typecode(msg)
|
tc = common.typecode(msg)
|
||||||
|
|
||||||
if tc < 9 or tc == 19 or tc > 22:
|
if tc is None or tc < 9 or tc == 19 or tc > 22:
|
||||||
raise RuntimeError("%s: Not a airborn position message" % msg)
|
raise RuntimeError("%s: Not an airborne position message" % msg)
|
||||||
|
|
||||||
mb = common.hex2bin(msg)[32:]
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
altbin = mb[8:20]
|
||||||
|
|
||||||
if tc < 19:
|
if tc < 19:
|
||||||
# barometric altitude
|
altcode = altbin[0:6] + "0" + altbin[6:]
|
||||||
q = mb[15]
|
return common.altitude(altcode)
|
||||||
if q:
|
|
||||||
n = common.bin2int(mb[8:15] + mb[16:20])
|
|
||||||
alt = n * 25 - 1000
|
|
||||||
else:
|
|
||||||
alt = None
|
|
||||||
else:
|
else:
|
||||||
# GNSS altitude, meters -> feet
|
return common.bin2int(altbin) * 3.28084 # type: ignore
|
||||||
alt = common.bin2int(mb[8:20]) * 3.28084
|
|
||||||
|
|
||||||
return alt
|
|
||||||
|
|||||||
@@ -1,37 +1,31 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 0,6
|
# BDS 0,6
|
||||||
# ADS-B TC=5-8
|
# ADS-B TC=5-8
|
||||||
# Surface position
|
# Surface movement
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from __future__ import annotations
|
||||||
from pyModeS.decoder import common
|
|
||||||
import math
|
from datetime import datetime
|
||||||
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):
|
def surface_position(
|
||||||
|
msg0: str,
|
||||||
|
msg1: str,
|
||||||
|
t0: int | datetime,
|
||||||
|
t1: int | datetime,
|
||||||
|
lat_ref: float,
|
||||||
|
lon_ref: float,
|
||||||
|
) -> None | tuple[float, float]:
|
||||||
|
|
||||||
"""Decode surface position from a pair of even and odd position message,
|
"""Decode surface position from a pair of even and odd position message,
|
||||||
the lat/lon of receiver must be provided to yield the correct solution.
|
the lat/lon of receiver must be provided to yield the correct solution.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg0 (string): even message (28 bytes hexadecimal string)
|
msg0 (string): even message (28 hexdigits)
|
||||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
msg1 (string): odd message (28 hexdigits)
|
||||||
t0 (int): timestamps for the even message
|
t0 (int): timestamps for the even message
|
||||||
t1 (int): timestamps for the odd message
|
t1 (int): timestamps for the odd message
|
||||||
lat_ref (float): latitude of the receiver
|
lat_ref (float): latitude of the receiver
|
||||||
@@ -45,13 +39,13 @@ def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):
|
|||||||
msgbin1 = common.hex2bin(msg1)
|
msgbin1 = common.hex2bin(msg1)
|
||||||
|
|
||||||
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
||||||
cprlat_even = common.bin2int(msgbin0[54:71]) / 131072.0
|
cprlat_even = common.bin2int(msgbin0[54:71]) / 131072
|
||||||
cprlon_even = common.bin2int(msgbin0[71:88]) / 131072.0
|
cprlon_even = common.bin2int(msgbin0[71:88]) / 131072
|
||||||
cprlat_odd = common.bin2int(msgbin1[54:71]) / 131072.0
|
cprlat_odd = common.bin2int(msgbin1[54:71]) / 131072
|
||||||
cprlon_odd = common.bin2int(msgbin1[71:88]) / 131072.0
|
cprlon_odd = common.bin2int(msgbin1[71:88]) / 131072
|
||||||
|
|
||||||
air_d_lat_even = 90.0 / 60
|
air_d_lat_even = 90 / 60
|
||||||
air_d_lat_odd = 90.0 / 59
|
air_d_lat_odd = 90 / 59
|
||||||
|
|
||||||
# compute latitude index 'j'
|
# compute latitude index 'j'
|
||||||
j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
||||||
@@ -61,8 +55,8 @@ def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):
|
|||||||
lat_odd_n = float(air_d_lat_odd * (j % 59 + cprlat_odd))
|
lat_odd_n = float(air_d_lat_odd * (j % 59 + cprlat_odd))
|
||||||
|
|
||||||
# solution for north hemisphere
|
# solution for north hemisphere
|
||||||
lat_even_s = lat_even_n - 90.0
|
lat_even_s = lat_even_n - 90
|
||||||
lat_odd_s = lat_odd_n - 90.0
|
lat_odd_s = lat_odd_n - 90
|
||||||
|
|
||||||
# chose which solution corrispondes to receiver location
|
# chose which solution corrispondes to receiver location
|
||||||
lat_even = lat_even_n if lat_ref > 0 else lat_even_s
|
lat_even = lat_even_n if lat_ref > 0 else lat_even_s
|
||||||
@@ -73,41 +67,44 @@ def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# compute ni, longitude index m, and longitude
|
# compute ni, longitude index m, and longitude
|
||||||
if t0 > t1:
|
# (people pass int+int or datetime+datetime)
|
||||||
|
if t0 > t1: # type: ignore
|
||||||
lat = lat_even
|
lat = lat_even
|
||||||
nl = common.cprNL(lat_even)
|
nl = common.cprNL(lat_even)
|
||||||
ni = max(common.cprNL(lat_even) - 0, 1)
|
ni = max(common.cprNL(lat_even) - 0, 1)
|
||||||
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
||||||
lon = (90.0 / ni) * (m % ni + cprlon_even)
|
lon = (90 / ni) * (m % ni + cprlon_even)
|
||||||
else:
|
else:
|
||||||
lat = lat_odd
|
lat = lat_odd
|
||||||
nl = common.cprNL(lat_odd)
|
nl = common.cprNL(lat_odd)
|
||||||
ni = max(common.cprNL(lat_odd) - 1, 1)
|
ni = max(common.cprNL(lat_odd) - 1, 1)
|
||||||
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
|
||||||
lon = (90.0 / ni) * (m % ni + cprlon_odd)
|
lon = (90 / ni) * (m % ni + cprlon_odd)
|
||||||
|
|
||||||
# four possible longitude solutions
|
# four possible longitude solutions
|
||||||
lons = [lon, lon + 90.0, lon + 180.0, lon + 270.0]
|
lons = [lon, lon + 90, lon + 180, lon + 270]
|
||||||
|
|
||||||
# make sure lons are between -180 and 180
|
# make sure lons are between -180 and 180
|
||||||
lons = [(l + 180) % 360 - 180 for l in lons]
|
lons = [(lon + 180) % 360 - 180 for lon in lons]
|
||||||
|
|
||||||
# the closest solution to receiver is the correct one
|
# the closest solution to receiver is the correct one
|
||||||
dls = [abs(lon_ref - l) for l in lons]
|
dls = [abs(lon_ref - lon) for lon in lons]
|
||||||
imin = min(range(4), key=dls.__getitem__)
|
imin = min(range(4), key=dls.__getitem__)
|
||||||
lon = lons[imin]
|
lon = lons[imin]
|
||||||
|
|
||||||
return round(lat, 5), round(lon, 5)
|
return round(lat, 5), round(lon, 5)
|
||||||
|
|
||||||
|
|
||||||
def surface_position_with_ref(msg, lat_ref, lon_ref):
|
def surface_position_with_ref(
|
||||||
|
msg: str, lat_ref: float, lon_ref: float
|
||||||
|
) -> tuple[float, float]:
|
||||||
"""Decode surface position with only one message,
|
"""Decode surface position with only one message,
|
||||||
knowing reference nearby location, such as previously calculated location,
|
knowing reference nearby location, such as previously calculated location,
|
||||||
ground station, or airport location, etc. The reference position shall
|
ground station, or airport location, etc. The reference position shall
|
||||||
be with in 45NM of the true position.
|
be within 45NM of the true position.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): even message (28 bytes hexadecimal string)
|
msg (str): even message (28 hexdigits)
|
||||||
lat_ref: previous known latitude
|
lat_ref: previous known latitude
|
||||||
lon_ref: previous known longitude
|
lon_ref: previous known longitude
|
||||||
|
|
||||||
@@ -117,11 +114,11 @@ def surface_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
|
|
||||||
mb = common.hex2bin(msg)[32:]
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
cprlat = common.bin2int(mb[22:39]) / 131072.0
|
cprlat = common.bin2int(mb[22:39]) / 131072
|
||||||
cprlon = common.bin2int(mb[39:56]) / 131072.0
|
cprlon = common.bin2int(mb[39:56]) / 131072
|
||||||
|
|
||||||
i = int(mb[21])
|
i = int(mb[21])
|
||||||
d_lat = 90.0 / 59 if i else 90.0 / 60
|
d_lat = 90 / 59 if i else 90 / 60
|
||||||
|
|
||||||
j = common.floor(lat_ref / d_lat) + common.floor(
|
j = common.floor(lat_ref / d_lat) + common.floor(
|
||||||
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
|
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
|
||||||
@@ -132,9 +129,9 @@ def surface_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
ni = common.cprNL(lat) - i
|
ni = common.cprNL(lat) - i
|
||||||
|
|
||||||
if ni > 0:
|
if ni > 0:
|
||||||
d_lon = 90.0 / ni
|
d_lon = 90 / ni
|
||||||
else:
|
else:
|
||||||
d_lon = 90.0
|
d_lon = 90
|
||||||
|
|
||||||
m = common.floor(lon_ref / d_lon) + common.floor(
|
m = common.floor(lon_ref / d_lon) + common.floor(
|
||||||
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
|
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
|
||||||
@@ -145,24 +142,29 @@ def surface_position_with_ref(msg, lat_ref, lon_ref):
|
|||||||
return round(lat, 5), round(lon, 5)
|
return round(lat, 5), round(lon, 5)
|
||||||
|
|
||||||
|
|
||||||
def surface_velocity(msg, rtn_sources=False):
|
def surface_velocity(
|
||||||
"""Decode surface velocity from from a surface position message
|
msg: str, source: bool = False
|
||||||
|
) -> tuple[None | float, float, int, str]:
|
||||||
|
"""Decode surface velocity from a surface position message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
rtn_source (boolean): If the function will return
|
source (boolean): Include direction and vertical rate sources in return.
|
||||||
the sources for direction of travel and vertical
|
Default to False.
|
||||||
rate. This will change the return value from a four
|
If set to True, the function will return six value instead of four.
|
||||||
element array to a six element array.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, float, int, string, string, None): speed (kt),
|
int, float, int, string, [string], [string]:
|
||||||
ground track (degree), None for rate of climb/descend (ft/min),
|
- Speed (kt)
|
||||||
and speed type ('GS' for ground speed), direction source
|
- Angle (degree), ground track
|
||||||
('true_north' for ground track / true north as reference),
|
- Vertical rate, always 0
|
||||||
None rate of climb/descent source.
|
- Speed type ('GS' for ground speed, 'AS' for airspeed)
|
||||||
"""
|
- [Optional] Direction source ('TRUE_NORTH')
|
||||||
|
- [Optional] Vertical rate source (None)
|
||||||
|
|
||||||
if common.typecode(msg) < 5 or common.typecode(msg) > 8:
|
"""
|
||||||
|
tc = common.typecode(msg)
|
||||||
|
if tc is None or tc < 5 or tc > 8:
|
||||||
raise RuntimeError("%s: Not a surface message, expecting 5<TC<8" % msg)
|
raise RuntimeError("%s: Not a surface message, expecting 5<TC<8" % msg)
|
||||||
|
|
||||||
mb = common.hex2bin(msg)[32:]
|
mb = common.hex2bin(msg)[32:]
|
||||||
@@ -170,29 +172,28 @@ def surface_velocity(msg, rtn_sources=False):
|
|||||||
# ground track
|
# ground track
|
||||||
trk_status = int(mb[12])
|
trk_status = int(mb[12])
|
||||||
if trk_status == 1:
|
if trk_status == 1:
|
||||||
trk = common.bin2int(mb[13:20]) * 360.0 / 128.0
|
trk = common.bin2int(mb[13:20]) * 360 / 128
|
||||||
trk = round(trk, 1)
|
trk = round(trk, 1)
|
||||||
else:
|
else:
|
||||||
trk = None
|
trk = None
|
||||||
|
|
||||||
# ground movment / speed
|
# ground movement / speed
|
||||||
mov = common.bin2int(mb[5:12])
|
mov = common.bin2int(mb[5:12])
|
||||||
|
|
||||||
if mov == 0 or mov > 124:
|
if mov == 0 or mov > 124:
|
||||||
spd = None
|
spd = None
|
||||||
elif mov == 1:
|
elif mov == 1:
|
||||||
spd = 0
|
spd = 0.0
|
||||||
elif mov == 124:
|
elif mov == 124:
|
||||||
spd = 175
|
spd = 175.0
|
||||||
else:
|
else:
|
||||||
movs = [2, 9, 13, 39, 94, 109, 124]
|
mov_lb = [2, 9, 13, 39, 94, 109, 124]
|
||||||
kts = [0.125, 1, 2, 15, 70, 100, 175]
|
kts_lb: list[float] = [0.125, 1, 2, 15, 70, 100, 175]
|
||||||
i = next(m[0] for m in enumerate(movs) if m[1] > mov)
|
step: list[float] = [0.125, 0.25, 0.5, 1, 2, 5]
|
||||||
step = (kts[i] - kts[i - 1]) * 1.0 / (movs[i] - movs[i - 1])
|
i = next(m[0] for m in enumerate(mov_lb) if m[1] > mov)
|
||||||
spd = kts[i - 1] + (mov - movs[i - 1]) * step
|
spd = kts_lb[i - 1] + (mov - mov_lb[i - 1]) * step[i - 1]
|
||||||
spd = round(spd, 2)
|
|
||||||
|
|
||||||
if rtn_sources:
|
if source:
|
||||||
return spd, trk, 0, "GS", "true_north", None
|
return spd, trk, 0, "GS", "TRUE_NORTH", None # type: ignore
|
||||||
else:
|
else:
|
||||||
return spd, trk, 0, "GS"
|
return spd, trk, 0, "GS"
|
||||||
|
|||||||
@@ -1,40 +1,24 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 0,8
|
# BDS 0,8
|
||||||
# ADS-B TC=1-4
|
# ADS-B TC=1-4
|
||||||
# Aircraft identitification and category
|
# Aircraft identification and category
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from ... import common
|
||||||
from pyModeS.decoder import common
|
|
||||||
|
|
||||||
|
|
||||||
def category(msg):
|
def category(msg: str) -> int:
|
||||||
"""Aircraft category number
|
"""Aircraft category number
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: category number
|
int: category number
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if common.typecode(msg) < 1 or common.typecode(msg) > 4:
|
tc = common.typecode(msg)
|
||||||
|
if tc is None or tc < 1 or tc > 4:
|
||||||
raise RuntimeError("%s: Not a identification message" % msg)
|
raise RuntimeError("%s: Not a identification message" % msg)
|
||||||
|
|
||||||
msgbin = common.hex2bin(msg)
|
msgbin = common.hex2bin(msg)
|
||||||
@@ -42,17 +26,18 @@ def category(msg):
|
|||||||
return common.bin2int(mebin[5:8])
|
return common.bin2int(mebin[5:8])
|
||||||
|
|
||||||
|
|
||||||
def callsign(msg):
|
def callsign(msg: str) -> str:
|
||||||
"""Aircraft callsign
|
"""Aircraft callsign
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
string: callsign
|
string: callsign
|
||||||
"""
|
"""
|
||||||
|
tc = common.typecode(msg)
|
||||||
|
|
||||||
if common.typecode(msg) < 1 or common.typecode(msg) > 4:
|
if tc is None or tc < 1 or tc > 4:
|
||||||
raise RuntimeError("%s: Not a identification message" % msg)
|
raise RuntimeError("%s: Not a identification message" % msg)
|
||||||
|
|
||||||
chars = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######"
|
chars = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######"
|
||||||
|
|||||||
@@ -1,53 +1,41 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 0,9
|
# BDS 0,9
|
||||||
# ADS-B TC=19
|
# ADS-B TC=19
|
||||||
# Aircraft Airborn velocity
|
# Aircraft Airborne velocity
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from __future__ import annotations
|
||||||
from pyModeS.decoder import common
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
def airborne_velocity(msg, rtn_sources=False):
|
|
||||||
"""Calculate the speed, track (or heading), and vertical rate
|
def airborne_velocity(
|
||||||
|
msg: str, source: bool = False
|
||||||
|
) -> None | tuple[None | int, None | float, None | int, str]:
|
||||||
|
"""Decode airborne velocity.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
rtn_source (boolean): If the function will return
|
source (boolean): Include direction and vertical rate sources in return.
|
||||||
the sources for direction of travel and vertical
|
Default to False.
|
||||||
rate. This will change the return value from a four
|
If set to True, the function will return six value instead of four.
|
||||||
element array to a six element array.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, float, int, string, string, string): speed (kt),
|
int, float, int, string, [string], [string]:
|
||||||
ground track or heading (degree),
|
- Speed (kt)
|
||||||
rate of climb/descent (ft/min), speed type
|
- Angle (degree), either ground track or heading
|
||||||
('GS' for ground speed, 'AS' for airspeed),
|
- Vertical rate (ft/min)
|
||||||
direction source ('true_north' for ground track / true north
|
- Speed type ('GS' for ground speed, 'AS' for airspeed)
|
||||||
as refrence, 'mag_north' for magnetic north as reference),
|
- [Optional] Direction source ('TRUE_NORTH' or 'MAGNETIC_NORTH')
|
||||||
rate of climb/descent source ('Baro' for barometer, 'GNSS'
|
- [Optional] Vertical rate source ('BARO' or 'GNSS')
|
||||||
for GNSS constellation).
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
"""
|
||||||
if common.typecode(msg) != 19:
|
if common.typecode(msg) != 19:
|
||||||
raise RuntimeError("%s: Not a airborne velocity message, expecting TC=19" % msg)
|
raise RuntimeError(
|
||||||
|
"%s: Not a airborne velocity message, expecting TC=19" % msg
|
||||||
|
)
|
||||||
|
|
||||||
mb = common.hex2bin(msg)[32:]
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
@@ -56,77 +44,100 @@ def airborne_velocity(msg, rtn_sources=False):
|
|||||||
if common.bin2int(mb[14:24]) == 0 or common.bin2int(mb[25:35]) == 0:
|
if common.bin2int(mb[14:24]) == 0 or common.bin2int(mb[25:35]) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
trk_or_hdg: None | float
|
||||||
|
spd: None | float
|
||||||
|
|
||||||
if subtype in (1, 2):
|
if subtype in (1, 2):
|
||||||
v_ew_sign = -1 if mb[13] == "1" else 1
|
|
||||||
v_ew = common.bin2int(mb[14:24]) - 1 # east-west velocity
|
|
||||||
if subtype == 2: # Supersonic
|
|
||||||
v_ew *= 4
|
|
||||||
|
|
||||||
v_ns_sign = -1 if mb[24] == "1" else 1
|
v_ew = common.bin2int(mb[14:24])
|
||||||
v_ns = common.bin2int(mb[25:35]) - 1 # north-south velocity
|
v_ns = common.bin2int(mb[25:35])
|
||||||
if subtype == 2: # Supersonic
|
|
||||||
v_ns *= 4
|
|
||||||
|
|
||||||
v_we = v_ew_sign * v_ew
|
if v_ew == 0 or v_ns == 0:
|
||||||
v_sn = v_ns_sign * v_ns
|
spd = None
|
||||||
|
trk_or_hdg = None
|
||||||
|
vs = None
|
||||||
|
else:
|
||||||
|
v_ew_sign = -1 if mb[13] == "1" else 1
|
||||||
|
v_ew = v_ew - 1 # east-west velocity
|
||||||
|
if subtype == 2: # Supersonic
|
||||||
|
v_ew *= 4
|
||||||
|
|
||||||
spd = math.sqrt(v_sn * v_sn + v_we * v_we) # unit in kts
|
v_ns_sign = -1 if mb[24] == "1" else 1
|
||||||
spd = int(spd)
|
v_ns = v_ns - 1 # north-south velocity
|
||||||
|
if subtype == 2: # Supersonic
|
||||||
|
v_ns *= 4
|
||||||
|
|
||||||
trk = math.atan2(v_we, v_sn)
|
v_we = v_ew_sign * v_ew
|
||||||
trk = math.degrees(trk) # convert to degrees
|
v_sn = v_ns_sign * v_ns
|
||||||
trk = trk if trk >= 0 else trk + 360 # no negative val
|
|
||||||
|
|
||||||
tag = "GS"
|
spd = math.sqrt(v_sn * v_sn + v_we * v_we) # unit in kts
|
||||||
trk_or_hdg = round(trk, 2)
|
spd = int(spd)
|
||||||
dir_type = "true_north"
|
|
||||||
|
trk = math.atan2(v_we, v_sn)
|
||||||
|
trk = math.degrees(trk) # convert to degrees
|
||||||
|
trk = trk if trk >= 0 else trk + 360 # no negative val
|
||||||
|
|
||||||
|
trk_or_hdg = round(trk, 2)
|
||||||
|
|
||||||
|
spd_type = "GS"
|
||||||
|
dir_type = "TRUE_NORTH"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if mb[13] == "0":
|
if mb[13] == "0":
|
||||||
hdg = None
|
hdg = None
|
||||||
else:
|
else:
|
||||||
hdg = common.bin2int(mb[14:24]) / 1024.0 * 360.0
|
hdg = common.bin2int(mb[14:24]) / 1024 * 360.0
|
||||||
hdg = round(hdg, 2)
|
hdg = round(hdg, 2)
|
||||||
|
|
||||||
trk_or_hdg = hdg
|
trk_or_hdg = hdg
|
||||||
|
|
||||||
spd = common.bin2int(mb[25:35])
|
spd = common.bin2int(mb[25:35])
|
||||||
spd = None if spd == 0 else spd - 1
|
spd = None if spd == 0 else spd - 1
|
||||||
if subtype == 4: # Supersonic
|
if subtype == 4 and spd is not None: # Supersonic
|
||||||
spd *= 4
|
spd *= 4
|
||||||
|
|
||||||
if mb[24] == "0":
|
if mb[24] == "0":
|
||||||
tag = "IAS"
|
spd_type = "IAS"
|
||||||
else:
|
else:
|
||||||
tag = "TAS"
|
spd_type = "TAS"
|
||||||
|
|
||||||
dir_type = "mag_north"
|
dir_type = "MAGNETIC_NORTH"
|
||||||
|
|
||||||
vr_source = "GNSS" if mb[35] == "0" else "Baro"
|
vr_source = "GNSS" if mb[35] == "0" else "BARO"
|
||||||
vr_sign = -1 if mb[36] == "1" else 1
|
vr_sign = -1 if mb[36] == "1" else 1
|
||||||
vr = common.bin2int(mb[37:46])
|
vr = common.bin2int(mb[37:46])
|
||||||
rocd = None if vr == 0 else int(vr_sign * (vr - 1) * 64)
|
vs = None if vr == 0 else int(vr_sign * (vr - 1) * 64)
|
||||||
|
|
||||||
if rtn_sources:
|
if source:
|
||||||
return spd, trk_or_hdg, rocd, tag, dir_type, vr_source
|
return ( # type: ignore
|
||||||
|
spd,
|
||||||
|
trk_or_hdg,
|
||||||
|
vs,
|
||||||
|
spd_type,
|
||||||
|
dir_type,
|
||||||
|
vr_source,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return spd, trk_or_hdg, rocd, tag
|
return spd, trk_or_hdg, vs, spd_type
|
||||||
|
|
||||||
|
|
||||||
def altitude_diff(msg):
|
def altitude_diff(msg: str) -> None | float:
|
||||||
"""Decode the differece between GNSS and barometric altitude
|
"""Decode the differece between GNSS and barometric altitude.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string, TC=19
|
msg (str): 28 hexdigits string, TC=19
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Altitude difference in ft. Negative value indicates GNSS altitude
|
int: Altitude difference in feet. Negative value indicates GNSS altitude
|
||||||
below barometric altitude.
|
below barometric altitude.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tc = common.typecode(msg)
|
tc = common.typecode(msg)
|
||||||
|
|
||||||
if tc != 19:
|
if tc is None or tc != 19:
|
||||||
raise RuntimeError("%s: Not a airborne velocity message, expecting TC=19" % msg)
|
raise RuntimeError(
|
||||||
|
"%s: Not a airborne velocity message, expecting TC=19" % msg
|
||||||
|
)
|
||||||
|
|
||||||
msgbin = common.hex2bin(msg)
|
msgbin = common.hex2bin(msg)
|
||||||
sign = -1 if int(msgbin[80]) else 1
|
sign = -1 if int(msgbin[80]) else 1
|
||||||
|
|||||||
@@ -1,68 +1,53 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 1,0
|
# BDS 1,0
|
||||||
# Data link capability report
|
# Data link capability report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is10(msg):
|
def is10(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 1,0
|
"""Check if a message is likely to be BDS code 1,0
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# first 8 bits must be 0x10
|
# first 8 bits must be 0x10
|
||||||
if d[0:8] != "00010000":
|
if d[0:8] != "00010000":
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# bit 10 to 14 are reserved
|
# bit 10 to 14 are reserved
|
||||||
if bin2int(d[9:14]) != 0:
|
if common.bin2int(d[9:14]) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# overlay capabilty conflict
|
# overlay capability conflict
|
||||||
if d[14] == "1" and bin2int(d[16:23]) < 5:
|
if d[14] == "1" and common.bin2int(d[16:23]) < 5:
|
||||||
return False
|
return False
|
||||||
if d[14] == "0" and bin2int(d[16:23]) > 4:
|
if d[14] == "0" and common.bin2int(d[16:23]) > 4:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def ovc10(msg):
|
def ovc10(msg: str) -> int:
|
||||||
"""Return the overlay control capability
|
"""Return the overlay control capability
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Whether the transponder is OVC capable
|
int: Whether the transponder is OVC capable
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
return int(d[14])
|
return int(d[14])
|
||||||
|
|||||||
@@ -1,45 +1,29 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 1,7
|
# BDS 1,7
|
||||||
# Common usage GICB capability report
|
# Common usage GICB capability report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from ... import common
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
|
|
||||||
|
|
||||||
|
|
||||||
def is17(msg):
|
def is17(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 1,7
|
"""Check if a message is likely to be BDS code 1,7
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if bin2int(d[28:56]) != 0:
|
if common.bin2int(d[24:56]) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
caps = cap17(msg)
|
caps = cap17(msg)
|
||||||
@@ -56,14 +40,14 @@ def is17(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def cap17(msg):
|
def cap17(msg: str) -> List[str]:
|
||||||
"""Extract capacities from BDS 1,7 message
|
"""Extract capacities from BDS 1,7 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: list of suport BDS codes
|
list: list of supported BDS codes
|
||||||
"""
|
"""
|
||||||
allbds = [
|
allbds = [
|
||||||
"05",
|
"05",
|
||||||
@@ -90,14 +74,10 @@ def cap17(msg):
|
|||||||
"56",
|
"56",
|
||||||
"5F",
|
"5F",
|
||||||
"60",
|
"60",
|
||||||
"NA",
|
|
||||||
"NA",
|
|
||||||
"E1",
|
|
||||||
"E2",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
idx = [i for i, v in enumerate(d[:28]) if v == "1"]
|
idx = [i for i, v in enumerate(d[:24]) if v == "1"]
|
||||||
capacity = ["BDS" + allbds[i] for i in idx if allbds[i] is not "NA"]
|
capacity = ["BDS" + allbds[i] for i in idx]
|
||||||
|
|
||||||
return capacity
|
return capacity
|
||||||
|
|||||||
@@ -1,74 +1,60 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 2,0
|
# BDS 2,0
|
||||||
# Aircraft identification
|
# Aircraft identification
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from ... import common
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
|
|
||||||
|
|
||||||
|
|
||||||
def is20(msg):
|
def is20(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 2,0
|
"""Check if a message is likely to be BDS code 2,0
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0:8] != "00100000":
|
if d[0:8] != "00100000":
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cs = cs20(msg)
|
# allow empty callsign
|
||||||
|
if common.bin2int(d[8:56]) == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
if "#" in cs:
|
if "#" in cs20(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def cs20(msg):
|
def cs20(msg: str) -> str:
|
||||||
"""Aircraft callsign
|
"""Aircraft callsign
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
string: callsign, max. 8 chars
|
string: callsign, max. 8 chars
|
||||||
"""
|
"""
|
||||||
chars = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######"
|
chars = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######"
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
cs = ""
|
cs = ""
|
||||||
cs += chars[bin2int(d[8:14])]
|
cs += chars[common.bin2int(d[8:14])]
|
||||||
cs += chars[bin2int(d[14:20])]
|
cs += chars[common.bin2int(d[14:20])]
|
||||||
cs += chars[bin2int(d[20:26])]
|
cs += chars[common.bin2int(d[20:26])]
|
||||||
cs += chars[bin2int(d[26:32])]
|
cs += chars[common.bin2int(d[26:32])]
|
||||||
cs += chars[bin2int(d[32:38])]
|
cs += chars[common.bin2int(d[32:38])]
|
||||||
cs += chars[bin2int(d[38:44])]
|
cs += chars[common.bin2int(d[38:44])]
|
||||||
cs += chars[bin2int(d[44:50])]
|
cs += chars[common.bin2int(d[44:50])]
|
||||||
cs += chars[bin2int(d[50:56])]
|
cs += chars[common.bin2int(d[50:56])]
|
||||||
|
|
||||||
return cs
|
return cs
|
||||||
|
|||||||
@@ -1,41 +1,25 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 3,0
|
# BDS 3,0
|
||||||
# ACAS active resolution advisory
|
# ACAS active resolution advisory
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from ... import common
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
|
|
||||||
|
|
||||||
|
|
||||||
def is30(msg):
|
def is30(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 2,0
|
"""Check if a message is likely to be BDS code 3,0
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0:8] != "00110000":
|
if d[0:8] != "00110000":
|
||||||
return False
|
return False
|
||||||
@@ -45,7 +29,7 @@ def is30(msg):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# reserved for ACAS III, in far future
|
# reserved for ACAS III, in far future
|
||||||
if bin2int(d[15:22]) >= 48:
|
if common.bin2int(d[15:22]) >= 48:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,136 +1,124 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 4,0
|
# BDS 4,0
|
||||||
# Selected vertical intention
|
# Selected vertical intention
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
import warnings
|
import warnings
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
from typing import Optional
|
||||||
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is40(msg):
|
def is40(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 4,0
|
"""Check if a message is likely to be BDS code 4,0
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 1, 14, and 27
|
# status bit 1, 14, and 27
|
||||||
|
|
||||||
if wrongstatus(d, 1, 2, 13):
|
if common.wrongstatus(d, 1, 2, 13):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 14, 15, 26):
|
if common.wrongstatus(d, 14, 15, 26):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 27, 28, 39):
|
if common.wrongstatus(d, 27, 28, 39):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 48, 49, 51):
|
if common.wrongstatus(d, 48, 49, 51):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 54, 55, 56):
|
if common.wrongstatus(d, 54, 55, 56):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# bits 40-47 and 52-53 shall all be zero
|
# bits 40-47 and 52-53 shall all be zero
|
||||||
|
|
||||||
if bin2int(d[39:47]) != 0:
|
if common.bin2int(d[39:47]) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if bin2int(d[51:53]) != 0:
|
if common.bin2int(d[51:53]) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def selalt40mcp(msg):
|
def selalt40mcp(msg: str) -> Optional[int]:
|
||||||
"""Selected altitude, MCP/FCU
|
"""Selected altitude, MCP/FCU
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: altitude in feet
|
int: altitude in feet
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0] == "0":
|
if d[0] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
alt = bin2int(d[1:13]) * 16 # ft
|
alt = common.bin2int(d[1:13]) * 16 # ft
|
||||||
return alt
|
return alt
|
||||||
|
|
||||||
|
|
||||||
def selalt40fms(msg):
|
def selalt40fms(msg: str) -> Optional[int]:
|
||||||
"""Selected altitude, FMS
|
"""Selected altitude, FMS
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: altitude in feet
|
int: altitude in feet
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[13] == "0":
|
if d[13] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
alt = bin2int(d[14:26]) * 16 # ft
|
alt = common.bin2int(d[14:26]) * 16 # ft
|
||||||
return alt
|
return alt
|
||||||
|
|
||||||
|
|
||||||
def p40baro(msg):
|
def p40baro(msg: str) -> Optional[float]:
|
||||||
"""Barometric pressure setting
|
"""Barometric pressure setting
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: pressure in millibar
|
float: pressure in millibar
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[26] == "0":
|
if d[26] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
p = bin2int(d[27:39]) * 0.1 + 800 # millibar
|
p = common.bin2int(d[27:39]) * 0.1 + 800 # millibar
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def alt40mcp(msg):
|
def alt40mcp(msg: str) -> Optional[int]:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"alt40mcp() has been renamed to selalt40mcp(). It will be removed in the future.",
|
"""alt40mcp() has been renamed to selalt40mcp().
|
||||||
|
It will be removed in the future.""",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
return selalt40mcp(msg)
|
return selalt40mcp(msg)
|
||||||
|
|
||||||
|
|
||||||
def alt40fms(msg):
|
def alt40fms(msg: str) -> Optional[int]:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"alt40fms() has been renamed to selalt40fms(). It will be removed in the future.",
|
"""alt40fms() has been renamed to selalt40fms().
|
||||||
|
It will be removed in the future.""",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
return selalt40mcp(msg)
|
return selalt40fms(msg)
|
||||||
|
|||||||
@@ -1,59 +1,45 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 4,4
|
# BDS 4,4
|
||||||
# Meteorological routine air report
|
# Meteorological routine air report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional, Tuple
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is44(msg):
|
def is44(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 4,4.
|
"""Check if a message is likely to be BDS code 4,4.
|
||||||
|
|
||||||
Meteorological routine air report
|
Meteorological routine air report
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 5, 35, 47, 50
|
# status bit 5, 35, 47, 50
|
||||||
if wrongstatus(d, 5, 6, 23):
|
if common.wrongstatus(d, 5, 6, 23):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 35, 36, 46):
|
if common.wrongstatus(d, 35, 36, 46):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 47, 48, 49):
|
if common.wrongstatus(d, 47, 48, 49):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 50, 51, 56):
|
if common.wrongstatus(d, 50, 51, 56):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Bits 1-4 indicate source, values > 4 reserved and should not occur
|
# Bits 1-4 indicate source, values > 4 reserved and should not occur
|
||||||
if bin2int(d[0:4]) > 4:
|
if common.bin2int(d[0:4]) > 4:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
vw, dw = wind44(msg)
|
vw, dw = wind44(msg)
|
||||||
@@ -67,44 +53,44 @@ def is44(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def wind44(msg):
|
def wind44(msg: str) -> Tuple[Optional[int], Optional[float]]:
|
||||||
"""Wind speed and direction.
|
"""Wind speed and direction.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(int, float): speed (kt), direction (degree)
|
(int, float): speed (kt), direction (degree)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
status = int(d[4])
|
status = int(d[4])
|
||||||
if not status:
|
if not status:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
speed = bin2int(d[5:14]) # knots
|
speed = common.bin2int(d[5:14]) # knots
|
||||||
direction = bin2int(d[14:23]) * 180.0 / 256.0 # degree
|
direction = common.bin2int(d[14:23]) * 180 / 256 # degree
|
||||||
|
|
||||||
return round(speed, 0), round(direction, 1)
|
return round(speed, 0), round(direction, 1)
|
||||||
|
|
||||||
|
|
||||||
def temp44(msg):
|
def temp44(msg: str) -> Tuple[float, float]:
|
||||||
"""Static air temperature.
|
"""Static air temperature.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float, float: temperature and alternative temperature in Celsius degree.
|
float, float: temperature and alternative temperature in Celsius degree.
|
||||||
Note: Two values returns due to what seems to be an inconsistancy
|
Note: Two values returns due to what seems to be an inconsistency
|
||||||
error in ICAO 9871 (2008) Appendix A-67.
|
error in ICAO 9871 (2008) Appendix A-67.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
sign = int(d[23])
|
sign = int(d[23])
|
||||||
value = bin2int(d[24:34])
|
value = common.bin2int(d[24:34])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 1024
|
value = value - 1024
|
||||||
@@ -118,60 +104,60 @@ def temp44(msg):
|
|||||||
return temp, temp_alternative
|
return temp, temp_alternative
|
||||||
|
|
||||||
|
|
||||||
def p44(msg):
|
def p44(msg: str) -> Optional[int]:
|
||||||
"""Static pressure.
|
"""Static pressure.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: static pressure in hPa
|
int: static pressure in hPa
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[34] == "0":
|
if d[34] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
p = bin2int(d[35:46]) # hPa
|
p = common.bin2int(d[35:46]) # hPa
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def hum44(msg):
|
def hum44(msg: str) -> Optional[float]:
|
||||||
"""humidity
|
"""humidity
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: percentage of humidity, [0 - 100] %
|
float: percentage of humidity, [0 - 100] %
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[49] == "0":
|
if d[49] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
hm = bin2int(d[50:56]) * 100.0 / 64 # %
|
hm = common.bin2int(d[50:56]) * 100 / 64 # %
|
||||||
|
|
||||||
return round(hm, 1)
|
return round(hm, 1)
|
||||||
|
|
||||||
|
|
||||||
def turb44(msg):
|
def turb44(msg: str) -> Optional[int]:
|
||||||
"""Turblence.
|
"""Turbulence.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[46] == "0":
|
if d[46] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
turb = bin2int(d[47:49])
|
turb = common.bin2int(d[47:49])
|
||||||
|
|
||||||
return turb
|
return turb
|
||||||
|
|||||||
@@ -1,71 +1,57 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 4,5
|
# BDS 4,5
|
||||||
# Meteorological hazard report
|
# Meteorological hazard report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is45(msg):
|
def is45(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 4,5.
|
"""Check if a message is likely to be BDS code 4,5.
|
||||||
|
|
||||||
Meteorological hazard report
|
Meteorological hazard report
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 1, 4, 7, 10, 13, 16, 27, 39
|
# status bit 1, 4, 7, 10, 13, 16, 27, 39
|
||||||
if wrongstatus(d, 1, 2, 3):
|
if common.wrongstatus(d, 1, 2, 3):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 4, 5, 6):
|
if common.wrongstatus(d, 4, 5, 6):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 7, 8, 9):
|
if common.wrongstatus(d, 7, 8, 9):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 10, 11, 12):
|
if common.wrongstatus(d, 10, 11, 12):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 13, 14, 15):
|
if common.wrongstatus(d, 13, 14, 15):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 16, 17, 26):
|
if common.wrongstatus(d, 16, 17, 26):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 27, 28, 38):
|
if common.wrongstatus(d, 27, 28, 38):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 39, 40, 51):
|
if common.wrongstatus(d, 39, 40, 51):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# reserved
|
# reserved
|
||||||
if bin2int(d[51:56]) != 0:
|
if common.bin2int(d[51:56]) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
temp = temp45(msg)
|
temp = temp45(msg)
|
||||||
@@ -76,110 +62,110 @@ def is45(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def turb45(msg):
|
def turb45(msg: str) -> Optional[int]:
|
||||||
"""Turbulence.
|
"""Turbulence.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: Turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[0] == "0":
|
if d[0] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
turb = bin2int(d[1:3])
|
turb = common.bin2int(d[1:3])
|
||||||
return turb
|
return turb
|
||||||
|
|
||||||
|
|
||||||
def ws45(msg):
|
def ws45(msg: str) -> Optional[int]:
|
||||||
"""Wind shear.
|
"""Wind shear.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Wind shear level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: Wind shear level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[3] == "0":
|
if d[3] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ws = bin2int(d[4:6])
|
ws = common.bin2int(d[4:6])
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
|
|
||||||
def mb45(msg):
|
def mb45(msg: str) -> Optional[int]:
|
||||||
"""Microburst.
|
"""Microburst.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Microburst level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: Microburst level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[6] == "0":
|
if d[6] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mb = bin2int(d[7:9])
|
mb = common.bin2int(d[7:9])
|
||||||
return mb
|
return mb
|
||||||
|
|
||||||
|
|
||||||
def ic45(msg):
|
def ic45(msg: str) -> Optional[int]:
|
||||||
"""Icing.
|
"""Icing.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Icing level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: Icing level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[9] == "0":
|
if d[9] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ic = bin2int(d[10:12])
|
ic = common.bin2int(d[10:12])
|
||||||
return ic
|
return ic
|
||||||
|
|
||||||
|
|
||||||
def wv45(msg):
|
def wv45(msg: str) -> Optional[int]:
|
||||||
"""Wake vortex.
|
"""Wake vortex.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Wake vortex level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
int: Wake vortex level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[12] == "0":
|
if d[12] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ws = bin2int(d[13:15])
|
ws = common.bin2int(d[13:15])
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
|
|
||||||
def temp45(msg):
|
def temp45(msg: str) -> Optional[float]:
|
||||||
"""Static air temperature.
|
"""Static air temperature.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: tmeperature in Celsius degree
|
float: tmeperature in Celsius degree
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
sign = int(d[16])
|
sign = int(d[16])
|
||||||
value = bin2int(d[17:26])
|
value = common.bin2int(d[17:26])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 512
|
value = value - 512
|
||||||
@@ -190,35 +176,35 @@ def temp45(msg):
|
|||||||
return temp
|
return temp
|
||||||
|
|
||||||
|
|
||||||
def p45(msg):
|
def p45(msg: str) -> Optional[int]:
|
||||||
"""Average static pressure.
|
"""Average static pressure.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: static pressure in hPa
|
int: static pressure in hPa
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[26] == "0":
|
if d[26] == "0":
|
||||||
return None
|
return None
|
||||||
p = bin2int(d[27:38]) # hPa
|
p = common.bin2int(d[27:38]) # hPa
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def rh45(msg):
|
def rh45(msg: str) -> Optional[int]:
|
||||||
"""Radio height.
|
"""Radio height.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: radio height in ft
|
int: radio height in ft
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
if d[38] == "0":
|
if d[38] == "0":
|
||||||
return None
|
return None
|
||||||
rh = bin2int(d[39:51]) * 16
|
rh = common.bin2int(d[39:51]) * 16
|
||||||
return rh
|
return rh
|
||||||
|
|||||||
@@ -1,62 +1,48 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 5,0
|
# BDS 5,0
|
||||||
# Track and turn report
|
# Track and turn report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is50(msg):
|
def is50(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 5,0
|
"""Check if a message is likely to be BDS code 5,0
|
||||||
(Track and turn report)
|
(Track and turn report)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 1, 12, 24, 35, 46
|
# status bit 1, 12, 24, 35, 46
|
||||||
|
|
||||||
if wrongstatus(d, 1, 3, 11):
|
if common.wrongstatus(d, 1, 3, 11):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 12, 13, 23):
|
if common.wrongstatus(d, 12, 13, 23):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 24, 25, 34):
|
if common.wrongstatus(d, 24, 25, 34):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 35, 36, 45):
|
if common.wrongstatus(d, 35, 36, 45):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 46, 47, 56):
|
if common.wrongstatus(d, 46, 47, 56):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
roll = roll50(msg)
|
roll = roll50(msg)
|
||||||
if (roll is not None) and abs(roll) > 60:
|
if (roll is not None) and abs(roll) > 50:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
gs = gs50(msg)
|
gs = gs50(msg)
|
||||||
@@ -73,52 +59,52 @@ def is50(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def roll50(msg):
|
def roll50(msg: str) -> Optional[float]:
|
||||||
"""Roll angle, BDS 5,0 message
|
"""Roll angle, BDS 5,0 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: angle in degrees,
|
float: angle in degrees,
|
||||||
negative->left wing down, positive->right wing down
|
negative->left wing down, positive->right wing down
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0] == "0":
|
if d[0] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[1]) # 1 -> left wing down
|
sign = int(d[1]) # 1 -> left wing down
|
||||||
value = bin2int(d[2:11])
|
value = common.bin2int(d[2:11])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 512
|
value = value - 512
|
||||||
|
|
||||||
angle = value * 45.0 / 256.0 # degree
|
angle = value * 45 / 256 # degree
|
||||||
return round(angle, 1)
|
return round(angle, 1)
|
||||||
|
|
||||||
|
|
||||||
def trk50(msg):
|
def trk50(msg: str) -> Optional[float]:
|
||||||
"""True track angle, BDS 5,0 message
|
"""True track angle, BDS 5,0 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: angle in degrees to true north (from 0 to 360)
|
float: angle in degrees to true north (from 0 to 360)
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[11] == "0":
|
if d[11] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[12]) # 1 -> west
|
sign = int(d[12]) # 1 -> west
|
||||||
value = bin2int(d[13:23])
|
value = common.bin2int(d[13:23])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 1024
|
value = value - 1024
|
||||||
|
|
||||||
trk = value * 90.0 / 512.0
|
trk = value * 90 / 512.0
|
||||||
|
|
||||||
# convert from [-180, 180] to [0, 360]
|
# convert from [-180, 180] to [0, 360]
|
||||||
if trk < 0:
|
if trk < 0:
|
||||||
@@ -127,34 +113,34 @@ def trk50(msg):
|
|||||||
return round(trk, 3)
|
return round(trk, 3)
|
||||||
|
|
||||||
|
|
||||||
def gs50(msg):
|
def gs50(msg: str) -> Optional[float]:
|
||||||
"""Ground speed, BDS 5,0 message
|
"""Ground speed, BDS 5,0 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: ground speed in knots
|
int: ground speed in knots
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[23] == "0":
|
if d[23] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
spd = bin2int(d[24:34]) * 2 # kts
|
spd = common.bin2int(d[24:34]) * 2 # kts
|
||||||
return spd
|
return spd
|
||||||
|
|
||||||
|
|
||||||
def rtrk50(msg):
|
def rtrk50(msg: str) -> Optional[float]:
|
||||||
"""Track angle rate, BDS 5,0 message
|
"""Track angle rate, BDS 5,0 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: angle rate in degrees/second
|
float: angle rate in degrees/second
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[34] == "0":
|
if d[34] == "0":
|
||||||
return None
|
return None
|
||||||
@@ -163,27 +149,27 @@ def rtrk50(msg):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[35]) # 1 -> negative value, two's complement
|
sign = int(d[35]) # 1 -> negative value, two's complement
|
||||||
value = bin2int(d[36:45])
|
value = common.bin2int(d[36:45])
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 512
|
value = value - 512
|
||||||
|
|
||||||
angle = value * 8.0 / 256.0 # degree / sec
|
angle = value * 8 / 256 # degree / sec
|
||||||
return round(angle, 3)
|
return round(angle, 3)
|
||||||
|
|
||||||
|
|
||||||
def tas50(msg):
|
def tas50(msg: str) -> Optional[float]:
|
||||||
"""Aircraft true airspeed, BDS 5,0 message
|
"""Aircraft true airspeed, BDS 5,0 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: true airspeed in knots
|
int: true airspeed in knots
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[45] == "0":
|
if d[45] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
tas = bin2int(d[46:56]) * 2 # kts
|
tas = common.bin2int(d[46:56]) * 2 # kts
|
||||||
return tas
|
return tas
|
||||||
|
|||||||
@@ -1,58 +1,44 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 5,3
|
# BDS 5,3
|
||||||
# Air-referenced state vector
|
# Air-referenced state vector
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
def is53(msg):
|
def is53(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 5,3
|
"""Check if a message is likely to be BDS code 5,3
|
||||||
(Air-referenced state vector)
|
(Air-referenced state vector)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 1, 13, 24, 34, 47
|
# status bit 1, 13, 24, 34, 47
|
||||||
|
|
||||||
if wrongstatus(d, 1, 3, 12):
|
if common.wrongstatus(d, 1, 3, 12):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 13, 14, 23):
|
if common.wrongstatus(d, 13, 14, 23):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 24, 25, 33):
|
if common.wrongstatus(d, 24, 25, 33):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 34, 35, 46):
|
if common.wrongstatus(d, 34, 35, 46):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 47, 49, 56):
|
if common.wrongstatus(d, 47, 49, 56):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ias = ias53(msg)
|
ias = ias53(msg)
|
||||||
@@ -74,27 +60,27 @@ def is53(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def hdg53(msg):
|
def hdg53(msg: str) -> Optional[float]:
|
||||||
"""Magnetic heading, BDS 5,3 message
|
"""Magnetic heading, BDS 5,3 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS53) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: angle in degrees to true north (from 0 to 360)
|
float: angle in degrees to true north (from 0 to 360)
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0] == "0":
|
if d[0] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[1]) # 1 -> west
|
sign = int(d[1]) # 1 -> west
|
||||||
value = bin2int(d[2:12])
|
value = common.bin2int(d[2:12])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 1024
|
value = value - 1024
|
||||||
|
|
||||||
hdg = value * 90.0 / 512.0 # degree
|
hdg = value * 90 / 512 # degree
|
||||||
|
|
||||||
# convert from [-180, 180] to [0, 360]
|
# convert from [-180, 180] to [0, 360]
|
||||||
if hdg < 0:
|
if hdg < 0:
|
||||||
@@ -103,76 +89,76 @@ def hdg53(msg):
|
|||||||
return round(hdg, 3)
|
return round(hdg, 3)
|
||||||
|
|
||||||
|
|
||||||
def ias53(msg):
|
def ias53(msg: str) -> Optional[float]:
|
||||||
"""Indicated airspeed, DBS 5,3 message
|
"""Indicated airspeed, DBS 5,3 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message
|
msg (str): 28 hexdigits
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: indicated arispeed in knots
|
int: indicated arispeed in knots
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[12] == "0":
|
if d[12] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ias = bin2int(d[13:23]) # knots
|
ias = common.bin2int(d[13:23]) # knots
|
||||||
return ias
|
return ias
|
||||||
|
|
||||||
|
|
||||||
def mach53(msg):
|
def mach53(msg: str) -> Optional[float]:
|
||||||
"""MACH number, DBS 5,3 message
|
"""MACH number, DBS 5,3 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message
|
msg (str): 28 hexdigits
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: MACH number
|
float: MACH number
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[23] == "0":
|
if d[23] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mach = bin2int(d[24:33]) * 0.008
|
mach = common.bin2int(d[24:33]) * 0.008
|
||||||
return round(mach, 3)
|
return round(mach, 3)
|
||||||
|
|
||||||
|
|
||||||
def tas53(msg):
|
def tas53(msg: str) -> Optional[float]:
|
||||||
"""Aircraft true airspeed, BDS 5,3 message
|
"""Aircraft true airspeed, BDS 5,3 message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message
|
msg (str): 28 hexdigits
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: true airspeed in knots
|
float: true airspeed in knots
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[33] == "0":
|
if d[33] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
tas = bin2int(d[34:46]) * 0.5 # kts
|
tas = common.bin2int(d[34:46]) * 0.5 # kts
|
||||||
return round(tas, 1)
|
return round(tas, 1)
|
||||||
|
|
||||||
|
|
||||||
def vr53(msg):
|
def vr53(msg: str) -> Optional[int]:
|
||||||
"""Vertical rate
|
"""Vertical rate
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits (BDS60) string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: vertical rate in feet/minutes
|
int: vertical rate in feet/minutes
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[46] == "0":
|
if d[46] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[47]) # 1 -> negative value, two's complement
|
sign = int(d[47]) # 1 -> negative value, two's complement
|
||||||
value = bin2int(d[48:56])
|
value = common.bin2int(d[48:56])
|
||||||
|
|
||||||
if value == 0 or value == 255: # all zeros or all ones
|
if value == 0 or value == 255: # all zeros or all ones
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -1,57 +1,44 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# BDS 6,0
|
# BDS 6,0
|
||||||
# Heading and speed report
|
# Heading and speed report
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
|
|
||||||
|
from ... import common
|
||||||
|
from ...extra import aero
|
||||||
|
|
||||||
|
|
||||||
def is60(msg):
|
def is60(msg: str) -> bool:
|
||||||
"""Check if a message is likely to be BDS code 6,0
|
"""Check if a message is likely to be BDS code 6,0
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True or False
|
bool: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if allzeros(msg):
|
if common.allzeros(msg):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
# status bit 1, 13, 24, 35, 46
|
# status bit 1, 13, 24, 35, 46
|
||||||
|
|
||||||
if wrongstatus(d, 1, 2, 12):
|
if common.wrongstatus(d, 1, 2, 12):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 13, 14, 23):
|
if common.wrongstatus(d, 13, 14, 23):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 24, 25, 34):
|
if common.wrongstatus(d, 24, 25, 34):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 35, 36, 45):
|
if common.wrongstatus(d, 35, 36, 45):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if wrongstatus(d, 46, 47, 56):
|
if common.wrongstatus(d, 46, 47, 56):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ias = ias60(msg)
|
ias = ias60(msg)
|
||||||
@@ -70,90 +57,98 @@ def is60(msg):
|
|||||||
if vr_ins is not None and abs(vr_ins) > 6000:
|
if vr_ins is not None and abs(vr_ins) > 6000:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# additional check knowing altitude
|
||||||
|
if (mach is not None) and (ias is not None) and (common.df(msg) == 20):
|
||||||
|
alt = common.altcode(msg)
|
||||||
|
if alt is not None:
|
||||||
|
ias_ = aero.mach2cas(mach, alt * aero.ft) / aero.kts
|
||||||
|
if abs(ias - ias_) > 20:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def hdg60(msg):
|
def hdg60(msg: str) -> Optional[float]:
|
||||||
"""Megnetic heading of aircraft
|
"""Megnetic heading of aircraft
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: heading in degrees to megnetic north (from 0 to 360)
|
float: heading in degrees to megnetic north (from 0 to 360)
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[0] == "0":
|
if d[0] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[1]) # 1 -> west
|
sign = int(d[1]) # 1 -> west
|
||||||
value = bin2int(d[2:12])
|
value = common.bin2int(d[2:12])
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
value = value - 1024
|
value = value - 1024
|
||||||
|
|
||||||
hdg = value * 90 / 512.0 # degree
|
hdg = value * 90 / 512 # degree
|
||||||
|
|
||||||
# convert from [-180, 180] to [0, 360]
|
# convert from [-180, 180] to [0, 360]
|
||||||
if hdg < 0:
|
if hdg < 0:
|
||||||
hdg = 360 + hdg
|
hdg = 360 + hdg
|
||||||
|
|
||||||
return round(hdg, 3)
|
return hdg
|
||||||
|
|
||||||
|
|
||||||
def ias60(msg):
|
def ias60(msg: str) -> Optional[float]:
|
||||||
"""Indicated airspeed
|
"""Indicated airspeed
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: indicated airspeed in knots
|
int: indicated airspeed in knots
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[12] == "0":
|
if d[12] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ias = bin2int(d[13:23]) # kts
|
ias = common.bin2int(d[13:23]) # kts
|
||||||
return ias
|
return ias
|
||||||
|
|
||||||
|
|
||||||
def mach60(msg):
|
def mach60(msg: str) -> Optional[float]:
|
||||||
"""Aircraft MACH number
|
"""Aircraft MACH number
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: MACH number
|
float: MACH number
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[23] == "0":
|
if d[23] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mach = bin2int(d[24:34]) * 2.048 / 512.0
|
mach = common.bin2int(d[24:34]) * 2.048 / 512.0
|
||||||
return round(mach, 3)
|
return mach
|
||||||
|
|
||||||
|
|
||||||
def vr60baro(msg):
|
def vr60baro(msg: str) -> Optional[int]:
|
||||||
"""Vertical rate from barometric measurement, this value may be very noisy.
|
"""Vertical rate from barometric measurement, this value may be very noisy.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: vertical rate in feet/minutes
|
int: vertical rate in feet/minutes
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[34] == "0":
|
if d[34] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[35]) # 1 -> negative value, two's complement
|
sign = int(d[35]) # 1 -> negative value, two's complement
|
||||||
value = bin2int(d[36:45])
|
value = common.bin2int(d[36:45])
|
||||||
|
|
||||||
if value == 0 or value == 511: # all zeros or all ones
|
if value == 0 or value == 511: # all zeros or all ones
|
||||||
return 0
|
return 0
|
||||||
@@ -164,22 +159,22 @@ def vr60baro(msg):
|
|||||||
return roc
|
return roc
|
||||||
|
|
||||||
|
|
||||||
def vr60ins(msg):
|
def vr60ins(msg: str) -> Optional[int]:
|
||||||
"""Vertical rate messured by onbard equiments (IRS, AHRS)
|
"""Vertical rate measurd by onbard equiments (IRS, AHRS)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: vertical rate in feet/minutes
|
int: vertical rate in feet/minutes
|
||||||
"""
|
"""
|
||||||
d = hex2bin(data(msg))
|
d = common.hex2bin(common.data(msg))
|
||||||
|
|
||||||
if d[45] == "0":
|
if d[45] == "0":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sign = int(d[46]) # 1 -> negative value, two's complement
|
sign = int(d[46]) # 1 -> negative value, two's complement
|
||||||
value = bin2int(d[47:56])
|
value = common.bin2int(d[47:56])
|
||||||
|
|
||||||
if value == 0 or value == 511: # all zeros or all ones
|
if value == 0 or value == 511: # all zeros or all ones
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
87
pyModeS/decoder/bds/bds61.py
Normal file
87
pyModeS/decoder/bds/bds61.py
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# ------------------------------------------
|
||||||
|
# BDS 6,1
|
||||||
|
# ADS-B TC=28
|
||||||
|
# Aircraft Airborne status
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
|
def is_emergency(msg: str) -> bool:
|
||||||
|
"""Check if the aircraft is reporting an emergency.
|
||||||
|
|
||||||
|
Non-emergencies are either a subtype of zero (no information) or
|
||||||
|
subtype of one and a value of zero (no emergency).
|
||||||
|
Subtype = 2 indicates an ACAS RA broadcast, look in BDS 3,0
|
||||||
|
|
||||||
|
:param msg: 28 bytes hexadecimal message string
|
||||||
|
:return: if the aircraft has declared an emergency
|
||||||
|
"""
|
||||||
|
if common.typecode(msg) != 28:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not an airborne status message, expecting TC=28" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
subtype = common.bin2int(mb[5:8])
|
||||||
|
|
||||||
|
if subtype == 2:
|
||||||
|
raise RuntimeError("%s: Emergency message is ACAS-RA, not implemented")
|
||||||
|
|
||||||
|
emergency_state = common.bin2int(mb[8:11])
|
||||||
|
|
||||||
|
if subtype == 1 and emergency_state == 1:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def emergency_state(msg: str) -> int:
|
||||||
|
"""Decode aircraft emergency state.
|
||||||
|
|
||||||
|
Value Meaning
|
||||||
|
----- -----------------------
|
||||||
|
0 No emergency
|
||||||
|
1 General emergency
|
||||||
|
2 Lifeguard/Medical
|
||||||
|
3 Minimum fuel
|
||||||
|
4 No communications
|
||||||
|
5 Unlawful communications
|
||||||
|
6-7 Reserved
|
||||||
|
|
||||||
|
:param msg: 28 bytes hexadecimal message string
|
||||||
|
:return: emergency state
|
||||||
|
"""
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
subtype = common.bin2int(mb[5:8])
|
||||||
|
|
||||||
|
if subtype == 2:
|
||||||
|
raise RuntimeError("%s: Emergency message is ACAS-RA, not implemented")
|
||||||
|
|
||||||
|
emergency_state = common.bin2int(mb[8:11])
|
||||||
|
return emergency_state
|
||||||
|
|
||||||
|
|
||||||
|
def emergency_squawk(msg: str) -> str:
|
||||||
|
"""Decode squawk code.
|
||||||
|
|
||||||
|
Emergency value 1: squawk 7700.
|
||||||
|
Emergency value 4: squawk 7600.
|
||||||
|
Emergency value 5: squawk 7500.
|
||||||
|
|
||||||
|
:param msg: 28 bytes hexadecimal message string
|
||||||
|
:return: aircraft squawk code
|
||||||
|
"""
|
||||||
|
if common.typecode(msg) != 28:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not an airborne status message, expecting TC=28" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
|
||||||
|
# construct the 13 bits Mode A ID code
|
||||||
|
idcode = msgbin[43:56]
|
||||||
|
|
||||||
|
squawk = common.squawk(idcode)
|
||||||
|
return squawk
|
||||||
553
pyModeS/decoder/bds/bds62.py
Normal file
553
pyModeS/decoder/bds/bds62.py
Normal file
@@ -0,0 +1,553 @@
|
|||||||
|
# ------------------------------------------
|
||||||
|
# BDS 6,2
|
||||||
|
# ADS-B TC=29
|
||||||
|
# Target State and Status
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from ... import common
|
||||||
|
|
||||||
|
|
||||||
|
def selected_altitude(msg: str) -> tuple[None | float, str]:
|
||||||
|
"""Decode selected altitude.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Selected altitude (ft)
|
||||||
|
string: Source ('MCP/FCU' or 'FMS')
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not"
|
||||||
|
" contain selected altitude, use target altitude instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
alt = common.bin2int(mb[9:20])
|
||||||
|
if alt == 0:
|
||||||
|
return None, "N/A"
|
||||||
|
alt = (alt - 1) * 32
|
||||||
|
alt_source = "MCP/FCU" if int(mb[8]) == 0 else "FMS"
|
||||||
|
|
||||||
|
return alt, alt_source
|
||||||
|
|
||||||
|
|
||||||
|
def target_altitude(msg: str) -> tuple[None | int, str, str]:
|
||||||
|
"""Decode target altitude.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Target altitude (ft)
|
||||||
|
string: Source ('MCP/FCU', 'Holding mode' or 'FMS/RNAV')
|
||||||
|
string: Altitude reference, either pressure altitude or barometric
|
||||||
|
corrected altitude ('FL' or 'MSL')
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not"
|
||||||
|
" contain target altitude, use selected altitude instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
alt_avail = common.bin2int(mb[7:9])
|
||||||
|
if alt_avail == 0:
|
||||||
|
return None, "N/A", ""
|
||||||
|
elif alt_avail == 1:
|
||||||
|
alt_source = "MCP/FCU"
|
||||||
|
elif alt_avail == 2:
|
||||||
|
alt_source = "Holding mode"
|
||||||
|
else:
|
||||||
|
alt_source = "FMS/RNAV"
|
||||||
|
|
||||||
|
alt_ref = "FL" if int(mb[9]) == 0 else "MSL"
|
||||||
|
|
||||||
|
alt = -1000 + common.bin2int(mb[15:25]) * 100
|
||||||
|
|
||||||
|
return alt, alt_source, alt_ref
|
||||||
|
|
||||||
|
|
||||||
|
def vertical_mode(msg: str) -> None | int:
|
||||||
|
"""Decode vertical mode.
|
||||||
|
|
||||||
|
Value Meaning
|
||||||
|
----- -----------------------
|
||||||
|
1 "Acquiring" mode
|
||||||
|
2 "Capturing" or "Maintaining" mode
|
||||||
|
3 Reserved
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Vertical mode
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not"
|
||||||
|
" contain vertical mode, use vnav mode instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
vertical_mode = common.bin2int(mb[13:15])
|
||||||
|
if vertical_mode == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return vertical_mode
|
||||||
|
|
||||||
|
|
||||||
|
def horizontal_mode(msg: str) -> None | int:
|
||||||
|
"""Decode horizontal mode.
|
||||||
|
|
||||||
|
Value Meaning
|
||||||
|
----- -----------------------
|
||||||
|
1 "Acquiring" mode
|
||||||
|
2 "Capturing" or "Maintaining" mode
|
||||||
|
3 Reserved
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Horizontal mode
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not "
|
||||||
|
"contain horizontal mode, use lnav mode instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
horizontal_mode = common.bin2int(mb[25:27])
|
||||||
|
if horizontal_mode == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return horizontal_mode
|
||||||
|
|
||||||
|
|
||||||
|
def selected_heading(msg: str) -> None | float:
|
||||||
|
"""Decode selected heading.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 bytes hexadecimal message string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
float: Selected heading (degree)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain selected heading, use target angle instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[29]) == 0:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
hdg_sign = int(mb[30])
|
||||||
|
hdg = (hdg_sign + 1) * common.bin2int(mb[31:39]) * (180 / 256)
|
||||||
|
hdg = round(hdg, 2)
|
||||||
|
|
||||||
|
return hdg
|
||||||
|
|
||||||
|
|
||||||
|
def target_angle(msg: str) -> tuple[None | int, str, str]:
|
||||||
|
"""Decode target heading/track angle.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 bytes hexadecimal message string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Target angle (degree)
|
||||||
|
string: Angle type ('Heading' or 'Track')
|
||||||
|
string: Source ('MCP/FCU', 'Autopilot Mode' or 'FMS/RNAV')
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not "
|
||||||
|
"contain target angle, use selected heading instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
angle_avail = common.bin2int(mb[25:27])
|
||||||
|
if angle_avail == 0:
|
||||||
|
return None, "", "N/A"
|
||||||
|
else:
|
||||||
|
angle = common.bin2int(mb[27:36])
|
||||||
|
|
||||||
|
if angle_avail == 1:
|
||||||
|
angle_source = "MCP/FCU"
|
||||||
|
elif angle_avail == 2:
|
||||||
|
angle_source = "Autopilot mode"
|
||||||
|
else:
|
||||||
|
angle_source = "FMS/RNAV"
|
||||||
|
|
||||||
|
angle_type = "Heading" if int(mb[36]) else "Track"
|
||||||
|
|
||||||
|
return angle, angle_type, angle_source
|
||||||
|
|
||||||
|
|
||||||
|
def baro_pressure_setting(msg: str) -> None | float:
|
||||||
|
"""Decode barometric pressure setting.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
float: Barometric pressure setting (millibars)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain barometric pressure setting" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
baro = common.bin2int(mb[20:29])
|
||||||
|
if baro == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return 800 + (baro - 1) * 0.8
|
||||||
|
|
||||||
|
|
||||||
|
def autopilot(msg) -> None | bool:
|
||||||
|
"""Decode autopilot engagement.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Autopilot engaged
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain autopilot engagement" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[46]) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
autopilot = True if int(mb[47]) == 1 else False
|
||||||
|
|
||||||
|
return autopilot
|
||||||
|
|
||||||
|
|
||||||
|
def vnav_mode(msg) -> None | bool:
|
||||||
|
"""Decode VNAV mode.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: VNAV mode engaged
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain vnav mode, use vertical mode instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[46]) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
vnav_mode = True if int(mb[48]) == 1 else False
|
||||||
|
|
||||||
|
return vnav_mode
|
||||||
|
|
||||||
|
|
||||||
|
def altitude_hold_mode(msg) -> None | bool:
|
||||||
|
"""Decode altitude hold mode.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Altitude hold mode engaged
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain altitude hold mode" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[46]) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
alt_hold_mode = True if int(mb[49]) == 1 else False
|
||||||
|
|
||||||
|
return alt_hold_mode
|
||||||
|
|
||||||
|
|
||||||
|
def approach_mode(msg) -> None | bool:
|
||||||
|
"""Decode approach mode.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Approach mode engaged
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain approach mode" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[46]) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
app_mode = True if int(mb[51]) == 1 else False
|
||||||
|
|
||||||
|
return app_mode
|
||||||
|
|
||||||
|
|
||||||
|
def lnav_mode(msg) -> None | bool:
|
||||||
|
"""Decode LNAV mode.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: LNAV mode engaged
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 1 target state and status message does not "
|
||||||
|
"contain lnav mode, use horizontal mode instead" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
if int(mb[46]) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
lnav_mode = True if int(mb[53]) == 1 else False
|
||||||
|
|
||||||
|
return lnav_mode
|
||||||
|
|
||||||
|
|
||||||
|
def tcas_operational(msg) -> None | bool:
|
||||||
|
"""Decode TCAS/ACAS operational.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 bytes hexadecimal message string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: TCAS/ACAS operational
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 0:
|
||||||
|
tcas = True if int(mb[51]) == 0 else False
|
||||||
|
else:
|
||||||
|
tcas = True if int(mb[52]) == 1 else False
|
||||||
|
|
||||||
|
return tcas
|
||||||
|
|
||||||
|
|
||||||
|
def tcas_ra(msg) -> bool:
|
||||||
|
"""Decode TCAS/ACAS Resolution advisory.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 bytes hexadecimal message string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: TCAS/ACAS Resolution advisory active
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not "
|
||||||
|
"contain TCAS/ACAS RA" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
tcas_ra = True if int(mb[52]) == 1 else False
|
||||||
|
|
||||||
|
return tcas_ra
|
||||||
|
|
||||||
|
|
||||||
|
def emergency_status(msg) -> int:
|
||||||
|
"""Decode aircraft emergency status.
|
||||||
|
|
||||||
|
Value Meaning
|
||||||
|
----- -----------------------
|
||||||
|
0 No emergency
|
||||||
|
1 General emergency
|
||||||
|
2 Lifeguard/medical emergency
|
||||||
|
3 Minimum fuel
|
||||||
|
4 No communications
|
||||||
|
5 Unlawful interference
|
||||||
|
6 Downed aircraft
|
||||||
|
7 Reserved
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 28 bytes hexadecimal message string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Emergency status
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if common.typecode(msg) != 29:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: Not a target state and status message, expecting TC=29" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
mb = common.hex2bin(msg)[32:]
|
||||||
|
|
||||||
|
subtype = common.bin2int(mb[5:7])
|
||||||
|
|
||||||
|
if subtype == 1:
|
||||||
|
raise RuntimeError(
|
||||||
|
"%s: ADS-B version 2 target state and status message does not "
|
||||||
|
"contain emergency status" % msg
|
||||||
|
)
|
||||||
|
|
||||||
|
return common.bin2int(mb[53:56])
|
||||||
@@ -1,37 +1,88 @@
|
|||||||
"""Comm-B Wrapper.
|
"""Comm-B module.
|
||||||
|
|
||||||
The Comm-B wrapper imports all functions from the following modules:
|
The Comm-B module imports all functions from the following modules:
|
||||||
|
|
||||||
**ELS - elementary surveillance**
|
ELS - elementary surveillance
|
||||||
- pyModeS.decoder.bds.bds10
|
|
||||||
- pyModeS.decoder.bds.bds17
|
|
||||||
- pyModeS.decoder.bds.bds20
|
|
||||||
- pyModeS.decoder.bds.bds30
|
|
||||||
|
|
||||||
**EHS - enhanced surveillance**
|
- pyModeS.decoder.bds.bds10
|
||||||
- pyModeS.decoder.bds.bds40
|
- pyModeS.decoder.bds.bds17
|
||||||
- pyModeS.decoder.bds.bds50
|
- pyModeS.decoder.bds.bds20
|
||||||
- pyModeS.decoder.bds.bds60
|
- pyModeS.decoder.bds.bds30
|
||||||
|
|
||||||
**MRAR and MHR**
|
EHS - enhanced surveillance
|
||||||
- pyModeS.decoder.bds.bds44
|
|
||||||
- pyModeS.decoder.bds.bds45
|
- pyModeS.decoder.bds.bds40
|
||||||
|
- pyModeS.decoder.bds.bds50
|
||||||
|
- pyModeS.decoder.bds.bds60
|
||||||
|
|
||||||
|
MRAR and MHR
|
||||||
|
|
||||||
|
- pyModeS.decoder.bds.bds44
|
||||||
|
- pyModeS.decoder.bds.bds45
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
|
|
||||||
# ELS - elementary surveillance
|
# ELS - elementary surveillance
|
||||||
from pyModeS.decoder.bds.bds10 import *
|
from .bds.bds10 import is10, ovc10
|
||||||
from pyModeS.decoder.bds.bds17 import *
|
from .bds.bds17 import is17, cap17
|
||||||
from pyModeS.decoder.bds.bds20 import *
|
from .bds.bds20 import is20, cs20
|
||||||
from pyModeS.decoder.bds.bds30 import *
|
from .bds.bds30 import is30
|
||||||
|
|
||||||
# ELS - enhanced surveillance
|
# ELS - enhanced surveillance
|
||||||
from pyModeS.decoder.bds.bds40 import *
|
from .bds.bds40 import (
|
||||||
from pyModeS.decoder.bds.bds50 import *
|
is40,
|
||||||
from pyModeS.decoder.bds.bds60 import *
|
selalt40fms,
|
||||||
|
selalt40mcp,
|
||||||
|
p40baro,
|
||||||
|
alt40fms,
|
||||||
|
alt40mcp,
|
||||||
|
)
|
||||||
|
from .bds.bds50 import is50, roll50, trk50, gs50, rtrk50, tas50
|
||||||
|
from .bds.bds60 import is60, hdg60, ias60, mach60, vr60baro, vr60ins
|
||||||
|
|
||||||
# MRAR and MHR
|
# MRAR and MHR
|
||||||
from pyModeS.decoder.bds.bds44 import *
|
from .bds.bds44 import is44, wind44, temp44, p44, hum44, turb44
|
||||||
from pyModeS.decoder.bds.bds45 import *
|
from .bds.bds45 import is45, turb45, ws45, mb45, ic45, wv45, temp45, p45, rh45
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"is10",
|
||||||
|
"ovc10",
|
||||||
|
"is17",
|
||||||
|
"cap17",
|
||||||
|
"is20",
|
||||||
|
"cs20",
|
||||||
|
"is30",
|
||||||
|
"is40",
|
||||||
|
"selalt40fms",
|
||||||
|
"selalt40mcp",
|
||||||
|
"p40baro",
|
||||||
|
"alt40fms",
|
||||||
|
"alt40mcp",
|
||||||
|
"is50",
|
||||||
|
"roll50",
|
||||||
|
"trk50",
|
||||||
|
"gs50",
|
||||||
|
"rtrk50",
|
||||||
|
"tas50",
|
||||||
|
"is60",
|
||||||
|
"hdg60",
|
||||||
|
"ias60",
|
||||||
|
"mach60",
|
||||||
|
"vr60baro",
|
||||||
|
"vr60ins",
|
||||||
|
"is44",
|
||||||
|
"wind44",
|
||||||
|
"temp44",
|
||||||
|
"p44",
|
||||||
|
"hum44",
|
||||||
|
"turb44",
|
||||||
|
"is45",
|
||||||
|
"turb45",
|
||||||
|
"ws45",
|
||||||
|
"mb45",
|
||||||
|
"ic45",
|
||||||
|
"wv45",
|
||||||
|
"temp45",
|
||||||
|
"p45",
|
||||||
|
"rh45",
|
||||||
|
]
|
||||||
|
|||||||
@@ -9,28 +9,58 @@ The EHS wrapper imports all functions from the following modules:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from pyModeS.decoder.bds.bds40 import *
|
from .bds.bds40 import (
|
||||||
from pyModeS.decoder.bds.bds50 import *
|
is40,
|
||||||
from pyModeS.decoder.bds.bds60 import *
|
selalt40fms,
|
||||||
from pyModeS.decoder.bds import infer
|
selalt40mcp,
|
||||||
|
p40baro,
|
||||||
|
alt40fms,
|
||||||
|
alt40mcp,
|
||||||
|
)
|
||||||
|
from .bds.bds50 import is50, roll50, trk50, gs50, rtrk50, tas50
|
||||||
|
from .bds.bds60 import is60, hdg60, ias60, mach60, vr60baro, vr60ins
|
||||||
|
from .bds import infer
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"is40",
|
||||||
|
"selalt40fms",
|
||||||
|
"selalt40mcp",
|
||||||
|
"p40baro",
|
||||||
|
"alt40fms",
|
||||||
|
"alt40mcp",
|
||||||
|
"is50",
|
||||||
|
"roll50",
|
||||||
|
"trk50",
|
||||||
|
"gs50",
|
||||||
|
"rtrk50",
|
||||||
|
"tas50",
|
||||||
|
"is60",
|
||||||
|
"hdg60",
|
||||||
|
"ias60",
|
||||||
|
"mach60",
|
||||||
|
"vr60baro",
|
||||||
|
"vr60ins",
|
||||||
|
"infer",
|
||||||
|
]
|
||||||
|
|
||||||
warnings.simplefilter("once", DeprecationWarning)
|
warnings.simplefilter("once", DeprecationWarning)
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"pms.ehs module is deprecated. Please use pms.commb instead.", DeprecationWarning
|
"pms.ehs module is deprecated. Please use pms.commb instead.",
|
||||||
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def BDS(msg):
|
def BDS(msg):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"pms.ehs.BDS() is deprecated, use pms.bds.infer() instead.", DeprecationWarning
|
"pms.ehs.BDS() is deprecated, use pms.bds.infer() instead.",
|
||||||
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
return infer(msg)
|
return infer(msg)
|
||||||
|
|
||||||
|
|
||||||
def icao(msg):
|
def icao(msg):
|
||||||
from pyModeS.decoder.common import icao
|
from . import common
|
||||||
|
|
||||||
return icao(msg)
|
return common.icao(msg)
|
||||||
|
|||||||
@@ -10,16 +10,26 @@ The ELS wrapper imports all functions from the following modules:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
|
|
||||||
from pyModeS.decoder.bds.bds10 import *
|
|
||||||
from pyModeS.decoder.bds.bds17 import *
|
|
||||||
from pyModeS.decoder.bds.bds20 import *
|
|
||||||
from pyModeS.decoder.bds.bds30 import *
|
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from .bds.bds10 import is10, ovc10
|
||||||
|
from .bds.bds17 import cap17, is17
|
||||||
|
from .bds.bds20 import cs20, is20
|
||||||
|
from .bds.bds30 import is30
|
||||||
|
|
||||||
warnings.simplefilter("once", DeprecationWarning)
|
warnings.simplefilter("once", DeprecationWarning)
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"pms.els module is deprecated. Please use pms.commb instead.", DeprecationWarning
|
"pms.els module is deprecated. Please use pms.commb instead.",
|
||||||
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"is10",
|
||||||
|
"ovc10",
|
||||||
|
"is17",
|
||||||
|
"cap17",
|
||||||
|
"is20",
|
||||||
|
"cs20",
|
||||||
|
"is30",
|
||||||
|
]
|
||||||
|
|||||||
25
pyModeS/decoder/flarm/__init__.py
Normal file
25
pyModeS/decoder/flarm/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
from .decode import flarm as flarm_decode
|
||||||
|
|
||||||
|
__all__ = ["DecodedMessage", "flarm"]
|
||||||
|
|
||||||
|
|
||||||
|
class DecodedMessage(TypedDict):
|
||||||
|
timestamp: int
|
||||||
|
icao24: str
|
||||||
|
latitude: float
|
||||||
|
longitude: float
|
||||||
|
altitude: int
|
||||||
|
vertical_speed: float
|
||||||
|
groundspeed: int
|
||||||
|
track: int
|
||||||
|
type: str
|
||||||
|
sensorLatitude: float
|
||||||
|
sensorLongitude: float
|
||||||
|
isIcao24: bool
|
||||||
|
noTrack: bool
|
||||||
|
stealth: bool
|
||||||
|
|
||||||
|
|
||||||
|
flarm = flarm_decode
|
||||||
124
pyModeS/decoder/flarm/core.c
Normal file
124
pyModeS/decoder/flarm/core.c
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#include "core.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* https://pastebin.com/YK2f8bfm
|
||||||
|
*
|
||||||
|
* NEW ENCRYPTION
|
||||||
|
*
|
||||||
|
* Swiss glider anti-colission system moved to a new encryption scheme: XXTEA
|
||||||
|
* The algorithm encrypts all the packet after the header: total 20 bytes or 5 long int words of data
|
||||||
|
*
|
||||||
|
* XXTEA description and code are found here: http://en.wikipedia.org/wiki/XXTEA
|
||||||
|
* The system uses 6 iterations of the main loop.
|
||||||
|
*
|
||||||
|
* The system version 6 sends two type of packets: position and ... some unknown data
|
||||||
|
* The difference is made by bit 0 of byte 3 of the packet: for position data this bit is zero.
|
||||||
|
*
|
||||||
|
* For position data the key used depends on the time and transmitting device address.
|
||||||
|
* The key is as well obscured by a weird algorithm.
|
||||||
|
* The code to generate the key is:
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
void make_key(int *key, long time, long address)
|
||||||
|
{
|
||||||
|
const long key1[4] = {0xe43276df, 0xdca83759, 0x9802b8ac, 0x4675a56b};
|
||||||
|
const long key1b[4] = {0xfc78ea65, 0x804b90ea, 0xb76542cd, 0x329dfa32};
|
||||||
|
const long *table = ((((time >> 23) & 255) & 0x01) != 0) ? key1b : key1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
key[i] = obscure(table[i] ^ ((time >> 6) ^ address), 0x045D9F3B) ^ 0x87B562F4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long obscure(long key, unsigned long seed)
|
||||||
|
{
|
||||||
|
unsigned int m1 = seed * (key ^ (key >> 16));
|
||||||
|
unsigned int m2 = seed * (m1 ^ (m1 >> 16));
|
||||||
|
return m2 ^ (m2 >> 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NEW PACKET FORMAT:
|
||||||
|
*
|
||||||
|
* Byte Bits
|
||||||
|
* 0 AAAA AAAA device address
|
||||||
|
* 1 AAAA AAAA
|
||||||
|
* 2 AAAA AAAA
|
||||||
|
* 3 00aa 0000 aa = 10 or 01
|
||||||
|
*
|
||||||
|
* 4 vvvv vvvv vertical speed
|
||||||
|
* 5 xxxx xxvv
|
||||||
|
* 6 gggg gggg GPS status
|
||||||
|
* 7 tttt gggg plane type
|
||||||
|
*
|
||||||
|
* 8 LLLL LLLL Latitude
|
||||||
|
* 9 LLLL LLLL
|
||||||
|
* 10 aaaa aLLL
|
||||||
|
* 11 aaaa aaaa Altitude
|
||||||
|
*
|
||||||
|
* 12 NNNN NNNN Longitude
|
||||||
|
* 13 NNNN NNNN
|
||||||
|
* 14 xxxx NNNN
|
||||||
|
* 15 FFxx xxxx multiplying factor
|
||||||
|
*
|
||||||
|
* 16 SSSS SSSS as in version 4
|
||||||
|
* 17 ssss ssss
|
||||||
|
* 18 KKKK KKKK
|
||||||
|
* 19 kkkk kkkk
|
||||||
|
*
|
||||||
|
* 20 EEEE EEEE
|
||||||
|
* 21 eeee eeee
|
||||||
|
* 22 PPPP PPPP
|
||||||
|
* 24 pppp pppp
|
||||||
|
* */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* https://en.wikipedia.org/wiki/XXTEA
|
||||||
|
*/
|
||||||
|
|
||||||
|
void btea(uint32_t *v, int n, uint32_t const key[4])
|
||||||
|
{
|
||||||
|
uint32_t y, z, sum;
|
||||||
|
unsigned p, rounds, e;
|
||||||
|
if (n > 1)
|
||||||
|
{ /* Coding Part */
|
||||||
|
/* Unused, should remove? */
|
||||||
|
rounds = 6 + 52 / n;
|
||||||
|
sum = 0;
|
||||||
|
z = v[n - 1];
|
||||||
|
do
|
||||||
|
{
|
||||||
|
sum += DELTA;
|
||||||
|
e = (sum >> 2) & 3;
|
||||||
|
for (p = 0; p < (unsigned)n - 1; p++)
|
||||||
|
{
|
||||||
|
y = v[p + 1];
|
||||||
|
z = v[p] += MX;
|
||||||
|
}
|
||||||
|
y = v[0];
|
||||||
|
z = v[n - 1] += MX;
|
||||||
|
} while (--rounds);
|
||||||
|
}
|
||||||
|
else if (n < -1)
|
||||||
|
{ /* Decoding Part */
|
||||||
|
n = -n;
|
||||||
|
rounds = 6; // + 52 / n;
|
||||||
|
sum = rounds * DELTA;
|
||||||
|
y = v[0];
|
||||||
|
do
|
||||||
|
{
|
||||||
|
e = (sum >> 2) & 3;
|
||||||
|
for (p = n - 1; p > 0; p--)
|
||||||
|
{
|
||||||
|
z = v[p - 1];
|
||||||
|
y = v[p] -= MX;
|
||||||
|
}
|
||||||
|
z = v[n - 1];
|
||||||
|
y = v[0] -= MX;
|
||||||
|
sum -= DELTA;
|
||||||
|
} while (--rounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
pyModeS/decoder/flarm/core.h
Normal file
13
pyModeS/decoder/flarm/core.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef __CORE_H__
|
||||||
|
#define __CORE_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define DELTA 0x9e3779b9
|
||||||
|
#define MX (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum ^ y) + (key[(p & 3) ^ e] ^ z)))
|
||||||
|
|
||||||
|
void make_key(int *key, long time, long address);
|
||||||
|
long obscure(long key, unsigned long seed);
|
||||||
|
void btea(uint32_t *v, int n, uint32_t const key[4]);
|
||||||
|
|
||||||
|
#endif
|
||||||
4
pyModeS/decoder/flarm/core.pxd
Normal file
4
pyModeS/decoder/flarm/core.pxd
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
cdef extern from "core.h":
|
||||||
|
void make_key(int*, long time, long address)
|
||||||
|
void btea(int*, int, int*)
|
||||||
14
pyModeS/decoder/flarm/decode.pyi
Normal file
14
pyModeS/decoder/flarm/decode.pyi
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from . import DecodedMessage
|
||||||
|
|
||||||
|
AIRCRAFT_TYPES: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
def flarm(
|
||||||
|
timestamp: int,
|
||||||
|
msg: str,
|
||||||
|
refLat: float,
|
||||||
|
refLon: float,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> DecodedMessage: ...
|
||||||
146
pyModeS/decoder/flarm/decode.pyx
Normal file
146
pyModeS/decoder/flarm/decode.pyx
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
from cpython cimport array
|
||||||
|
|
||||||
|
from .core cimport make_key as c_make_key, btea as c_btea
|
||||||
|
|
||||||
|
import array
|
||||||
|
import math
|
||||||
|
from ctypes import c_byte
|
||||||
|
from textwrap import wrap
|
||||||
|
|
||||||
|
AIRCRAFT_TYPES = [
|
||||||
|
"Unknown", # 0
|
||||||
|
"Glider", # 1
|
||||||
|
"Tow-Plane", # 2
|
||||||
|
"Helicopter", # 3
|
||||||
|
"Parachute", # 4
|
||||||
|
"Parachute Drop-Plane", # 5
|
||||||
|
"Hangglider", # 6
|
||||||
|
"Paraglider", # 7
|
||||||
|
"Aircraft", # 8
|
||||||
|
"Jet", # 9
|
||||||
|
"UFO", # 10
|
||||||
|
"Balloon", # 11
|
||||||
|
"Airship", # 12
|
||||||
|
"UAV", # 13
|
||||||
|
"Reserved", # 14
|
||||||
|
"Static Obstacle", # 15
|
||||||
|
]
|
||||||
|
|
||||||
|
cdef long bytearray2int(str icao24):
|
||||||
|
return (
|
||||||
|
(int(icao24[4:6], 16) & 0xFF)
|
||||||
|
| ((int(icao24[2:4], 16) & 0xFF) << 8)
|
||||||
|
| ((int(icao24[:2], 16) & 0xFF) << 16)
|
||||||
|
)
|
||||||
|
|
||||||
|
cpdef array.array make_key(long timestamp, str icao24):
|
||||||
|
cdef long addr = bytearray2int(icao24)
|
||||||
|
cdef array.array a = array.array('i', [0, 0, 0, 0])
|
||||||
|
c_make_key(a.data.as_ints, timestamp, (addr << 8) & 0xffffff)
|
||||||
|
return a
|
||||||
|
|
||||||
|
cpdef array.array btea(long timestamp, str msg):
|
||||||
|
cdef int p
|
||||||
|
cdef str icao24 = msg[4:6] + msg[2:4] + msg[:2]
|
||||||
|
cdef array.array key = make_key(timestamp, icao24)
|
||||||
|
|
||||||
|
pieces = wrap(msg[8:], 8)
|
||||||
|
cdef array.array toDecode = array.array('i', len(pieces) * [0])
|
||||||
|
for i, piece in enumerate(pieces):
|
||||||
|
p = 0
|
||||||
|
for elt in wrap(piece, 2)[::-1]:
|
||||||
|
p = (p << 8) + int(elt, 16)
|
||||||
|
toDecode[i] = p
|
||||||
|
|
||||||
|
c_btea(toDecode.data.as_ints, -5, key.data.as_ints)
|
||||||
|
return toDecode
|
||||||
|
|
||||||
|
cdef float velocity(int ns, int ew):
|
||||||
|
return math.hypot(ew / 4, ns / 4)
|
||||||
|
|
||||||
|
def heading(ns, ew, velocity):
|
||||||
|
if velocity < 1e-6:
|
||||||
|
velocity = 1
|
||||||
|
return (math.atan2(ew / velocity / 4, ns / velocity / 4) / 0.01745) % 360
|
||||||
|
|
||||||
|
def turningRate(a1, a2):
|
||||||
|
return ((((a2 - a1)) + 540) % 360) - 180
|
||||||
|
|
||||||
|
def flarm(long timestamp, str msg, float refLat, float refLon, **kwargs):
|
||||||
|
"""Decode a FLARM message.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
timestamp (int)
|
||||||
|
msg (str)
|
||||||
|
refLat (float): the receiver's location
|
||||||
|
refLon (float): the receiver's location
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
a dictionary with all decoded fields. Any extra keyword argument passed
|
||||||
|
is included in the output dictionary.
|
||||||
|
"""
|
||||||
|
cdef str icao24 = msg[4:6] + msg[2:4] + msg[:2]
|
||||||
|
cdef int magic = int(msg[6:8], 16)
|
||||||
|
|
||||||
|
if magic != 0x10 and magic != 0x20:
|
||||||
|
return None
|
||||||
|
|
||||||
|
cdef array.array decoded = btea(timestamp, msg)
|
||||||
|
|
||||||
|
cdef int aircraft_type = (decoded[0] >> 28) & 0xF
|
||||||
|
cdef int gps = (decoded[0] >> 16) & 0xFFF
|
||||||
|
cdef int raw_vs = c_byte(decoded[0] & 0x3FF).value
|
||||||
|
|
||||||
|
noTrack = ((decoded[0] >> 14) & 0x1) == 1
|
||||||
|
stealth = ((decoded[0] >> 13) & 0x1) == 1
|
||||||
|
|
||||||
|
cdef int altitude = (decoded[1] >> 19) & 0x1FFF
|
||||||
|
|
||||||
|
cdef int lat = decoded[1] & 0x7FFFF
|
||||||
|
|
||||||
|
cdef int mult_factor = 1 << ((decoded[2] >> 30) & 0x3)
|
||||||
|
cdef int lon = decoded[2] & 0xFFFFF
|
||||||
|
|
||||||
|
ns = list(
|
||||||
|
c_byte((decoded[3] >> (i * 8)) & 0xFF).value * mult_factor
|
||||||
|
for i in range(4)
|
||||||
|
)
|
||||||
|
ew = list(
|
||||||
|
c_byte((decoded[4] >> (i * 8)) & 0xFF).value * mult_factor
|
||||||
|
for i in range(4)
|
||||||
|
)
|
||||||
|
|
||||||
|
cdef int roundLat = int(refLat * 1e7) >> 7
|
||||||
|
lat = (lat - roundLat) % 0x080000
|
||||||
|
if lat >= 0x040000:
|
||||||
|
lat -= 0x080000
|
||||||
|
lat = (((lat + roundLat) << 7) + 0x40)
|
||||||
|
|
||||||
|
roundLon = int(refLon * 1e7) >> 7
|
||||||
|
lon = (lon - roundLon) % 0x100000
|
||||||
|
if lon >= 0x080000:
|
||||||
|
lon -= 0x100000
|
||||||
|
lon = (((lon + roundLon) << 7) + 0x40)
|
||||||
|
|
||||||
|
speed = sum(velocity(n, e) for n, e in zip(ns, ew)) / 4
|
||||||
|
|
||||||
|
heading4 = heading(ns[0], ew[0], speed)
|
||||||
|
heading8 = heading(ns[1], ew[1], speed)
|
||||||
|
|
||||||
|
return dict(
|
||||||
|
timestamp=timestamp,
|
||||||
|
icao24=icao24,
|
||||||
|
latitude=round(lat * 1e-7, 6),
|
||||||
|
longitude=round(lon * 1e-7, 6),
|
||||||
|
geoaltitude=altitude,
|
||||||
|
vertical_speed=raw_vs * mult_factor / 10,
|
||||||
|
groundspeed=round(speed),
|
||||||
|
track=round(heading4 - 4 * turningRate(heading4, heading8) / 4),
|
||||||
|
type=AIRCRAFT_TYPES[aircraft_type],
|
||||||
|
sensorLatitude=refLat,
|
||||||
|
sensorLongitude=refLon,
|
||||||
|
isIcao24=magic==0x10,
|
||||||
|
noTrack=noTrack,
|
||||||
|
stealth=stealth,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
@@ -1,23 +1,138 @@
|
|||||||
# Copyright (C) 2018 Junzi Sun (TU Delft)
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Warpper for short roll call surveillance replies DF=4/5
|
Decode short roll call surveillance replies, with downlink format 4 or 5
|
||||||
|
|
||||||
[To be implemented]
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function, division
|
from __future__ import annotations
|
||||||
from pyModeS.decoder import common
|
from typing import Callable, TypeVar
|
||||||
|
|
||||||
|
from .. import common
|
||||||
|
|
||||||
|
T = TypeVar("T")
|
||||||
|
F = Callable[[str], T]
|
||||||
|
|
||||||
|
|
||||||
|
def _checkdf(func: F[T]) -> F[T]:
|
||||||
|
"""Ensure downlink format is 4 or 5."""
|
||||||
|
|
||||||
|
def wrapper(msg: str) -> T:
|
||||||
|
df = common.df(msg)
|
||||||
|
if df not in [4, 5]:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Incorrect downlink format, expect 4 or 5, got {}".format(df)
|
||||||
|
)
|
||||||
|
return func(msg)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def fs(msg: str) -> tuple[int, str]:
|
||||||
|
"""Decode flight status.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: flight status, description
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
fs = common.bin2int(msgbin[5:8])
|
||||||
|
text = ""
|
||||||
|
|
||||||
|
if fs == 0:
|
||||||
|
text = "no alert, no SPI, aircraft is airborne"
|
||||||
|
elif fs == 1:
|
||||||
|
text = "no alert, no SPI, aircraft is on-ground"
|
||||||
|
elif fs == 2:
|
||||||
|
text = "alert, no SPI, aircraft is airborne"
|
||||||
|
elif fs == 3:
|
||||||
|
text = "alert, no SPI, aircraft is on-ground"
|
||||||
|
elif fs == 4:
|
||||||
|
text = "alert, SPI, aircraft is airborne or on-ground"
|
||||||
|
elif fs == 5:
|
||||||
|
text = "no alert, SPI, aircraft is airborne or on-ground"
|
||||||
|
|
||||||
|
return fs, text
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def dr(msg: str) -> tuple[int, str]:
|
||||||
|
"""Decode downlink request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: downlink request, description
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
dr = common.bin2int(msgbin[8:13])
|
||||||
|
|
||||||
|
text = ""
|
||||||
|
|
||||||
|
if dr == 0:
|
||||||
|
text = "no downlink request"
|
||||||
|
elif dr == 1:
|
||||||
|
text = "request to send Comm-B message"
|
||||||
|
elif dr == 4:
|
||||||
|
text = "Comm-B broadcast 1 available"
|
||||||
|
elif dr == 5:
|
||||||
|
text = "Comm-B broadcast 2 available"
|
||||||
|
elif dr >= 16:
|
||||||
|
text = "ELM downlink segments available: {}".format(dr - 15)
|
||||||
|
|
||||||
|
return dr, text
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def um(msg: str) -> tuple[int, int, None | str]:
|
||||||
|
"""Decode utility message.
|
||||||
|
|
||||||
|
Utility message contains interrogator identifier and reservation type.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: interrogator identifier code that triggered the reply, and
|
||||||
|
reservation type made by the interrogator
|
||||||
|
"""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
iis = common.bin2int(msgbin[13:17])
|
||||||
|
ids = common.bin2int(msgbin[17:19])
|
||||||
|
if ids == 0:
|
||||||
|
ids_text = None
|
||||||
|
if ids == 1:
|
||||||
|
ids_text = "Comm-B interrogator identifier code"
|
||||||
|
if ids == 2:
|
||||||
|
ids_text = "Comm-C interrogator identifier code"
|
||||||
|
if ids == 3:
|
||||||
|
ids_text = "Comm-D interrogator identifier code"
|
||||||
|
return iis, ids, ids_text
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def altitude(msg: str) -> None | int:
|
||||||
|
"""Decode altitude.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (String): 14 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: altitude in ft
|
||||||
|
|
||||||
|
"""
|
||||||
|
return common.altcode(msg)
|
||||||
|
|
||||||
|
|
||||||
|
@_checkdf
|
||||||
|
def identity(msg: str) -> str:
|
||||||
|
"""Decode squawk code.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (String): 14 hexdigits string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: squawk code
|
||||||
|
|
||||||
|
"""
|
||||||
|
return common.idcode(msg)
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
"""Uncertainty parameters.
|
"""Uncertainty parameters.
|
||||||
|
|
||||||
See source code at: https://github.com/junzis/pyModeS/blob/master/pyModeS/decoder/uncertainty.py
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info < (3, 8):
|
||||||
|
from typing_extensions import TypedDict
|
||||||
|
else:
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
NA = None
|
NA = None
|
||||||
|
|
||||||
TC_NUCp_lookup = {
|
TC_NUCp_lookup = {
|
||||||
@@ -26,7 +34,7 @@ TC_NUCp_lookup = {
|
|||||||
22: 0,
|
22: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
TC_NICv1_lookup = {
|
TC_NICv1_lookup: dict[int, int | dict[int, int]] = {
|
||||||
5: 11,
|
5: 11,
|
||||||
6: 10,
|
6: 10,
|
||||||
7: 9,
|
7: 9,
|
||||||
@@ -46,7 +54,7 @@ TC_NICv1_lookup = {
|
|||||||
22: 0,
|
22: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
TC_NICv2_lookup = {
|
TC_NICv2_lookup: dict[int, int | dict[int, int]] = {
|
||||||
5: 11,
|
5: 11,
|
||||||
6: 10,
|
6: 10,
|
||||||
7: {2: 9, 0: 8},
|
7: {2: 9, 0: 8},
|
||||||
@@ -67,7 +75,13 @@ TC_NICv2_lookup = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NUCp = {
|
class NUCpEntry(TypedDict):
|
||||||
|
HPL: None | float
|
||||||
|
RCu: None | int
|
||||||
|
RCv: None | int
|
||||||
|
|
||||||
|
|
||||||
|
NUCp: dict[int, NUCpEntry] = {
|
||||||
9: {"HPL": 7.5, "RCu": 3, "RCv": 4},
|
9: {"HPL": 7.5, "RCu": 3, "RCv": 4},
|
||||||
8: {"HPL": 25, "RCu": 10, "RCv": 15},
|
8: {"HPL": 25, "RCu": 10, "RCv": 15},
|
||||||
7: {"HPL": 185, "RCu": 93, "RCv": NA},
|
7: {"HPL": 185, "RCu": 93, "RCv": NA},
|
||||||
@@ -80,7 +94,13 @@ NUCp = {
|
|||||||
0: {"HPL": NA, "RCu": NA, "RCv": NA},
|
0: {"HPL": NA, "RCu": NA, "RCv": NA},
|
||||||
}
|
}
|
||||||
|
|
||||||
NUCv = {
|
|
||||||
|
class NUCvEntry(TypedDict):
|
||||||
|
HVE: None | float
|
||||||
|
VVE: None | float
|
||||||
|
|
||||||
|
|
||||||
|
NUCv: dict[int, NUCvEntry] = {
|
||||||
0: {"HVE": NA, "VVE": NA},
|
0: {"HVE": NA, "VVE": NA},
|
||||||
1: {"HVE": 10, "VVE": 15.2},
|
1: {"HVE": 10, "VVE": 15.2},
|
||||||
2: {"HVE": 3, "VVE": 4.5},
|
2: {"HVE": 3, "VVE": 4.5},
|
||||||
@@ -88,7 +108,13 @@ NUCv = {
|
|||||||
4: {"HVE": 0.3, "VVE": 0.46},
|
4: {"HVE": 0.3, "VVE": 0.46},
|
||||||
}
|
}
|
||||||
|
|
||||||
NACp = {
|
|
||||||
|
class NACpEntry(TypedDict):
|
||||||
|
EPU: None | int
|
||||||
|
VEPU: None | int
|
||||||
|
|
||||||
|
|
||||||
|
NACp: dict[int, NACpEntry] = {
|
||||||
11: {"EPU": 3, "VEPU": 4},
|
11: {"EPU": 3, "VEPU": 4},
|
||||||
10: {"EPU": 10, "VEPU": 15},
|
10: {"EPU": 10, "VEPU": 15},
|
||||||
9: {"EPU": 30, "VEPU": 45},
|
9: {"EPU": 30, "VEPU": 45},
|
||||||
@@ -103,7 +129,13 @@ NACp = {
|
|||||||
0: {"EPU": NA, "VEPU": NA},
|
0: {"EPU": NA, "VEPU": NA},
|
||||||
}
|
}
|
||||||
|
|
||||||
NACv = {
|
|
||||||
|
class NACvEntry(TypedDict):
|
||||||
|
HFOMr: None | float
|
||||||
|
VFOMr: None | float
|
||||||
|
|
||||||
|
|
||||||
|
NACv: dict[int, NACvEntry] = {
|
||||||
0: {"HFOMr": NA, "VFOMr": NA},
|
0: {"HFOMr": NA, "VFOMr": NA},
|
||||||
1: {"HFOMr": 10, "VFOMr": 15.2},
|
1: {"HFOMr": 10, "VFOMr": 15.2},
|
||||||
2: {"HFOMr": 3, "VFOMr": 4.5},
|
2: {"HFOMr": 3, "VFOMr": 4.5},
|
||||||
@@ -111,7 +143,13 @@ NACv = {
|
|||||||
4: {"HFOMr": 0.3, "VFOMr": 0.46},
|
4: {"HFOMr": 0.3, "VFOMr": 0.46},
|
||||||
}
|
}
|
||||||
|
|
||||||
SIL = {
|
|
||||||
|
class SILEntry(TypedDict):
|
||||||
|
PE_RCu: None | float
|
||||||
|
PE_VPL: None | float
|
||||||
|
|
||||||
|
|
||||||
|
SIL: dict[int, SILEntry] = {
|
||||||
3: {"PE_RCu": 1e-7, "PE_VPL": 2e-7},
|
3: {"PE_RCu": 1e-7, "PE_VPL": 2e-7},
|
||||||
2: {"PE_RCu": 1e-5, "PE_VPL": 1e-5},
|
2: {"PE_RCu": 1e-5, "PE_VPL": 1e-5},
|
||||||
1: {"PE_RCu": 1e-3, "PE_VPL": 1e-3},
|
1: {"PE_RCu": 1e-3, "PE_VPL": 1e-3},
|
||||||
@@ -119,7 +157,12 @@ SIL = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NICv1 = {
|
class NICv1Entry(TypedDict):
|
||||||
|
Rc: None | float
|
||||||
|
VPL: None | float
|
||||||
|
|
||||||
|
|
||||||
|
NICv1: dict[int, dict[int, NICv1Entry]] = {
|
||||||
# NIC is used as the index at second Level
|
# NIC is used as the index at second Level
|
||||||
11: {0: {"Rc": 7.5, "VPL": 11}},
|
11: {0: {"Rc": 7.5, "VPL": 11}},
|
||||||
10: {0: {"Rc": 25, "VPL": 37.5}},
|
10: {0: {"Rc": 25, "VPL": 37.5}},
|
||||||
@@ -135,7 +178,12 @@ NICv1 = {
|
|||||||
0: {0: {"Rc": NA, "VPL": NA}},
|
0: {0: {"Rc": NA, "VPL": NA}},
|
||||||
}
|
}
|
||||||
|
|
||||||
NICv2 = {
|
|
||||||
|
class NICv2Entry(TypedDict):
|
||||||
|
Rc: None | float
|
||||||
|
|
||||||
|
|
||||||
|
NICv2: dict[int, dict[int, NICv2Entry]] = {
|
||||||
# Decimal value of [NICa NICb/NICc] is used as the index at second Level
|
# Decimal value of [NICa NICb/NICc] is used as the index at second Level
|
||||||
11: {0: {"Rc": 7.5}},
|
11: {0: {"Rc": 7.5}},
|
||||||
10: {0: {"Rc": 25}},
|
10: {0: {"Rc": 25}},
|
||||||
|
|||||||
223
pyModeS/decoder/uplink.py
Normal file
223
pyModeS/decoder/uplink.py
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from .. import common
|
||||||
|
from textwrap import wrap
|
||||||
|
|
||||||
|
|
||||||
|
def uplink_icao(msg: str) -> str:
|
||||||
|
"Calculate the ICAO address from a Mode-S interrogation (uplink message)"
|
||||||
|
p_gen = 0xFFFA0480 << ((len(msg) - 14) * 4)
|
||||||
|
data = int(msg[:-6], 16)
|
||||||
|
PA = int(msg[-6:], 16)
|
||||||
|
ad = 0
|
||||||
|
topbit = 0b1 << (len(msg) * 4 - 25)
|
||||||
|
for j in range(0, len(msg) * 4, 1):
|
||||||
|
if data & topbit:
|
||||||
|
data ^= p_gen
|
||||||
|
data = (data << 1) + ((PA >> 23) & 1)
|
||||||
|
PA = PA << 1
|
||||||
|
if j > (len(msg) * 4 - 26):
|
||||||
|
ad = ad + ((data >> (len(msg) * 4 - 25)) & 1)
|
||||||
|
ad = ad << 1
|
||||||
|
return "%06X" % (ad >> 2)
|
||||||
|
|
||||||
|
|
||||||
|
def uf(msg: str) -> int:
|
||||||
|
"""Decode Uplink Format value, bits 1 to 5."""
|
||||||
|
ufbin = common.hex2bin(msg[:2])
|
||||||
|
return min(common.bin2int(ufbin[0:5]), 24)
|
||||||
|
|
||||||
|
|
||||||
|
def bds(msg: str) -> Optional[str]:
|
||||||
|
"Decode requested BDS register from selective (Roll Call) interrogation."
|
||||||
|
UF = uf(msg)
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
msgbin_split = wrap(msgbin, 8)
|
||||||
|
mbytes = list(map(common.bin2int, msgbin_split))
|
||||||
|
|
||||||
|
if UF in {4, 5, 20, 21}:
|
||||||
|
|
||||||
|
di = mbytes[1] & 0x7 # DI - Designator Identification
|
||||||
|
RR = mbytes[1] >> 3 & 0x1F
|
||||||
|
if RR > 15:
|
||||||
|
BDS1 = RR - 16
|
||||||
|
if di == 7:
|
||||||
|
RRS = mbytes[2] & 0x0F
|
||||||
|
BDS2 = RRS
|
||||||
|
elif di == 3:
|
||||||
|
RRS = ((mbytes[2] & 0x1) << 3) | ((mbytes[3] & 0xE0) >> 5)
|
||||||
|
BDS2 = RRS
|
||||||
|
else:
|
||||||
|
# for other values of DI, the BDS2 is assumed 0
|
||||||
|
# (as per ICAO Annex 10 Vol IV)
|
||||||
|
BDS2 = 0
|
||||||
|
|
||||||
|
return str(format(BDS1,"X")) + str(format(BDS2,"X"))
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def pr(msg: str) -> Optional[int]:
|
||||||
|
"""Decode PR (probability of reply) field from All Call interrogation.
|
||||||
|
Interpretation:
|
||||||
|
0 signifies reply with probability of 1
|
||||||
|
1 signifies reply with probability of 1/2
|
||||||
|
2 signifies reply with probability of 1/4
|
||||||
|
3 signifies reply with probability of 1/8
|
||||||
|
4 signifies reply with probability of 1/16
|
||||||
|
5, 6, 7 not assigned
|
||||||
|
8 signifies disregard lockout, reply with probability of 1
|
||||||
|
9 signifies disregard lockout, reply with probability of 1/2
|
||||||
|
10 signifies disregard lockout, reply with probability of 1/4
|
||||||
|
11 signifies disregard lockout, reply with probability of 1/8
|
||||||
|
12 signifies disregard lockout, reply with probability of 1/16
|
||||||
|
13, 14, 15 not assigned.
|
||||||
|
"""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
msgbin_split = wrap(msgbin, 8)
|
||||||
|
mbytes = list(map(common.bin2int, msgbin_split))
|
||||||
|
if uf(msg) == 11:
|
||||||
|
return ((mbytes[0] & 0x7) << 1) | ((mbytes[1] & 0x80) >> 7)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def ic(msg: str) -> Optional[str]:
|
||||||
|
"""Decode IC (interrogator code) from a ground-based interrogation."""
|
||||||
|
|
||||||
|
UF = uf(msg)
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
msgbin_split = wrap(msgbin, 8)
|
||||||
|
mbytes = list(map(common.bin2int, msgbin_split))
|
||||||
|
IC = None
|
||||||
|
if UF == 11:
|
||||||
|
|
||||||
|
codeLabel = mbytes[1] & 0x7
|
||||||
|
icField = (mbytes[1] >> 3) & 0xF
|
||||||
|
|
||||||
|
# Store the Interogator Code
|
||||||
|
ic_switcher = {
|
||||||
|
0: "II" + str(icField),
|
||||||
|
1: "SI" + str(icField),
|
||||||
|
2: "SI" + str(icField + 16),
|
||||||
|
3: "SI" + str(icField + 32),
|
||||||
|
4: "SI" + str(icField + 48),
|
||||||
|
}
|
||||||
|
IC = ic_switcher.get(codeLabel, "")
|
||||||
|
|
||||||
|
if UF in {4, 5, 20, 21}:
|
||||||
|
di = mbytes[1] & 0x7
|
||||||
|
RR = mbytes[1] >> 3 & 0x1F
|
||||||
|
if RR > 15:
|
||||||
|
BDS1 = RR - 16 # noqa: F841
|
||||||
|
if di == 0 or di == 1 or di == 7:
|
||||||
|
# II
|
||||||
|
II = (mbytes[2] >> 4) & 0xF
|
||||||
|
IC = "II" + str(II)
|
||||||
|
elif di == 3:
|
||||||
|
# SI
|
||||||
|
SI = (mbytes[2] >> 2) & 0x3F
|
||||||
|
IC = "SI" + str(SI)
|
||||||
|
return IC
|
||||||
|
|
||||||
|
|
||||||
|
def lockout(msg):
|
||||||
|
"""Decode the lockout command from selective (Roll Call) interrogation."""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
msgbin_split = wrap(msgbin, 8)
|
||||||
|
mbytes = list(map(common.bin2int, msgbin_split))
|
||||||
|
|
||||||
|
if uf(msg) in {4, 5, 20, 21}:
|
||||||
|
lockout = False
|
||||||
|
di = mbytes[1] & 0x7
|
||||||
|
if di == 7:
|
||||||
|
# LOS
|
||||||
|
if ((mbytes[3] & 0x40) >> 6) == 1:
|
||||||
|
lockout = True
|
||||||
|
elif di == 3:
|
||||||
|
# LSS
|
||||||
|
if ((mbytes[2] & 0x2) >> 1) == 1:
|
||||||
|
lockout = True
|
||||||
|
return lockout
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def uplink_fields(msg):
|
||||||
|
"""Decode individual fields of a ground-based interrogation."""
|
||||||
|
msgbin = common.hex2bin(msg)
|
||||||
|
msgbin_split = wrap(msgbin, 8)
|
||||||
|
mbytes = list(map(common.bin2int, msgbin_split))
|
||||||
|
PR = ""
|
||||||
|
IC = ""
|
||||||
|
lockout = False
|
||||||
|
di = ""
|
||||||
|
RR = ""
|
||||||
|
RRS = ""
|
||||||
|
BDS = ""
|
||||||
|
if uf(msg) == 11:
|
||||||
|
|
||||||
|
# Probability of Reply decoding
|
||||||
|
|
||||||
|
PR = ((mbytes[0] & 0x7) << 1) | ((mbytes[1] & 0x80) >> 7)
|
||||||
|
|
||||||
|
# Get cl and ic bit fields from the data
|
||||||
|
# Decode the SI or II interrogator code
|
||||||
|
codeLabel = mbytes[1] & 0x7
|
||||||
|
icField = (mbytes[1] >> 3) & 0xF
|
||||||
|
|
||||||
|
# Store the Interogator Code
|
||||||
|
ic_switcher = {
|
||||||
|
0: "II" + str(icField),
|
||||||
|
1: "SI" + str(icField),
|
||||||
|
2: "SI" + str(icField + 16),
|
||||||
|
3: "SI" + str(icField + 32),
|
||||||
|
4: "SI" + str(icField + 48),
|
||||||
|
}
|
||||||
|
IC = ic_switcher.get(codeLabel, "")
|
||||||
|
|
||||||
|
if uf(msg) in {4, 5, 20, 21}:
|
||||||
|
# Decode the DI and get the lockout information conveniently
|
||||||
|
# (LSS or LOS)
|
||||||
|
|
||||||
|
# DI - Designator Identification
|
||||||
|
di = mbytes[1] & 0x7
|
||||||
|
RR = mbytes[1] >> 3 & 0x1F
|
||||||
|
if RR > 15:
|
||||||
|
BDS1 = RR - 16
|
||||||
|
BDS2 = 0
|
||||||
|
if di == 0 or di == 1:
|
||||||
|
# II
|
||||||
|
II = (mbytes[2] >> 4) & 0xF
|
||||||
|
IC = "II" + str(II)
|
||||||
|
elif di == 7:
|
||||||
|
# LOS
|
||||||
|
if ((mbytes[3] & 0x40) >> 6) == 1:
|
||||||
|
lockout = True
|
||||||
|
# II
|
||||||
|
II = (mbytes[2] >> 4) & 0xF
|
||||||
|
IC = "II" + str(II)
|
||||||
|
RRS = mbytes[2] & 0x0F
|
||||||
|
BDS2 = RRS
|
||||||
|
elif di == 3:
|
||||||
|
# LSS
|
||||||
|
if ((mbytes[2] & 0x2) >> 1) == 1:
|
||||||
|
lockout = True
|
||||||
|
# SI
|
||||||
|
SI = (mbytes[2] >> 2) & 0x3F
|
||||||
|
IC = "SI" + str(SI)
|
||||||
|
RRS = ((mbytes[2] & 0x1) << 3) | ((mbytes[3] & 0xE0) >> 5)
|
||||||
|
BDS2 = RRS
|
||||||
|
if RR > 15:
|
||||||
|
BDS = str(format(BDS1,"X")) + str(format(BDS2,"X"))
|
||||||
|
|
||||||
|
return {
|
||||||
|
"DI": di,
|
||||||
|
"IC": IC,
|
||||||
|
"LOS": lockout,
|
||||||
|
"PR": PR,
|
||||||
|
"RR": RR,
|
||||||
|
"RRS": RRS,
|
||||||
|
"BDS": BDS,
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
from __future__ import absolute_import, print_function, division
|
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ International Standard Atmosphere
|
|||||||
|
|
||||||
p,rho,T = atmos(H) # atmos as function of geopotential altitude H [m]
|
p,rho,T = atmos(H) # atmos as function of geopotential altitude H [m]
|
||||||
a = vsound(H) # speed of sound [m/s] as function of H[m]
|
a = vsound(H) # speed of sound [m/s] as function of H[m]
|
||||||
p = pressure(H) # calls atmos but retruns only pressure [Pa]
|
p = pressure(H) # calls atmos but returns only pressure [Pa]
|
||||||
T = temperature(H) # calculates temperature [K]
|
T = temperature(H) # calculates temperature [K]
|
||||||
rho = density(H) # calls atmos but retruns only pressure [Pa]
|
rho = density(H) # calls atmos but returns only pressure [Pa]
|
||||||
|
|
||||||
Speed conversion at altitude H[m] in ISA
|
Speed conversion at altitude H[m] in ISA
|
||||||
::
|
::
|
||||||
|
|
||||||
Mach = tas2mach(Vtas,H) # true airspeed (Vtas) to mach number conversion
|
Mach = tas2mach(Vtas,H) # true airspeed (Vtas) to mach number conversion
|
||||||
Vtas = mach2tas(Mach,H) # true airspeed (Vtas) to mach number conversion
|
Vtas = mach2tas(Mach,H) # mach number to true airspeed (Vtas) conversion
|
||||||
Vtas = eas2tas(Veas,H) # equivalent airspeed to true airspeed, H in [m]
|
Vtas = eas2tas(Veas,H) # equivalent airspeed to true airspeed, H in [m]
|
||||||
Veas = tas2eas(Vtas,H) # true airspeed to equivent airspeed, H in [m]
|
Veas = tas2eas(Vtas,H) # true airspeed to equivent airspeed, H in [m]
|
||||||
Vtas = cas2tas(Vcas,H) # Vcas to Vtas conversion both m/s, H in [m]
|
Vtas = cas2tas(Vcas,H) # Vcas to Vtas conversion both m/s, H in [m]
|
||||||
@@ -35,18 +35,18 @@ ft = 0.3048 # ft -> m
|
|||||||
fpm = 0.00508 # ft/min -> m/s
|
fpm = 0.00508 # ft/min -> m/s
|
||||||
inch = 0.0254 # inch -> m
|
inch = 0.0254 # inch -> m
|
||||||
sqft = 0.09290304 # 1 square foot
|
sqft = 0.09290304 # 1 square foot
|
||||||
nm = 1852.0 # nautical mile -> m
|
nm = 1852 # nautical mile -> m
|
||||||
lbs = 0.453592 # pound -> kg
|
lbs = 0.453592 # pound -> kg
|
||||||
g0 = 9.80665 # m/s2, Sea level gravity constant
|
g0 = 9.80665 # m/s2, Sea level gravity constant
|
||||||
R = 287.05287 # m2/(s2 x K), gas constant, sea level ISA
|
R = 287.05287 # m2/(s2 x K), gas constant, sea level ISA
|
||||||
p0 = 101325.0 # Pa, air pressure, sea level ISA
|
p0 = 101325 # Pa, air pressure, sea level ISA
|
||||||
rho0 = 1.225 # kg/m3, air density, sea level ISA
|
rho0 = 1.225 # kg/m3, air density, sea level ISA
|
||||||
T0 = 288.15 # K, temperature, sea level ISA
|
T0 = 288.15 # K, temperature, sea level ISA
|
||||||
gamma = 1.40 # cp/cv for air
|
gamma = 1.40 # cp/cv for air
|
||||||
gamma1 = 0.2 # (gamma-1)/2 for air
|
gamma1 = 0.2 # (gamma-1)/2 for air
|
||||||
gamma2 = 3.5 # gamma/(gamma-1) for air
|
gamma2 = 3.5 # gamma/(gamma-1) for air
|
||||||
beta = -0.0065 # [K/m] ISA temp gradient below tropopause
|
beta = -0.0065 # [K/m] ISA temp gradient below tropopause
|
||||||
r_earth = 6371000.0 # m, average earth radius
|
r_earth = 6371000 # m, average earth radius
|
||||||
a0 = 340.293988 # m/s, sea level speed of sound ISA, sqrt(gamma*R*T0)
|
a0 = 340.293988 # m/s, sea level speed of sound ISA, sqrt(gamma*R*T0)
|
||||||
|
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ def distance(lat1, lon1, lat2, lon2, H=0):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# phi = 90 - latitude
|
# phi = 90 - latitude
|
||||||
phi1 = np.radians(90.0 - lat1)
|
phi1 = np.radians(90 - lat1)
|
||||||
phi2 = np.radians(90.0 - lat2)
|
phi2 = np.radians(90 - lat2)
|
||||||
|
|
||||||
# theta = longitude
|
# theta = longitude
|
||||||
theta1 = np.radians(lon1)
|
theta1 = np.radians(lon1)
|
||||||
@@ -158,16 +158,16 @@ def tas2eas(Vtas, H):
|
|||||||
def cas2tas(Vcas, H):
|
def cas2tas(Vcas, H):
|
||||||
"""Calibrated Airspeed to True Airspeed"""
|
"""Calibrated Airspeed to True Airspeed"""
|
||||||
p, rho, T = atmos(H)
|
p, rho, T = atmos(H)
|
||||||
qdyn = p0 * ((1.0 + rho0 * Vcas * Vcas / (7.0 * p0)) ** 3.5 - 1.0)
|
qdyn = p0 * ((1 + rho0 * Vcas * Vcas / (7 * p0)) ** 3.5 - 1.0)
|
||||||
Vtas = np.sqrt(7.0 * p / rho * ((1.0 + qdyn / p) ** (2.0 / 7.0) - 1.0))
|
Vtas = np.sqrt(7 * p / rho * ((1 + qdyn / p) ** (2 / 7.0) - 1.0))
|
||||||
return Vtas
|
return Vtas
|
||||||
|
|
||||||
|
|
||||||
def tas2cas(Vtas, H):
|
def tas2cas(Vtas, H):
|
||||||
"""True Airspeed to Calibrated Airspeed"""
|
"""True Airspeed to Calibrated Airspeed"""
|
||||||
p, rho, T = atmos(H)
|
p, rho, T = atmos(H)
|
||||||
qdyn = p * ((1.0 + rho * Vtas * Vtas / (7.0 * p)) ** 3.5 - 1.0)
|
qdyn = p * ((1 + rho * Vtas * Vtas / (7 * p)) ** 3.5 - 1.0)
|
||||||
Vcas = np.sqrt(7.0 * p0 / rho0 * ((qdyn / p0 + 1.0) ** (2.0 / 7.0) - 1.0))
|
Vcas = np.sqrt(7 * p0 / rho0 * ((qdyn / p0 + 1.0) ** (2 / 7.0) - 1.0))
|
||||||
return Vcas
|
return Vcas
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
pyModeS/extra/demod2400/__init__.py
Normal file
3
pyModeS/extra/demod2400/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from .core import demod2400
|
||||||
|
|
||||||
|
__all__ = ["demod2400"]
|
||||||
4
pyModeS/extra/demod2400/core.pyi
Normal file
4
pyModeS/extra/demod2400/core.pyi
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import numpy as np
|
||||||
|
import numpy.typing as npt
|
||||||
|
|
||||||
|
def demod2400(data: npt.NDArray[np.uint16], timestamp: float): ...
|
||||||
49
pyModeS/extra/demod2400/core.pyx
Normal file
49
pyModeS/extra/demod2400/core.pyx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
from libc.stdint cimport uint16_t, uint8_t
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from ...c_common cimport crc, df
|
||||||
|
|
||||||
|
cdef extern from "demod2400.h":
|
||||||
|
int demodulate2400(uint16_t *data, uint8_t *msg, int len_data, int* len_msg)
|
||||||
|
|
||||||
|
|
||||||
|
def demod2400(uint16_t[:] data, float timestamp):
|
||||||
|
cdef uint8_t[:] msg_bin
|
||||||
|
cdef int i = 0, j, length, crc_msg = 1
|
||||||
|
cdef long size = data.shape[0]
|
||||||
|
|
||||||
|
msg_bin = np.zeros(14, dtype=np.uint8)
|
||||||
|
|
||||||
|
while i < size:
|
||||||
|
j = demodulate2400(&data[i], &msg_bin[0], size-i, &length)
|
||||||
|
if j == 0:
|
||||||
|
yield dict(
|
||||||
|
# 1 sample data = 2 IQ samples (hence 2*)
|
||||||
|
timestamp=timestamp + 2.*i/2400000.,
|
||||||
|
payload=None,
|
||||||
|
crc=None,
|
||||||
|
index=i,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
i += j
|
||||||
|
msg_clip = np.asarray(msg_bin)[:length]
|
||||||
|
msg = "".join(f"{elt:02X}" for elt in msg_clip)
|
||||||
|
crc_msg = crc(msg)
|
||||||
|
# if df(msg) != 17 or crc_msg == 0:
|
||||||
|
if crc_msg == 0:
|
||||||
|
yield dict(
|
||||||
|
# 1 sample data = 2 IQ samples (hence 2*)
|
||||||
|
timestamp=timestamp + 2.*i/2400000.,
|
||||||
|
payload=msg,
|
||||||
|
crc=crc_msg,
|
||||||
|
index=i,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield dict(
|
||||||
|
# 1 sample data = 2 IQ samples (hence 2*)
|
||||||
|
timestamp=timestamp + 2.*i/2400000.,
|
||||||
|
payload=None,
|
||||||
|
crc=None,
|
||||||
|
index=i,
|
||||||
|
)
|
||||||
|
return
|
||||||
256
pyModeS/extra/demod2400/demod2400.c
Normal file
256
pyModeS/extra/demod2400/demod2400.c
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
#include "demod2400.h"
|
||||||
|
|
||||||
|
static inline int slice_phase0(uint16_t *m)
|
||||||
|
{
|
||||||
|
return 5 * m[0] - 3 * m[1] - 2 * m[2];
|
||||||
|
}
|
||||||
|
static inline int slice_phase1(uint16_t *m)
|
||||||
|
{
|
||||||
|
return 4 * m[0] - m[1] - 3 * m[2];
|
||||||
|
}
|
||||||
|
static inline int slice_phase2(uint16_t *m)
|
||||||
|
{
|
||||||
|
return 3 * m[0] + m[1] - 4 * m[2];
|
||||||
|
}
|
||||||
|
static inline int slice_phase3(uint16_t *m)
|
||||||
|
{
|
||||||
|
return 2 * m[0] + 3 * m[1] - 5 * m[2];
|
||||||
|
}
|
||||||
|
static inline int slice_phase4(uint16_t *m)
|
||||||
|
{
|
||||||
|
return m[0] + 5 * m[1] - 5 * m[2] - m[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
int demodulate2400(uint16_t *mag, uint8_t *msg, int len_mag, int *len_msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t j;
|
||||||
|
for (j = 0; j < len_mag / 2 - 300; j++)
|
||||||
|
{ // SALE
|
||||||
|
|
||||||
|
uint16_t *preamble = &mag[j];
|
||||||
|
int high;
|
||||||
|
uint32_t base_signal, base_noise;
|
||||||
|
|
||||||
|
// quick check: we must have a rising edge 0->1 and a falling edge 12->13
|
||||||
|
if (!(preamble[0] < preamble[1] && preamble[12] > preamble[13]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (preamble[1] > preamble[2] && // 1
|
||||||
|
preamble[2] < preamble[3] && preamble[3] > preamble[4] && // 3
|
||||||
|
preamble[8] < preamble[9] && preamble[9] > preamble[10] && // 9
|
||||||
|
preamble[10] < preamble[11])
|
||||||
|
{ // 11-12
|
||||||
|
// peaks at 1,3,9,11-12: phase 3
|
||||||
|
high = (preamble[1] + preamble[3] + preamble[9] + preamble[11] + preamble[12]) / 4;
|
||||||
|
base_signal = preamble[1] + preamble[3] + preamble[9];
|
||||||
|
base_noise = preamble[5] + preamble[6] + preamble[7];
|
||||||
|
}
|
||||||
|
else if (preamble[1] > preamble[2] && // 1
|
||||||
|
preamble[2] < preamble[3] && preamble[3] > preamble[4] && // 3
|
||||||
|
preamble[8] < preamble[9] && preamble[9] > preamble[10] && // 9
|
||||||
|
preamble[11] < preamble[12])
|
||||||
|
{ // 12
|
||||||
|
// peaks at 1,3,9,12: phase 4
|
||||||
|
high = (preamble[1] + preamble[3] + preamble[9] + preamble[12]) / 4;
|
||||||
|
base_signal = preamble[1] + preamble[3] + preamble[9] + preamble[12];
|
||||||
|
base_noise = preamble[5] + preamble[6] + preamble[7] + preamble[8];
|
||||||
|
}
|
||||||
|
else if (preamble[1] > preamble[2] && // 1
|
||||||
|
preamble[2] < preamble[3] && preamble[4] > preamble[5] && // 3-4
|
||||||
|
preamble[8] < preamble[9] && preamble[10] > preamble[11] && // 9-10
|
||||||
|
preamble[11] < preamble[12])
|
||||||
|
{ // 12
|
||||||
|
// peaks at 1,3-4,9-10,12: phase 5
|
||||||
|
high = (preamble[1] + preamble[3] + preamble[4] + preamble[9] + preamble[10] + preamble[12]) / 4;
|
||||||
|
base_signal = preamble[1] + preamble[12];
|
||||||
|
base_noise = preamble[6] + preamble[7];
|
||||||
|
}
|
||||||
|
else if (preamble[1] > preamble[2] && // 1
|
||||||
|
preamble[3] < preamble[4] && preamble[4] > preamble[5] && // 4
|
||||||
|
preamble[9] < preamble[10] && preamble[10] > preamble[11] && // 10
|
||||||
|
preamble[11] < preamble[12])
|
||||||
|
{ // 12
|
||||||
|
// peaks at 1,4,10,12: phase 6
|
||||||
|
high = (preamble[1] + preamble[4] + preamble[10] + preamble[12]) / 4;
|
||||||
|
base_signal = preamble[1] + preamble[4] + preamble[10] + preamble[12];
|
||||||
|
base_noise = preamble[5] + preamble[6] + preamble[7] + preamble[8];
|
||||||
|
}
|
||||||
|
else if (preamble[2] > preamble[3] && // 1-2
|
||||||
|
preamble[3] < preamble[4] && preamble[4] > preamble[5] && // 4
|
||||||
|
preamble[9] < preamble[10] && preamble[10] > preamble[11] && // 10
|
||||||
|
preamble[11] < preamble[12])
|
||||||
|
{ // 12
|
||||||
|
// peaks at 1-2,4,10,12: phase 7
|
||||||
|
high = (preamble[1] + preamble[2] + preamble[4] + preamble[10] + preamble[12]) / 4;
|
||||||
|
base_signal = preamble[4] + preamble[10] + preamble[12];
|
||||||
|
base_noise = preamble[6] + preamble[7] + preamble[8];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// no suitable peaks
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for enough signal
|
||||||
|
if (base_signal * 2 < 3 * base_noise) // about 3.5dB SNR
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Check that the "quiet" bits 6,7,15,16,17 are actually quiet
|
||||||
|
if (preamble[5] >= high ||
|
||||||
|
preamble[6] >= high ||
|
||||||
|
preamble[7] >= high ||
|
||||||
|
preamble[8] >= high ||
|
||||||
|
preamble[14] >= high ||
|
||||||
|
preamble[15] >= high ||
|
||||||
|
preamble[16] >= high ||
|
||||||
|
preamble[17] >= high ||
|
||||||
|
preamble[18] >= high)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// // try all phases
|
||||||
|
// Modes.stats_current.demod_preambles++;
|
||||||
|
// bestmsg = NULL; bestscore = -2; bestphase = -1;
|
||||||
|
for (int try_phase = 4; try_phase <= 8; ++try_phase)
|
||||||
|
{
|
||||||
|
uint16_t *pPtr;
|
||||||
|
int phase, i, bytelen;
|
||||||
|
|
||||||
|
// Decode all the next 112 bits, regardless of the actual message
|
||||||
|
// size. We'll check the actual message type later
|
||||||
|
|
||||||
|
pPtr = &mag[j + 19] + (try_phase / 5);
|
||||||
|
phase = try_phase % 5;
|
||||||
|
|
||||||
|
bytelen = MODES_LONG_MSG_BYTES;
|
||||||
|
for (i = 0; i < bytelen; ++i)
|
||||||
|
{
|
||||||
|
uint8_t theByte = 0;
|
||||||
|
|
||||||
|
switch (phase)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
theByte =
|
||||||
|
(slice_phase0(pPtr) > 0 ? 0x80 : 0) |
|
||||||
|
(slice_phase2(pPtr + 2) > 0 ? 0x40 : 0) |
|
||||||
|
(slice_phase4(pPtr + 4) > 0 ? 0x20 : 0) |
|
||||||
|
(slice_phase1(pPtr + 7) > 0 ? 0x10 : 0) |
|
||||||
|
(slice_phase3(pPtr + 9) > 0 ? 0x08 : 0) |
|
||||||
|
(slice_phase0(pPtr + 12) > 0 ? 0x04 : 0) |
|
||||||
|
(slice_phase2(pPtr + 14) > 0 ? 0x02 : 0) |
|
||||||
|
(slice_phase4(pPtr + 16) > 0 ? 0x01 : 0);
|
||||||
|
|
||||||
|
phase = 1;
|
||||||
|
pPtr += 19;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
theByte =
|
||||||
|
(slice_phase1(pPtr) > 0 ? 0x80 : 0) |
|
||||||
|
(slice_phase3(pPtr + 2) > 0 ? 0x40 : 0) |
|
||||||
|
(slice_phase0(pPtr + 5) > 0 ? 0x20 : 0) |
|
||||||
|
(slice_phase2(pPtr + 7) > 0 ? 0x10 : 0) |
|
||||||
|
(slice_phase4(pPtr + 9) > 0 ? 0x08 : 0) |
|
||||||
|
(slice_phase1(pPtr + 12) > 0 ? 0x04 : 0) |
|
||||||
|
(slice_phase3(pPtr + 14) > 0 ? 0x02 : 0) |
|
||||||
|
(slice_phase0(pPtr + 17) > 0 ? 0x01 : 0);
|
||||||
|
|
||||||
|
phase = 2;
|
||||||
|
pPtr += 19;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
theByte =
|
||||||
|
(slice_phase2(pPtr) > 0 ? 0x80 : 0) |
|
||||||
|
(slice_phase4(pPtr + 2) > 0 ? 0x40 : 0) |
|
||||||
|
(slice_phase1(pPtr + 5) > 0 ? 0x20 : 0) |
|
||||||
|
(slice_phase3(pPtr + 7) > 0 ? 0x10 : 0) |
|
||||||
|
(slice_phase0(pPtr + 10) > 0 ? 0x08 : 0) |
|
||||||
|
(slice_phase2(pPtr + 12) > 0 ? 0x04 : 0) |
|
||||||
|
(slice_phase4(pPtr + 14) > 0 ? 0x02 : 0) |
|
||||||
|
(slice_phase1(pPtr + 17) > 0 ? 0x01 : 0);
|
||||||
|
|
||||||
|
phase = 3;
|
||||||
|
pPtr += 19;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
theByte =
|
||||||
|
(slice_phase3(pPtr) > 0 ? 0x80 : 0) |
|
||||||
|
(slice_phase0(pPtr + 3) > 0 ? 0x40 : 0) |
|
||||||
|
(slice_phase2(pPtr + 5) > 0 ? 0x20 : 0) |
|
||||||
|
(slice_phase4(pPtr + 7) > 0 ? 0x10 : 0) |
|
||||||
|
(slice_phase1(pPtr + 10) > 0 ? 0x08 : 0) |
|
||||||
|
(slice_phase3(pPtr + 12) > 0 ? 0x04 : 0) |
|
||||||
|
(slice_phase0(pPtr + 15) > 0 ? 0x02 : 0) |
|
||||||
|
(slice_phase2(pPtr + 17) > 0 ? 0x01 : 0);
|
||||||
|
|
||||||
|
phase = 4;
|
||||||
|
pPtr += 19;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
theByte =
|
||||||
|
(slice_phase4(pPtr) > 0 ? 0x80 : 0) |
|
||||||
|
(slice_phase1(pPtr + 3) > 0 ? 0x40 : 0) |
|
||||||
|
(slice_phase3(pPtr + 5) > 0 ? 0x20 : 0) |
|
||||||
|
(slice_phase0(pPtr + 8) > 0 ? 0x10 : 0) |
|
||||||
|
(slice_phase2(pPtr + 10) > 0 ? 0x08 : 0) |
|
||||||
|
(slice_phase4(pPtr + 12) > 0 ? 0x04 : 0) |
|
||||||
|
(slice_phase1(pPtr + 15) > 0 ? 0x02 : 0) |
|
||||||
|
(slice_phase3(pPtr + 17) > 0 ? 0x01 : 0);
|
||||||
|
|
||||||
|
phase = 0;
|
||||||
|
pPtr += 20;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg[i] = theByte;
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
switch (msg[0] >> 3)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
case 11:
|
||||||
|
bytelen = MODES_SHORT_MSG_BYTES;
|
||||||
|
*len_msg = MODES_SHORT_MSG_BYTES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
case 17:
|
||||||
|
case 18:
|
||||||
|
case 20:
|
||||||
|
case 21:
|
||||||
|
case 24:
|
||||||
|
*len_msg = MODES_LONG_MSG_BYTES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
bytelen = 1; // unknown DF, give up immediately
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return j + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Score the mode S message and see if it's any good.
|
||||||
|
// score = scoreModesMessage(msg, i*8);
|
||||||
|
// if (score > bestscore) {
|
||||||
|
// // new high score!
|
||||||
|
// bestmsg = msg;
|
||||||
|
// bestscore = score;
|
||||||
|
// bestphase = try_phase;
|
||||||
|
// // swap to using the other buffer so we don't clobber our demodulated data
|
||||||
|
// // (if we find a better result then we'll swap back, but that's OK because
|
||||||
|
// // we no longer need this copy if we found a better one)
|
||||||
|
// msg = (msg == msg1) ? msg2 : msg1;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
11
pyModeS/extra/demod2400/demod2400.h
Normal file
11
pyModeS/extra/demod2400/demod2400.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef __DEMOD_2400_H__
|
||||||
|
#define __DEMOD_2400_H__
|
||||||
|
|
||||||
|
#define MODES_LONG_MSG_BYTES 14
|
||||||
|
#define MODES_SHORT_MSG_BYTES 7
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int demodulate2400(uint16_t *mag, uint8_t *msg, int len_mag, int* len_msg);
|
||||||
|
|
||||||
|
#endif
|
||||||
133
pyModeS/extra/demod2400/rtlreader.py
Normal file
133
pyModeS/extra/demod2400/rtlreader.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
import numpy as np
|
||||||
|
import pyModeS as pms
|
||||||
|
from pyModeS.extra.demod2400 import demod2400
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
import rtlsdr # type: ignore
|
||||||
|
except ImportError:
|
||||||
|
print(
|
||||||
|
"------------------------------------------------------------------------"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"! Warning: pyrtlsdr not installed (required for using RTL-SDR devices) !"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"------------------------------------------------------------------------"
|
||||||
|
)
|
||||||
|
|
||||||
|
modes_frequency = 1090e6
|
||||||
|
sampling_rate = 2.4e6
|
||||||
|
buffer_size = 16 * 16384
|
||||||
|
read_size = buffer_size / 2
|
||||||
|
|
||||||
|
|
||||||
|
class RtlReader(object):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(RtlReader, self).__init__()
|
||||||
|
self.signal_buffer = [] # amplitude of the sample only
|
||||||
|
self.sdr = rtlsdr.RtlSdr()
|
||||||
|
self.sdr.sample_rate = sampling_rate
|
||||||
|
self.sdr.center_freq = modes_frequency
|
||||||
|
self.sdr.gain = "auto"
|
||||||
|
|
||||||
|
self.debug = kwargs.get("debug", False)
|
||||||
|
self.raw_pipe_in = None
|
||||||
|
self.stop_flag = False
|
||||||
|
self.exception_queue = None
|
||||||
|
|
||||||
|
def _process_buffer(self):
|
||||||
|
"""process raw IQ data in the buffer"""
|
||||||
|
|
||||||
|
# Mode S messages
|
||||||
|
messages = []
|
||||||
|
|
||||||
|
data = (np.array(self.signal_buffer) * 65535).astype(np.uint16)
|
||||||
|
|
||||||
|
for s in demod2400(data, self.timestamp):
|
||||||
|
if s["payload"] is None:
|
||||||
|
idx = s["index"]
|
||||||
|
# reset the buffer
|
||||||
|
self.signal_buffer = self.signal_buffer[idx:]
|
||||||
|
self.timestamp = s["timestamp"]
|
||||||
|
break
|
||||||
|
if self._check_msg(s["payload"]):
|
||||||
|
messages.append([s["payload"], time.time()]) # s["timestamp"]])
|
||||||
|
if self.debug:
|
||||||
|
self._debug_msg(s["payload"])
|
||||||
|
|
||||||
|
self.timestamp = s["timestamp"]
|
||||||
|
return messages
|
||||||
|
|
||||||
|
def _check_msg(self, msg):
|
||||||
|
df = pms.df(msg)
|
||||||
|
msglen = len(msg)
|
||||||
|
if df == 17 and msglen == 28:
|
||||||
|
if pms.crc(msg) == 0:
|
||||||
|
return True
|
||||||
|
elif df in [20, 21] and msglen == 28:
|
||||||
|
return True
|
||||||
|
elif df in [4, 5, 11] and msglen == 14:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _debug_msg(self, msg):
|
||||||
|
df = pms.df(msg)
|
||||||
|
msglen = len(msg)
|
||||||
|
if df == 17 and msglen == 28:
|
||||||
|
print(msg, pms.icao(msg), df, pms.crc(msg))
|
||||||
|
print(pms.tell(msg))
|
||||||
|
elif df in [20, 21] and msglen == 28:
|
||||||
|
print(msg, pms.icao(msg), df)
|
||||||
|
elif df in [4, 5, 11] and msglen == 14:
|
||||||
|
print(msg, pms.icao(msg), df)
|
||||||
|
else:
|
||||||
|
# print("[*]", msg)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _read_callback(self, data, rtlsdr_obj):
|
||||||
|
amp = np.absolute(data)
|
||||||
|
self.signal_buffer.extend(amp.tolist())
|
||||||
|
|
||||||
|
if len(self.signal_buffer) >= buffer_size:
|
||||||
|
messages = self._process_buffer()
|
||||||
|
self.handle_messages(messages)
|
||||||
|
|
||||||
|
def handle_messages(self, messages):
|
||||||
|
"""re-implement this method to handle the messages"""
|
||||||
|
for msg, t in messages:
|
||||||
|
# print("%15.9f %s" % (t, msg))
|
||||||
|
pass
|
||||||
|
|
||||||
|
def stop(self, *args, **kwargs):
|
||||||
|
self.sdr.close()
|
||||||
|
|
||||||
|
def run(self, raw_pipe_in=None, stop_flag=None, exception_queue=None):
|
||||||
|
self.raw_pipe_in = raw_pipe_in
|
||||||
|
self.exception_queue = exception_queue
|
||||||
|
self.stop_flag = stop_flag
|
||||||
|
|
||||||
|
try:
|
||||||
|
# raise RuntimeError("test exception")
|
||||||
|
self.timestamp = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data = self.sdr.read_samples(read_size)
|
||||||
|
self._read_callback(data, None)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
if self.exception_queue is not None:
|
||||||
|
self.exception_queue.put(tb)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import signal
|
||||||
|
|
||||||
|
rtl = RtlReader()
|
||||||
|
signal.signal(signal.SIGINT, rtl.stop)
|
||||||
|
|
||||||
|
rtl.debug = True
|
||||||
|
rtl.run()
|
||||||
@@ -1,90 +1,120 @@
|
|||||||
|
import time
|
||||||
|
import traceback
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyModeS as pms
|
import pyModeS as pms
|
||||||
from rtlsdr import RtlSdr
|
|
||||||
import time
|
|
||||||
|
|
||||||
modes_sample_rate = 2e6
|
try:
|
||||||
|
import rtlsdr # type: ignore
|
||||||
|
except:
|
||||||
|
print("------------------------------------------------------------------------")
|
||||||
|
print("! Warning: pyrtlsdr not installed (required for using RTL-SDR devices) !")
|
||||||
|
print("------------------------------------------------------------------------")
|
||||||
|
|
||||||
|
sampling_rate = 2e6
|
||||||
|
smaples_per_microsec = 2
|
||||||
|
|
||||||
modes_frequency = 1090e6
|
modes_frequency = 1090e6
|
||||||
buffer_size = 1024 * 100
|
buffer_size = 1024 * 200
|
||||||
read_size = 1024 * 20
|
read_size = 1024 * 100
|
||||||
|
|
||||||
pbits = 8
|
pbits = 8
|
||||||
fbits = 112
|
fbits = 112
|
||||||
preamble = [1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]
|
preamble = [1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]
|
||||||
th_amp = 0.2 # signal amplitude threshold for 0 and 1 bit
|
|
||||||
th_amp_diff = 0.8 # signal amplitude threshold difference between 0 and 1 bit
|
th_amp_diff = 0.8 # signal amplitude threshold difference between 0 and 1 bit
|
||||||
|
|
||||||
|
|
||||||
class RtlReader(object):
|
class RtlReader(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(RtlReader, self).__init__()
|
super(RtlReader, self).__init__()
|
||||||
self.signal_buffer = []
|
self.signal_buffer = [] # amplitude of the sample only
|
||||||
self.sdr = RtlSdr()
|
self.sdr = rtlsdr.RtlSdr()
|
||||||
self.sdr.sample_rate = modes_sample_rate
|
self.sdr.sample_rate = sampling_rate
|
||||||
self.sdr.center_freq = modes_frequency
|
self.sdr.center_freq = modes_frequency
|
||||||
self.sdr.gain = "auto"
|
self.sdr.gain = "auto"
|
||||||
# sdr.freq_correction = 75
|
|
||||||
|
|
||||||
self.debug = kwargs.get("debug", False)
|
self.debug = kwargs.get("debug", False)
|
||||||
self.raw_pipe_in = None
|
self.raw_pipe_in = None
|
||||||
self.stop_flag = False
|
self.stop_flag = False
|
||||||
|
self.noise_floor = 1e6
|
||||||
|
|
||||||
|
self.exception_queue = None
|
||||||
|
|
||||||
|
def _calc_noise(self):
|
||||||
|
"""Calculate noise floor"""
|
||||||
|
window = smaples_per_microsec * 100
|
||||||
|
total_len = len(self.signal_buffer)
|
||||||
|
means = (
|
||||||
|
np.array(self.signal_buffer[: total_len // window * window])
|
||||||
|
.reshape(-1, window)
|
||||||
|
.mean(axis=1)
|
||||||
|
)
|
||||||
|
return min(means)
|
||||||
|
|
||||||
def _process_buffer(self):
|
def _process_buffer(self):
|
||||||
|
"""process raw IQ data in the buffer"""
|
||||||
|
|
||||||
|
# update noise floor
|
||||||
|
self.noise_floor = min(self._calc_noise(), self.noise_floor)
|
||||||
|
|
||||||
|
# set minimum signal amplitude
|
||||||
|
min_sig_amp = 3.162 * self.noise_floor # 10 dB SNR
|
||||||
|
|
||||||
|
# Mode S messages
|
||||||
messages = []
|
messages = []
|
||||||
|
|
||||||
# signal_array = np.array(self.signal_buffer)
|
|
||||||
# pulses_array = np.where(np.array(self.signal_buffer) < th_amp, 0, 1)
|
|
||||||
# pulses = "".join(str(x) for x in pulses_array)
|
|
||||||
buffer_length = len(self.signal_buffer)
|
buffer_length = len(self.signal_buffer)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < buffer_length:
|
while i < buffer_length:
|
||||||
if self.signal_buffer[i] < th_amp:
|
if self.signal_buffer[i] < min_sig_amp:
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# if pulses[i : i + pbits * 2] == preamble:
|
|
||||||
if self._check_preamble(self.signal_buffer[i : i + pbits * 2]):
|
if self._check_preamble(self.signal_buffer[i : i + pbits * 2]):
|
||||||
frame_start = i + pbits * 2
|
frame_start = i + pbits * 2
|
||||||
frame_end = i + pbits * 2 + (fbits + 1) * 2
|
frame_end = i + pbits * 2 + (fbits + 1) * 2
|
||||||
frame_length = (fbits + 1) * 2
|
frame_length = (fbits + 1) * 2
|
||||||
frame_pulses = self.signal_buffer[frame_start:frame_end]
|
frame_pulses = self.signal_buffer[frame_start:frame_end]
|
||||||
|
|
||||||
msgbin = ""
|
threshold = max(frame_pulses) * 0.2
|
||||||
|
|
||||||
|
msgbin = []
|
||||||
for j in range(0, frame_length, 2):
|
for j in range(0, frame_length, 2):
|
||||||
p2 = frame_pulses[j : j + 2]
|
p2 = frame_pulses[j : j + 2]
|
||||||
if len(p2) < 2:
|
if len(p2) < 2:
|
||||||
break
|
break
|
||||||
|
|
||||||
if p2[0] < th_amp and p2[1] < th_amp:
|
if p2[0] < threshold and p2[1] < threshold:
|
||||||
break
|
break
|
||||||
elif p2[0] >= p2[1]:
|
elif p2[0] >= p2[1]:
|
||||||
c = "1"
|
c = 1
|
||||||
elif p2[0] < p2[1]:
|
elif p2[0] < p2[1]:
|
||||||
c = "0"
|
c = 0
|
||||||
else:
|
else:
|
||||||
msgbin = ""
|
msgbin = []
|
||||||
break
|
break
|
||||||
msgbin += c
|
|
||||||
|
msgbin.append(c)
|
||||||
|
|
||||||
# advance i with a jump
|
# advance i with a jump
|
||||||
i = frame_start + j
|
i = frame_start + j
|
||||||
|
|
||||||
if len(msgbin) > 0:
|
if len(msgbin) > 0:
|
||||||
msghex = pms.bin2hex(msgbin)
|
msghex = pms.bin2hex("".join([str(i) for i in msgbin]))
|
||||||
if self._check_msg(msghex):
|
if self._check_msg(msghex):
|
||||||
messages.append([msghex, time.time()])
|
messages.append([msghex, time.time()])
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self._debug_msg(msghex)
|
self._debug_msg(msghex)
|
||||||
|
|
||||||
elif i > buffer_length - 500:
|
# elif i > buffer_length - 500:
|
||||||
# save some for next process
|
# # save some for next process
|
||||||
break
|
# break
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# keep reminder of buffer for next iteration
|
# reset the buffer
|
||||||
self.signal_buffer = self.signal_buffer[i:]
|
self.signal_buffer = self.signal_buffer[i:]
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def _check_preamble(self, pulses):
|
def _check_preamble(self, pulses):
|
||||||
@@ -122,10 +152,8 @@ class RtlReader(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _read_callback(self, data, rtlsdr_obj):
|
def _read_callback(self, data, rtlsdr_obj):
|
||||||
# scaling signal (imporatant)
|
|
||||||
amp = np.absolute(data)
|
amp = np.absolute(data)
|
||||||
amp_norm = np.interp(amp, (amp.min(), amp.max()), (0, 1))
|
self.signal_buffer.extend(amp.tolist())
|
||||||
self.signal_buffer.extend(amp_norm.tolist())
|
|
||||||
|
|
||||||
if len(self.signal_buffer) >= buffer_size:
|
if len(self.signal_buffer) >= buffer_size:
|
||||||
messages = self._process_buffer()
|
messages = self._process_buffer()
|
||||||
@@ -138,18 +166,25 @@ class RtlReader(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def stop(self, *args, **kwargs):
|
def stop(self, *args, **kwargs):
|
||||||
self.sdr.cancel_read_async()
|
self.sdr.close()
|
||||||
|
|
||||||
def run(self, raw_pipe_in=None, stop_flag=None):
|
def run(self, raw_pipe_in=None, stop_flag=None, exception_queue=None):
|
||||||
self.raw_pipe_in = raw_pipe_in
|
self.raw_pipe_in = raw_pipe_in
|
||||||
|
self.exception_queue = exception_queue
|
||||||
self.stop_flag = stop_flag
|
self.stop_flag = stop_flag
|
||||||
self.sdr.read_samples_async(self._read_callback, read_size)
|
|
||||||
|
|
||||||
# count = 1
|
try:
|
||||||
# while count < 1000:
|
# raise RuntimeError("test exception")
|
||||||
# count += 1
|
|
||||||
# data = self.sdr.read_samples(read_size)
|
while True:
|
||||||
# self._read_callback(data, None)
|
data = self.sdr.read_samples(read_size)
|
||||||
|
self._read_callback(data, None)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
if self.exception_queue is not None:
|
||||||
|
self.exception_queue.put(tb)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"""Stream beast raw data from a TCP server, convert to mode-s messages."""
|
"""Stream beast raw data from a TCP server, convert to mode-s messages."""
|
||||||
|
|
||||||
from __future__ import print_function, division
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@@ -8,11 +7,6 @@ import pyModeS as pms
|
|||||||
import traceback
|
import traceback
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
if sys.version_info > (3, 0):
|
|
||||||
PY_VERSION = 3
|
|
||||||
else:
|
|
||||||
PY_VERSION = 2
|
|
||||||
|
|
||||||
|
|
||||||
class TcpClient(object):
|
class TcpClient(object):
|
||||||
def __init__(self, host, port, datatype):
|
def __init__(self, host, port, datatype):
|
||||||
@@ -29,6 +23,8 @@ class TcpClient(object):
|
|||||||
self.raw_pipe_in = None
|
self.raw_pipe_in = None
|
||||||
self.stop_flag = False
|
self.stop_flag = False
|
||||||
|
|
||||||
|
self.exception_queue = None
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.socket = zmq.Context().socket(zmq.STREAM)
|
self.socket = zmq.Context().socket(zmq.STREAM)
|
||||||
self.socket.setsockopt(zmq.LINGER, 0)
|
self.socket.setsockopt(zmq.LINGER, 0)
|
||||||
@@ -36,7 +32,7 @@ class TcpClient(object):
|
|||||||
self.socket.connect("tcp://%s:%s" % (self.host, self.port))
|
self.socket.connect("tcp://%s:%s" % (self.host, self.port))
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.socket.disconnect()
|
self.socket.close()
|
||||||
|
|
||||||
def read_raw_buffer(self):
|
def read_raw_buffer(self):
|
||||||
""" Read raw ADS-B data type.
|
""" Read raw ADS-B data type.
|
||||||
@@ -170,7 +166,7 @@ class TcpClient(object):
|
|||||||
Start character '$'
|
Start character '$'
|
||||||
|
|
||||||
MS field - Payload
|
MS field - Payload
|
||||||
Postion 1 through 14:
|
Position 1 through 14:
|
||||||
14 bytes = 112 bits
|
14 bytes = 112 bits
|
||||||
Mode-S payload
|
Mode-S payload
|
||||||
In case of DF types that only carry 7 bytes of information
|
In case of DF types that only carry 7 bytes of information
|
||||||
@@ -254,8 +250,9 @@ class TcpClient(object):
|
|||||||
for msg, t in messages:
|
for msg, t in messages:
|
||||||
print("%15.9f %s" % (t, msg))
|
print("%15.9f %s" % (t, msg))
|
||||||
|
|
||||||
def run(self, raw_pipe_in=None, stop_flag=None):
|
def run(self, raw_pipe_in=None, stop_flag=None, exception_queue=None):
|
||||||
self.raw_pipe_in = raw_pipe_in
|
self.raw_pipe_in = raw_pipe_in
|
||||||
|
self.exception_queue = exception_queue
|
||||||
self.stop_flag = stop_flag
|
self.stop_flag = stop_flag
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
@@ -263,17 +260,9 @@ class TcpClient(object):
|
|||||||
try:
|
try:
|
||||||
received = [i for i in self.socket.recv(4096)]
|
received = [i for i in self.socket.recv(4096)]
|
||||||
|
|
||||||
if PY_VERSION == 2:
|
|
||||||
received = [ord(i) for i in received]
|
|
||||||
|
|
||||||
self.buffer.extend(received)
|
self.buffer.extend(received)
|
||||||
# print(''.join(x.encode('hex') for x in self.buffer))
|
# print(''.join(x.encode('hex') for x in self.buffer))
|
||||||
|
|
||||||
# process self.buffer when it is longer enough
|
|
||||||
# if len(self.buffer) < 2048:
|
|
||||||
# continue
|
|
||||||
# -- Removed!! Cause delay in low data rate scenario --
|
|
||||||
|
|
||||||
if self.datatype == "beast":
|
if self.datatype == "beast":
|
||||||
messages = self.read_beast_buffer()
|
messages = self.read_beast_buffer()
|
||||||
elif self.datatype == "raw":
|
elif self.datatype == "raw":
|
||||||
@@ -286,22 +275,15 @@ class TcpClient(object):
|
|||||||
else:
|
else:
|
||||||
self.handle_messages(messages)
|
self.handle_messages(messages)
|
||||||
|
|
||||||
except Exception as e:
|
# raise RuntimeError("test exception")
|
||||||
# Provides the user an option to supply the environment
|
|
||||||
# variable PYMODES_DEBUG to halt the execution
|
|
||||||
# for debugging purposes
|
|
||||||
debug_intent = os.environ.get("PYMODES_DEBUG", "false")
|
|
||||||
if debug_intent.lower() == "true":
|
|
||||||
traceback.print_exc()
|
|
||||||
sys.exit()
|
|
||||||
else:
|
|
||||||
print("Unexpected Error:", e)
|
|
||||||
|
|
||||||
try:
|
except zmq.error.Again:
|
||||||
sock = self.connect()
|
continue
|
||||||
time.sleep(1)
|
except Exception as e:
|
||||||
except Exception as e:
|
tb = traceback.format_exc()
|
||||||
print("Unexpected Error:", e)
|
if self.exception_queue is not None:
|
||||||
|
self.exception_queue.put(tb)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -310,4 +292,7 @@ if __name__ == "__main__":
|
|||||||
port = int(sys.argv[2])
|
port = int(sys.argv[2])
|
||||||
datatype = sys.argv[3]
|
datatype = sys.argv[3]
|
||||||
client = TcpClient(host=host, port=port, datatype=datatype)
|
client = TcpClient(host=host, port=port, datatype=datatype)
|
||||||
client.run()
|
try:
|
||||||
|
client.run()
|
||||||
|
finally:
|
||||||
|
client.stop()
|
||||||
|
|||||||
0
pyModeS/py.typed
Normal file
0
pyModeS/py.typed
Normal file
@@ -1,61 +1,46 @@
|
|||||||
from __future__ import absolute_import, print_function, division
|
from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
|
|
||||||
|
|
||||||
def hex2bin(hexstr):
|
def hex2bin(hexstr: str) -> str:
|
||||||
"""Convert a hexdecimal string to binary string, with zero fillings."""
|
"""Convert a hexadecimal string to binary string, with zero fillings."""
|
||||||
num_of_bits = len(hexstr) * 4
|
num_of_bits = len(hexstr) * 4
|
||||||
binstr = bin(int(hexstr, 16))[2:].zfill(int(num_of_bits))
|
binstr = bin(int(hexstr, 16))[2:].zfill(int(num_of_bits))
|
||||||
return binstr
|
return binstr
|
||||||
|
|
||||||
|
|
||||||
def hex2int(hexstr):
|
def hex2int(hexstr: str) -> int:
|
||||||
"""Convert a hexdecimal string to integer."""
|
"""Convert a hexadecimal string to integer."""
|
||||||
return int(hexstr, 16)
|
return int(hexstr, 16)
|
||||||
|
|
||||||
|
|
||||||
def int2hex(n):
|
def bin2int(binstr: str) -> int:
|
||||||
"""Convert a integer to hexadecimal string."""
|
|
||||||
# strip 'L' for python 2
|
|
||||||
return hex(n)[2:].rjust(6, "0").upper().rstrip("L")
|
|
||||||
|
|
||||||
|
|
||||||
def bin2int(binstr):
|
|
||||||
"""Convert a binary string to integer."""
|
"""Convert a binary string to integer."""
|
||||||
return int(binstr, 2)
|
return int(binstr, 2)
|
||||||
|
|
||||||
|
|
||||||
def bin2hex(hexstr):
|
def bin2hex(binstr: str) -> str:
|
||||||
"""Convert a hexdecimal string to integer."""
|
"""Convert a binary string to hexadecimal string."""
|
||||||
return int2hex(bin2int(hexstr))
|
return "{0:X}".format(int(binstr, 2))
|
||||||
|
|
||||||
|
|
||||||
def bin2np(binstr):
|
def df(msg: str) -> int:
|
||||||
"""Convert a binary string to numpy array."""
|
"""Decode Downlink Format value, bits 1 to 5."""
|
||||||
return np.array([int(i) for i in binstr])
|
dfbin = hex2bin(msg[:2])
|
||||||
|
return min(bin2int(dfbin[0:5]), 24)
|
||||||
|
|
||||||
|
|
||||||
def np2bin(npbin):
|
def crc(msg: str, encode: bool = False) -> int:
|
||||||
"""Convert a binary numpy array to string."""
|
|
||||||
return np.array2string(npbin, separator="")[1:-1]
|
|
||||||
|
|
||||||
|
|
||||||
def df(msg):
|
|
||||||
"""Decode Downlink Format vaule, bits 1 to 5."""
|
|
||||||
msgbin = hex2bin(msg)
|
|
||||||
return min(bin2int(msgbin[0:5]), 24)
|
|
||||||
|
|
||||||
|
|
||||||
def crc(msg, encode=False):
|
|
||||||
"""Mode-S Cyclic Redundancy Check.
|
"""Mode-S Cyclic Redundancy Check.
|
||||||
|
|
||||||
Detect if bit error occurs in the Mode-S message. When encode option is on,
|
Detect if bit error occurs in the Mode-S message. When encode option is on,
|
||||||
the checksum is generated.
|
the checksum is generated.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (string): 28 bytes hexadecimal message string
|
msg: 28 bytes hexadecimal message string
|
||||||
encode (bool): True to encode the date only and return the checksum
|
encode: True to encode the date only and return the checksum
|
||||||
Returns:
|
Returns:
|
||||||
int: message checksum, or partity bits (encoder)
|
int: message checksum, or partity bits (encoder)
|
||||||
|
|
||||||
@@ -92,7 +77,7 @@ def crc(msg, encode=False):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def crc_legacy(msg, encode=False):
|
def crc_legacy(msg: str, encode: bool = False) -> int:
|
||||||
"""Mode-S Cyclic Redundancy Check. (Legacy code, 2x slow)."""
|
"""Mode-S Cyclic Redundancy Check. (Legacy code, 2x slow)."""
|
||||||
# the polynominal generattor code for CRC [1111111111111010000001001]
|
# the polynominal generattor code for CRC [1111111111111010000001001]
|
||||||
generator = np.array(
|
generator = np.array(
|
||||||
@@ -100,7 +85,7 @@ def crc_legacy(msg, encode=False):
|
|||||||
)
|
)
|
||||||
ng = len(generator)
|
ng = len(generator)
|
||||||
|
|
||||||
msgnpbin = bin2np(hex2bin(msg))
|
msgnpbin = np.array([int(i) for i in hex2bin(msg)])
|
||||||
|
|
||||||
if encode:
|
if encode:
|
||||||
msgnpbin[-24:] = [0] * 24
|
msgnpbin[-24:] = [0] * 24
|
||||||
@@ -114,11 +99,13 @@ def crc_legacy(msg, encode=False):
|
|||||||
msgnpbin[i : i + ng] = np.bitwise_xor(msgnpbin[i : i + ng], generator)
|
msgnpbin[i : i + ng] = np.bitwise_xor(msgnpbin[i : i + ng], generator)
|
||||||
|
|
||||||
# last 24 bits
|
# last 24 bits
|
||||||
reminder = bin2int(np2bin(msgnpbin[-24:]))
|
msgbin = np.array2string(msgnpbin[-24:], separator="")[1:-1]
|
||||||
|
reminder = bin2int(msgbin)
|
||||||
|
|
||||||
return reminder
|
return reminder
|
||||||
|
|
||||||
|
|
||||||
def floor(x):
|
def floor(x: float) -> int:
|
||||||
"""Mode-S floor function.
|
"""Mode-S floor function.
|
||||||
|
|
||||||
Defined as the greatest integer value k, such that k <= x
|
Defined as the greatest integer value k, such that k <= x
|
||||||
@@ -128,7 +115,7 @@ def floor(x):
|
|||||||
return int(np.floor(x))
|
return int(np.floor(x))
|
||||||
|
|
||||||
|
|
||||||
def icao(msg):
|
def icao(msg: str) -> Optional[str]:
|
||||||
"""Calculate the ICAO address from an Mode-S message.
|
"""Calculate the ICAO address from an Mode-S message.
|
||||||
|
|
||||||
Applicable only with DF4, DF5, DF20, DF21 messages.
|
Applicable only with DF4, DF5, DF20, DF21 messages.
|
||||||
@@ -140,13 +127,14 @@ def icao(msg):
|
|||||||
String: ICAO address in 6 bytes hexadecimal string
|
String: ICAO address in 6 bytes hexadecimal string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
addr: Optional[str]
|
||||||
DF = df(msg)
|
DF = df(msg)
|
||||||
|
|
||||||
if DF in (11, 17, 18):
|
if DF in (11, 17, 18):
|
||||||
addr = msg[2:8]
|
addr = msg[2:8]
|
||||||
elif DF in (0, 4, 5, 16, 20, 21):
|
elif DF in (0, 4, 5, 16, 20, 21):
|
||||||
c0 = crc(msg, encode=True)
|
c0 = crc(msg, encode=True)
|
||||||
c1 = hex2int(msg[-6:])
|
c1 = int(msg[-6:], 16)
|
||||||
addr = "%06X" % (c0 ^ c1)
|
addr = "%06X" % (c0 ^ c1)
|
||||||
else:
|
else:
|
||||||
addr = None
|
addr = None
|
||||||
@@ -154,12 +142,12 @@ def icao(msg):
|
|||||||
return addr
|
return addr
|
||||||
|
|
||||||
|
|
||||||
def is_icao_assigned(icao):
|
def is_icao_assigned(icao: str) -> bool:
|
||||||
"""Check whether the ICAO address is assigned (Annex 10, Vol 3)."""
|
"""Check whether the ICAO address is assigned (Annex 10, Vol 3)."""
|
||||||
if (icao is None) or (not isinstance(icao, str)) or (len(icao) != 6):
|
if (icao is None) or (not isinstance(icao, str)) or (len(icao) != 6):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
icaoint = hex2int(icao)
|
icaoint = int(icao, 16)
|
||||||
|
|
||||||
if 0x200000 < icaoint < 0x27FFFF:
|
if 0x200000 < icaoint < 0x27FFFF:
|
||||||
return False # AFI
|
return False # AFI
|
||||||
@@ -183,7 +171,7 @@ def is_icao_assigned(icao):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def typecode(msg):
|
def typecode(msg: str) -> Optional[int]:
|
||||||
"""Type code of ADS-B message
|
"""Type code of ADS-B message
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -195,35 +183,30 @@ def typecode(msg):
|
|||||||
if df(msg) not in (17, 18):
|
if df(msg) not in (17, 18):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
msgbin = hex2bin(msg)
|
tcbin = hex2bin(msg[8:10])
|
||||||
return bin2int(msgbin[32:37])
|
return bin2int(tcbin[0:5])
|
||||||
|
|
||||||
|
|
||||||
def cprNL(lat):
|
def cprNL(lat: float) -> int:
|
||||||
"""NL() function in CPR decoding."""
|
"""NL() function in CPR decoding."""
|
||||||
|
|
||||||
if lat == 0:
|
if np.isclose(lat, 0):
|
||||||
return 59
|
return 59
|
||||||
|
elif np.isclose(abs(lat), 87):
|
||||||
if lat == 87 or lat == -87:
|
|
||||||
return 2
|
return 2
|
||||||
|
elif lat > 87 or lat < -87:
|
||||||
if lat > 87 or lat < -87:
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
nz = 15
|
nz = 15
|
||||||
a = 1 - np.cos(np.pi / (2 * nz))
|
a = 1 - np.cos(np.pi / (2 * nz))
|
||||||
b = np.cos(np.pi / 180.0 * abs(lat)) ** 2
|
b = np.cos(np.pi / 180 * abs(lat)) ** 2
|
||||||
nl = 2 * np.pi / (np.arccos(1 - a / b))
|
nl = 2 * np.pi / (np.arccos(1 - a / b))
|
||||||
NL = floor(nl)
|
NL = floor(nl)
|
||||||
return NL
|
return NL
|
||||||
|
|
||||||
|
|
||||||
def idcode(msg):
|
def idcode(msg: str) -> str:
|
||||||
"""Compute identity (squawk code).
|
"""Compute identity code (squawk) encoded in DF5 or DF21 message.
|
||||||
|
|
||||||
Applicable only for DF5 or DF21 messages, bit 20-32.
|
|
||||||
credit: @fbyrkjeland
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (String): 28 bytes hexadecimal message string
|
||||||
@@ -236,20 +219,37 @@ def idcode(msg):
|
|||||||
raise RuntimeError("Message must be Downlink Format 5 or 21.")
|
raise RuntimeError("Message must be Downlink Format 5 or 21.")
|
||||||
|
|
||||||
mbin = hex2bin(msg)
|
mbin = hex2bin(msg)
|
||||||
|
idcodebin = mbin[19:32]
|
||||||
|
|
||||||
C1 = mbin[19]
|
return squawk(idcodebin)
|
||||||
A1 = mbin[20]
|
|
||||||
C2 = mbin[21]
|
|
||||||
A2 = mbin[22]
|
def squawk(binstr: str) -> str:
|
||||||
C4 = mbin[23]
|
"""Decode 13 bits identity (squawk) code.
|
||||||
A4 = mbin[24]
|
|
||||||
# _ = mbin[25]
|
Args:
|
||||||
B1 = mbin[26]
|
binstr (String): 13 bits binary string
|
||||||
D1 = mbin[27]
|
|
||||||
B2 = mbin[28]
|
Returns:
|
||||||
D2 = mbin[29]
|
int: altitude in ft
|
||||||
B4 = mbin[30]
|
|
||||||
D4 = mbin[31]
|
"""
|
||||||
|
if len(binstr) != 13 or not set(binstr).issubset(set("01")):
|
||||||
|
raise RuntimeError("Input must be 13 bits binary string")
|
||||||
|
|
||||||
|
C1 = binstr[0]
|
||||||
|
A1 = binstr[1]
|
||||||
|
C2 = binstr[2]
|
||||||
|
A2 = binstr[3]
|
||||||
|
C4 = binstr[4]
|
||||||
|
A4 = binstr[5]
|
||||||
|
# X = binstr[6]
|
||||||
|
B1 = binstr[7]
|
||||||
|
D1 = binstr[8]
|
||||||
|
B2 = binstr[9]
|
||||||
|
D2 = binstr[10]
|
||||||
|
B4 = binstr[11]
|
||||||
|
D4 = binstr[12]
|
||||||
|
|
||||||
byte1 = int(A4 + A2 + A1, 2)
|
byte1 = int(A4 + A2 + A1, 2)
|
||||||
byte2 = int(B4 + B2 + B1, 2)
|
byte2 = int(B4 + B2 + B1, 2)
|
||||||
@@ -259,11 +259,8 @@ def idcode(msg):
|
|||||||
return str(byte1) + str(byte2) + str(byte3) + str(byte4)
|
return str(byte1) + str(byte2) + str(byte3) + str(byte4)
|
||||||
|
|
||||||
|
|
||||||
def altcode(msg):
|
def altcode(msg: str) -> Optional[int]:
|
||||||
"""Compute the altitude.
|
"""Compute altitude encoded in DF4 or DF20 message.
|
||||||
|
|
||||||
Applicable only for DF4 or DF20 message, bit 20-32.
|
|
||||||
credit: @fbyrkjeland
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
msg (String): 28 bytes hexadecimal message string
|
msg (String): 28 bytes hexadecimal message string
|
||||||
@@ -272,50 +269,78 @@ def altcode(msg):
|
|||||||
int: altitude in ft
|
int: altitude in ft
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
alt: Optional[int]
|
||||||
|
|
||||||
if df(msg) not in [0, 4, 16, 20]:
|
if df(msg) not in [0, 4, 16, 20]:
|
||||||
raise RuntimeError("Message must be Downlink Format 0, 4, 16, or 20.")
|
raise RuntimeError("Message must be Downlink Format 0, 4, 16, or 20.")
|
||||||
|
|
||||||
# Altitude code, bit 20-32
|
# Altitude code, bit 20-32
|
||||||
mbin = hex2bin(msg)
|
mbin = hex2bin(msg)
|
||||||
|
|
||||||
mbit = mbin[25] # M bit: 26
|
altitude_code = mbin[19:32]
|
||||||
qbit = mbin[27] # Q bit: 28
|
|
||||||
|
|
||||||
if mbit == "0": # unit in ft
|
alt = altitude(altitude_code)
|
||||||
if qbit == "1": # 25ft interval
|
|
||||||
vbin = mbin[19:25] + mbin[26] + mbin[28:32]
|
return alt
|
||||||
|
|
||||||
|
|
||||||
|
def altitude(binstr: str) -> Optional[int]:
|
||||||
|
"""Decode 13 bits altitude code.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
binstr (String): 13 bits binary string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: altitude in ft
|
||||||
|
|
||||||
|
"""
|
||||||
|
alt: Optional[int]
|
||||||
|
|
||||||
|
if len(binstr) != 13 or not set(binstr).issubset(set("01")):
|
||||||
|
raise RuntimeError("Input must be 13 bits binary string")
|
||||||
|
|
||||||
|
Mbit = binstr[6]
|
||||||
|
Qbit = binstr[8]
|
||||||
|
|
||||||
|
if bin2int(binstr) == 0:
|
||||||
|
# altitude unknown or invalid
|
||||||
|
alt = None
|
||||||
|
|
||||||
|
elif Mbit == "0": # unit in ft
|
||||||
|
if Qbit == "1": # 25ft interval
|
||||||
|
vbin = binstr[:6] + binstr[7] + binstr[9:]
|
||||||
alt = bin2int(vbin) * 25 - 1000
|
alt = bin2int(vbin) * 25 - 1000
|
||||||
if qbit == "0": # 100ft interval, above 50175ft
|
if Qbit == "0": # 100ft interval, above 50187.5ft
|
||||||
C1 = mbin[19]
|
C1 = binstr[0]
|
||||||
A1 = mbin[20]
|
A1 = binstr[1]
|
||||||
C2 = mbin[21]
|
C2 = binstr[2]
|
||||||
A2 = mbin[22]
|
A2 = binstr[3]
|
||||||
C4 = mbin[23]
|
C4 = binstr[4]
|
||||||
A4 = mbin[24]
|
A4 = binstr[5]
|
||||||
# _ = mbin[25]
|
# M = binstr[6]
|
||||||
B1 = mbin[26]
|
B1 = binstr[7]
|
||||||
# D1 = mbin[27] # always zero
|
# Q = binstr[8]
|
||||||
B2 = mbin[28]
|
B2 = binstr[9]
|
||||||
D2 = mbin[29]
|
D2 = binstr[10]
|
||||||
B4 = mbin[30]
|
B4 = binstr[11]
|
||||||
D4 = mbin[31]
|
D4 = binstr[12]
|
||||||
|
|
||||||
graystr = D2 + D4 + A1 + A2 + A4 + B1 + B2 + B4 + C1 + C2 + C4
|
graystr = D2 + D4 + A1 + A2 + A4 + B1 + B2 + B4 + C1 + C2 + C4
|
||||||
alt = gray2alt(graystr)
|
alt = gray2alt(graystr)
|
||||||
|
|
||||||
if mbit == "1": # unit in meter
|
if Mbit == "1": # unit in meter
|
||||||
vbin = mbin[19:25] + mbin[26:31]
|
vbin = binstr[:6] + binstr[7:]
|
||||||
alt = int(bin2int(vbin) * 3.28084) # convert to ft
|
alt = int(bin2int(vbin) * 3.28084) # convert to ft
|
||||||
|
|
||||||
return alt
|
return alt
|
||||||
|
|
||||||
|
|
||||||
def gray2alt(codestr):
|
def gray2alt(binstr: str) -> Optional[int]:
|
||||||
gc500 = codestr[:8]
|
gc500 = binstr[:8]
|
||||||
n500 = gray2int(gc500)
|
n500 = gray2int(gc500)
|
||||||
|
|
||||||
# in 100-ft step must be converted first
|
# in 100-ft step must be converted first
|
||||||
gc100 = codestr[8:]
|
gc100 = binstr[8:]
|
||||||
n100 = gray2int(gc100)
|
n100 = gray2int(gc100)
|
||||||
|
|
||||||
if n100 in [0, 5, 6]:
|
if n100 in [0, 5, 6]:
|
||||||
@@ -331,9 +356,9 @@ def gray2alt(codestr):
|
|||||||
return alt
|
return alt
|
||||||
|
|
||||||
|
|
||||||
def gray2int(graystr):
|
def gray2int(binstr: str) -> int:
|
||||||
"""Convert greycode to binary."""
|
"""Convert greycode to binary."""
|
||||||
num = bin2int(graystr)
|
num = bin2int(binstr)
|
||||||
num ^= num >> 8
|
num ^= num >> 8
|
||||||
num ^= num >> 4
|
num ^= num >> 4
|
||||||
num ^= num >> 2
|
num ^= num >> 2
|
||||||
@@ -341,12 +366,12 @@ def gray2int(graystr):
|
|||||||
return num
|
return num
|
||||||
|
|
||||||
|
|
||||||
def data(msg):
|
def data(msg: str) -> str:
|
||||||
"""Return the data frame in the message, bytes 9 to 22."""
|
"""Return the data frame in the message, bytes 9 to 22."""
|
||||||
return msg[8:-6]
|
return msg[8:-6]
|
||||||
|
|
||||||
|
|
||||||
def allzeros(msg):
|
def allzeros(msg: str) -> bool:
|
||||||
"""Check if the data bits are all zeros.
|
"""Check if the data bits are all zeros.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -364,7 +389,7 @@ def allzeros(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def wrongstatus(data, sb, msb, lsb):
|
def wrongstatus(data: str, sb: int, msb: int, lsb: int) -> bool:
|
||||||
"""Check if the status bit and field bits are consistency.
|
"""Check if the status bit and field bits are consistency.
|
||||||
|
|
||||||
This Function is used for checking BDS code versions.
|
This Function is used for checking BDS code versions.
|
||||||
@@ -379,3 +404,85 @@ def wrongstatus(data, sb, msb, lsb):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def fs(msg):
|
||||||
|
"""Decode flight status for DF 4, 5, 20, and 21.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: flight status, description
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgbin = hex2bin(msg)
|
||||||
|
fs = bin2int(msgbin[5:8])
|
||||||
|
text = None
|
||||||
|
|
||||||
|
if fs == 0:
|
||||||
|
text = "no alert, no SPI, aircraft is airborne"
|
||||||
|
elif fs == 1:
|
||||||
|
text = "no alert, no SPI, aircraft is on-ground"
|
||||||
|
elif fs == 2:
|
||||||
|
text = "alert, no SPI, aircraft is airborne"
|
||||||
|
elif fs == 3:
|
||||||
|
text = "alert, no SPI, aircraft is on-ground"
|
||||||
|
elif fs == 4:
|
||||||
|
text = "alert, SPI, aircraft is airborne or on-ground"
|
||||||
|
elif fs == 5:
|
||||||
|
text = "no alert, SPI, aircraft is airborne or on-ground"
|
||||||
|
|
||||||
|
return fs, text
|
||||||
|
|
||||||
|
|
||||||
|
def dr(msg):
|
||||||
|
"""Decode downlink request for DF 4, 5, 20, and 21.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: downlink request, description
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgbin = hex2bin(msg)
|
||||||
|
dr = bin2int(msgbin[8:13])
|
||||||
|
|
||||||
|
text = None
|
||||||
|
|
||||||
|
if dr == 0:
|
||||||
|
text = "no downlink request"
|
||||||
|
elif dr == 1:
|
||||||
|
text = "request to send Comm-B message"
|
||||||
|
elif dr == 4:
|
||||||
|
text = "Comm-B broadcast 1 available"
|
||||||
|
elif dr == 5:
|
||||||
|
text = "Comm-B broadcast 2 available"
|
||||||
|
elif dr >= 16:
|
||||||
|
text = "ELM downlink segments available: {}".format(dr - 15)
|
||||||
|
|
||||||
|
return dr, text
|
||||||
|
|
||||||
|
|
||||||
|
def um(msg):
|
||||||
|
"""Decode utility message for DF 4, 5, 20, and 21.
|
||||||
|
|
||||||
|
Utility message contains interrogator identifier and reservation type.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): 14 hexdigits string
|
||||||
|
Returns:
|
||||||
|
int, str: interrogator identifier code that triggered the reply, and
|
||||||
|
reservation type made by the interrogator
|
||||||
|
"""
|
||||||
|
msgbin = hex2bin(msg)
|
||||||
|
iis = bin2int(msgbin[13:17])
|
||||||
|
ids = bin2int(msgbin[17:19])
|
||||||
|
if ids == 0:
|
||||||
|
ids_text = None
|
||||||
|
if ids == 1:
|
||||||
|
ids_text = "Comm-B interrogator identifier code"
|
||||||
|
if ids == 2:
|
||||||
|
ids_text = "Comm-C interrogator identifier code"
|
||||||
|
if ids == 3:
|
||||||
|
ids_text = "Comm-D interrogator identifier code"
|
||||||
|
return iis, ids, ids_text
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user