2010-10-19 00:59:08 +08:00
|
|
|
#
|
2012-06-20 06:43:43 +08:00
|
|
|
# Copyright 2010, 2012 Nick Foster
|
2010-10-19 00:59:08 +08:00
|
|
|
#
|
|
|
|
# This file is part of gr-air-modes
|
|
|
|
#
|
|
|
|
# gr-air-modes is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# gr-air-modes is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with gr-air-modes; see the file COPYING. If not, write to
|
|
|
|
# the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
|
2010-09-15 13:01:56 +08:00
|
|
|
import time, os, sys
|
|
|
|
from string import split, join
|
2012-07-17 10:27:09 +08:00
|
|
|
import air_modes
|
|
|
|
from air_modes.exceptions import *
|
2010-10-18 10:45:19 +08:00
|
|
|
import math
|
|
|
|
|
2012-07-17 10:27:09 +08:00
|
|
|
class output_print(air_modes.parse):
|
2010-10-24 09:00:58 +08:00
|
|
|
def __init__(self, mypos):
|
2012-07-17 10:27:09 +08:00
|
|
|
air_modes.parse.__init__(self, mypos)
|
2010-10-24 09:00:58 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
def parse(self, message):
|
2012-06-22 00:42:58 +08:00
|
|
|
[data, ecc, reference, timestamp] = message.split()
|
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
ecc = long(ecc, 16)
|
|
|
|
reference = float(reference)
|
2011-05-17 09:06:54 +08:00
|
|
|
timestamp = float(timestamp)
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2010-10-25 10:00:10 +08:00
|
|
|
if reference == 0.0:
|
2012-06-20 06:43:43 +08:00
|
|
|
refdb = -150.0
|
2010-10-24 07:51:09 +08:00
|
|
|
else:
|
2012-07-22 02:26:49 +08:00
|
|
|
refdb = 20.0*math.log10(reference)
|
2012-06-20 06:43:43 +08:00
|
|
|
output = "(%.0f %.10f) " % (refdb, timestamp);
|
|
|
|
|
2012-06-24 08:55:17 +08:00
|
|
|
try:
|
2012-07-17 10:27:09 +08:00
|
|
|
data = air_modes.modes_reply(long(data, 16))
|
2012-06-24 08:55:17 +08:00
|
|
|
msgtype = data["df"]
|
2012-06-20 06:43:43 +08:00
|
|
|
if msgtype == 0:
|
2012-06-22 00:42:58 +08:00
|
|
|
output += self.print0(data, ecc)
|
2012-06-20 06:43:43 +08:00
|
|
|
elif msgtype == 4:
|
2012-06-22 00:42:58 +08:00
|
|
|
output += self.print4(data, ecc)
|
2012-06-20 06:43:43 +08:00
|
|
|
elif msgtype == 5:
|
2012-06-22 00:42:58 +08:00
|
|
|
output += self.print5(data, ecc)
|
2012-06-20 06:43:43 +08:00
|
|
|
elif msgtype == 11:
|
2012-06-22 00:42:58 +08:00
|
|
|
output += self.print11(data, ecc)
|
2012-06-20 06:43:43 +08:00
|
|
|
elif msgtype == 17:
|
2012-06-22 00:42:58 +08:00
|
|
|
output += self.print17(data)
|
2012-06-30 00:32:58 +08:00
|
|
|
elif msgtype == 20 or msgtype == 21:
|
|
|
|
output += self.print20(data, ecc)
|
2012-06-24 08:55:17 +08:00
|
|
|
else:
|
2012-06-27 06:37:20 +08:00
|
|
|
output += "No handler for message type %i from %x (but it's in modes_parse)" % (msgtype, ecc)
|
2012-07-04 10:21:42 +08:00
|
|
|
return output
|
2012-06-20 06:43:43 +08:00
|
|
|
except NoHandlerError as e:
|
2012-06-27 14:27:58 +08:00
|
|
|
output += "No handler for message type %s from %x" % (e.msgtype, ecc)
|
2012-07-04 10:21:42 +08:00
|
|
|
return output
|
2012-06-20 06:43:43 +08:00
|
|
|
except MetricAltError:
|
|
|
|
pass
|
|
|
|
except CPRNoPositionError:
|
|
|
|
pass
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2012-07-04 10:21:42 +08:00
|
|
|
def output(self, msg):
|
|
|
|
print self.parse(msg)
|
|
|
|
|
2012-06-13 22:49:22 +08:00
|
|
|
def print0(self, shortdata, ecc):
|
|
|
|
[vs, cc, sl, ri, altitude] = self.parse0(shortdata)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr = "Type 0 (short A-A surveillance) from %x at %ift" % (ecc, altitude)
|
|
|
|
if ri == 0:
|
|
|
|
retstr += " (No TCAS)"
|
|
|
|
elif ri == 2:
|
|
|
|
retstr += " (TCAS resolution inhibited)"
|
|
|
|
elif ri == 3:
|
|
|
|
retstr += " (Vertical TCAS resolution only)"
|
|
|
|
elif ri == 4:
|
|
|
|
retstr += " (Full TCAS resolution)"
|
|
|
|
elif ri == 9:
|
|
|
|
retstr += " (speed <75kt)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif ri > 9:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (speed %i-%ikt)" % (75 * (1 << (ri-10)), 75 * (1 << (ri-9)))
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if vs is True:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (aircraft is on the ground)"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-13 22:49:22 +08:00
|
|
|
def print4(self, shortdata, ecc):
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-13 22:49:22 +08:00
|
|
|
[fs, dr, um, altitude] = self.parse4(shortdata)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr = "Type 4 (short surveillance altitude reply) from %x at %ift" % (ecc, altitude)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if fs == 1:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (aircraft is on the ground)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 2:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (AIRBORNE ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 3:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (GROUND ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 4:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (SPI ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 5:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (SPI)"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-13 22:49:22 +08:00
|
|
|
def print5(self, shortdata, ecc):
|
2012-06-22 00:42:58 +08:00
|
|
|
[fs, dr, um, ident] = self.parse5(shortdata)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr = "Type 5 (short surveillance ident reply) from %x with ident %i" % (ecc, ident)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if fs == 1:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (aircraft is on the ground)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 2:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (AIRBORNE ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 3:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (GROUND ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 4:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (SPI ALERT)"
|
2010-10-18 10:45:19 +08:00
|
|
|
elif fs == 5:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (SPI)"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
def print11(self, data, ecc):
|
|
|
|
[icao24, interrogator, ca] = self.parse11(data, ecc)
|
2012-06-27 14:27:58 +08:00
|
|
|
retstr = "Type 11 (all call reply) from %x in reply to interrogator %i with capability level %i" % (icao24, interrogator, ca+1)
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
def print17(self, data):
|
|
|
|
icao24 = data["aa"]
|
2012-07-17 00:16:48 +08:00
|
|
|
bdsreg = data["me"].get_type()
|
2010-10-25 10:00:10 +08:00
|
|
|
|
2012-06-24 08:55:17 +08:00
|
|
|
retstr = None
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-07-17 00:16:48 +08:00
|
|
|
if bdsreg == 0x08:
|
2012-06-24 08:26:47 +08:00
|
|
|
(msg, typestring) = self.parseBDS08(data)
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS0,8 (ident) from %x type %s ident %s" % (icao24, typestring, msg)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-07-17 00:16:48 +08:00
|
|
|
elif bdsreg == 0x06:
|
2012-06-27 14:27:58 +08:00
|
|
|
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS0,6 (surface report) from %x at (%.6f, %.6f) ground track %i" % (icao24, decoded_lat, decoded_lon, ground_track)
|
2012-06-24 08:55:17 +08:00
|
|
|
if rnge is not None and bearing is not None:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr += " (%.2f @ %.0f)" % (rnge, bearing)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-07-17 00:16:48 +08:00
|
|
|
elif bdsreg == 0x05:
|
2012-06-24 08:26:47 +08:00
|
|
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS0,5 (position report) from %x at (%.6f, %.6f)" % (icao24, decoded_lat, decoded_lon)
|
2012-06-24 08:55:17 +08:00
|
|
|
if rnge is not None and bearing is not None:
|
|
|
|
retstr += " (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")"
|
|
|
|
retstr += " at " + str(altitude) + "ft"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-07-17 00:16:48 +08:00
|
|
|
elif bdsreg == 0x09:
|
|
|
|
subtype = data["bds09"].get_type()
|
2012-07-22 02:10:15 +08:00
|
|
|
if subtype == 0:
|
|
|
|
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data)
|
|
|
|
retstr = "Type 17 BDS0,9-%i (track report) from %x with velocity %.0fkt heading %.0f VS %.0f turn rate %.0f" \
|
|
|
|
% (subtype, icao24, velocity, heading, vert_spd, turnrate)
|
|
|
|
elif subtype == 1:
|
|
|
|
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS0,9-%i (track report) from %x with velocity %.0fkt heading %.0f VS %.0f" % (subtype, icao24, velocity, heading, vert_spd)
|
2012-07-22 02:10:15 +08:00
|
|
|
elif subtype == 3:
|
|
|
|
[mag_hdg, vel_src, vel, vert_spd, geo_diff] = self.parseBDS09_3(data)
|
|
|
|
retstr = "Type 17 BDS0,9-%i (air course report) from %x with %s %.0fkt magnetic heading %.0f VS %.0f geo. diff. from baro. alt. %.0fft" \
|
|
|
|
% (subtype, icao24, vel_src, vel, mag_hdg, vert_spd, geo_diff)
|
|
|
|
|
2012-06-27 06:37:20 +08:00
|
|
|
else:
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS0,9-%i from %x not implemented" % (subtype, icao24)
|
2012-06-27 06:37:20 +08:00
|
|
|
|
2012-07-17 00:16:48 +08:00
|
|
|
elif bdsreg == 0x62:
|
2012-06-27 06:37:20 +08:00
|
|
|
emerg_str = self.parseBDS62(data)
|
2012-07-17 00:16:48 +08:00
|
|
|
retstr = "Type 17 BDS6,2 (emergency) from %x type %s" % (icao24, emerg_str)
|
2012-06-27 06:37:20 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
else:
|
2012-06-27 06:37:20 +08:00
|
|
|
retstr = "Type 17 subtype %i from %x not implemented" % (subtype, icao24)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|
2012-06-27 10:25:31 +08:00
|
|
|
|
|
|
|
def print20(self, data, ecc):
|
2012-06-30 00:32:58 +08:00
|
|
|
msgtype = data["df"]
|
|
|
|
if(msgtype == 20):
|
|
|
|
[fs, dr, um, alt] = self.parse4(data)
|
|
|
|
else:
|
|
|
|
[fs, dr, um, ident] = self.parse5(data)
|
2012-07-01 05:31:20 +08:00
|
|
|
bds1 = data["bds1"]
|
|
|
|
bds2 = data["bds2"]
|
2012-06-27 10:25:31 +08:00
|
|
|
|
|
|
|
if bds2 != 0:
|
|
|
|
retstr = "No handler for BDS2 == %i from %x" % (bds2, ecc)
|
|
|
|
|
|
|
|
elif bds1 == 0:
|
|
|
|
retstr = "No handler for BDS1 == 0 from %x" % ecc
|
|
|
|
elif bds1 == 1:
|
|
|
|
retstr = "Type 20 link capability report from %x: ACS: 0x%x, BCS: 0x%x, ECS: 0x%x, continues %i" \
|
2012-07-01 05:31:20 +08:00
|
|
|
% (ecc, data["acs"], data["bcs"], data["ecs"], data["cfs"])
|
2012-06-27 10:25:31 +08:00
|
|
|
elif bds1 == 2:
|
|
|
|
retstr = "Type 20 identification from %x with text %s" % (ecc, self.parseMB_id(data))
|
|
|
|
elif bds2 == 3:
|
2012-07-21 13:05:03 +08:00
|
|
|
retstr = "Type 20 TCAS report from %x: " % ecc
|
2012-07-01 05:31:20 +08:00
|
|
|
tti = data["tti"]
|
2012-06-27 10:25:31 +08:00
|
|
|
if tti == 1:
|
|
|
|
(resolutions, complements, rat, mte, threat_id) = self.parseMB_TCAS_threatid(data)
|
|
|
|
retstr += "threat ID: %x advised: %s complement: %s" % (threat_id, resolutions, complements)
|
|
|
|
elif tti == 2:
|
|
|
|
(resolutions, complements, rat, mte, threat_alt, threat_range, threat_bearing) = self.parseMB_TCAS_threatloc(data)
|
|
|
|
retstr += "range: %i bearing: %i alt: %i advised: %s complement: %s" % (threat_range, threat_bearing, threat_alt, resolutions, complements)
|
|
|
|
else:
|
|
|
|
retstr += " (no handler for TTI=%i)" % tti
|
|
|
|
if mte == 1:
|
|
|
|
retstr += " (multiple threats)"
|
|
|
|
if rat == 1:
|
|
|
|
retstr += " (resolved)"
|
|
|
|
else:
|
|
|
|
retstr = "No handler for BDS1 == %i from %x" % (bds1, ecc)
|
2012-06-30 00:32:58 +08:00
|
|
|
|
2012-07-21 12:10:14 +08:00
|
|
|
# if(msgtype == 20):
|
|
|
|
# retstr += " at %ift" % altitude
|
|
|
|
# else:
|
|
|
|
# retstr += " ident %x" % ident
|
2012-06-27 10:25:31 +08:00
|
|
|
|
|
|
|
return retstr
|