Skip to content

Commit

Permalink
with mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Apr 18, 2022
1 parent 65ce1a6 commit 6e33ac0
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
pip install -U pytest codecov pytest-cov
pip install .
# - name: Type checking
# run: |
# mypy pyModeS tests
- name: Type checking
run: |
mypy pyModeS
- name: Run tests (without Cython)
run: |
Expand Down
4 changes: 2 additions & 2 deletions pyModeS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from . import c_common as common
from .c_common import *
except:
from . import py_common as common
from .py_common import *
from . import py_common as common # type: ignore
from .py_common import * # type: ignore

from .decoder import tell
from .decoder import adsb
Expand Down
29 changes: 29 additions & 0 deletions pyModeS/c_common.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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: ...
37 changes: 24 additions & 13 deletions pyModeS/decoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def _print(label, value, unit=None):
_print("CPR Longitude", cprlon)
_print("Altitude", alt, "feet")

if tc == 29: # target state and status
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 = {0: "Not Engaged", 1: "Engaged"}
types_29 = {0: "Not Engaged", 1: "Engaged"}
tcas_operational_types = {0: "Not Operational", 1: "Operational"}
if subtype == 0:
emergency_types = {
Expand All @@ -87,11 +87,11 @@ def _print(label, value, unit=None):
4: "No communications",
5: "Unlawful interference",
6: "Downed aircraft",
7: "Reserved"
7: "Reserved",
}
vertical_horizontal_types = {
1: "Acquiring mode",
2: "Capturing/Maintaining mode"
2: "Capturing/Maintaining mode",
}
tcas_ra_types = {0: "Not active", 1: "Active"}
alt, alt_source, alt_ref = adsb.target_altitude(msg)
Expand All @@ -108,7 +108,12 @@ def _print(label, value, unit=None):
_print("Angle Source", angle_source)
_print("Vertical mode", vertical_horizontal_types[vertical_mode])
_print("Horizontal mode", vertical_horizontal_types[horizontal_mode])
_print("TCAS/ACAS", tcas_operational_types[tcas_operational])
_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:
Expand All @@ -124,14 +129,20 @@ def _print(label, value, unit=None):
_print("Altitude source", alt_source)
_print("Barometric pressure setting", baro, "millibars")
_print("Selected Heading", hdg, "°")
if not(common.bin2int((common.hex2bin(msg)[32:])[46]) == 0):
_print("Autopilot", types[autopilot])
_print("VNAV mode", types[vnav])
_print("Altitude hold mode", types[alt_hold])
_print("Approach mode", types[app])
_print("TCAS/ACAS", tcas_operational_types[tcas_operational])
_print("LNAV mode", types[lnav])

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:
_print("Protocol", "Mode-S Comm-B altitude reply")
Expand Down
2 changes: 0 additions & 2 deletions pyModeS/decoder/adsb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# noqa

"""ADS-B module.
The ADS-B module also imports functions from the following modules:
Expand Down
Loading

0 comments on commit 6e33ac0

Please sign in to comment.