Skip to content

Commit cb67c63

Browse files
Flyer350junzis
authored andcommitted
Create uplink.py (#55)
First basic functionality for uplink messages - UF and ICAO address.
1 parent bddaf9a commit cb67c63

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pyModeS/decoder/uplink.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pyModeS.decoder import common
2+
3+
def uplink_icao(msg):
4+
"""Calculate the ICAO address from a Mode-S interrogation (uplink message)"""
5+
p_gen = 0xfffa0480 << ((len(msg)-14)*4)
6+
data = int(msg[:-6],16)
7+
PA = int(msg[-6:],16)
8+
ad = 0
9+
topbit = 0b1 << (len(msg)*4-25)
10+
for j in range(0,len(msg)*4,1):
11+
if (data & topbit):
12+
data^=p_gen
13+
data = (data << 1) + ((PA >> 23) & 1)
14+
PA = PA << 1
15+
if (j>(len(msg)*4-26)):
16+
ad = ad + ((data >> (len(msg)*4-25)) & 1)
17+
ad = ad << 1
18+
return "%06X" % (ad >> 2)
19+
20+
21+
def uf(msg):
22+
"""Decode Uplink Format value, bits 1 to 5."""
23+
ufbin = common.hex2bin(msg[:2])
24+
return min(common.bin2int(ufbin[0:5]), 24)

0 commit comments

Comments
 (0)