11def 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