Update allcall.py
This commit is contained in:
+54
-21
@@ -3,31 +3,61 @@ from pyModeS import common
|
|||||||
Decoding all call replies DF=11
|
Decoding all call replies DF=11
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def ipcode(msg):
|
def ipcode(msg):
|
||||||
'''Returns the IP code of the Mode S all-call reply (DF11)'''
|
if common.df(msg) == 11: # check that the msg is DF11
|
||||||
binaryraw=common.hex2bin(msg)
|
'''Returns the IP code of the Mode S all-call reply (DF11)'''
|
||||||
PI=binaryraw[-24:]
|
binaryraw=common.hex2bin(msg)
|
||||||
DATA=binaryraw[:-24]
|
PI=binaryraw[-24:]
|
||||||
|
DATA=binaryraw[:-24]
|
||||||
|
|
||||||
Gx='1111111111111010000001001000'
|
Gx='1111111111111010000001001000'
|
||||||
Mx=DATA[::-1].zfill(len(DATA)+24)[::-1]
|
Mx=DATA[::-1].zfill(len(DATA)+24)[::-1]
|
||||||
initialdifference=len(Mx)-len(Gx)
|
initialdifference=len(Mx)-len(Gx)
|
||||||
Gx = Gx[::-1].zfill(len(Mx))[::-1]
|
Gx = Gx[::-1].zfill(len(Mx))[::-1]
|
||||||
while len(Mx)>initialdifference:
|
while len(Mx)>initialdifference:
|
||||||
MSB=Mx[0]
|
MSB=Mx[0]
|
||||||
if MSB=='1':
|
if MSB=='1':
|
||||||
result=int(Mx,2)^int(Gx,2)
|
result=int(Mx,2)^int(Gx,2)
|
||||||
Mx = str(bin(result)[2:])
|
Mx = str(bin(result)[2:])
|
||||||
Gx = Gx.rstrip('0')[::-1].zfill(len(Mx))[::-1]
|
Gx = Gx.rstrip('0')[::-1].zfill(len(Mx))[::-1]
|
||||||
|
|
||||||
else: #If the Mx starts with a 0
|
else: #If the Mx starts with a 0
|
||||||
Mx=Mx[1:]
|
Mx=Mx[1:]
|
||||||
Gx=Gx[:-1]
|
Gx=Gx[:-1]
|
||||||
|
|
||||||
SIcode=(int(Mx,2)^int(PI,2)) #Mx is the parity sequence and PI is the last field of the DF11.
|
SIcode=bin(int(Mx,2)^int(PI,2)).zfill(7) #Mx is the parity sequence and PI is the last field of the DF11.
|
||||||
return SIcode
|
if int(SIcode[0:3],2)>0:
|
||||||
|
return str("SI" + str(int(SIcode[3:],2)))
|
||||||
|
else:
|
||||||
|
return str("II" + str(int(SIcode,2)))
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|
||||||
|
def flight_status(msg):
|
||||||
|
'''returns the flight status'''
|
||||||
|
if common.df(msg) == 11: # check that the msg is DF11
|
||||||
|
binaryraw=common.hex2bin(msg)
|
||||||
|
CA = (int(binaryraw[5:8],2))
|
||||||
|
if CA in [0, 1, 2, 3, 6, 7]: #reserved
|
||||||
|
return None
|
||||||
|
if CA == 4:#level 2 transponder, ability to set CA to 7 and on ground
|
||||||
|
return "on ground"
|
||||||
|
if CA == 5:#level 2 transponder, ability to set CA to 7 and airborn
|
||||||
|
return "airborne"
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|
||||||
|
def transponder_level(msg):
|
||||||
|
'''returns the transponder level'''
|
||||||
|
if common.df(msg) == 11:#check that the msg is DF11
|
||||||
|
binaryraw=common.hex2bin(msg)
|
||||||
|
CA = (int(binaryraw[5:8],2))
|
||||||
|
if CA in [1, 2, 3, 4, 5, 6, 7]: #reserved
|
||||||
|
return 2
|
||||||
|
if CA == 0:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|
||||||
def capability(msg):
|
def capability(msg):
|
||||||
'''return the capability code'''
|
'''return the capability code'''
|
||||||
@@ -51,4 +81,7 @@ def capability(msg):
|
|||||||
|
|
||||||
def AA(msg):
|
def AA(msg):
|
||||||
'''returns the icao code of the aircraft'''
|
'''returns the icao code of the aircraft'''
|
||||||
return (msg[2:8])
|
if common.df(msg) == 11: # check that the msg is DF11
|
||||||
|
return (msg[2:8])
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Incorrect or inconsistent message types")
|
||||||
|
|||||||
Reference in New Issue
Block a user