7 Commits

Author SHA1 Message Date
junzis
140f312c11 new release v1.1.1 2017-03-23 16:15:15 +01:00
junzis
fefd26a787 fix import error in Python3 2017-03-23 16:10:22 +01:00
junzis
1e82b5c59c update EHS module 2017-03-23 13:12:33 +01:00
junzis
a1615767b6 Merge branch 'master' of github.com:junzis/pyModeS 2017-03-23 12:08:36 +01:00
junzis
03a62dc68c update EHS module 2017-03-23 12:08:15 +01:00
junzis
46fee6b7dc update EHS module 2017-03-23 11:48:51 +01:00
Junzi Sun
8aa821c8dd Update requirements.txt 2017-03-22 21:25:07 +01:00
8 changed files with 210 additions and 44 deletions

View File

@@ -1 +1 @@
pyModeS==1.0.5
pyModeS==1.1.0

View File

@@ -17,8 +17,9 @@
A python package for decoding ABS-D messages.
"""
from __future__ import absolute_import, print_function, division
import math
import util
from . import util
def df(msg):

View File

@@ -17,9 +17,8 @@
A python package for decoding ModeS (DF20, DF21) messages.
"""
import util
from util import crc
from __future__ import absolute_import, print_function, division
from . import util
def df(msg):
"""Get the downlink format (DF) number
@@ -53,7 +52,7 @@ def icao(msg):
# raise RuntimeError("Message DF must be in (4, 5, 20, 21)")
return None
c0 = util.bin2int(crc(msg, encode=True))
c0 = util.bin2int(util.crc(msg, encode=True))
c1 = util.hex2int(msg[-6:])
icao = '%06X' % (c0 ^ c1)
return icao
@@ -75,6 +74,59 @@ def checkbits(data, sb, msb, lsb):
return True
# ------------------------------------------
# Common functions
# ------------------------------------------
def isnull(msg):
"""check if the data bits are all zeros
Args:
msg (String): 28 bytes hexadecimal message string
Returns:
bool: True or False
"""
d = util.hex2bin(data(msg))
if util.bin2int(d) > 0:
return False
else:
return True
def df20alt(msg):
"""Computes the altitude from DF20 bit 20-32
Args:
msg (String): 28 bytes hexadecimal message string
Returns:
int: altitude in ft
"""
if df(msg) != 20:
raise RuntimeError("Message must be Downlink Format 20.")
# Altitude code, bit 20-32
mbin = util.hex2bin(msg)
mbit = mbin[25] # M bit: 26
qbit = mbin[27] # Q bit: 28
if mbit == '0': # unit in ft
if qbit == '1': # 25ft interval
vbin = mbin[19:25] + mbin[26] + mbin[28:32]
alt = util.bin2int(vbin) * 25
if qbit == '0': # 100ft interval
# to be implemented
alt = None
if mbit == '1': # unit in meter
vbin = mbin[19:25] + mbin[26:32]
alt = int(util.bin2int(vbin) * 3.28084) # convert to ft
return alt
# ------------------------------------------
# DF 20/21, BDS 2,0
# ------------------------------------------
@@ -89,6 +141,9 @@ def isBDS20(msg):
bool: True or False
"""
if isnull(msg):
return False
# status bit 1, 14, and 27
d = util.hex2bin(data(msg))
@@ -145,6 +200,9 @@ def isBDS40(msg):
bool: True or False
"""
if isnull(msg):
return False
# status bit 1, 14, and 27
d = util.hex2bin(data(msg))
@@ -173,6 +231,10 @@ def alt40mcp(msg):
int: altitude in feet
"""
d = util.hex2bin(data(msg))
if d[0] == '0':
return None
alt = util.bin2int(d[1:13]) * 16 # ft
return alt
@@ -187,6 +249,10 @@ def alt40fms(msg):
int: altitude in feet
"""
d = util.hex2bin(data(msg))
if d[13] == '0':
return None
alt = util.bin2int(d[14:26]) * 16 # ft
return alt
@@ -201,6 +267,10 @@ def p40baro(msg):
float: pressure in millibar
"""
d = util.hex2bin(data(msg))
if d[26] == '0':
return None
p = util.bin2int(d[27:39]) * 0.1 + 800 # millibar
return p
@@ -221,6 +291,9 @@ def isBDS44(msg, rev=False):
bool: True or False
"""
if isnull(msg):
return False
d = util.hex2bin(data(msg))
result = True
@@ -231,15 +304,17 @@ def isBDS44(msg, rev=False):
& checkbits(d, 35, 36, 46) & checkbits(d, 47, 48, 49) \
& checkbits(d, 50, 51, 56)
else:
# status bit 5, 15, 24, 36, 49
result = result & checkbits(d, 5, 6, 14) \
& checkbits(d, 15, 16, 23) & checkbits(d, 24, 25, 35) \
& checkbits(d, 36, 37, 47) & checkbits(d, 49, 50, 56)
if not result:
return False
vw = wind44(msg, rev=rev)
if vw and vw[0] > 250:
if vw is not None and vw[0] > 250:
result &= False
# if temp44(msg):
@@ -295,13 +370,14 @@ def temp44(msg, rev=False):
d = util.hex2bin(data(msg))
if not rev:
if d[22] == '0':
return None
sign = int(d[23])
temp = util.bin2int(d[24:34]) * 0.125 # celsius
temp = round(temp, 1)
else:
status = int(d[23])
if not status:
if d[23] == '0':
return None
sign = int(d[24])
@@ -324,15 +400,13 @@ def p44(msg, rev=False):
d = util.hex2bin(data(msg))
if not rev:
status = int(d[34])
if not status:
if d[34] == '0':
return None
p = util.bin2int(d[35:46]) # hPa
else:
status = int(d[35])
if not status:
if d[35] == '0':
return None
p = util.bin2int(d[36:47]) # hPa
@@ -353,15 +427,13 @@ def hum44(msg, rev=False):
d = util.hex2bin(data(msg))
if not rev:
status = int(d[49])
if not status:
if d[49] == '0':
return None
hm = util.bin2int(d[50:56]) * 100.0 / 64 # %
else:
status = int(d[48])
if not status:
if d[48] == '0':
return None
hm = util.bin2int(d[49:56]) # %
@@ -385,6 +457,9 @@ def isBDS50(msg):
bool: True or False
"""
if isnull(msg):
return False
# status bit 1, 12, 24, 35, 46
d = util.hex2bin(data(msg))
@@ -394,19 +469,25 @@ def isBDS50(msg):
& checkbits(d, 24, 25, 34) & checkbits(d, 35, 36, 45) \
& checkbits(d, 46, 47, 56)
if not result:
return False
if d[2:11] == "000000000":
result &= True
else:
if abs(roll50(msg)) > 30:
roll = abs(roll50(msg))
if roll and roll > 30:
result &= False
if gs50(msg) > 600:
gs = gs50(msg)
if gs is not None and gs > 600:
result &= False
if tas50(msg) > 500:
tas = tas50(msg)
if tas is not None and tas > 500:
result &= False
if abs(tas50(msg) - gs50(msg)) > 100:
if (gs is not None) and (tas is not None) and (abs(tas - gs) > 200):
result &= False
return result
@@ -423,6 +504,10 @@ def roll50(msg):
negative->left wing down, positive->right wing down
"""
d = util.hex2bin(data(msg))
if d[0] == '0':
return None
sign = int(d[1]) # 1 -> left wing down
value = util.bin2int(d[2:11]) * 45.0 / 256.0 # degree
angle = -1 * value if sign else value
@@ -439,6 +524,10 @@ def trk50(msg):
float: angle in degrees to true north (from 0 to 360)
"""
d = util.hex2bin(data(msg))
if d[11] == '0':
return None
sign = int(d[12]) # 1 -> west
value = util.bin2int(d[13:23]) * 90.0 / 512.0 # degree
angle = 360 - value if sign else value
@@ -455,6 +544,10 @@ def gs50(msg):
int: ground speed in knots
"""
d = util.hex2bin(data(msg))
if d[23] == '0':
return None
spd = util.bin2int(d[24:34]) * 2 # kts
return spd
@@ -469,6 +562,13 @@ def rtrk50(msg):
float: angle rate in degrees/second
"""
d = util.hex2bin(data(msg))
if d[34] == '0':
return None
if d[36:45] == "111111111":
return None
sign = int(d[35]) # 1 -> minus
value = util.bin2int(d[36:45]) * 8.0 / 256.0 # degree / sec
angle = -1 * value if sign else value
@@ -485,6 +585,10 @@ def tas50(msg):
int: true airspeed in knots
"""
d = util.hex2bin(data(msg))
if d[45] == '0':
return None
tas = util.bin2int(d[46:56]) * 2 # kts
return tas
@@ -505,6 +609,9 @@ def isBDS53(msg):
bool: True or False
"""
if isnull(msg):
return False
# status bit 1, 13, 24, 34, 47
d = util.hex2bin(data(msg))
@@ -514,16 +621,23 @@ def isBDS53(msg):
& checkbits(d, 24, 25, 33) & checkbits(d, 34, 35, 46) \
& checkbits(d, 47, 49, 56)
if ias53(msg) > 500:
if not result:
return False
ias = ias53(msg)
if ias is not None and ias > 500:
result &= False
if mach53(msg) > 1:
mach = mach53(msg)
if mach is not None and mach > 1:
result &= False
if tas53(msg) > 500:
tas = tas53(msg)
if tas is not None and tas > 500:
result &= False
if abs(vr53(msg)) > 8000:
vr = vr53(msg)
if vr is not None and abs(vr) > 8000:
result &= False
return result
@@ -539,6 +653,10 @@ def hdg53(msg):
float: angle in degrees to true north (from 0 to 360)
"""
d = util.hex2bin(data(msg))
if d[0] == '0':
return None
sign = int(d[1]) # 1 -> west
value = util.bin2int(d[2:12]) * 90.0 / 512.0 # degree
angle = 360 - value if sign else value
@@ -555,6 +673,10 @@ def ias53(msg):
int: indicated arispeed in knots
"""
d = util.hex2bin(data(msg))
if d[12] == '0':
return None
ias = util.bin2int(d[13:23]) # knots
return ias
@@ -569,6 +691,10 @@ def mach53(msg):
float: MACH number
"""
d = util.hex2bin(data(msg))
if d[23] == '0':
return None
mach = util.bin2int(d[24:33]) * 0.008
return round(mach, 3)
@@ -583,6 +709,10 @@ def tas53(msg):
float: true airspeed in knots
"""
d = util.hex2bin(data(msg))
if d[33] == '0':
return None
tas = util.bin2int(d[34:46]) * 0.5 # kts
return round(tas, 1)
@@ -596,6 +726,10 @@ def vr53(msg):
int: vertical rate in feet/minutes
"""
d = util.hex2bin(data(msg))
if d[46] == '0':
return None
sign = d[47] # 1 -> minus
value = util.bin2int(d[48:56]) * 64 # feet/min
roc = -1*value if sign else value
@@ -615,6 +749,10 @@ def isBDS60(msg):
Returns:
bool: True or False
"""
if isnull(msg):
return False
# status bit 1, 13, 24, 35, 46
d = util.hex2bin(data(msg))
@@ -624,16 +762,23 @@ def isBDS60(msg):
& checkbits(d, 24, 25, 34) & checkbits(d, 35, 36, 45) \
& checkbits(d, 46, 47, 56)
if not (1 < ias60(msg) < 500):
if not result:
return False
ias = ias60(msg)
if ias is not None and ias > 500:
result &= False
if not (0.0 < mach60(msg) < 1.0):
mach = mach60(msg)
if mach is not None and mach > 1:
result &= False
if abs(vr60baro(msg)) > 5000:
vrb = vr60baro(msg)
if vrb is not None and abs(vrb) > 5000:
result &= False
if abs(vr60ins(msg)) > 5000:
vri = vr60ins(msg)
if vri is not None and abs(vri) > 5000:
result &= False
return result
@@ -649,6 +794,10 @@ def hdg60(msg):
float: heading in degrees to megnetic north (from 0 to 360)
"""
d = util.hex2bin(data(msg))
if d[0] == '0':
return None
sign = int(d[1]) # 1 -> west
value = util.bin2int(d[2:12]) * 90 / 512.0 # degree
hdg = 360 - value if sign else value
@@ -665,6 +814,10 @@ def ias60(msg):
int: indicated airspeed in knots
"""
d = util.hex2bin(data(msg))
if d[12] == '0':
return None
ias = util.bin2int(d[13:23]) # kts
return ias
@@ -679,6 +832,10 @@ def mach60(msg):
float: MACH number
"""
d = util.hex2bin(data(msg))
if d[23] == '0':
return None
mach = util.bin2int(d[24:34]) * 2.048 / 512.0
return round(mach, 3)
@@ -693,6 +850,10 @@ def vr60baro(msg):
int: vertical rate in feet/minutes
"""
d = util.hex2bin(data(msg))
if d[34] == '0':
return None
sign = d[35] # 1 -> minus
value = util.bin2int(d[36:45]) * 32 # feet/min
roc = -1*value if sign else value
@@ -709,6 +870,10 @@ def vr60ins(msg):
int: vertical rate in feet/minutes
"""
d = util.hex2bin(data(msg))
if d[45] == '0':
return None
sign = d[46] # 1 -> minus
value = util.bin2int(d[47:56]) * 32 # feet/min
roc = -1*value if sign else value
@@ -724,6 +889,10 @@ def BDS(msg):
Returns:
String or None: Version: "BDS20", "BDS40", "BDS50", or "BDS60". Or None, if nothing matched
"""
if isnull(msg):
return None
is20 = isBDS20(msg)
is40 = isBDS40(msg)
is44 = isBDS44(msg)

View File

@@ -30,7 +30,7 @@ setup(
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.1.0',
version='1.1.1',
description='Python Mode-S Decoder',
long_description=long_description,

View File

@@ -1,6 +1,4 @@
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'/pyModeS')
import adsb, ehs, util
from pyModeS import adsb, ehs, util
# === Decode sample data file ===

View File

@@ -1,6 +1,4 @@
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'/pyModeS')
import adsb
from pyModeS import adsb
# === TEST ADS-B package ===

View File

@@ -1,6 +1,4 @@
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'/pyModeS')
import ehs
from pyModeS import ehs
def test_ehs_icao():
@@ -9,6 +7,10 @@ def test_ehs_icao():
assert ehs.icao("A000029CFFBAA11E2004727281F1") == '4243D0'
def test_df20alt():
assert ehs.df20alt("A02014B400000000000000F9D514") == 33300
def test_ehs_BDS():
assert ehs.BDS("A0001838201584F23468207CDFA5") == 'BDS20'
assert ehs.BDS("A0001839CA3800315800007448D9") == 'BDS40'

View File

@@ -1,6 +1,4 @@
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'/pyModeS')
import util
from pyModeS import util
def test_hex2bin():