Skip to content

Commit 4af7976

Browse files
committed
fully annotated code
1 parent d3607a1 commit 4af7976

32 files changed

+872
-407
lines changed

pyModeS/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
try:
55
from . import c_common as common
66
from .c_common import *
7-
except:
7+
except Exception:
88
from . import py_common as common # type: ignore
99
from .py_common import * # type: ignore
1010

@@ -17,6 +17,18 @@
1717
from .extra import aero
1818
from .extra import tcpclient
1919

20+
__all__ = [
21+
"common",
22+
"tell",
23+
"adsb",
24+
"commb",
25+
"allcall",
26+
"surv",
27+
"bds",
28+
"aero",
29+
"tcpclient",
30+
]
31+
2032

2133
warnings.simplefilter("once", DeprecationWarning)
2234

pyModeS/c_common.pyi

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@ def hex2bin(hexstr: str) -> str: ...
22
def bin2int(binstr: str) -> int: ...
33
def hex2int(hexstr: str) -> int: ...
44
def bin2hex(binstr: str) -> str: ...
5-
6-
75
def df(msg: str) -> int: ...
86
def crc(msg: str, encode: bool = False) -> int: ...
9-
10-
117
def floor(x: float) -> float: ...
128
def icao(msg: str) -> str: ...
139
def is_icao_assigned(icao: str) -> bool: ...
14-
15-
1610
def typecode(msg: str) -> int: ...
1711
def cprNL(lat: float) -> int: ...
18-
19-
2012
def idcode(msg: str) -> str: ...
2113
def squawk(binstr: str) -> str: ...
22-
23-
2414
def altcode(msg: str) -> int: ...
2515
def altitude(binstr: str) -> int: ...
26-
27-
2816
def data(msg: str) -> str: ...
2917
def allzeros(msg: str) -> bool: ...
18+
def wrongstatus(data: str, sb: int, msb: int, lsb: int) -> bool: ...

pyModeS/common.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Optional
2+
3+
def hex2bin(hexstr: str) -> str: ...
4+
def bin2int(binstr: str) -> int: ...
5+
def hex2int(hexstr: str) -> int: ...
6+
def bin2hex(binstr: str) -> str: ...
7+
def df(msg: str) -> int: ...
8+
def crc(msg: str, encode: bool = False) -> int: ...
9+
def floor(x: float) -> float: ...
10+
def icao(msg: str) -> Optional[str]: ...
11+
def is_icao_assigned(icao: str) -> bool: ...
12+
def typecode(msg: str) -> Optional[int]: ...
13+
def cprNL(lat: float) -> int: ...
14+
def idcode(msg: str) -> str: ...
15+
def squawk(binstr: str) -> str: ...
16+
def altcode(msg: str) -> Optional[int]: ...
17+
def altitude(binstr: str) -> Optional[int]: ...
18+
def gray2alt(binstr: str) -> Optional[int]: ...
19+
def gray2int(binstr: str) -> int: ...
20+
def data(msg: str) -> str: ...
21+
def allzeros(msg: str) -> bool: ...
22+
def wrongstatus(data: str, sb: int, msb: int, lsb: int) -> bool: ...

pyModeS/decoder/__init__.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def tell(msg: str) -> None:
2-
from pyModeS import common, adsb, commb, bds
2+
from .. import common, adsb, commb, bds
33

44
def _print(label, value, unit=None):
55
print("%28s: " % label, end="")
@@ -20,6 +20,11 @@ def _print(label, value, unit=None):
2020
_print("Protocol", "Mode-S Extended Squitter (ADS-B)")
2121

2222
tc = common.typecode(msg)
23+
24+
if tc is None:
25+
_print("ERROR", "Unknown typecode")
26+
return
27+
2328
if 1 <= tc <= 4: # callsign
2429
callsign = adsb.callsign(msg)
2530
_print("Type", "Identification and category")
@@ -52,12 +57,14 @@ def _print(label, value, unit=None):
5257

5358
if tc == 19:
5459
_print("Type", "Airborne velocity")
55-
spd, trk, vr, t = adsb.velocity(msg)
56-
types = {"GS": "Ground speed", "TAS": "True airspeed"}
57-
_print("Speed", spd, "knots")
58-
_print("Track", trk, "degrees")
59-
_print("Vertical rate", vr, "feet/minute")
60-
_print("Type", types[t])
60+
velocity = adsb.velocity(msg)
61+
if velocity is not None:
62+
spd, trk, vr, t = velocity
63+
types = {"GS": "Ground speed", "TAS": "True airspeed"}
64+
_print("Speed", spd, "knots")
65+
_print("Track", trk, "degrees")
66+
_print("Vertical rate", vr, "feet/minute")
67+
_print("Type", types[t])
6168

6269
if 20 <= tc <= 22: # airborne position
6370
_print("Type", "Airborne position (with GNSS altitude)")
@@ -106,8 +113,16 @@ def _print(label, value, unit=None):
106113
_print("Angle", angle, "°")
107114
_print("Angle Type", angle_type)
108115
_print("Angle Source", angle_source)
109-
_print("Vertical mode", vertical_horizontal_types[vertical_mode])
110-
_print("Horizontal mode", vertical_horizontal_types[horizontal_mode])
116+
if vertical_mode is not None:
117+
_print(
118+
"Vertical mode",
119+
vertical_horizontal_types[vertical_mode],
120+
)
121+
if horizontal_mode is not None:
122+
_print(
123+
"Horizontal mode",
124+
vertical_horizontal_types[horizontal_mode],
125+
)
111126
_print(
112127
"TCAS/ACAS",
113128
tcas_operational_types[tcas_operational]
@@ -117,7 +132,7 @@ def _print(label, value, unit=None):
117132
_print("TCAS/ACAS RA", tcas_ra_types[tcas_ra])
118133
_print("Emergency status", emergency_types[emergency_status])
119134
else:
120-
alt, alt_source = adsb.selected_altitude(msg)
135+
alt, alt_source = adsb.selected_altitude(msg) # type: ignore
121136
baro = adsb.baro_pressure_setting(msg)
122137
hdg = adsb.selected_heading(msg)
123138
autopilot = adsb.autopilot(msg)
@@ -127,13 +142,20 @@ def _print(label, value, unit=None):
127142
lnav = adsb.lnav_mode(msg)
128143
_print("Selected altitude", alt, "feet")
129144
_print("Altitude source", alt_source)
130-
_print("Barometric pressure setting", baro, "" if baro == None else "millibars")
145+
_print(
146+
"Barometric pressure setting",
147+
baro,
148+
"" if baro is None else "millibars",
149+
)
131150
_print("Selected Heading", hdg, "°")
132151
if not (common.bin2int((common.hex2bin(msg)[32:])[46]) == 0):
133-
_print("Autopilot", types_29[autopilot] if autopilot else None)
152+
_print(
153+
"Autopilot", types_29[autopilot] if autopilot else None
154+
)
134155
_print("VNAV mode", types_29[vnav] if vnav else None)
135156
_print(
136-
"Altitude hold mode", types_29[alt_hold] if alt_hold else None
157+
"Altitude hold mode",
158+
types_29[alt_hold] if alt_hold else None,
137159
)
138160
_print("Approach mode", types_29[app] if app else None)
139161
_print(
@@ -167,7 +189,7 @@ def _print(label, value, unit=None):
167189
}
168190

169191
BDS = bds.infer(msg, mrar=True)
170-
if BDS in labels.keys():
192+
if BDS is not None and BDS in labels.keys():
171193
_print("BDS", "%s (%s)" % (BDS, labels[BDS]))
172194
else:
173195
_print("BDS", BDS)

0 commit comments

Comments
 (0)