Skip to content

Commit

Permalink
Merge pull request #162 from paulmadejong/altitude_none_return
Browse files Browse the repository at this point in the history
Properly return None if altitude could not be decoded
  • Loading branch information
junzis authored Dec 18, 2023
2 parents 7727315 + eea0922 commit 4cf024f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyModeS/c_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ cpdef int altitude(str binstr):

if bin2int(binstr) == 0:
# altitude unknown or invalid
alt = -9999
alt = -999999

elif Mbit == 48: # unit in ft, "0" -> 48
if Qbit == 49: # 25ft interval, "1" -> 49
Expand Down
7 changes: 6 additions & 1 deletion pyModeS/decoder/bds/bds05.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def altitude(msg: str) -> None | int:

if tc < 19:
altcode = altbin[0:6] + "0" + altbin[6:]
return common.altitude(altcode)
alt = common.altitude(altcode)
if alt != -999999:
return alt
else:
# return None if altitude is invalid
return None
else:
return common.bin2int(altbin) * 3.28084 # type: ignore

0 comments on commit 4cf024f

Please sign in to comment.