|
|
|
@ -24,6 +24,7 @@
|
|
|
|
|
from __future__ import absolute_import, print_function, division
|
|
|
|
|
from pyModeS.decoder import common
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def airborne_position(msg0, msg1, t0, t1):
|
|
|
|
|
"""Decode airborn position from a pair of even and odd position message
|
|
|
|
|
|
|
|
|
@ -40,6 +41,16 @@ def airborne_position(msg0, msg1, t0, t1):
|
|
|
|
|
mb0 = common.hex2bin(msg0)[32:]
|
|
|
|
|
mb1 = common.hex2bin(msg1)[32:]
|
|
|
|
|
|
|
|
|
|
oe0 = int(mb0[21])
|
|
|
|
|
oe1 = int(mb1[21])
|
|
|
|
|
if oe0 == 0 and oe1 == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif oe0 == 1 and oe1 == 0:
|
|
|
|
|
mb0, mb1 = mb1, mb0
|
|
|
|
|
t0, t1 = t1, t0
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError("Both even and odd CPR frames are required.")
|
|
|
|
|
|
|
|
|
|
# 131072 is 2^17, since CPR lat and lon are 17 bits each.
|
|
|
|
|
cprlat_even = common.bin2int(mb0[22:39]) / 131072.0
|
|
|
|
|
cprlon_even = common.bin2int(mb0[39:56]) / 131072.0
|
|
|
|
@ -66,7 +77,7 @@ def airborne_position(msg0, msg1, t0, t1):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# compute ni, longitude index m, and longitude
|
|
|
|
|
if (t0 > t1):
|
|
|
|
|
if t0 > t1:
|
|
|
|
|
lat = lat_even
|
|
|
|
|
nl = common.cprNL(lat)
|
|
|
|
|
ni = max(common.cprNL(lat) - 0, 1)
|
|
|
|
@ -100,7 +111,6 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|
|
|
|
(float, float): (latitude, longitude) of the aircraft
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mb = common.hex2bin(msg)[32:]
|
|
|
|
|
|
|
|
|
|
cprlat = common.bin2int(mb[22:39]) / 131072.0
|
|
|
|
@ -109,8 +119,9 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|
|
|
|
i = int(mb[21])
|
|
|
|
|
d_lat = 360.0 / 59 if i else 360.0 / 60
|
|
|
|
|
|
|
|
|
|
j = common.floor(lat_ref / d_lat) \
|
|
|
|
|
+ common.floor(0.5 + ((lat_ref % d_lat) / d_lat) - cprlat)
|
|
|
|
|
j = common.floor(lat_ref / d_lat) + common.floor(
|
|
|
|
|
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
lat = d_lat * (j + cprlat)
|
|
|
|
|
|
|
|
|
@ -121,8 +132,9 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
|
|
|
|
|
else:
|
|
|
|
|
d_lon = 360.0
|
|
|
|
|
|
|
|
|
|
m = common.floor(lon_ref / d_lon) \
|
|
|
|
|
+ common.floor(0.5 + ((lon_ref % d_lon) / d_lon) - cprlon)
|
|
|
|
|
m = common.floor(lon_ref / d_lon) + common.floor(
|
|
|
|
|
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
lon = d_lon * (m + cprlon)
|
|
|
|
|
|
|
|
|
|