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
|
2010-10-18 10:45:19 +08:00
|
|
|
import modes_parse
|
2012-06-20 06:43:43 +08:00
|
|
|
from modes_exceptions import *
|
2010-10-18 10:45:19 +08:00
|
|
|
import math
|
|
|
|
|
|
|
|
class modes_output_print(modes_parse.modes_parse):
|
2010-10-24 09:00:58 +08:00
|
|
|
def __init__(self, mypos):
|
|
|
|
modes_parse.modes_parse.__init__(self, mypos)
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
#TODO FIXME HALP
|
2012-06-24 08:26:47 +08:00
|
|
|
data = modes_parse.modes_reply(long(data, 16))
|
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
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
try:
|
|
|
|
msgtype = data["df"]
|
|
|
|
except NoHandlerError as err:
|
|
|
|
print "No handler for msgtype %s" % err.msgtype
|
|
|
|
return
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2012-06-20 06:43:43 +08:00
|
|
|
#TODO this is suspect
|
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-06-20 06:43:43 +08:00
|
|
|
refdb = 10.0*math.log10(reference)
|
|
|
|
output = "(%.0f %.10f) " % (refdb, timestamp);
|
|
|
|
|
|
|
|
try:
|
|
|
|
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-20 06:43:43 +08:00
|
|
|
print output
|
|
|
|
except NoHandlerError as e:
|
|
|
|
output += "No handler for message type " + str(e.msgtype) + " from %x" % ecc
|
|
|
|
print output
|
|
|
|
except MetricAltError:
|
|
|
|
pass
|
|
|
|
except CPRNoPositionError:
|
|
|
|
pass
|
2010-10-18 10:45:19 +08:00
|
|
|
|
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
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
retstr = "Type 0 (short A-A surveillance) from " + "%x" % ecc + " at " + str(altitude) + "ft"
|
|
|
|
# the ri values below 9 are used for other things. might want to print those someday.
|
|
|
|
if ri == 9:
|
|
|
|
retstr = retstr + " (speed <75kt)"
|
|
|
|
elif ri > 9:
|
|
|
|
retstr = retstr + " (speed " + str(75 * (1 << (ri-10))) + "-" + str(75 * (1 << (ri-9))) + "kt)"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if vs is True:
|
|
|
|
retstr = 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
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
retstr = "Type 4 (short surveillance altitude reply) from " + "%x" % ecc + " at " + str(altitude) + "ft"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if fs == 1:
|
|
|
|
retstr = retstr + " (aircraft is on the ground)"
|
|
|
|
elif fs == 2:
|
|
|
|
retstr = retstr + " (AIRBORNE ALERT)"
|
|
|
|
elif fs == 3:
|
|
|
|
retstr = retstr + " (GROUND ALERT)"
|
|
|
|
elif fs == 4:
|
|
|
|
retstr = retstr + " (SPI ALERT)"
|
|
|
|
elif fs == 5:
|
|
|
|
retstr = 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-22 00:42:58 +08:00
|
|
|
retstr = "Type 5 (short surveillance ident reply) from " + "%x" % ecc + " with ident " + str(ident)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
if fs == 1:
|
|
|
|
retstr = retstr + " (aircraft is on the ground)"
|
|
|
|
elif fs == 2:
|
|
|
|
retstr = retstr + " (AIRBORNE ALERT)"
|
|
|
|
elif fs == 3:
|
|
|
|
retstr = retstr + " (GROUND ALERT)"
|
|
|
|
elif fs == 4:
|
|
|
|
retstr = retstr + " (SPI ALERT)"
|
|
|
|
elif fs == 5:
|
|
|
|
retstr = 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)
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
retstr = "Type 11 (all call reply) from " + "%x" % icao24 + " in reply to interrogator " + str(interrogator)
|
|
|
|
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"]
|
|
|
|
subtype = data["me"]["ftc"]
|
2010-10-25 10:00:10 +08:00
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
retstr = ""
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-13 22:49:22 +08:00
|
|
|
if 1 <= subtype <= 4:
|
2012-06-24 08:26:47 +08:00
|
|
|
(msg, typestring) = self.parseBDS08(data)
|
2012-06-13 22:49:22 +08:00
|
|
|
retstr = "Type 17 subtype 04 (ident) from " + "%x" % icao24 + " of type " + typestring + " with ident " + msg
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
elif subtype >= 5 and subtype <= 8:
|
2012-06-24 08:26:47 +08:00
|
|
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
2010-10-25 10:00:10 +08:00
|
|
|
if decoded_lat is not None:
|
2012-06-13 22:49:22 +08:00
|
|
|
retstr = "Type 17 subtype 06 (surface report) from " + "%x" % icao24 + " at (" + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
|
|
|
|
if rnge is not None and bearing is not None:
|
|
|
|
retstr += " (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
elif subtype >= 9 and subtype <= 18:
|
2012-06-24 08:26:47 +08:00
|
|
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
2010-10-22 14:02:48 +08:00
|
|
|
if decoded_lat is not None:
|
2012-06-13 22:49:22 +08:00
|
|
|
retstr = "Type 17 subtype 05 (position report) from " + "%x" % icao24 + " at (" + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
|
|
|
|
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
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
elif subtype == 19:
|
2012-06-24 08:26:47 +08:00
|
|
|
pass
|
|
|
|
# subsubtype = (longdata >> 48) & 0x07
|
|
|
|
# if subsubtype == 0:
|
|
|
|
# [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata)
|
|
|
|
# retstr = "Type 17 subtype 09-0 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
# elif subsubtype == 1:
|
|
|
|
# [velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata)
|
|
|
|
# retstr = "Type 17 subtype 09-1 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2012-06-24 08:26:47 +08:00
|
|
|
# else:
|
|
|
|
# retstr = "Type 17 subtype 09-%i" % (subsubtype) + " not implemented"
|
2010-10-18 10:45:19 +08:00
|
|
|
else:
|
2010-10-25 10:00:10 +08:00
|
|
|
retstr = "Type 17 subtype " + str(subtype) + " not implemented"
|
2010-09-15 13:01:56 +08:00
|
|
|
|
2010-10-18 10:45:19 +08:00
|
|
|
return retstr
|