Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
140f312c11 | ||
|
|
fefd26a787 | ||
|
|
1e82b5c59c | ||
|
|
a1615767b6 | ||
|
|
03a62dc68c | ||
|
|
46fee6b7dc | ||
|
|
8aa821c8dd | ||
|
|
621d3e7580 | ||
|
|
3b3609bf2b | ||
|
|
ef2268127c |
57
README.rst
57
README.rst
@@ -9,11 +9,15 @@ implemented to decode the following messages:
|
||||
- aircraft information that contains: ICAO address, position,
|
||||
altitude, velocity (ground speed), callsign, etc.
|
||||
|
||||
- Mode-S Enhanced Surveillance (EHS) (DF20 and DF21)
|
||||
- Mode-S Enhanced Surveillance (EHS) (DF20 and DF21). Additional information in response to SSR interrogation, such as: true airspeed, indicated airspeed, mach number, wind, temperature, etc.
|
||||
|
||||
- additional information in response to SSR interrogation, such as:
|
||||
true airspeed, indicated airspeed, mach number, track angle,
|
||||
heading, roll angle, etc.
|
||||
- BDS 2,0 Aircraft identification
|
||||
- BDS 2,1 Aircraft and airline registration markings
|
||||
- BDS 4,0 Selected vertical intention
|
||||
- BDS 4,4 Meteorological routine air report
|
||||
- BDS 5,0 Track and turn report
|
||||
- BDS 5,3 Air-referenced state vector
|
||||
- BDS 6,0 Heading and speed report
|
||||
|
||||
A detailed manual on Mode-S decoding is published by the author, at:
|
||||
http://adsb-decode-guide.readthedocs.io
|
||||
@@ -93,26 +97,45 @@ Core functions for EHS decoding:
|
||||
pms.ehs.BDS(msg) # Comm-B Data Selector Version
|
||||
|
||||
# for BDS version 2,0
|
||||
pms.ehs.isBDS20(msg) # Check if message is BDS 2,0
|
||||
pms.ehs.callsign(msg) # Aircraft callsign
|
||||
|
||||
# for BDS version 4,0
|
||||
pms.ehs.alt_mcp(msg) # MCP/FCU selected altitude (ft)
|
||||
pms.ehs.alt_fms(msg) # FMS selected altitude (ft)
|
||||
pms.ehs.alt_pbaro(msg) # Barometric pressure (mb)
|
||||
pms.ehs.isBDS40(msg) # Check if message is BDS 4,0
|
||||
pms.ehs.alt40mcp(msg) # MCP/FCU selected altitude (ft)
|
||||
pms.ehs.alt40fms(msg) # FMS selected altitude (ft)
|
||||
pms.ehs.p40baro(msg) # Barometric pressure (mb)
|
||||
|
||||
# for BDS version 4,4
|
||||
pms.ehs.isBDS44(msg, rev=False) # Check if message is BDS 4,4
|
||||
pms.ehs.wind44(msg, rev=False) # wind speed (kt) and heading (deg)
|
||||
pms.ehs.temp44(msg, rev=False) # temperature (C)
|
||||
pms.ehs.p44(msg, rev=False) # pressure (hPa)
|
||||
pms.ehs.hum44(msg, rev=False) # humidity (%)
|
||||
|
||||
# for BDS version 5,0
|
||||
pms.ehs.roll(msg) # roll angle (deg)
|
||||
pms.ehs.track(msg) # track angle (deg)
|
||||
pms.ehs.gs(msg) # ground speed (kt)
|
||||
pms.ehs.rtrack(msg) # track angle rate (deg/sec)
|
||||
pms.ehs.tas(msg) # true airspeed (kt)
|
||||
pms.ehs.isBDS50(msg) # Check if message is BDS 5,0
|
||||
pms.ehs.roll50(msg) # roll angle (deg)
|
||||
pms.ehs.trk50(msg) # track angle (deg)
|
||||
pms.ehs.gs50(msg) # ground speed (kt)
|
||||
pms.ehs.rtrk50(msg) # track angle rate (deg/sec)
|
||||
pms.ehs.tas50(msg) # true airspeed (kt)
|
||||
|
||||
# for BDS version 5,3
|
||||
pms.ehs.isBDS53(msg) # Check if message is BDS 5,3
|
||||
pms.ehs.hdg53(msg) # magnetic heading (deg)
|
||||
pms.ehs.ias53(msg) # indicated airspeed (kt)
|
||||
pms.ehs.mach53(msg) # MACH number
|
||||
pms.ehs.tas53(msg) # true airspeed (kt)
|
||||
pms.ehs.vr53(msg) # vertical rate (fpm)
|
||||
|
||||
# for BDS version 6,0
|
||||
pms.ehs.heading(msg) # heading (deg)
|
||||
pms.ehs.ias(msg) # indicated airspeed (kt)
|
||||
pms.ehs.mach(msg) # MACH number
|
||||
pms.ehs.baro_vr(msg) # barometric altitude rate (ft/min)
|
||||
pms.ehs.ins_vr(msg) # inertial vertical speed (ft/min)
|
||||
pms.ehs.isBDS60(msg) # Check if message is BDS 6,0
|
||||
pms.ehs.hdg60(msg) # heading (deg)
|
||||
pms.ehs.ias60(msg) # indicated airspeed (kt)
|
||||
pms.ehs.mach60(msg) # MACH number
|
||||
pms.ehs.vr60baro(msg) # barometric altitude rate (ft/min)
|
||||
pms.ehs.vr60ins(msg) # inertial vertical speed (ft/min)
|
||||
|
||||
Developement
|
||||
------------
|
||||
|
||||
@@ -1 +1 @@
|
||||
pyModeS==1.0.5
|
||||
pyModeS==1.1.0
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
A python package for decoding ABS-D messages.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, print_function, division
|
||||
import math
|
||||
from . import util
|
||||
|
||||
@@ -638,6 +639,7 @@ def surface_velocity(msg):
|
||||
hdg_status = int(msgbin[44])
|
||||
if hdg_status == 1:
|
||||
hdg = util.bin2int(msgbin[45:52]) * 360.0 / 128.0
|
||||
hdg = round(hdg, 1)
|
||||
else:
|
||||
hdg = None
|
||||
|
||||
@@ -656,5 +658,6 @@ def surface_velocity(msg):
|
||||
i = next(m[0] for m in enumerate(movs) if m[1] > mov)
|
||||
step = (kts[i] - kts[i-1]) * 1.0 / (movs[i]-movs[i-1])
|
||||
spd = kts[i-1] + (mov-movs[i-1]) * step
|
||||
spd = round(spd, 2)
|
||||
|
||||
return round(spd, 2), round(hdg, 1), 0, 'GS'
|
||||
return spd, hdg, 0, 'GS'
|
||||
|
||||
408
pyModeS/ehs.py
408
pyModeS/ehs.py
@@ -17,9 +17,8 @@
|
||||
A python package for decoding ModeS (DF20, DF21) messages.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, print_function, division
|
||||
from . import util
|
||||
from .util import crc
|
||||
|
||||
|
||||
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))
|
||||
|
||||
@@ -163,7 +221,7 @@ def isBDS40(msg):
|
||||
return result
|
||||
|
||||
|
||||
def alt_mcp(msg):
|
||||
def alt40mcp(msg):
|
||||
"""Selected altitude, MCP/FCU
|
||||
|
||||
Args:
|
||||
@@ -173,11 +231,15 @@ def alt_mcp(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
|
||||
|
||||
|
||||
def alt_fms(msg):
|
||||
def alt40fms(msg):
|
||||
"""Selected altitude, FMS
|
||||
|
||||
Args:
|
||||
@@ -187,11 +249,15 @@ def alt_fms(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
|
||||
|
||||
|
||||
def pbaro(msg):
|
||||
def p40baro(msg):
|
||||
"""Barometric pressure setting
|
||||
|
||||
Args:
|
||||
@@ -201,6 +267,10 @@ def pbaro(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
|
||||
|
||||
@@ -209,7 +279,7 @@ def pbaro(msg):
|
||||
# DF 20/21, BDS 4,4
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS44(msg, rev=True):
|
||||
def isBDS44(msg, rev=False):
|
||||
"""Check if a message is likely to be BDS code 4,4
|
||||
Meteorological routine air report
|
||||
|
||||
@@ -221,6 +291,9 @@ def isBDS44(msg, rev=True):
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
if isnull(msg):
|
||||
return False
|
||||
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
result = True
|
||||
@@ -231,25 +304,27 @@ def isBDS44(msg, rev=True):
|
||||
& 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)
|
||||
|
||||
vw = wind(msg, rev=rev)
|
||||
if vw and vw[0] > 250:
|
||||
if not result:
|
||||
return False
|
||||
|
||||
vw = wind44(msg, rev=rev)
|
||||
if vw is not None and vw[0] > 250:
|
||||
result &= False
|
||||
|
||||
# if temperature(msg):
|
||||
# if temperature(msg) > 60 or temperature(msg) < -80:
|
||||
# if temp44(msg):
|
||||
# if temp44(msg) > 60 or temp44(msg) < -80:
|
||||
# result &= False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def wind(msg, rev=True):
|
||||
def wind44(msg, rev=False):
|
||||
"""reported wind speed and direction
|
||||
|
||||
Args:
|
||||
@@ -282,7 +357,7 @@ def wind(msg, rev=True):
|
||||
return round(speed, 0), round(direction, 1)
|
||||
|
||||
|
||||
def temperature(msg, rev=True):
|
||||
def temp44(msg, rev=False):
|
||||
"""reported air temperature
|
||||
|
||||
Args:
|
||||
@@ -295,23 +370,24 @@ def temperature(msg, rev=True):
|
||||
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])
|
||||
temp = util.bin2int(d[25:35]) * 0.125 # celsius
|
||||
temp = round(temp, 1)
|
||||
|
||||
return temp if sign else -1*temp
|
||||
return -1*temp if sign else temp
|
||||
|
||||
|
||||
def pressure(msg, rev=True):
|
||||
def p44(msg, rev=False):
|
||||
"""reported average static pressure
|
||||
|
||||
Args:
|
||||
@@ -324,15 +400,13 @@ def pressure(msg, rev=True):
|
||||
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
|
||||
@@ -340,7 +414,7 @@ def pressure(msg, rev=True):
|
||||
return p
|
||||
|
||||
|
||||
def humidity(msg, rev=True):
|
||||
def hum44(msg, rev=False):
|
||||
"""reported humidity
|
||||
|
||||
Args:
|
||||
@@ -353,15 +427,13 @@ def humidity(msg, rev=True):
|
||||
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]) # %
|
||||
@@ -371,10 +443,12 @@ def humidity(msg, rev=True):
|
||||
|
||||
# ------------------------------------------
|
||||
# DF 20/21, BDS 5,0
|
||||
# Track and turn report
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS50(msg):
|
||||
"""Check if a message is likely to be BDS code 5,0
|
||||
(Track and turn report)
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
@@ -383,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))
|
||||
|
||||
@@ -392,26 +469,32 @@ 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(roll(msg)) > 30:
|
||||
roll = abs(roll50(msg))
|
||||
if roll and roll > 30:
|
||||
result &= False
|
||||
|
||||
if gs(msg) > 600:
|
||||
gs = gs50(msg)
|
||||
if gs is not None and gs > 600:
|
||||
result &= False
|
||||
|
||||
if tas(msg) > 500:
|
||||
tas = tas50(msg)
|
||||
if tas is not None and tas > 500:
|
||||
result &= False
|
||||
|
||||
if abs(tas(msg) - gs(msg)) > 100:
|
||||
if (gs is not None) and (tas is not None) and (abs(tas - gs) > 200):
|
||||
result &= False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def roll(msg):
|
||||
"""Aircraft roll angle
|
||||
def roll50(msg):
|
||||
"""Roll angle, BDS 5,0 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
@@ -421,14 +504,18 @@ def roll(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 / 256.0 # degree
|
||||
value = util.bin2int(d[2:11]) * 45.0 / 256.0 # degree
|
||||
angle = -1 * value if sign else value
|
||||
return round(angle, 1)
|
||||
|
||||
|
||||
def track(msg):
|
||||
"""True track angle
|
||||
def trk50(msg):
|
||||
"""True track angle, BDS 5,0 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
@@ -437,14 +524,18 @@ def track(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 / 512.0 # degree
|
||||
value = util.bin2int(d[13:23]) * 90.0 / 512.0 # degree
|
||||
angle = 360 - value if sign else value
|
||||
return round(angle, 1)
|
||||
|
||||
|
||||
def gs(msg):
|
||||
"""Aircraft ground speed
|
||||
def gs50(msg):
|
||||
"""Ground speed, BDS 5,0 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
@@ -453,12 +544,16 @@ def gs(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
|
||||
|
||||
|
||||
def rtrack(msg):
|
||||
"""Track angle rate
|
||||
def rtrk50(msg):
|
||||
"""Track angle rate, BDS 5,0 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
@@ -467,14 +562,21 @@ def rtrack(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 / 256.0 # degree / sec
|
||||
value = util.bin2int(d[36:45]) * 8.0 / 256.0 # degree / sec
|
||||
angle = -1 * value if sign else value
|
||||
return round(angle, 3)
|
||||
|
||||
|
||||
def tas(msg):
|
||||
"""Aircraft true airspeed
|
||||
def tas50(msg):
|
||||
"""Aircraft true airspeed, BDS 5,0 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS50) string
|
||||
@@ -483,8 +585,155 @@ def tas(msg):
|
||||
int: true airspeed in knots
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
spd = util.bin2int(d[46:56]) * 2 # kts
|
||||
return spd
|
||||
|
||||
if d[45] == '0':
|
||||
return None
|
||||
|
||||
tas = util.bin2int(d[46:56]) * 2 # kts
|
||||
return tas
|
||||
|
||||
|
||||
# ------------------------------------------
|
||||
# DF 20/21, BDS 5,3
|
||||
# Air-referenced state vector
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS53(msg):
|
||||
"""Check if a message is likely to be BDS code 5,3
|
||||
(Air-referenced state vector)
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
if isnull(msg):
|
||||
return False
|
||||
|
||||
# status bit 1, 13, 24, 34, 47
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
result = True
|
||||
|
||||
result = result & checkbits(d, 1, 3, 12) & checkbits(d, 13, 14, 23) \
|
||||
& checkbits(d, 24, 25, 33) & checkbits(d, 34, 35, 46) \
|
||||
& checkbits(d, 47, 49, 56)
|
||||
|
||||
if not result:
|
||||
return False
|
||||
|
||||
ias = ias53(msg)
|
||||
if ias is not None and ias > 500:
|
||||
result &= False
|
||||
|
||||
mach = mach53(msg)
|
||||
if mach is not None and mach > 1:
|
||||
result &= False
|
||||
|
||||
tas = tas53(msg)
|
||||
if tas is not None and tas > 500:
|
||||
result &= False
|
||||
|
||||
vr = vr53(msg)
|
||||
if vr is not None and abs(vr) > 8000:
|
||||
result &= False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def hdg53(msg):
|
||||
"""Magnetic heading, BDS 5,3 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS53) string
|
||||
|
||||
Returns:
|
||||
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
|
||||
return round(angle, 1)
|
||||
|
||||
|
||||
def ias53(msg):
|
||||
"""Indicated airspeed, DBS 5,3 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message
|
||||
|
||||
Returns:
|
||||
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
|
||||
|
||||
|
||||
def mach53(msg):
|
||||
"""MACH number, DBS 5,3 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message
|
||||
|
||||
Returns:
|
||||
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)
|
||||
|
||||
|
||||
def tas53(msg):
|
||||
"""Aircraft true airspeed, BDS 5,3 message
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message
|
||||
|
||||
Returns:
|
||||
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)
|
||||
|
||||
def vr53(msg):
|
||||
"""Vertical rate
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS60) string
|
||||
|
||||
Returns:
|
||||
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
|
||||
return roc
|
||||
|
||||
|
||||
# ------------------------------------------
|
||||
@@ -500,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))
|
||||
|
||||
@@ -509,22 +762,29 @@ def isBDS60(msg):
|
||||
& checkbits(d, 24, 25, 34) & checkbits(d, 35, 36, 45) \
|
||||
& checkbits(d, 46, 47, 56)
|
||||
|
||||
if not (1 < ias(msg) < 500):
|
||||
if not result:
|
||||
return False
|
||||
|
||||
ias = ias60(msg)
|
||||
if ias is not None and ias > 500:
|
||||
result &= False
|
||||
|
||||
if not (0.0 < mach(msg) < 1.0):
|
||||
mach = mach60(msg)
|
||||
if mach is not None and mach > 1:
|
||||
result &= False
|
||||
|
||||
if abs(baro_vr(msg)) > 5000:
|
||||
vrb = vr60baro(msg)
|
||||
if vrb is not None and abs(vrb) > 5000:
|
||||
result &= False
|
||||
|
||||
if abs(ins_vr(msg)) > 5000:
|
||||
vri = vr60ins(msg)
|
||||
if vri is not None and abs(vri) > 5000:
|
||||
result &= False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def heading(msg):
|
||||
def hdg60(msg):
|
||||
"""Megnetic heading of aircraft
|
||||
|
||||
Args:
|
||||
@@ -534,13 +794,17 @@ def heading(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
|
||||
return round(hdg, 1)
|
||||
|
||||
|
||||
def ias(msg):
|
||||
def ias60(msg):
|
||||
"""Indicated airspeed
|
||||
|
||||
Args:
|
||||
@@ -550,11 +814,15 @@ def ias(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
|
||||
|
||||
|
||||
def mach(msg):
|
||||
def mach60(msg):
|
||||
"""Aircraft MACH number
|
||||
|
||||
Args:
|
||||
@@ -564,11 +832,15 @@ def mach(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)
|
||||
|
||||
|
||||
def baro_vr(msg):
|
||||
def vr60baro(msg):
|
||||
"""Vertical rate from barometric measurement
|
||||
|
||||
Args:
|
||||
@@ -578,13 +850,17 @@ def baro_vr(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
|
||||
return roc
|
||||
|
||||
|
||||
def ins_vr(msg):
|
||||
def vr60ins(msg):
|
||||
"""Vertical rate messured by onbard equiments (IRS, AHRS)
|
||||
|
||||
Args:
|
||||
@@ -594,6 +870,10 @@ def ins_vr(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
|
||||
@@ -609,16 +889,24 @@ 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)
|
||||
is44 = isBDS44(msg)
|
||||
is40 = isBDS40(msg)
|
||||
is44 = isBDS44(msg)
|
||||
is44rev = isBDS44(msg, rev=True)
|
||||
is50 = isBDS50(msg)
|
||||
is53 = isBDS53(msg)
|
||||
is60 = isBDS60(msg)
|
||||
|
||||
BDS = ["BDS20", "BDS40", "BDS44", "BDS50", "BDS60"]
|
||||
isBDS = [is20, is40, is44, is50, is60]
|
||||
BDS = ["BDS20", "BDS40", "BDS44", "BDS44REV", "BDS50", "BDS53", "BDS60"]
|
||||
isBDS = [is20, is40, is44, is44rev, is50, is53, is60]
|
||||
|
||||
if sum(isBDS) == 0:
|
||||
return None
|
||||
if sum(isBDS) == 1:
|
||||
return BDS[isBDS.index(True)]
|
||||
else:
|
||||
return None
|
||||
return [bds for (bds, i) in zip(BDS, isBDS) if i]
|
||||
|
||||
2
setup.py
2
setup.py
@@ -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.0.9',
|
||||
version='1.1.1',
|
||||
|
||||
description='Python Mode-S Decoder',
|
||||
long_description=long_description,
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
# If you get import error run with ipython
|
||||
from pyModeS import adsb
|
||||
from pyModeS import ehs
|
||||
from pyModeS import util
|
||||
from pyModeS import adsb, ehs, util
|
||||
|
||||
|
||||
# === Decode sample data file ===
|
||||
@@ -54,27 +51,33 @@ def ehs_decode_all(n=None):
|
||||
vBDS = ehs.BDS(m)
|
||||
|
||||
if vBDS:
|
||||
if isinstance(vBDS, list):
|
||||
print(ts, m, icao, vBDS)
|
||||
if vBDS == "BDS20":
|
||||
print(ts, m, icao, vBDS, ehs.callsign(m))
|
||||
|
||||
if vBDS == "BDS40":
|
||||
print(ts, m, icao, vBDS, ehs.alt_mcp(m),
|
||||
ehs.alt_fms(m), ehs.pbaro(m))
|
||||
print(ts, m, icao, vBDS, ehs.alt40mcp(m),
|
||||
ehs.alt40fms(m), ehs.p40baro(m))
|
||||
|
||||
if vBDS == "BDS44":
|
||||
print(ts, m, icao, vBDS, ehs.wind(m),
|
||||
ehs.temperature(m), ehs.pressure(m))
|
||||
print(ts, m, icao, vBDS, ehs.wind44(m),
|
||||
ehs.temp44(m), ehs.p44(m))
|
||||
|
||||
if vBDS == "BDS50":
|
||||
print(ts, m, icao, vBDS, ehs.roll(m), ehs.track(m),
|
||||
ehs.gs(m), ehs.rtrack(m), ehs.tas(m))
|
||||
print(ts, m, icao, vBDS, ehs.roll50(m), ehs.trk50(m),
|
||||
ehs.gs50(m), ehs.rtrk50(m), ehs.tas50(m))
|
||||
|
||||
if vBDS == "BDS53":
|
||||
print(ts, m, icao, vBDS, ehs.hdg53(m), ehs.ias53(m),
|
||||
ehs.mach53(m), ehs.tas53(m), ehs.vr53(m))
|
||||
|
||||
if vBDS == "BDS60":
|
||||
print(ts, m, icao, vBDS, ehs.heading(m), ehs.ias(m),
|
||||
ehs.mach(m), ehs.baro_vr(m), ehs.ins_vr(m))
|
||||
print(ts, m, icao, vBDS, ehs.hdg60(m), ehs.ias60(m),
|
||||
ehs.mach60(m), ehs.vr60baro(m), ehs.vr60ins(m))
|
||||
else:
|
||||
print(ts, m, icao, 'UNKNOWN')
|
||||
|
||||
if __name__ == '__main__':
|
||||
adsb_decode_all(100)
|
||||
# adsb_decode_all(100)
|
||||
ehs_decode_all(100)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from pyModeS import adsb
|
||||
|
||||
|
||||
# === TEST ADS-B package ===
|
||||
|
||||
def test_adsb_icao():
|
||||
|
||||
@@ -7,13 +7,15 @@ 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'
|
||||
assert ehs.BDS("A000139381951536E024D4CCF6B5") == 'BDS50'
|
||||
assert ehs.BDS("A000029CFFBAA11E2004727281F1") == 'BDS60'
|
||||
assert ehs.BDS("A0281838CAE9E12FA03FFF2DDDE5") == 'BDS44'
|
||||
assert ehs.BDS("A00017B0C8480030A4000024512F") is None
|
||||
|
||||
|
||||
def test_ehs_BDS20_callsign():
|
||||
@@ -22,22 +24,22 @@ def test_ehs_BDS20_callsign():
|
||||
|
||||
|
||||
def test_ehs_BDS40_functions():
|
||||
assert ehs.alt_mcp("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.alt_fms("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.pbaro("A000029C85E42F313000007047D3") == 1020.0
|
||||
assert ehs.alt40mcp("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.alt40fms("A000029C85E42F313000007047D3") == 3008
|
||||
assert ehs.p40baro("A000029C85E42F313000007047D3") == 1020.0
|
||||
|
||||
|
||||
def test_ehs_BDS50_functions():
|
||||
assert ehs.roll("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert ehs.track("A000139381951536E024D4CCF6B5") == 114.3
|
||||
assert ehs.gs("A000139381951536E024D4CCF6B5") == 438
|
||||
assert ehs.rtrack("A000139381951536E024D4CCF6B5") == 0.125
|
||||
assert ehs.tas("A000139381951536E024D4CCF6B5") == 424
|
||||
assert ehs.roll50("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert ehs.trk50("A000139381951536E024D4CCF6B5") == 114.3
|
||||
assert ehs.gs50("A000139381951536E024D4CCF6B5") == 438
|
||||
assert ehs.rtrk50("A000139381951536E024D4CCF6B5") == 0.125
|
||||
assert ehs.tas50("A000139381951536E024D4CCF6B5") == 424
|
||||
|
||||
|
||||
def test_ehs_BDS60_functions():
|
||||
assert ehs.heading("A000029CFFBAA11E2004727281F1") == 180.9
|
||||
assert ehs.ias("A000029CFFBAA11E2004727281F1") == 336
|
||||
assert ehs.mach("A000029CFFBAA11E2004727281F1") == 0.48
|
||||
assert ehs.baro_vr("A000029CFFBAA11E2004727281F1") == 0
|
||||
assert ehs.ins_vr("A000029CFFBAA11E2004727281F1") == -3648
|
||||
assert ehs.hdg60("A000029CFFBAA11E2004727281F1") == 180.9
|
||||
assert ehs.ias60("A000029CFFBAA11E2004727281F1") == 336
|
||||
assert ehs.mach60("A000029CFFBAA11E2004727281F1") == 0.48
|
||||
assert ehs.vr60baro("A000029CFFBAA11E2004727281F1") == 0
|
||||
assert ehs.vr60ins("A000029CFFBAA11E2004727281F1") == -3648
|
||||
|
||||
@@ -12,4 +12,4 @@ def test_crc_decode():
|
||||
|
||||
def test_crc_encode():
|
||||
parity = util.crc("8D406B902015A678D4D220AA4BDA", encode=True)
|
||||
assert util.hex2bin("AA4BDA") == parity
|
||||
assert util.hex2bin("AA4BDA") == parity
|
||||
|
||||
Reference in New Issue
Block a user