Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
220b8e9716 | ||
|
|
3691d6f73d | ||
|
|
dad1cd89a9 | ||
|
|
3b3fc27a42 | ||
|
|
4bafa1de19 | ||
|
|
b648f4e7a5 | ||
|
|
a08c91a3a1 | ||
|
|
567fcda931 | ||
|
|
56dbb618c6 | ||
|
|
58447346aa | ||
|
|
bccc319856 | ||
|
|
375041717b | ||
|
|
23192a97fd | ||
|
|
240f706e81 | ||
|
|
168acfb88d | ||
|
|
70e9aa7c8d | ||
|
|
fc286299ec | ||
|
|
700b290047 | ||
|
|
55fbdcd029 | ||
|
|
7a62d1dbfb | ||
|
|
2f89d1a95c | ||
|
|
2fccacd724 | ||
|
|
556e499064 | ||
|
|
5518816b32 | ||
|
|
faf43134e5 | ||
|
|
4666de403d | ||
|
|
a196d673df | ||
|
|
8ef02fa2b1 | ||
|
|
72f2bcd275 | ||
|
|
1ccd4fd83b |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -54,3 +54,6 @@ docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
65
README.rst
65
README.rst
@@ -1,29 +1,31 @@
|
||||
A Python Mode-S Decoder
|
||||
=======================
|
||||
|
||||
Python library for Mode-S message decoding. Two seprate methods are
|
||||
develop to decode the following messages:
|
||||
Python library for Mode-S message decoding. Two separate methods are
|
||||
implemented to decode the following messages:
|
||||
|
||||
- Automatic Dependent Surveillance - Broadcast (ADS-B) (DF17)
|
||||
|
||||
- aircraft infomation that cotains: icao address, position,
|
||||
altitude, velocity (ground speed), and callsign, etc.
|
||||
- aircraft information that contains: ICAO address, position,
|
||||
altitude, velocity (ground speed), callsign, etc.
|
||||
|
||||
- Mode-S Enhanced Surveillance (EHS) (DF20 and DF21)
|
||||
|
||||
- additional information in response to SSR interogation, such as:
|
||||
- additional information in response to SSR interrogation, such as:
|
||||
true airspeed, indicated airspeed, mach number, track angle,
|
||||
heading, and roll angle, etc.
|
||||
heading, roll angle, etc.
|
||||
|
||||
A detailed manuel on Mode-S decoding is published by the author, at:
|
||||
http://adsb-decode-guide.readthedocs.org
|
||||
A detailed manual on Mode-S decoding is published by the author, at:
|
||||
http://adsb-decode-guide.readthedocs.io
|
||||
|
||||
|
||||
Source code
|
||||
-----------
|
||||
Checkourt and contribute to this open source project at:
|
||||
Checkout and contribute to this open source project at:
|
||||
https://github.com/junzis/pyModeS
|
||||
|
||||
API documentation at:
|
||||
http://pymodes.readthedocs.io
|
||||
|
||||
Install
|
||||
-------
|
||||
@@ -41,22 +43,49 @@ Usage
|
||||
|
||||
import pyModeS as pms
|
||||
|
||||
|
||||
Common function for Mode-S message:
|
||||
|
||||
.. code:: python
|
||||
|
||||
pms.df(msg) # Downlink Format
|
||||
pms.crc(msg, encode=False) # Perform CRC or generate parity bit
|
||||
|
||||
pms.hex2bin(str) # Convert hexadecimal string to binary string
|
||||
pms.bin2int(str) # Convert binary string to integer
|
||||
pms.hex2int(str) # Convert hexadecimal string to integer
|
||||
|
||||
|
||||
Core functions for ADS-B decoding:
|
||||
|
||||
.. code:: python
|
||||
|
||||
pms.adsb.icao(msg)
|
||||
pms.adsb.callsign(msg)
|
||||
pms.adsb.position(msg_odd, msg_even, t_odd, t_even)
|
||||
|
||||
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.surface_position(msg_even, msg_odd, t_even, t_odd, lat_ref, lon_ref)
|
||||
|
||||
pms.adsb.position_with_ref(msg, lat_ref, lon_ref)
|
||||
pms.adsb.airborne_position_with_ref(msg, lat_ref, lon_ref)
|
||||
pms.adsb.surface_position_with_ref(msg, lat_ref, lon_ref)
|
||||
|
||||
pms.adsb.altitude(msg)
|
||||
pms.adsb.velocity(msg)
|
||||
pms.adsb.speed_heading(msg)
|
||||
|
||||
**Hint: When you have a fix position of the aircraft, it is convenient to
|
||||
use `position_with_ref()` method to decode with only one position message
|
||||
(either odd or even). This works with both airborne and surface position
|
||||
messages. But the reference position shall be with in 180NM (airborne)
|
||||
or 45NM (surface) of the true position.**
|
||||
|
||||
Core functions for EHS decoding:
|
||||
|
||||
.. code:: python
|
||||
|
||||
pms.ehs.icao(msg) # icao address
|
||||
pms.ehs.icao(msg) # ICAO address
|
||||
pms.ehs.BDS(msg) # Comm-B Data Selector Version
|
||||
|
||||
# for BDS version 2,0
|
||||
@@ -81,11 +110,9 @@ Core functions for EHS decoding:
|
||||
pms.ehs.baro_vr(msg) # barometric altitude rate (ft/min)
|
||||
pms.ehs.ins_vr(msg) # inertial vertical speed (ft/min)
|
||||
|
||||
Some helper functions:
|
||||
|
||||
.. code:: python
|
||||
|
||||
pms.df(msg) # downlink format of a Mode-S message
|
||||
pms.hex2bin(msg) # convert hexadecimal string to binary string
|
||||
pms.hex2int(msg) # convert hexadecimal string to integer
|
||||
pms.bin2int(msg) # convert binary string to integer
|
||||
Developement
|
||||
------------
|
||||
To run tests, run the following commands:
|
||||
```
|
||||
$ tox
|
||||
```
|
||||
|
||||
3
doc/.gitignore
vendored
Normal file
3
doc/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
_build
|
||||
_static
|
||||
_templates
|
||||
225
doc/Makefile
Normal file
225
doc/Makefile
Normal file
@@ -0,0 +1,225 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " applehelp to make an Apple Help Book"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " epub3 to make an epub3"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
@echo " coverage to run coverage check of the documentation (if enabled)"
|
||||
@echo " dummy to check syntax errors of document sources"
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
.PHONY: html
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
.PHONY: dirhtml
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
.PHONY: singlehtml
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
.PHONY: pickle
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
.PHONY: json
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
.PHONY: htmlhelp
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
.PHONY: qthelp
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pyModeS.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pyModeS.qhc"
|
||||
|
||||
.PHONY: applehelp
|
||||
applehelp:
|
||||
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
|
||||
@echo
|
||||
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
|
||||
@echo "N.B. You won't be able to view it unless you put it in" \
|
||||
"~/Library/Documentation/Help or install it in your application" \
|
||||
"bundle."
|
||||
|
||||
.PHONY: devhelp
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/pyModeS"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pyModeS"
|
||||
@echo "# devhelp"
|
||||
|
||||
.PHONY: epub
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
.PHONY: epub3
|
||||
epub3:
|
||||
$(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
|
||||
@echo
|
||||
@echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
|
||||
|
||||
.PHONY: latex
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
.PHONY: latexpdf
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
.PHONY: latexpdfja
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
.PHONY: text
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
.PHONY: man
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
.PHONY: texinfo
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
.PHONY: info
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
.PHONY: gettext
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
.PHONY: changes
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
.PHONY: linkcheck
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
.PHONY: doctest
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
.PHONY: coverage
|
||||
coverage:
|
||||
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
|
||||
@echo "Testing of coverage in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/coverage/python.txt."
|
||||
|
||||
.PHONY: xml
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
.PHONY: pseudoxml
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
||||
|
||||
.PHONY: dummy
|
||||
dummy:
|
||||
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
|
||||
@echo
|
||||
@echo "Build finished. Dummy builder generates no files."
|
||||
337
doc/conf.py
Normal file
337
doc/conf.py
Normal file
@@ -0,0 +1,337 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# pyModeS documentation build configuration file, created by
|
||||
# sphinx-quickstart on Tue Aug 16 15:47:05 2016.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.doctest',
|
||||
'sphinx.ext.todo',
|
||||
'sphinx.ext.coverage',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'pyModeS'
|
||||
copyright = u'2016, Junzi Sun'
|
||||
author = u'Junzi Sun'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'1.0.5'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'1.0.5'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#
|
||||
# today = ''
|
||||
#
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#
|
||||
# default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
# keep_warnings = False
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = True
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
# html_theme = 'alabaster'
|
||||
|
||||
# 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
|
||||
# documentation.
|
||||
#
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents.
|
||||
# "<project> v<release> documentation" by default.
|
||||
#
|
||||
# html_title = u'pyModeS v1.0.5'
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (relative to this directory) to use as a favicon of
|
||||
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
#
|
||||
# html_extra_path = []
|
||||
|
||||
# If not None, a 'Last updated on:' timestamp is inserted at every page
|
||||
# bottom, using the given strftime format.
|
||||
# The empty string is equivalent to '%b %d, %Y'.
|
||||
#
|
||||
# html_last_updated_fmt = None
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Language to be used for generating the HTML full-text search index.
|
||||
# Sphinx supports the following languages:
|
||||
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
|
||||
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
|
||||
#
|
||||
# html_search_language = 'en'
|
||||
|
||||
# A dictionary with options for the search language support, empty by default.
|
||||
# 'ja' uses this config value.
|
||||
# 'zh' user can custom change `jieba` dictionary path.
|
||||
#
|
||||
# html_search_options = {'type': 'default'}
|
||||
|
||||
# The name of a javascript file (relative to the configuration directory) that
|
||||
# implements a search results scorer. If empty, the default will be used.
|
||||
#
|
||||
# html_search_scorer = 'scorer.js'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'pyModeSdoc'
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'pyModeS.tex', u'pyModeS Documentation',
|
||||
u'Junzi Sun', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'pymodes', u'pyModeS Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'pyModeS', u'pyModeS Documentation',
|
||||
author, 'pyModeS', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#
|
||||
# texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#
|
||||
# texinfo_no_detailmenu = False
|
||||
40
doc/index.rst
Normal file
40
doc/index.rst
Normal file
@@ -0,0 +1,40 @@
|
||||
.. pyModeS documentation master file, created by
|
||||
sphinx-quickstart on Tue Aug 16 15:47:05 2016.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
|
||||
pyModeS APIs
|
||||
=====================
|
||||
|
||||
This document contains all the functions within pyModeS package.
|
||||
|
||||
Source code and user guide: https://github.com/junzis/pyModeS
|
||||
|
||||
|
||||
pyModeS.adsb module
|
||||
-------------------
|
||||
|
||||
.. automodule:: pyModeS.adsb
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
pyModeS.ehs module
|
||||
------------------
|
||||
|
||||
.. automodule:: pyModeS.ehs
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
pyModeS.util module
|
||||
-------------------
|
||||
|
||||
.. automodule:: pyModeS.util
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
1
doc/requirements.txt
Normal file
1
doc/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
pyModeS==1.0.5
|
||||
@@ -1,3 +1,5 @@
|
||||
from util import hex2bin, bin2int, hex2int, df
|
||||
import adsb
|
||||
import ehs
|
||||
from __future__ import absolute_import, print_function, division
|
||||
|
||||
from .util import *
|
||||
from . import adsb
|
||||
from . import ehs
|
||||
|
||||
355
pyModeS/adsb.py
355
pyModeS/adsb.py
@@ -1,60 +1,32 @@
|
||||
# Copyright (C) 2015 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/>.
|
||||
|
||||
"""
|
||||
A python package for decoding ABS-D messages.
|
||||
|
||||
Copyright (C) 2015 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/>.
|
||||
"""
|
||||
|
||||
import math
|
||||
import util
|
||||
|
||||
|
||||
def checksum(msg):
|
||||
"""CRC check the ADS-B message
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
Returns:
|
||||
bool: Checksum passed or not
|
||||
"""
|
||||
if len(msg) == 28:
|
||||
offset = 0
|
||||
elif len(msg) == 14:
|
||||
offset = 112-56
|
||||
else:
|
||||
# raise exception
|
||||
return False
|
||||
|
||||
msgbin = util.hex2bin(msg)
|
||||
checksum = int(msg[22:28], 16)
|
||||
|
||||
crc = 0
|
||||
for i in xrange(len(msgbin)):
|
||||
# print msgbin[i]
|
||||
if int(msgbin[i]):
|
||||
crc ^= util.MODES_CHECKSUM_TABLE[i+offset]
|
||||
|
||||
if crc == checksum:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
from . import util
|
||||
|
||||
|
||||
def df(msg):
|
||||
"""Get the downlink format (DF) number
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: DF number
|
||||
"""
|
||||
@@ -63,8 +35,10 @@ def df(msg):
|
||||
|
||||
def icao(msg):
|
||||
"""Get the ICAO 24 bits address, bytes 3 to 8.
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
String: ICAO address in 6 bytes hexadecimal string
|
||||
"""
|
||||
@@ -78,8 +52,10 @@ def data(msg):
|
||||
|
||||
def typecode(msg):
|
||||
"""Type code of ADS-B message
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: type code number
|
||||
"""
|
||||
@@ -92,8 +68,10 @@ def typecode(msg):
|
||||
# ---------------------------------------------
|
||||
def category(msg):
|
||||
"""Aircraft category number
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: category number
|
||||
"""
|
||||
@@ -106,8 +84,10 @@ def category(msg):
|
||||
|
||||
def callsign(msg):
|
||||
"""Aircraft callsign
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
string: callsign
|
||||
"""
|
||||
@@ -141,8 +121,10 @@ def callsign(msg):
|
||||
|
||||
def oe_flag(msg):
|
||||
"""Check the odd/even flag. Bit 54, 0 for even, 1 for odd.
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: 0 or 1, for even or odd frame
|
||||
"""
|
||||
@@ -155,8 +137,10 @@ def oe_flag(msg):
|
||||
|
||||
def cprlat(msg):
|
||||
"""CPR encoded latitude
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: encoded latitude
|
||||
"""
|
||||
@@ -169,8 +153,10 @@ def cprlat(msg):
|
||||
|
||||
def cprlon(msg):
|
||||
"""CPR encoded longitude
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: encoded longitude
|
||||
"""
|
||||
@@ -181,26 +167,51 @@ def cprlon(msg):
|
||||
return util.bin2int(msgbin[71:88])
|
||||
|
||||
|
||||
def position(msg0, msg1, t0, t1):
|
||||
"""Decode position from the combination of even and odd position message
|
||||
131072 is 2^17, since CPR lat and lon are 17 bits each.
|
||||
def position(msg0, msg1, t0, t1, lat_ref=None, lon_ref=None):
|
||||
"""Decode position from a pair of even and odd position message
|
||||
(works with both airborne and surface position messages)
|
||||
|
||||
Args:
|
||||
msg0 (string): even message (28 bytes hexadecimal string)
|
||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
||||
t0 (int): timestamps for the even message
|
||||
t1 (int): timestamps for the odd message
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
if typecode(msg0) < 5 or typecode(msg0) > 18:
|
||||
raise RuntimeError("%s: Not a position message" % msg0)
|
||||
if (5 <= typecode(msg0) <= 8 and 5 <= typecode(msg1) <= 8):
|
||||
if (not lat_ref) or (not lon_ref):
|
||||
raise RuntimeError("Surface position encountered, a reference \
|
||||
position lat/lon required. Location of \
|
||||
receiver can be used.")
|
||||
else:
|
||||
return surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref)
|
||||
|
||||
if typecode(msg1) < 5 or typecode(msg1) > 18:
|
||||
raise RuntimeError("%s: Not a position message" % msg1)
|
||||
elif (9 <= typecode(msg0) <= 18 and 9 <= typecode(msg1) <= 18):
|
||||
return airborne_position(msg0, msg1, t0, t1)
|
||||
|
||||
else:
|
||||
raise RuntimeError("incorrect or inconsistant message types")
|
||||
|
||||
|
||||
def airborne_position(msg0, msg1, t0, t1):
|
||||
"""Decode airborn position from a pair of even and odd position message
|
||||
|
||||
Args:
|
||||
msg0 (string): even message (28 bytes hexadecimal string)
|
||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
||||
t0 (int): timestamps for the even message
|
||||
t1 (int): timestamps for the odd message
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
|
||||
msgbin0 = util.hex2bin(msg0)
|
||||
msgbin1 = util.hex2bin(msg1)
|
||||
|
||||
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
||||
cprlat_even = util.bin2int(msgbin0[54:71]) / 131072.0
|
||||
cprlon_even = util.bin2int(msgbin0[71:88]) / 131072.0
|
||||
cprlat_odd = util.bin2int(msgbin1[54:71]) / 131072.0
|
||||
@@ -210,7 +221,7 @@ def position(msg0, msg1, t0, t1):
|
||||
air_d_lat_odd = 360.0 / 59
|
||||
|
||||
# compute latitude index 'j'
|
||||
j = int(math.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5))
|
||||
j = util.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
||||
|
||||
lat_even = float(air_d_lat_even * (j % 60 + cprlat_even))
|
||||
lat_odd = float(air_d_lat_odd * (j % 59 + cprlat_odd))
|
||||
@@ -227,17 +238,17 @@ def position(msg0, msg1, t0, t1):
|
||||
|
||||
# compute ni, longitude index m, and longitude
|
||||
if (t0 > t1):
|
||||
ni = _cprN(lat_even, 0)
|
||||
m = math.floor(cprlon_even * (_cprNL(lat_even)-1) -
|
||||
cprlon_odd * _cprNL(lat_even) + 0.5)
|
||||
lon = (360.0 / ni) * (m % ni + cprlon_even)
|
||||
lat = lat_even
|
||||
nl = _cprNL(lat)
|
||||
ni = max(_cprNL(lat)- 0, 1)
|
||||
m = util.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
|
||||
lon = (360.0 / ni) * (m % ni + cprlon_even)
|
||||
else:
|
||||
ni = _cprN(lat_odd, 1)
|
||||
m = math.floor(cprlon_even * (_cprNL(lat_odd)-1) -
|
||||
cprlon_odd * _cprNL(lat_odd) + 0.5)
|
||||
lon = (360.0 / ni) * (m % ni + cprlon_odd)
|
||||
lat = lat_odd
|
||||
nl = _cprNL(lat)
|
||||
ni = max(_cprNL(lat) - 1, 1)
|
||||
m = util.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
|
||||
lon = (360.0 / ni) * (m % ni + cprlon_odd)
|
||||
|
||||
if lon > 180:
|
||||
lon = lon - 360
|
||||
@@ -245,27 +256,215 @@ def position(msg0, msg1, t0, t1):
|
||||
return round(lat, 5), round(lon, 5)
|
||||
|
||||
|
||||
def _cprN(lat, is_odd):
|
||||
nl = _cprNL(lat) - is_odd
|
||||
return nl if nl > 1 else 1
|
||||
def position_with_ref(msg, lat_ref, lon_ref):
|
||||
"""Decode position with only one message,
|
||||
knowing reference nearby location, such as previously
|
||||
calculated location, ground station, or airport location, etc.
|
||||
Works with both airborne and surface position messages.
|
||||
The reference position shall be with in 180NM (airborne) or 45NM (surface)
|
||||
of the true position.
|
||||
|
||||
Args:
|
||||
msg0 (string): even message (28 bytes hexadecimal string)
|
||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
||||
t0 (int): timestamps for the even message
|
||||
t1 (int): timestamps for the odd message
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
if 5 <= typecode(msg) <= 8:
|
||||
return airborne_position_with_ref(msg, lat_ref, lon_ref)
|
||||
|
||||
elif 9 <= typecode(msg) <= 18:
|
||||
return surface_position_with_ref(msg, lat_ref, lon_ref)
|
||||
|
||||
else:
|
||||
raise RuntimeError("incorrect or inconsistant message types")
|
||||
|
||||
|
||||
def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
||||
"""Decode airborne position with only one message,
|
||||
knowing reference nearby location, such as previously calculated location,
|
||||
ground station, or airport location, etc. The reference position shall
|
||||
be with in 180NM of the true position.
|
||||
|
||||
Args:
|
||||
msg (string): even message (28 bytes hexadecimal string)
|
||||
lat_ref: previous known latitude
|
||||
lon_ref: previous known longitude
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
|
||||
i = oe_flag(msg)
|
||||
d_lat = 360.0/59 if i else 360.0/60
|
||||
|
||||
msgbin = util.hex2bin(msg)
|
||||
cprlat = util.bin2int(msgbin[54:71]) / 131072.0
|
||||
cprlon = util.bin2int(msgbin[71:88]) / 131072.0
|
||||
|
||||
j = util.floor(lat_ref / d_lat) \
|
||||
+ util.floor(0.5 + ((lat_ref % d_lat) / d_lat) - cprlat)
|
||||
|
||||
lat = d_lat * (j + cprlat)
|
||||
|
||||
ni = _cprNL(lat) - i
|
||||
|
||||
if ni > 0:
|
||||
d_lon = 360.0 / ni
|
||||
else:
|
||||
d_lon = 360.0
|
||||
|
||||
m = util.floor(lon_ref / d_lon) \
|
||||
+ util.floor(0.5 + ((lon_ref % d_lon) / d_lon) - cprlon)
|
||||
|
||||
lon = d_lon * (m + cprlon)
|
||||
|
||||
return round(lat, 5), round(lon, 5)
|
||||
|
||||
|
||||
def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):
|
||||
"""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.
|
||||
|
||||
Args:
|
||||
msg0 (string): even message (28 bytes hexadecimal string)
|
||||
msg1 (string): odd message (28 bytes hexadecimal string)
|
||||
t0 (int): timestamps for the even message
|
||||
t1 (int): timestamps for the odd message
|
||||
lat_ref (float): latitude of the receiver
|
||||
lon_ref (float): longitude of the receiver
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
|
||||
msgbin0 = util.hex2bin(msg0)
|
||||
msgbin1 = util.hex2bin(msg1)
|
||||
|
||||
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
||||
cprlat_even = util.bin2int(msgbin0[54:71]) / 131072.0
|
||||
cprlon_even = util.bin2int(msgbin0[71:88]) / 131072.0
|
||||
cprlat_odd = util.bin2int(msgbin1[54:71]) / 131072.0
|
||||
cprlon_odd = util.bin2int(msgbin1[71:88]) / 131072.0
|
||||
|
||||
air_d_lat_even = 90.0 / 60
|
||||
air_d_lat_odd = 90.0 / 59
|
||||
|
||||
# compute latitude index 'j'
|
||||
j = util.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
|
||||
|
||||
# solution for north hemisphere
|
||||
lat_even_n = float(air_d_lat_even * (j % 60 + cprlat_even))
|
||||
lat_odd_n = float(air_d_lat_odd * (j % 59 + cprlat_odd))
|
||||
|
||||
# solution for north hemisphere
|
||||
lat_even_s = lat_even_n - 90.0
|
||||
lat_odd_s = lat_odd_n - 90.0
|
||||
|
||||
# chose which solution corrispondes to receiver location
|
||||
lat_even = lat_even_n if lat_ref > 0 else lat_even_s
|
||||
lat_odd = lat_odd_n if lat_ref > 0 else lat_odd_s
|
||||
|
||||
# check if both are in the same latidude zone, rare but possible
|
||||
if _cprNL(lat_even) != _cprNL(lat_odd):
|
||||
return None
|
||||
|
||||
# compute ni, longitude index m, and longitude
|
||||
if (t0 > t1):
|
||||
lat = lat_even
|
||||
nl = _cprNL(lat_even)
|
||||
ni = max(_cprNL(lat_even) - 0, 1)
|
||||
m = util.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
|
||||
lon = (90.0 / ni) * (m % ni + cprlon_even)
|
||||
else:
|
||||
lat = lat_odd
|
||||
nl = _cprNL(lat_odd)
|
||||
ni = max(_cprNL(lat_odd) - 1, 1)
|
||||
m = util.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
|
||||
lon = (90.0 / ni) * (m % ni + cprlon_odd)
|
||||
|
||||
# four possible longitude solutions
|
||||
lons = [lon, lon + 90.0, lon + 180.0, lon + 270.0]
|
||||
|
||||
# the closest solution to receiver is the correct one
|
||||
dls = [abs(lon_ref - l) for l in lons]
|
||||
imin = min(range(4), key=dls.__getitem__)
|
||||
lon = lons[imin]
|
||||
|
||||
return round(lat, 5), round(lon, 5)
|
||||
|
||||
|
||||
def surface_position_with_ref(msg, lat_ref, lon_ref):
|
||||
"""Decode surface position with only one message,
|
||||
knowing reference nearby location, such as previously calculated location,
|
||||
ground station, or airport location, etc. The reference position shall
|
||||
be with in 45NM of the true position.
|
||||
|
||||
Args:
|
||||
msg (string): even message (28 bytes hexadecimal string)
|
||||
lat_ref: previous known latitude
|
||||
lon_ref: previous known longitude
|
||||
|
||||
Returns:
|
||||
(float, float): (latitude, longitude) of the aircraft
|
||||
"""
|
||||
|
||||
i = oe_flag(msg)
|
||||
d_lat = 90.0/59 if i else 90.0/60
|
||||
|
||||
msgbin = util.hex2bin(msg)
|
||||
cprlat = util.bin2int(msgbin[54:71]) / 131072.0
|
||||
cprlon = util.bin2int(msgbin[71:88]) / 131072.0
|
||||
|
||||
j = util.floor(lat_ref / d_lat) \
|
||||
+ util.floor(0.5 + ((lat_ref % d_lat) / d_lat) - cprlat)
|
||||
|
||||
lat = d_lat * (j + cprlat)
|
||||
|
||||
ni = _cprNL(lat) - i
|
||||
|
||||
if ni > 0:
|
||||
d_lon = 360.0 / ni
|
||||
else:
|
||||
d_lon = 360.0
|
||||
|
||||
m = util.floor(lon_ref / d_lon) \
|
||||
+ util.floor(0.5 + ((lon_ref % d_lon) / d_lon) - cprlon)
|
||||
|
||||
lon = d_lon * (m + cprlon)
|
||||
|
||||
return round(lat, 5), round(lon, 5)
|
||||
|
||||
|
||||
def _cprNL(lat):
|
||||
try:
|
||||
nz = 60
|
||||
a = 1 - math.cos(math.pi * 2 / nz)
|
||||
b = math.cos(math.pi / 180.0 * abs(lat)) ** 2
|
||||
nl = 2 * math.pi / (math.acos(1 - a/b))
|
||||
return int(nl)
|
||||
except:
|
||||
# happens when latitude is +/-90 degree
|
||||
"""NL() function in CPR decoding
|
||||
"""
|
||||
if lat == 0:
|
||||
return 59
|
||||
|
||||
if lat == 87 or lat == -87:
|
||||
return 2
|
||||
|
||||
if lat > 87 or lat < -87:
|
||||
return 1
|
||||
|
||||
nz = 15
|
||||
a = 1 - math.cos(math.pi / (2 * nz))
|
||||
b = math.cos(math.pi / 180.0 * abs(lat)) ** 2
|
||||
nl = 2 * math.pi / (math.acos(1 - a/b))
|
||||
NL = util.floor(nl)
|
||||
return NL
|
||||
|
||||
|
||||
def altitude(msg):
|
||||
"""Decode aircraft altitude
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: altitude in feet
|
||||
"""
|
||||
@@ -284,8 +483,10 @@ def altitude(msg):
|
||||
|
||||
def nic(msg):
|
||||
"""Calculate NIC, navigation integrity category
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: NIC number (from 0 to 11), -1 if not applicable
|
||||
"""
|
||||
@@ -333,8 +534,10 @@ def nic(msg):
|
||||
|
||||
def velocity(msg):
|
||||
"""Calculate the speed, heading, and vertical rate
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
(int, float, int, string): speed (kt), heading (degree),
|
||||
rate of climb/descend (ft/min), and speed type
|
||||
@@ -373,16 +576,18 @@ def velocity(msg):
|
||||
tag = 'AS'
|
||||
|
||||
vr_sign = util.bin2int(msgbin[68])
|
||||
vr = util.bin2int(msgbin[68:77]) # vertical rate
|
||||
rocd = -1*vr if vr_sign else vr # rate of climb/descend
|
||||
vr = (util.bin2int(msgbin[69:78]) - 1) * 64 # vertical rate, fpm
|
||||
rocd = -1*vr if vr_sign else vr # rate of climb/descend
|
||||
|
||||
return int(spd), round(hdg, 1), int(rocd), tag
|
||||
|
||||
|
||||
def speed_heading(msg):
|
||||
"""Get speed and heading only from the velocity message
|
||||
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
(int, float): speed (kt), heading (degree)
|
||||
"""
|
||||
|
||||
252
pyModeS/ehs.py
252
pyModeS/ehs.py
@@ -1,52 +1,32 @@
|
||||
# Copyright (C) 2016 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/>.
|
||||
|
||||
"""
|
||||
A python package for decoding ModeS (DF20, DF21) messages.
|
||||
|
||||
Copyright (C) 2016 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/>.
|
||||
"""
|
||||
|
||||
import util
|
||||
|
||||
|
||||
def crc(msg):
|
||||
"""Calculate the cyclic redundancy checksum of an message
|
||||
Args:
|
||||
msg (String): 28 or 14 bytes hexadecimal message string
|
||||
Returns:
|
||||
int: checksum in integer
|
||||
"""
|
||||
if len(msg) == 28:
|
||||
offset = 0
|
||||
elif len(msg) == 14:
|
||||
offset = 112-56
|
||||
else:
|
||||
raise RuntimeError("wrong message length, need to be 28 or 14 bytes")
|
||||
|
||||
msgbin = util.hex2bin(msg)
|
||||
|
||||
crc = 0
|
||||
for i in xrange(len(msgbin)):
|
||||
if int(msgbin[i]):
|
||||
crc ^= util.MODES_CHECKSUM_TABLE[i+offset]
|
||||
return crc
|
||||
from . import util
|
||||
from .util import crc
|
||||
|
||||
|
||||
def df(msg):
|
||||
"""Get the downlink format (DF) number
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
int: DF number
|
||||
"""
|
||||
@@ -60,9 +40,11 @@ def data(msg):
|
||||
|
||||
def icao(msg):
|
||||
"""Calculate the ICAO address from an Mode-S message
|
||||
with DF4, DF5, DF20, DF21
|
||||
with DF4, DF5, DF20, DF21
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
String: ICAO address in 6 bytes hexadecimal string
|
||||
"""
|
||||
@@ -71,7 +53,7 @@ def icao(msg):
|
||||
# raise RuntimeError("Message DF must be in (4, 5, 20, 21)")
|
||||
return None
|
||||
|
||||
c0 = crc(msg)
|
||||
c0 = util.bin2int(crc(msg, encode=True))
|
||||
c1 = util.hex2int(msg[-6:])
|
||||
icao = '%06X' % (c0 ^ c1)
|
||||
return icao
|
||||
@@ -79,8 +61,9 @@ def icao(msg):
|
||||
|
||||
def checkbits(data, sb, msb, lsb):
|
||||
"""Check if the status bit and field bits are consistency. This Function
|
||||
is used for checking BDS code versions.
|
||||
is used for checking BDS code versions.
|
||||
"""
|
||||
|
||||
# status bit, most significant bit, least significant bit
|
||||
status = int(data[sb-1])
|
||||
value = util.bin2int(data[msb-1:lsb])
|
||||
@@ -98,11 +81,14 @@ def checkbits(data, sb, msb, lsb):
|
||||
|
||||
def isBDS20(msg):
|
||||
"""Check if a message is likely to be BDS code 2,0
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
# status bit 1, 14, and 27
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
@@ -121,8 +107,10 @@ def isBDS20(msg):
|
||||
|
||||
def callsign(msg):
|
||||
"""Aircraft callsign
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
||||
|
||||
Returns:
|
||||
string: callsign, max. 8 chars
|
||||
"""
|
||||
@@ -149,11 +137,14 @@ def callsign(msg):
|
||||
|
||||
def isBDS40(msg):
|
||||
"""Check if a message is likely to be BDS code 4,0
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
# status bit 1, 14, and 27
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
@@ -174,8 +165,10 @@ def isBDS40(msg):
|
||||
|
||||
def alt_mcp(msg):
|
||||
"""Selected altitude, MCP/FCU
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
||||
|
||||
Returns:
|
||||
int: altitude in feet
|
||||
"""
|
||||
@@ -186,8 +179,10 @@ def alt_mcp(msg):
|
||||
|
||||
def alt_fms(msg):
|
||||
"""Selected altitude, FMS
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
||||
|
||||
Returns:
|
||||
int: altitude in feet
|
||||
"""
|
||||
@@ -198,8 +193,10 @@ def alt_fms(msg):
|
||||
|
||||
def pbaro(msg):
|
||||
"""Barometric pressure setting
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS40) string
|
||||
|
||||
Returns:
|
||||
float: pressure in millibar
|
||||
"""
|
||||
@@ -208,17 +205,138 @@ def pbaro(msg):
|
||||
return p
|
||||
|
||||
|
||||
# ------------------------------------------
|
||||
# DF 20/21, BDS 4,4
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS44(msg):
|
||||
"""Check if a message is likely to be BDS code 4,4
|
||||
Meteorological routine air report
|
||||
|
||||
WARNING: there is two different definition for BDS4,4. This part of the
|
||||
decoder is likely to be wrong...
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
# status bit 5, 15, 24, 36, 49
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
result = True
|
||||
|
||||
# --- current version ---
|
||||
result = result & checkbits(d, 5, 6, 23) \
|
||||
& checkbits(d, 35, 36, 46) & checkbits(d, 47, 48, 49) \
|
||||
& checkbits(d, 50, 51, 56)
|
||||
|
||||
# # --- revised future version ---
|
||||
# result = result & checkbits(d, 5, 6, 14) \
|
||||
# & checkbits(d, 15, 16, 23) & checkbits(d, 24, 25, 35) \
|
||||
# & checkbits(d, 36, 37, 47) & checkbits(d, 49, 50, 56)
|
||||
|
||||
if wind(msg) and wind(msg)[0] > 250:
|
||||
result &= False
|
||||
|
||||
# if temperature(msg):
|
||||
# if temperature(msg) > 60 or temperature(msg) < -80:
|
||||
# result &= False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def wind(msg):
|
||||
"""reported wind speed and direction
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
|
||||
Returns:
|
||||
(int, float): speed (kt), direction (degree)
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[4])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
speed = util.bin2int(d[5:14]) # knots
|
||||
direction = util.bin2int(d[14:23]) * 180.0 / 256.0 # degree
|
||||
return round(speed, 0), round(direction, 1)
|
||||
|
||||
|
||||
def temperature(msg):
|
||||
"""reported air temperature
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
|
||||
Returns:
|
||||
float: tmeperature in Celsius degree
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
sign = int(d[23]) # 1 -> minus
|
||||
temp = util.bin2int(d[24:34]) * 0.25 # celsius
|
||||
temp = round(temp, 1)
|
||||
return -1 * temp if sign else temp
|
||||
|
||||
|
||||
def pressure(msg):
|
||||
"""reported average static pressure
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
|
||||
Returns:
|
||||
int: static pressure in hPa
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[34])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
p = util.bin2int(d[35:46]) # hPa
|
||||
return p
|
||||
|
||||
|
||||
def humidity(msg):
|
||||
"""reported humidity
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
|
||||
Returns:
|
||||
float: percentage of humidity, [0 - 100] %
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[49])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
hm = util.bin2int(d[50:56]) * 100.0 / 64 # %
|
||||
return round(hm, 1)
|
||||
|
||||
|
||||
# ------------------------------------------
|
||||
# DF 20/21, BDS 5,0
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS50(msg):
|
||||
"""Check if a message is likely to be BDS code 5,0
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
# status bit 1, 12, 24, 35, 46
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
@@ -248,8 +366,10 @@ def isBDS50(msg):
|
||||
|
||||
def roll(msg):
|
||||
"""Aircraft roll angle
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
|
||||
Returns:
|
||||
float: angle in degrees,
|
||||
negative->left wing down, positive->right wing down
|
||||
@@ -263,8 +383,10 @@ def roll(msg):
|
||||
|
||||
def track(msg):
|
||||
"""True track angle
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
|
||||
Returns:
|
||||
float: angle in degrees to true north (from 0 to 360)
|
||||
"""
|
||||
@@ -277,8 +399,10 @@ def track(msg):
|
||||
|
||||
def gs(msg):
|
||||
"""Aircraft ground speed
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
|
||||
Returns:
|
||||
int: ground speed in knots
|
||||
"""
|
||||
@@ -289,8 +413,10 @@ def gs(msg):
|
||||
|
||||
def rtrack(msg):
|
||||
"""Track angle rate
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
|
||||
Returns:
|
||||
float: angle rate in degrees/second
|
||||
"""
|
||||
@@ -303,8 +429,10 @@ def rtrack(msg):
|
||||
|
||||
def tas(msg):
|
||||
"""Aircraft true airspeed
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
|
||||
Returns:
|
||||
int: true airspeed in knots
|
||||
"""
|
||||
@@ -319,8 +447,10 @@ def tas(msg):
|
||||
|
||||
def isBDS60(msg):
|
||||
"""Check if a message is likely to be BDS code 6,0
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
@@ -350,8 +480,10 @@ def isBDS60(msg):
|
||||
|
||||
def heading(msg):
|
||||
"""Megnetic heading of aircraft
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
float: heading in degrees to megnetic north (from 0 to 360)
|
||||
"""
|
||||
@@ -364,8 +496,10 @@ def heading(msg):
|
||||
|
||||
def ias(msg):
|
||||
"""Indicated airspeed
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
int: indicated airspeed in knots
|
||||
"""
|
||||
@@ -376,8 +510,10 @@ def ias(msg):
|
||||
|
||||
def mach(msg):
|
||||
"""Aircraft MACH number
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
float: MACH number
|
||||
"""
|
||||
@@ -388,8 +524,10 @@ def mach(msg):
|
||||
|
||||
def baro_vr(msg):
|
||||
"""Vertical rate from barometric measurement
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
int: vertical rate in feet/minutes
|
||||
"""
|
||||
@@ -402,8 +540,10 @@ def baro_vr(msg):
|
||||
|
||||
def ins_vr(msg):
|
||||
"""Vertical rate messured by onbard equiments (IRS, AHRS)
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
int: vertical rate in feet/minutes
|
||||
"""
|
||||
@@ -416,23 +556,23 @@ def ins_vr(msg):
|
||||
|
||||
def BDS(msg):
|
||||
"""Estimate the most likely BDS code of an message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
String|None: Version: "BDS40", "BDS50", or "BDS60". Or None, if nothing
|
||||
matched
|
||||
String or None: Version: "BDS20", "BDS40", "BDS50", or "BDS60". Or None, if nothing matched
|
||||
"""
|
||||
is2 = isBDS20(msg)
|
||||
is4 = isBDS40(msg)
|
||||
is5 = isBDS50(msg)
|
||||
is6 = isBDS60(msg)
|
||||
if is2 and not is4 and not is5 and not is6:
|
||||
return "BDS20"
|
||||
elif not is2 and is4 and not is5 and not is6:
|
||||
return "BDS40"
|
||||
elif not is2 and not is4 and is5 and not is6:
|
||||
return "BDS50"
|
||||
elif not is2 and not is4 and not is5 and is6:
|
||||
return "BDS60"
|
||||
is20 = isBDS20(msg)
|
||||
is44 = isBDS44(msg)
|
||||
is40 = isBDS40(msg)
|
||||
is50 = isBDS50(msg)
|
||||
is60 = isBDS60(msg)
|
||||
|
||||
BDS = ["BDS20", "BDS40", "BDS44", "BDS50", "BDS60"]
|
||||
isBDS = [is20, is40, is44, is50, is60]
|
||||
|
||||
if sum(isBDS) == 1:
|
||||
return BDS[isBDS.index(True)]
|
||||
else:
|
||||
return None
|
||||
|
||||
106
pyModeS/util.py
106
pyModeS/util.py
@@ -1,54 +1,28 @@
|
||||
# Copyright (C) 2015 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/>.
|
||||
|
||||
|
||||
"""
|
||||
Common functions for ADS-B and Mode-S EHS decoder
|
||||
|
||||
Copyright (C) 2015 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/>.
|
||||
"""
|
||||
|
||||
|
||||
import math
|
||||
|
||||
MODES_CHECKSUM_TABLE = [
|
||||
0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf,
|
||||
0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178,
|
||||
0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13,
|
||||
0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14,
|
||||
0x682e0a, 0x341705, 0xe5f186, 0x72f8c3,
|
||||
0xc68665, 0x9cb936, 0x4e5c9b, 0xd8d449,
|
||||
0x939020, 0x49c810, 0x24e408, 0x127204,
|
||||
0x093902, 0x049c81, 0xfdb444, 0x7eda22,
|
||||
0x3f6d11, 0xe04c8c, 0x702646, 0x381323,
|
||||
0xe3f395, 0x8e03ce, 0x4701e7, 0xdc7af7,
|
||||
0x91c77f, 0xb719bb, 0xa476d9, 0xadc168,
|
||||
0x56e0b4, 0x2b705a, 0x15b82d, 0xf52612,
|
||||
0x7a9309, 0xc2b380, 0x6159c0, 0x30ace0,
|
||||
0x185670, 0x0c2b38, 0x06159c, 0x030ace,
|
||||
0x018567, 0xff38b7, 0x80665f, 0xbfc92b,
|
||||
0xa01e91, 0xaff54c, 0x57faa6, 0x2bfd53,
|
||||
0xea04ad, 0x8af852, 0x457c29, 0xdd4410,
|
||||
0x6ea208, 0x375104, 0x1ba882, 0x0dd441,
|
||||
0xf91024, 0x7c8812, 0x3e4409, 0xe0d800,
|
||||
0x706c00, 0x383600, 0x1c1b00, 0x0e0d80,
|
||||
0x0706c0, 0x038360, 0x01c1b0, 0x00e0d8,
|
||||
0x00706c, 0x003836, 0x001c1b, 0xfff409,
|
||||
0x000000, 0x000000, 0x000000, 0x000000,
|
||||
0x000000, 0x000000, 0x000000, 0x000000,
|
||||
0x000000, 0x000000, 0x000000, 0x000000,
|
||||
0x000000, 0x000000, 0x000000, 0x000000,
|
||||
0x000000, 0x000000, 0x000000, 0x000000,
|
||||
0x000000, 0x000000, 0x000000, 0x000000
|
||||
]
|
||||
# the polynominal generattor code for CRC
|
||||
GENERATOR = "1111111111111010000001001"
|
||||
|
||||
|
||||
def hex2bin(hexstr):
|
||||
@@ -60,14 +34,54 @@ def hex2bin(hexstr):
|
||||
|
||||
|
||||
def bin2int(binstr):
|
||||
"""Convert a binary string to integer. """
|
||||
return int(binstr, 2)
|
||||
|
||||
|
||||
def hex2int(hexstr):
|
||||
"""Convert a hexdecimal string to integer. """
|
||||
return int(hexstr, 16)
|
||||
|
||||
|
||||
def df(msg):
|
||||
"""Decode Downlink Format vaule, bits 1 to 5."""
|
||||
msgbin = hex2bin(msg)
|
||||
return bin2int(msgbin[0: 5])
|
||||
return bin2int(msgbin[0:5])
|
||||
|
||||
|
||||
def crc(msg, encode=False):
|
||||
"""Mode-S Cyclic Redundancy Check
|
||||
Detect if bit error occurs in the Mode-S message
|
||||
Args:
|
||||
msg (string): 28 bytes hexadecimal message string
|
||||
encode (bool): True to encode the date only and return the checksum
|
||||
Returns:
|
||||
string: message checksum, or partity bits (encoder)
|
||||
"""
|
||||
|
||||
msgbin = list(hex2bin(msg))
|
||||
|
||||
if encode:
|
||||
msgbin[-24:] = ['0'] * 24
|
||||
|
||||
# loop all bits, except last 24 piraty bits
|
||||
for i in range(len(msgbin)-24):
|
||||
# if 1, perform modulo 2 multiplication,
|
||||
if msgbin[i] == '1':
|
||||
for j in range(len(GENERATOR)):
|
||||
# modulo 2 multiplication = XOR
|
||||
msgbin[i+j] = str((int(msgbin[i+j]) ^ int(GENERATOR[j])))
|
||||
|
||||
# last 24 bits
|
||||
reminder = ''.join(msgbin[-24:])
|
||||
return reminder
|
||||
|
||||
|
||||
def floor(x):
|
||||
""" Mode-S floor function
|
||||
|
||||
Defined as the greatest integer value k, such that k <= x
|
||||
|
||||
eg.: floor(3.6) = 3, while floor(-3.6) = -4
|
||||
"""
|
||||
return int(math.floor(x))
|
||||
|
||||
10
setup.py
10
setup.py
@@ -23,7 +23,7 @@ setup(
|
||||
# Versions should comply with PEP440. For a discussion on single-sourcing
|
||||
# the version across setup.py and the project code, see
|
||||
# https://packaging.python.org/en/latest/single_source_version.html
|
||||
version='1.0.2',
|
||||
version='1.0.7',
|
||||
|
||||
description='Python Mode-S Decoder',
|
||||
long_description=long_description,
|
||||
@@ -58,10 +58,10 @@ setup(
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
# 'Programming Language :: Python :: 3',
|
||||
# 'Programming Language :: Python :: 3.3',
|
||||
# 'Programming Language :: Python :: 3.4',
|
||||
# 'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
],
|
||||
|
||||
# What does your project relate to?
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# the inclusion of the tests module is not meant to offer best practices for
|
||||
# testing in general, but rather to support the `find_packages` example in
|
||||
# setup.py that excludes installing the "tests" package
|
||||
171
tests/run.py
171
tests/run.py
@@ -1,171 +0,0 @@
|
||||
import os, sys, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(
|
||||
inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(currentdir)
|
||||
sys.path.insert(0, parentdir)
|
||||
|
||||
import pyModeS as pms
|
||||
from pyModeS import adsb
|
||||
from pyModeS import ehs
|
||||
|
||||
|
||||
# === TEST ADS-B package ===
|
||||
|
||||
def test_adsb_icao():
|
||||
assert adsb.icao("8D406B902015A678D4D220AA4BDA") == "406B90"
|
||||
|
||||
|
||||
def test_adsb_category():
|
||||
assert adsb.category("8D406B902015A678D4D220AA4BDA") == 5
|
||||
|
||||
|
||||
def test_adsb_callsign():
|
||||
assert adsb.callsign("8D406B902015A678D4D220AA4BDA") == "EZY85MH_"
|
||||
|
||||
|
||||
def test_adsb_position():
|
||||
pos = adsb.position("8D40058B58C901375147EFD09357",
|
||||
"8D40058B58C904A87F402D3B8C59",
|
||||
1446332400, 1446332405)
|
||||
assert pos == (49.81755, 6.08442)
|
||||
|
||||
|
||||
def test_adsb_alt():
|
||||
assert adsb.altitude("8D40058B58C901375147EFD09357") == 39000
|
||||
|
||||
|
||||
def test_adsb_velocity():
|
||||
vgs = adsb.velocity("8D485020994409940838175B284F")
|
||||
vas = adsb.velocity("8DA05F219B06B6AF189400CBC33F")
|
||||
assert vgs == (159, 182.9, -263, 'GS')
|
||||
assert vas == (376, 244.0, -274, 'AS')
|
||||
|
||||
|
||||
def test_nic():
|
||||
assert adsb.nic('8D3C70A390AB11F55B8C57F65FE6') == 0
|
||||
assert adsb.nic('8DE1C9738A4A430B427D219C8225') == 1
|
||||
assert adsb.nic('8D44058880B50006B1773DC2A7E9') == 2
|
||||
assert adsb.nic('8D44058881B50006B1773DC2A7E9') == 3
|
||||
assert adsb.nic('8D4AB42A78000640000000FA0D0A') == 4
|
||||
assert adsb.nic('8D4405887099F5D9772F37F86CB6') == 5
|
||||
assert adsb.nic('8D4841A86841528E72D9B472DAC2') == 6
|
||||
assert adsb.nic('8D44057560B9760C0B840A51C89F') == 7
|
||||
assert adsb.nic('8D40621D58C382D690C8AC2863A7') == 8
|
||||
assert adsb.nic('8F48511C598D04F12CCF82451642') == 9
|
||||
assert adsb.nic('8DA4D53A50DBF8C6330F3B35458F') == 10
|
||||
assert adsb.nic('8D3C4ACF4859F1736F8E8ADF4D67') == 11
|
||||
|
||||
|
||||
# === TEST Mode-S EHS package ===
|
||||
|
||||
def test_ehs_icao():
|
||||
assert ehs.icao("A0001839CA3800315800007448D9") == '400940'
|
||||
assert ehs.icao("A000139381951536E024D4CCF6B5") == '3C4DD2'
|
||||
assert ehs.icao("A000029CFFBAA11E2004727281F1") == '4243D0'
|
||||
|
||||
|
||||
def test_ehs_BDS():
|
||||
assert ehs.BDS("A0001838201584F23468207CDFA5") == 'BDS20'
|
||||
assert ehs.BDS("A0001839CA3800315800007448D9") == 'BDS40'
|
||||
assert ehs.BDS("A000139381951536E024D4CCF6B5") == 'BDS50'
|
||||
assert ehs.BDS("A000029CFFBAA11E2004727281F1") == 'BDS60'
|
||||
assert ehs.BDS("A0281838CAE9E12FA03FFF2DDDE5") is None
|
||||
|
||||
|
||||
def test_ehs_BDS20_callsign():
|
||||
assert ehs.callsign("A000083E202CC371C31DE0AA1CCF") == 'KLM1017_'
|
||||
assert ehs.callsign("A0001993202422F2E37CE038738E") == 'IBK2873_'
|
||||
|
||||
|
||||
def test_ehs_BDS40_functions():
|
||||
assert ehs.alt_mcp("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.alt_fms("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.pbaro("A000029C85E42F313000007047D3") == 1020.0
|
||||
|
||||
|
||||
def test_ehs_BDS50_functions():
|
||||
assert ehs.roll("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert ehs.track("A000139381951536E024D4CCF6B5") == 114.3
|
||||
assert ehs.gs("A000139381951536E024D4CCF6B5") == 438
|
||||
assert ehs.rtrack("A000139381951536E024D4CCF6B5") == 0.125
|
||||
assert ehs.tas("A000139381951536E024D4CCF6B5") == 424
|
||||
|
||||
|
||||
def test_ehs_BDS60_functions():
|
||||
assert ehs.heading("A000029CFFBAA11E2004727281F1") == 180.9
|
||||
assert ehs.ias("A000029CFFBAA11E2004727281F1") == 336
|
||||
assert ehs.mach("A000029CFFBAA11E2004727281F1") == 0.48
|
||||
assert ehs.baro_vr("A000029CFFBAA11E2004727281F1") == 0
|
||||
assert ehs.ins_vr("A000029CFFBAA11E2004727281F1") == -3648
|
||||
|
||||
|
||||
# === Decode sample data file ===
|
||||
|
||||
def adsb_decode_all(n=None):
|
||||
print "===== Decode all ADS-B sample data====="
|
||||
import csv
|
||||
f = open('adsb.csv', 'rt')
|
||||
|
||||
msg0 = None
|
||||
msg1 = None
|
||||
|
||||
for i, r in enumerate(csv.reader(f)):
|
||||
if n and i > n:
|
||||
break
|
||||
|
||||
ts = r[0]
|
||||
m = r[1]
|
||||
icao = adsb.icao(m)
|
||||
tc = adsb.typecode(m)
|
||||
if 1 <= tc <= 4:
|
||||
print ts, m, icao, tc, adsb.category(m), adsb.callsign(m)
|
||||
if tc == 19:
|
||||
print ts, m, icao, tc, adsb.velocity(m)
|
||||
if 5 <= tc <= 18:
|
||||
if adsb.oe_flag(m):
|
||||
msg1 = m
|
||||
t1 = ts
|
||||
else:
|
||||
msg0 = m
|
||||
t0 = ts
|
||||
|
||||
if msg0 and msg1:
|
||||
pos = adsb.position(msg0, msg1, t0, t1)
|
||||
alt = adsb.altitude(m)
|
||||
print ts, m, icao, tc, pos, alt
|
||||
|
||||
|
||||
def ehs_decode_all(n=None):
|
||||
print "===== Decode all Mode-S EHS sample data====="
|
||||
import csv
|
||||
f = open('ehs.csv', 'rt')
|
||||
for i, r in enumerate(csv.reader(f)):
|
||||
if n and i > n:
|
||||
break
|
||||
|
||||
ts = r[1]
|
||||
m = r[2]
|
||||
icao = ehs.icao(m)
|
||||
vBDS = ehs.BDS(m)
|
||||
|
||||
if vBDS:
|
||||
if vBDS == "BDS20":
|
||||
print ts, m, icao, vBDS, ehs.callsign(m)
|
||||
|
||||
if vBDS == "BDS40":
|
||||
print ts, m, icao, vBDS, ehs.alt_mcp(m), \
|
||||
ehs.alt_fms(m), ehs.pbaro(m)
|
||||
|
||||
if vBDS == "BDS50":
|
||||
print ts, m, icao, vBDS, ehs.roll(m), ehs.track(m), \
|
||||
ehs.gs(m), ehs.rtrack(m), ehs.tas(m)
|
||||
|
||||
if vBDS == "BDS60":
|
||||
print ts, m, icao, vBDS, ehs.heading(m), ehs.ias(m), \
|
||||
ehs.mach(m), ehs.baro_vr(m), ehs.ins_vr(m)
|
||||
else:
|
||||
print ts, m, icao, vBDS
|
||||
|
||||
if __name__ == '__main__':
|
||||
adsb_decode_all(100)
|
||||
ehs_decode_all(100)
|
||||
79
tests/sample_data_test.py
Normal file
79
tests/sample_data_test.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# If you get import error run with ipython
|
||||
from pyModeS import adsb
|
||||
from pyModeS import ehs
|
||||
from pyModeS import util
|
||||
|
||||
|
||||
# === Decode sample data file ===
|
||||
|
||||
def adsb_decode_all(n=None):
|
||||
print("===== Decode all ADS-B sample data=====")
|
||||
import csv
|
||||
f = open('tests/sample_data_adsb.csv', 'rt')
|
||||
|
||||
msg0 = None
|
||||
msg1 = None
|
||||
|
||||
for i, r in enumerate(csv.reader(f)):
|
||||
if n and i > n:
|
||||
break
|
||||
|
||||
ts = r[0]
|
||||
m = r[1]
|
||||
icao = adsb.icao(m)
|
||||
tc = adsb.typecode(m)
|
||||
if 1 <= tc <= 4:
|
||||
print(ts, m, icao, tc, adsb.category(m), adsb.callsign(m))
|
||||
if tc == 19:
|
||||
print(ts, m, icao, tc, adsb.velocity(m))
|
||||
if 5 <= tc <= 18:
|
||||
if adsb.oe_flag(m):
|
||||
msg1 = m
|
||||
t1 = ts
|
||||
else:
|
||||
msg0 = m
|
||||
t0 = ts
|
||||
|
||||
if msg0 and msg1:
|
||||
pos = adsb.position(msg0, msg1, t0, t1)
|
||||
alt = adsb.altitude(m)
|
||||
print(ts, m, icao, tc, pos, alt)
|
||||
|
||||
|
||||
def ehs_decode_all(n=None):
|
||||
print("===== Decode all Mode-S EHS sample data=====")
|
||||
import csv
|
||||
f = open('tests/sample_data_ehs.csv', 'rt')
|
||||
for i, r in enumerate(csv.reader(f)):
|
||||
if n and i > n:
|
||||
break
|
||||
|
||||
ts = r[1]
|
||||
m = r[2]
|
||||
icao = ehs.icao(m)
|
||||
vBDS = ehs.BDS(m)
|
||||
|
||||
if vBDS:
|
||||
if vBDS == "BDS20":
|
||||
print(ts, m, icao, vBDS, ehs.callsign(m))
|
||||
|
||||
if vBDS == "BDS40":
|
||||
print(ts, m, icao, vBDS, ehs.alt_mcp(m),
|
||||
ehs.alt_fms(m), ehs.pbaro(m))
|
||||
|
||||
if vBDS == "BDS44":
|
||||
print(ts, m, icao, vBDS, ehs.wind(m))
|
||||
|
||||
if vBDS == "BDS50":
|
||||
print(ts, m, icao, vBDS, ehs.roll(m), ehs.track(m),
|
||||
ehs.gs(m), ehs.rtrack(m), ehs.tas(m))
|
||||
|
||||
if vBDS == "BDS60":
|
||||
print(ts, m, icao, vBDS, ehs.heading(m), ehs.ias(m),
|
||||
ehs.mach(m), ehs.baro_vr(m), ehs.ins_vr(m))
|
||||
else:
|
||||
print(ts, m, icao, 'UNKNOWN')
|
||||
|
||||
if __name__ == '__main__':
|
||||
adsb_decode_all(100)
|
||||
ehs_decode_all(100)
|
||||
70
tests/test_adsb.py
Normal file
70
tests/test_adsb.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from pyModeS import adsb
|
||||
|
||||
|
||||
# === TEST ADS-B package ===
|
||||
|
||||
def test_adsb_icao():
|
||||
assert adsb.icao("8D406B902015A678D4D220AA4BDA") == "406B90"
|
||||
|
||||
|
||||
def test_adsb_category():
|
||||
assert adsb.category("8D406B902015A678D4D220AA4BDA") == 5
|
||||
|
||||
|
||||
def test_adsb_callsign():
|
||||
assert adsb.callsign("8D406B902015A678D4D220AA4BDA") == "EZY85MH_"
|
||||
|
||||
|
||||
def test_adsb_position():
|
||||
pos = adsb.position("8D40058B58C901375147EFD09357",
|
||||
"8D40058B58C904A87F402D3B8C59",
|
||||
1446332400, 1446332405)
|
||||
assert pos == (49.81755, 6.08442)
|
||||
|
||||
|
||||
def test_adsb_airborne_position_with_ref():
|
||||
pos = adsb.airborne_position_with_ref("8D40058B58C901375147EFD09357",
|
||||
49.0, 6.0)
|
||||
assert pos == (49.82410, 6.06785)
|
||||
pos = adsb.airborne_position_with_ref("8D40058B58C904A87F402D3B8C59",
|
||||
49.0, 6.0)
|
||||
assert pos == (49.81755, 6.08442)
|
||||
|
||||
|
||||
def test_adsb_surface_position_with_ref():
|
||||
pos = adsb.surface_position_with_ref("8FC8200A3AB8F5F893096B22B4A8",
|
||||
-43.5, 172.5)
|
||||
assert pos == (-43.48564, 175.87195)
|
||||
|
||||
|
||||
def test_adsb_surface_position():
|
||||
pos = adsb.surface_position("8CC8200A3AC8F009BCDEF2000000",
|
||||
"8FC8200A3AB8F5F893096B000000",
|
||||
0, 2,
|
||||
-43.496, 172.558)
|
||||
assert pos == (-43.48564, 172.53942)
|
||||
|
||||
def test_adsb_alt():
|
||||
assert adsb.altitude("8D40058B58C901375147EFD09357") == 39000
|
||||
|
||||
|
||||
def test_adsb_velocity():
|
||||
vgs = adsb.velocity("8D485020994409940838175B284F")
|
||||
vas = adsb.velocity("8DA05F219B06B6AF189400CBC33F")
|
||||
assert vgs == (159, 182.9, -832, 'GS')
|
||||
assert vas == (376, 244.0, -2304, 'AS')
|
||||
|
||||
|
||||
def test_nic():
|
||||
assert adsb.nic('8D3C70A390AB11F55B8C57F65FE6') == 0
|
||||
assert adsb.nic('8DE1C9738A4A430B427D219C8225') == 1
|
||||
assert adsb.nic('8D44058880B50006B1773DC2A7E9') == 2
|
||||
assert adsb.nic('8D44058881B50006B1773DC2A7E9') == 3
|
||||
assert adsb.nic('8D4AB42A78000640000000FA0D0A') == 4
|
||||
assert adsb.nic('8D4405887099F5D9772F37F86CB6') == 5
|
||||
assert adsb.nic('8D4841A86841528E72D9B472DAC2') == 6
|
||||
assert adsb.nic('8D44057560B9760C0B840A51C89F') == 7
|
||||
assert adsb.nic('8D40621D58C382D690C8AC2863A7') == 8
|
||||
assert adsb.nic('8F48511C598D04F12CCF82451642') == 9
|
||||
assert adsb.nic('8DA4D53A50DBF8C6330F3B35458F') == 10
|
||||
assert adsb.nic('8D3C4ACF4859F1736F8E8ADF4D67') == 11
|
||||
43
tests/test_ehs.py
Normal file
43
tests/test_ehs.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from pyModeS import ehs
|
||||
|
||||
|
||||
def test_ehs_icao():
|
||||
assert ehs.icao("A0001839CA3800315800007448D9") == '400940'
|
||||
assert ehs.icao("A000139381951536E024D4CCF6B5") == '3C4DD2'
|
||||
assert ehs.icao("A000029CFFBAA11E2004727281F1") == '4243D0'
|
||||
|
||||
|
||||
def test_ehs_BDS():
|
||||
assert ehs.BDS("A0001838201584F23468207CDFA5") == 'BDS20'
|
||||
assert ehs.BDS("A0001839CA3800315800007448D9") == 'BDS40'
|
||||
assert ehs.BDS("A000139381951536E024D4CCF6B5") == 'BDS50'
|
||||
assert ehs.BDS("A000029CFFBAA11E2004727281F1") == 'BDS60'
|
||||
assert ehs.BDS("A0281838CAE9E12FA03FFF2DDDE5") == 'BDS44'
|
||||
assert ehs.BDS("A00017B0C8480030A4000024512F") is None
|
||||
|
||||
|
||||
def test_ehs_BDS20_callsign():
|
||||
assert ehs.callsign("A000083E202CC371C31DE0AA1CCF") == 'KLM1017_'
|
||||
assert ehs.callsign("A0001993202422F2E37CE038738E") == 'IBK2873_'
|
||||
|
||||
|
||||
def test_ehs_BDS40_functions():
|
||||
assert ehs.alt_mcp("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.alt_fms("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.pbaro("A000029C85E42F313000007047D3") == 1020.0
|
||||
|
||||
|
||||
def test_ehs_BDS50_functions():
|
||||
assert ehs.roll("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert ehs.track("A000139381951536E024D4CCF6B5") == 114.3
|
||||
assert ehs.gs("A000139381951536E024D4CCF6B5") == 438
|
||||
assert ehs.rtrack("A000139381951536E024D4CCF6B5") == 0.125
|
||||
assert ehs.tas("A000139381951536E024D4CCF6B5") == 424
|
||||
|
||||
|
||||
def test_ehs_BDS60_functions():
|
||||
assert ehs.heading("A000029CFFBAA11E2004727281F1") == 180.9
|
||||
assert ehs.ias("A000029CFFBAA11E2004727281F1") == 336
|
||||
assert ehs.mach("A000029CFFBAA11E2004727281F1") == 0.48
|
||||
assert ehs.baro_vr("A000029CFFBAA11E2004727281F1") == 0
|
||||
assert ehs.ins_vr("A000029CFFBAA11E2004727281F1") == -3648
|
||||
15
tests/test_util.py
Normal file
15
tests/test_util.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from pyModeS import util
|
||||
|
||||
|
||||
def test_hex2bin():
|
||||
assert util.hex2bin('6E406B') == "011011100100000001101011"
|
||||
|
||||
|
||||
def test_crc_decode():
|
||||
checksum = util.crc("8D406B902015A678D4D220AA4BDA")
|
||||
assert checksum == "000000000000000000000000"
|
||||
|
||||
|
||||
def test_crc_encode():
|
||||
parity = util.crc("8D406B902015A678D4D220AA4BDA", encode=True)
|
||||
assert util.hex2bin("AA4BDA") == parity
|
||||
Reference in New Issue
Block a user