update imports

This commit is contained in:
Junzi Sun 2020-02-26 00:54:49 +01:00
parent ea7653ef79
commit 0ff628bb8e
23 changed files with 196 additions and 180 deletions

View File

@ -1,9 +1,9 @@
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import adsb, commb, common, bds
def tell(msg):
from pyModeS import common, adsb, commb, bds
def _print(label, value, unit=None):
print("%20s: " % label, end="")
print("%s " % value, end="")

View File

@ -3,6 +3,3 @@ Decoding Air-Air Surveillance (ACAS) DF=0/16
[To be implemented]
"""
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common

View File

@ -16,7 +16,9 @@ The ADS-B wrapper also imports functions from the following modules:
from __future__ import absolute_import, print_function, division
import pyModeS as pms
from pyModeS.decoder import common
from pyModeS import common
from pyModeS.decoder import uncertainty
# from pyModeS.decoder.bds import bds05, bds06, bds09

View File

@ -3,6 +3,3 @@ Decoding all call replies DF=11
[To be implemented]
"""
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common

View File

@ -22,7 +22,13 @@ from __future__ import absolute_import, print_function, division
import numpy as np
from pyModeS.extra import aero
from pyModeS.decoder import common
try:
from pyModeS.decoder import c_common as common
except:
from pyModeS.decoder import common
from pyModeS.decoder.bds import (
bds05,
bds06,

View File

@ -6,7 +6,8 @@
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common
from pyModeS import common
def airborne_position(msg0, msg1, t0, t1):

View File

@ -5,8 +5,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common
import math
from pyModeS import common
def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref):

View File

@ -5,7 +5,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common
from pyModeS import common
def category(msg):

View File

@ -6,6 +6,10 @@
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common
from pyModeS import common
import math

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
from pyModeS import common
def is10(msg):
@ -17,23 +18,23 @@ def is10(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# first 8 bits must be 0x10
if d[0:8] != "00010000":
return False
# bit 10 to 14 are reserved
if bin2int(d[9:14]) != 0:
if common.bin2int(d[9:14]) != 0:
return False
# overlay capability conflict
if d[14] == "1" and bin2int(d[16:23]) < 5:
if d[14] == "1" and common.bin2int(d[16:23]) < 5:
return False
if d[14] == "0" and bin2int(d[16:23]) > 4:
if d[14] == "0" and common.bin2int(d[16:23]) > 4:
return False
return True
@ -48,6 +49,6 @@ def ovc10(msg):
Returns:
int: Whether the transponder is OVC capable
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
return int(d[14])

View File

@ -5,7 +5,8 @@
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
from pyModeS import common
def is17(msg):
@ -18,12 +19,12 @@ def is17(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if bin2int(d[28:56]) != 0:
if common.bin2int(d[28:56]) != 0:
return False
caps = cap17(msg)
@ -80,7 +81,7 @@ def cap17(msg):
"E2",
]
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
idx = [i for i, v in enumerate(d[:28]) if v == "1"]
capacity = ["BDS" + allbds[i] for i in idx if allbds[i] is not "NA"]

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
from pyModeS import common
def is20(msg):
@ -17,10 +18,10 @@ def is20(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0:8] != "00100000":
return False
@ -44,16 +45,16 @@ def cs20(msg):
"""
chars = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######"
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
cs = ""
cs += chars[bin2int(d[8:14])]
cs += chars[bin2int(d[14:20])]
cs += chars[bin2int(d[20:26])]
cs += chars[bin2int(d[26:32])]
cs += chars[bin2int(d[32:38])]
cs += chars[bin2int(d[38:44])]
cs += chars[bin2int(d[44:50])]
cs += chars[bin2int(d[50:56])]
cs += chars[common.bin2int(d[8:14])]
cs += chars[common.bin2int(d[14:20])]
cs += chars[common.bin2int(d[20:26])]
cs += chars[common.bin2int(d[26:32])]
cs += chars[common.bin2int(d[32:38])]
cs += chars[common.bin2int(d[38:44])]
cs += chars[common.bin2int(d[44:50])]
cs += chars[common.bin2int(d[50:56])]
return cs

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros
from pyModeS import common
def is30(msg):
@ -17,10 +18,10 @@ def is30(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0:8] != "00110000":
return False
@ -30,7 +31,7 @@ def is30(msg):
return False
# reserved for ACAS III, in far future
if bin2int(d[15:22]) >= 48:
if common.bin2int(d[15:22]) >= 48:
return False
return True

View File

@ -5,7 +5,8 @@
from __future__ import absolute_import, print_function, division
import warnings
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is40(msg):
@ -18,34 +19,34 @@ def is40(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 1, 14, and 27
if wrongstatus(d, 1, 2, 13):
if common.wrongstatus(d, 1, 2, 13):
return False
if wrongstatus(d, 14, 15, 26):
if common.wrongstatus(d, 14, 15, 26):
return False
if wrongstatus(d, 27, 28, 39):
if common.wrongstatus(d, 27, 28, 39):
return False
if wrongstatus(d, 48, 49, 51):
if common.wrongstatus(d, 48, 49, 51):
return False
if wrongstatus(d, 54, 55, 56):
if common.wrongstatus(d, 54, 55, 56):
return False
# bits 40-47 and 52-53 shall all be zero
if bin2int(d[39:47]) != 0:
if common.bin2int(d[39:47]) != 0:
return False
if bin2int(d[51:53]) != 0:
if common.bin2int(d[51:53]) != 0:
return False
return True
@ -60,12 +61,12 @@ def selalt40mcp(msg):
Returns:
int: altitude in feet
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0] == "0":
return None
alt = bin2int(d[1:13]) * 16 # ft
alt = common.bin2int(d[1:13]) * 16 # ft
return alt
@ -78,12 +79,12 @@ def selalt40fms(msg):
Returns:
int: altitude in feet
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[13] == "0":
return None
alt = bin2int(d[14:26]) * 16 # ft
alt = common.bin2int(d[14:26]) * 16 # ft
return alt
@ -96,12 +97,12 @@ def p40baro(msg):
Returns:
float: pressure in millibar
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[26] == "0":
return None
p = bin2int(d[27:39]) * 0.1 + 800 # millibar
p = common.bin2int(d[27:39]) * 0.1 + 800 # millibar
return p

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is44(msg):
@ -19,26 +20,26 @@ def is44(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 5, 35, 47, 50
if wrongstatus(d, 5, 6, 23):
if common.wrongstatus(d, 5, 6, 23):
return False
if wrongstatus(d, 35, 36, 46):
if common.wrongstatus(d, 35, 36, 46):
return False
if wrongstatus(d, 47, 48, 49):
if common.wrongstatus(d, 47, 48, 49):
return False
if wrongstatus(d, 50, 51, 56):
if common.wrongstatus(d, 50, 51, 56):
return False
# Bits 1-4 indicate source, values > 4 reserved and should not occur
if bin2int(d[0:4]) > 4:
if common.bin2int(d[0:4]) > 4:
return False
vw, dw = wind44(msg)
@ -62,14 +63,14 @@ def wind44(msg):
(int, float): speed (kt), direction (degree)
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
status = int(d[4])
if not status:
return None, None
speed = bin2int(d[5:14]) # knots
direction = bin2int(d[14:23]) * 180.0 / 256.0 # degree
speed = common.bin2int(d[5:14]) # knots
direction = common.bin2int(d[14:23]) * 180.0 / 256.0 # degree
return round(speed, 0), round(direction, 1)
@ -86,10 +87,10 @@ def temp44(msg):
error in ICAO 9871 (2008) Appendix A-67.
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
sign = int(d[23])
value = bin2int(d[24:34])
value = common.bin2int(d[24:34])
if sign:
value = value - 1024
@ -113,12 +114,12 @@ def p44(msg):
int: static pressure in hPa
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[34] == "0":
return None
p = bin2int(d[35:46]) # hPa
p = common.bin2int(d[35:46]) # hPa
return p
@ -132,12 +133,12 @@ def hum44(msg):
Returns:
float: percentage of humidity, [0 - 100] %
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[49] == "0":
return None
hm = bin2int(d[50:56]) * 100.0 / 64 # %
hm = common.bin2int(d[50:56]) * 100.0 / 64 # %
return round(hm, 1)
@ -152,11 +153,11 @@ def turb44(msg):
int: turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[46] == "0":
return None
turb = bin2int(d[47:49])
turb = common.bin2int(d[47:49])
return turb

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is45(msg):
@ -19,38 +20,38 @@ def is45(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 1, 4, 7, 10, 13, 16, 27, 39
if wrongstatus(d, 1, 2, 3):
if common.wrongstatus(d, 1, 2, 3):
return False
if wrongstatus(d, 4, 5, 6):
if common.wrongstatus(d, 4, 5, 6):
return False
if wrongstatus(d, 7, 8, 9):
if common.wrongstatus(d, 7, 8, 9):
return False
if wrongstatus(d, 10, 11, 12):
if common.wrongstatus(d, 10, 11, 12):
return False
if wrongstatus(d, 13, 14, 15):
if common.wrongstatus(d, 13, 14, 15):
return False
if wrongstatus(d, 16, 17, 26):
if common.wrongstatus(d, 16, 17, 26):
return False
if wrongstatus(d, 27, 28, 38):
if common.wrongstatus(d, 27, 28, 38):
return False
if wrongstatus(d, 39, 40, 51):
if common.wrongstatus(d, 39, 40, 51):
return False
# reserved
if bin2int(d[51:56]) != 0:
if common.bin2int(d[51:56]) != 0:
return False
temp = temp45(msg)
@ -71,11 +72,11 @@ def turb45(msg):
int: Turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0] == "0":
return None
turb = bin2int(d[1:3])
turb = common.bin2int(d[1:3])
return turb
@ -89,11 +90,11 @@ def ws45(msg):
int: Wind shear level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[3] == "0":
return None
ws = bin2int(d[4:6])
ws = common.bin2int(d[4:6])
return ws
@ -107,11 +108,11 @@ def mb45(msg):
int: Microburst level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[6] == "0":
return None
mb = bin2int(d[7:9])
mb = common.bin2int(d[7:9])
return mb
@ -125,11 +126,11 @@ def ic45(msg):
int: Icing level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[9] == "0":
return None
ic = bin2int(d[10:12])
ic = common.bin2int(d[10:12])
return ic
@ -143,11 +144,11 @@ def wv45(msg):
int: Wake vortex level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[12] == "0":
return None
ws = bin2int(d[13:15])
ws = common.bin2int(d[13:15])
return ws
@ -161,10 +162,10 @@ def temp45(msg):
float: tmeperature in Celsius degree
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
sign = int(d[16])
value = bin2int(d[17:26])
value = common.bin2int(d[17:26])
if sign:
value = value - 512
@ -185,10 +186,10 @@ def p45(msg):
int: static pressure in hPa
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[26] == "0":
return None
p = bin2int(d[27:38]) # hPa
p = common.bin2int(d[27:38]) # hPa
return p
@ -202,8 +203,8 @@ def rh45(msg):
int: radio height in ft
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[38] == "0":
return None
rh = bin2int(d[39:51]) * 16
rh = common.bin2int(d[39:51]) * 16
return rh

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is50(msg):
@ -18,26 +19,26 @@ def is50(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 1, 12, 24, 35, 46
if wrongstatus(d, 1, 3, 11):
if common.wrongstatus(d, 1, 3, 11):
return False
if wrongstatus(d, 12, 13, 23):
if common.wrongstatus(d, 12, 13, 23):
return False
if wrongstatus(d, 24, 25, 34):
if common.wrongstatus(d, 24, 25, 34):
return False
if wrongstatus(d, 35, 36, 45):
if common.wrongstatus(d, 35, 36, 45):
return False
if wrongstatus(d, 46, 47, 56):
if common.wrongstatus(d, 46, 47, 56):
return False
roll = roll50(msg)
@ -68,13 +69,13 @@ def roll50(msg):
float: angle in degrees,
negative->left wing down, positive->right wing down
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0] == "0":
return None
sign = int(d[1]) # 1 -> left wing down
value = bin2int(d[2:11])
value = common.bin2int(d[2:11])
if sign:
value = value - 512
@ -92,13 +93,13 @@ def trk50(msg):
Returns:
float: angle in degrees to true north (from 0 to 360)
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[11] == "0":
return None
sign = int(d[12]) # 1 -> west
value = bin2int(d[13:23])
value = common.bin2int(d[13:23])
if sign:
value = value - 1024
@ -121,12 +122,12 @@ def gs50(msg):
Returns:
int: ground speed in knots
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[23] == "0":
return None
spd = bin2int(d[24:34]) * 2 # kts
spd = common.bin2int(d[24:34]) * 2 # kts
return spd
@ -139,7 +140,7 @@ def rtrk50(msg):
Returns:
float: angle rate in degrees/second
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[34] == "0":
return None
@ -148,7 +149,7 @@ def rtrk50(msg):
return None
sign = int(d[35]) # 1 -> negative value, two's complement
value = bin2int(d[36:45])
value = common.bin2int(d[36:45])
if sign:
value = value - 512
@ -165,10 +166,10 @@ def tas50(msg):
Returns:
int: true airspeed in knots
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[45] == "0":
return None
tas = bin2int(d[46:56]) * 2 # kts
tas = common.bin2int(d[46:56]) * 2 # kts
return tas

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is53(msg):
@ -18,26 +19,26 @@ def is53(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 1, 13, 24, 34, 47
if wrongstatus(d, 1, 3, 12):
if common.wrongstatus(d, 1, 3, 12):
return False
if wrongstatus(d, 13, 14, 23):
if common.wrongstatus(d, 13, 14, 23):
return False
if wrongstatus(d, 24, 25, 33):
if common.wrongstatus(d, 24, 25, 33):
return False
if wrongstatus(d, 34, 35, 46):
if common.wrongstatus(d, 34, 35, 46):
return False
if wrongstatus(d, 47, 49, 56):
if common.wrongstatus(d, 47, 49, 56):
return False
ias = ias53(msg)
@ -68,13 +69,13 @@ def hdg53(msg):
Returns:
float: angle in degrees to true north (from 0 to 360)
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0] == "0":
return None
sign = int(d[1]) # 1 -> west
value = bin2int(d[2:12])
value = common.bin2int(d[2:12])
if sign:
value = value - 1024
@ -97,12 +98,12 @@ def ias53(msg):
Returns:
int: indicated arispeed in knots
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[12] == "0":
return None
ias = bin2int(d[13:23]) # knots
ias = common.bin2int(d[13:23]) # knots
return ias
@ -115,12 +116,12 @@ def mach53(msg):
Returns:
float: MACH number
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[23] == "0":
return None
mach = bin2int(d[24:33]) * 0.008
mach = common.bin2int(d[24:33]) * 0.008
return round(mach, 3)
@ -133,12 +134,12 @@ def tas53(msg):
Returns:
float: true airspeed in knots
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[33] == "0":
return None
tas = bin2int(d[34:46]) * 0.5 # kts
tas = common.bin2int(d[34:46]) * 0.5 # kts
return round(tas, 1)
@ -151,13 +152,13 @@ def vr53(msg):
Returns:
int: vertical rate in feet/minutes
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[46] == "0":
return None
sign = int(d[47]) # 1 -> negative value, two's complement
value = bin2int(d[48:56])
value = common.bin2int(d[48:56])
if value == 0 or value == 255: # all zeros or all ones
return 0

View File

@ -4,7 +4,8 @@
# ------------------------------------------
from __future__ import absolute_import, print_function, division
from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus
from pyModeS import common
def is60(msg):
@ -17,26 +18,26 @@ def is60(msg):
bool: True or False
"""
if allzeros(msg):
if common.allzeros(msg):
return False
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
# status bit 1, 13, 24, 35, 46
if wrongstatus(d, 1, 2, 12):
if common.wrongstatus(d, 1, 2, 12):
return False
if wrongstatus(d, 13, 14, 23):
if common.wrongstatus(d, 13, 14, 23):
return False
if wrongstatus(d, 24, 25, 34):
if common.wrongstatus(d, 24, 25, 34):
return False
if wrongstatus(d, 35, 36, 45):
if common.wrongstatus(d, 35, 36, 45):
return False
if wrongstatus(d, 46, 47, 56):
if common.wrongstatus(d, 46, 47, 56):
return False
ias = ias60(msg)
@ -67,13 +68,13 @@ def hdg60(msg):
Returns:
float: heading in degrees to megnetic north (from 0 to 360)
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[0] == "0":
return None
sign = int(d[1]) # 1 -> west
value = bin2int(d[2:12])
value = common.bin2int(d[2:12])
if sign:
value = value - 1024
@ -96,12 +97,12 @@ def ias60(msg):
Returns:
int: indicated airspeed in knots
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[12] == "0":
return None
ias = bin2int(d[13:23]) # kts
ias = common.bin2int(d[13:23]) # kts
return ias
@ -114,12 +115,12 @@ def mach60(msg):
Returns:
float: MACH number
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[23] == "0":
return None
mach = bin2int(d[24:34]) * 2.048 / 512.0
mach = common.bin2int(d[24:34]) * 2.048 / 512.0
return round(mach, 3)
@ -132,13 +133,13 @@ def vr60baro(msg):
Returns:
int: vertical rate in feet/minutes
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[34] == "0":
return None
sign = int(d[35]) # 1 -> negative value, two's complement
value = bin2int(d[36:45])
value = common.bin2int(d[36:45])
if value == 0 or value == 511: # all zeros or all ones
return 0
@ -158,13 +159,13 @@ def vr60ins(msg):
Returns:
int: vertical rate in feet/minutes
"""
d = hex2bin(data(msg))
d = common.hex2bin(common.data(msg))
if d[45] == "0":
return None
sign = int(d[46]) # 1 -> negative value, two's complement
value = bin2int(d[47:56])
value = common.bin2int(d[47:56])
if value == 0 or value == 511: # all zeros or all ones
return 0

View File

@ -19,5 +19,5 @@ cpdef int cprNL(double lat)
cpdef str idcode(str msg)
cpdef int altcode(str msg)
cdef str data(str msg)
cpdef str data(str msg)
cpdef bint allzeros(str msg)

View File

@ -391,7 +391,7 @@ cdef int gray2int(str graystr):
return num
cdef str data(str msg):
cpdef str data(str msg):
"""Return the data frame in the message, bytes 9 to 22."""
return msg[8:-6]

View File

@ -3,6 +3,3 @@ Warpper for short roll call surveillance replies DF=4/5
[To be implemented]
"""
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common

View File

@ -1,21 +1,22 @@
from pyModeS.decoder import common
from pyModeS import common
def uplink_icao(msg):
"""Calculate the ICAO address from a Mode-S interrogation (uplink message)"""
p_gen = 0xfffa0480 << ((len(msg)-14)*4)
data = int(msg[:-6],16)
PA = int(msg[-6:],16)
ad = 0
topbit = 0b1 << (len(msg)*4-25)
for j in range(0,len(msg)*4,1):
if (data & topbit):
data^=p_gen
data = (data << 1) + ((PA >> 23) & 1)
PA = PA << 1
if (j>(len(msg)*4-26)):
ad = ad + ((data >> (len(msg)*4-25)) & 1)
ad = ad << 1
return "%06X" % (ad >> 2)
"""Calculate the ICAO address from a Mode-S interrogation (uplink message)"""
p_gen = 0xFFFA0480 << ((len(msg) - 14) * 4)
data = int(msg[:-6], 16)
PA = int(msg[-6:], 16)
ad = 0
topbit = 0b1 << (len(msg) * 4 - 25)
for j in range(0, len(msg) * 4, 1):
if data & topbit:
data ^= p_gen
data = (data << 1) + ((PA >> 23) & 1)
PA = PA << 1
if j > (len(msg) * 4 - 26):
ad = ad + ((data >> (len(msg) * 4 - 25)) & 1)
ad = ad << 1
return "%06X" % (ad >> 2)
def uf(msg):