add NIC decoding

This commit is contained in:
Junzi Sun 2016-01-04 17:57:36 +01:00
parent cc7ce36111
commit f36ab91aa4
2 changed files with 48 additions and 4 deletions

View File

@ -103,6 +103,42 @@ def get_tc(msg):
return bin2int(msgbin[32:37]) return bin2int(msgbin[32:37])
def get_nic(msg):
"""
Calculate NIC, navigation integrity category,
return -1 if not applicable
"""
msgbin = hex2bin(msg)
tc = get_tc(msg)
nic_sup_b = bin2int(msgbin[39])
if tc in [0, 18, 22]:
nic = 0
elif tc == 17:
nic = 1
elif tc == 16:
if nic_sup_b:
nic = 3
else:
nic = 2
elif tc == 15:
nic = 4
elif tc == 14:
nic = 5
elif tc == 13:
nic = 6
elif tc == 12:
nic = 7
elif tc == 11:
if nic_sup_b:
nic = 9
else:
nic = 8
else:
nic = -1
return nic
def get_oe_flag(msg): def get_oe_flag(msg):
"""Check the odd/even flag. Bit 54, 0 for even, 1 for odd.""" """Check the odd/even flag. Bit 54, 0 for even, 1 for odd."""
msgbin = hex2bin(msg) msgbin = hex2bin(msg)

View File

@ -12,10 +12,10 @@ print 'Call sign:', cs
print print
# decode position # decode position
msg0 = '8D51004E901DF3041D06127582A1' msg0 = '8D40058B58C901375147EFD09357'
msg1 = '8D51004E901DF66EB4FEE010C7A9' msg1 = '8D40058B58C904A87F402D3B8C59'
t0 = 1442566675 t0 = 1446332400
t1 = 1442566674 t1 = 1446332405
pos = decoder.get_position(msg0, msg1, t0, t1) pos = decoder.get_position(msg0, msg1, t0, t1)
print 'Message E:', msg0 print 'Message E:', msg0
print 'Message O:', msg1 print 'Message O:', msg1
@ -28,3 +28,11 @@ sh = decoder.get_speed_heading(msg)
print 'Message:', msg print 'Message:', msg
print 'Speed and heading:', sh print 'Speed and heading:', sh
print print
# test NIC
# decode position
msg = '8D40058B58C901375147EFD09357'
nic = decoder.get_nic(msg1)
print 'Message:', msg
print 'NIC:', nic
print