First stab at using real exception handling instead of returning [None] everywhere
This commit is contained in:
parent
e3ac472a1a
commit
db62aaf399
@ -34,6 +34,7 @@ GR_PYTHON_INSTALL(
|
|||||||
altitude.py
|
altitude.py
|
||||||
cpr.py
|
cpr.py
|
||||||
mlat.py
|
mlat.py
|
||||||
|
modes_exceptions.py
|
||||||
modes_flightgear.py
|
modes_flightgear.py
|
||||||
modes_kml.py
|
modes_kml.py
|
||||||
modes_parse.py
|
modes_parse.py
|
||||||
|
@ -56,6 +56,7 @@ from modes_sql import modes_output_sql
|
|||||||
from modes_sbs1 import modes_output_sbs1
|
from modes_sbs1 import modes_output_sbs1
|
||||||
from modes_kml import modes_kml
|
from modes_kml import modes_kml
|
||||||
from modes_raw_server import modes_raw_server
|
from modes_raw_server import modes_raw_server
|
||||||
|
from modes_exceptions import *
|
||||||
#this is try/excepted in case the user doesn't have numpy installed
|
#this is try/excepted in case the user doesn't have numpy installed
|
||||||
try:
|
try:
|
||||||
from modes_flightgear import modes_flightgear
|
from modes_flightgear import modes_flightgear
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
# For reference into the methodology used to decode altitude,
|
# For reference into the methodology used to decode altitude,
|
||||||
# see RTCA DO-181D p.42
|
# see RTCA DO-181D p.42
|
||||||
|
|
||||||
|
from modes_exceptions import *
|
||||||
|
|
||||||
def decode_alt(alt, bit13):
|
def decode_alt(alt, bit13):
|
||||||
mbit = alt & 0x0040
|
mbit = alt & 0x0040
|
||||||
qbit = alt & 0x0010
|
qbit = alt & 0x0010
|
||||||
@ -30,7 +32,7 @@ def decode_alt(alt, bit13):
|
|||||||
if mbit and bit13:
|
if mbit and bit13:
|
||||||
#TBD: bits 20-25, 27-31 encode alt in meters
|
#TBD: bits 20-25, 27-31 encode alt in meters
|
||||||
#remember that bits are left justified (bit 20 is MSB)
|
#remember that bits are left justified (bit 20 is MSB)
|
||||||
return "METRIC ERROR"
|
raise MetricAltError
|
||||||
|
|
||||||
if qbit: #a mode S-style reply
|
if qbit: #a mode S-style reply
|
||||||
#bit13 is false for BDS0,5 ADS-B squitters, and is true otherwise
|
#bit13 is false for BDS0,5 ADS-B squitters, and is true otherwise
|
||||||
@ -122,12 +124,14 @@ def encode_alt_modes(alt, bit13):
|
|||||||
return (encalt & 0x0F) | tmp1 | tmp2 | (mbit << 6) | (qbit << 4)
|
return (encalt & 0x0F) | tmp1 | tmp2 | (mbit << 6) | (qbit << 4)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for alt in range(-1000, 101400, 25):
|
try:
|
||||||
dec = decode_alt(encode_alt_modes(alt, False), False)
|
for alt in range(-1000, 101400, 25):
|
||||||
if dec != alt:
|
dec = decode_alt(encode_alt_modes(alt, False), False)
|
||||||
print "Failure at %i with bit13 clear (got %s)" % (alt, dec)
|
if dec != alt:
|
||||||
for alt in range(-1000, 101400, 25):
|
print "Failure at %i with bit13 clear (got %s)" % (alt, dec)
|
||||||
dec = decode_alt(encode_alt_modes(alt, True), True)
|
for alt in range(-1000, 101400, 25):
|
||||||
if dec != alt:
|
dec = decode_alt(encode_alt_modes(alt, True), True)
|
||||||
print "Failure at %i with bit13 set (got %s)" % (alt, dec)
|
if dec != alt:
|
||||||
|
print "Failure at %i with bit13 set (got %s)" % (alt, dec)
|
||||||
|
except MetricAltError:
|
||||||
|
print "Failure at %i due to metric alt bit" % alt
|
||||||
|
@ -20,9 +20,8 @@
|
|||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
#from string import split, join
|
|
||||||
#from math import pi, floor, cos, acos
|
|
||||||
import math, time
|
import math, time
|
||||||
|
from modes_exceptions import *
|
||||||
#this implements CPR position decoding and encoding.
|
#this implements CPR position decoding and encoding.
|
||||||
#the decoder is implemented as a class, cpr_decoder, which keeps state for local decoding.
|
#the decoder is implemented as a class, cpr_decoder, which keeps state for local decoding.
|
||||||
#the encoder is cpr_encode([lat, lon], type (even=0, odd=1), and surface (0 for surface, 1 for airborne))
|
#the encoder is cpr_encode([lat, lon], type (even=0, odd=1), and surface (0 for surface, 1 for airborne))
|
||||||
@ -121,7 +120,7 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface):
|
|||||||
#If so, you can't get a globally-resolvable location.
|
#If so, you can't get a globally-resolvable location.
|
||||||
if nl(rlateven) != nl(rlatodd):
|
if nl(rlateven) != nl(rlatodd):
|
||||||
#print "Boundary straddle!"
|
#print "Boundary straddle!"
|
||||||
return (None, None,)
|
raise CPRBoundaryStraddleError
|
||||||
|
|
||||||
if mostrecent == 0:
|
if mostrecent == 0:
|
||||||
rlat = rlateven
|
rlat = rlateven
|
||||||
@ -218,8 +217,9 @@ class cpr_decoder:
|
|||||||
elif ((icao24 in self.evenlist) and (icao24 in self.oddlist) and abs(self.evenlist[icao24][2] - self.oddlist[icao24][2]) < 10):
|
elif ((icao24 in self.evenlist) and (icao24 in self.oddlist) and abs(self.evenlist[icao24][2] - self.oddlist[icao24][2]) < 10):
|
||||||
newer = (self.oddlist[icao24][2] - self.evenlist[icao24][2]) > 0 #figure out which report is newer
|
newer = (self.oddlist[icao24][2] - self.evenlist[icao24][2]) > 0 #figure out which report is newer
|
||||||
[decoded_lat, decoded_lon] = cpr_resolve_global(self.evenlist[icao24][0:2], self.oddlist[icao24][0:2], newer, surface) #do a global decode
|
[decoded_lat, decoded_lon] = cpr_resolve_global(self.evenlist[icao24][0:2], self.oddlist[icao24][0:2], newer, surface) #do a global decode
|
||||||
if decoded_lat is not None:
|
self.lkplist[icao24] = [decoded_lat, decoded_lon, time.time()]
|
||||||
self.lkplist[icao24] = [decoded_lat, decoded_lon, time.time()]
|
else:
|
||||||
|
raise CPRNoPositionError
|
||||||
|
|
||||||
#so we really can't guarantee that local decoding will work unless you are POSITIVE that you can't hear more than 180nm out.
|
#so we really can't guarantee that local decoding will work unless you are POSITIVE that you can't hear more than 180nm out.
|
||||||
#this will USUALLY work, but you can't guarantee it!
|
#this will USUALLY work, but you can't guarantee it!
|
||||||
@ -230,7 +230,7 @@ class cpr_decoder:
|
|||||||
# self.lkplist[icao24] = [local_lat, local_lon, time.time()] #update the local position for next time
|
# self.lkplist[icao24] = [local_lat, local_lon, time.time()] #update the local position for next time
|
||||||
# [decoded_lat, decoded_lon] = [local_lat, local_lon]
|
# [decoded_lat, decoded_lon] = [local_lat, local_lon]
|
||||||
|
|
||||||
if decoded_lat is not None and self.my_location is not None:
|
if self.my_location is not None:
|
||||||
[rnge, bearing] = range_bearing(self.my_location, [decoded_lat, decoded_lon])
|
[rnge, bearing] = range_bearing(self.my_location, [decoded_lat, decoded_lon])
|
||||||
else:
|
else:
|
||||||
rnge = None
|
rnge = None
|
||||||
@ -283,15 +283,21 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
#perform a global decode
|
#perform a global decode
|
||||||
icao = random.randint(0, 0xffffff)
|
icao = random.randint(0, 0xffffff)
|
||||||
evenpos = decoder.decode(icao, evenenclat, evenenclon, False, False)
|
try:
|
||||||
if evenpos != [None, None, None, None]:
|
evenpos = decoder.decode(icao, evenenclat, evenenclon, False, False)
|
||||||
#print "CPR global decode with only one report: %f %f" % (evenpos[0], evenpos[1])
|
#print "CPR global decode with only one report: %f %f" % (evenpos[0], evenpos[1])
|
||||||
raise Exception("CPR test failure: global decode with only one report")
|
raise Exception("CPR test failure: global decode with only one report")
|
||||||
(odddeclat, odddeclon, rng, brg) = decoder.decode(icao, oddenclat, oddenclon, True, False)
|
except CPRNoPositionError:
|
||||||
|
pass
|
||||||
|
|
||||||
if odddeclat is None: #boundary straddle, just move on, it's normal
|
try:
|
||||||
|
(odddeclat, odddeclon, rng, brg) = decoder.decode(icao, oddenclat, oddenclon, True, False)
|
||||||
|
except CPRBoundaryStraddleError:
|
||||||
bs += 1
|
bs += 1
|
||||||
continue
|
continue
|
||||||
|
except CPRNoPositionError:
|
||||||
|
raise Exception("CPR test failure: no decode after even/odd inputs")
|
||||||
|
|
||||||
#print "Lat: %f Lon: %f" % (ac_lat, ac_lon)
|
#print "Lat: %f Lon: %f" % (ac_lat, ac_lon)
|
||||||
|
|
||||||
if abs(odddeclat - ac_lat) > threshold or abs(odddeclon - ac_lon) > threshold:
|
if abs(odddeclat - ac_lat) > threshold or abs(odddeclon - ac_lon) > threshold:
|
||||||
@ -299,7 +305,10 @@ if __name__ == '__main__':
|
|||||||
#print "odddeclon: %f ac_lon: %f" % (odddeclon, ac_lon)
|
#print "odddeclon: %f ac_lon: %f" % (odddeclon, ac_lon)
|
||||||
raise Exception("CPR test failure: global decode error greater than threshold")
|
raise Exception("CPR test failure: global decode error greater than threshold")
|
||||||
|
|
||||||
(evendeclat, evendeclon) = cpr_resolve_local([ac_lat, ac_lon], [evenenclat, evenenclon], False, False)
|
try:
|
||||||
|
(evendeclat, evendeclon) = cpr_resolve_local([ac_lat, ac_lon], [evenenclat, evenenclon], False, False)
|
||||||
|
except CPRNoPositionError:
|
||||||
|
raise Exception("CPR test failure: local decode failure to resolve")
|
||||||
|
|
||||||
if abs(evendeclat - ac_lat) > threshold or abs(evendeclon - ac_lon) > threshold:
|
if abs(evendeclat - ac_lat) > threshold or abs(evendeclon - ac_lon) > threshold:
|
||||||
raise Exception("CPR test failure: local decode error greater than threshold")
|
raise Exception("CPR test failure: local decode error greater than threshold")
|
||||||
|
42
python/modes_exceptions.py
Normal file
42
python/modes_exceptions.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2012 Nick Foster
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
class ADSBError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class MetricAltError(ADSBError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ParserError(ADSBError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NoHandlerError(ADSBError):
|
||||||
|
def __init__(self, msgtype):
|
||||||
|
self.msgtype = msgtype
|
||||||
|
|
||||||
|
class MlatNonConvergeError(ADSBError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CPRNoPositionError(ADSBError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CPRBoundaryStraddleError(CPRNoPositionError):
|
||||||
|
pass
|
@ -11,6 +11,7 @@ import string, threading, math, time
|
|||||||
from air_modes.modes_sql import modes_output_sql
|
from air_modes.modes_sql import modes_output_sql
|
||||||
from Quaternion import Quat
|
from Quaternion import Quat
|
||||||
import numpy
|
import numpy
|
||||||
|
from modes_exceptions import *
|
||||||
|
|
||||||
class modes_flightgear(modes_parse.modes_parse):
|
class modes_flightgear(modes_parse.modes_parse):
|
||||||
def __init__(self, localpos, hostname, port):
|
def __init__(self, localpos, hostname, port):
|
||||||
@ -31,36 +32,38 @@ class modes_flightgear(modes_parse.modes_parse):
|
|||||||
longdata = long(longdata, 16)
|
longdata = long(longdata, 16)
|
||||||
msgtype = int(msgtype)
|
msgtype = int(msgtype)
|
||||||
|
|
||||||
if msgtype == 17: #ADS-B report
|
try:
|
||||||
icao24 = shortdata & 0xFFFFFF
|
if msgtype == 17: #ADS-B report
|
||||||
subtype = (longdata >> 51) & 0x1F
|
icao24 = shortdata & 0xFFFFFF
|
||||||
if subtype == 4: #ident packet
|
subtype = (longdata >> 51) & 0x1F
|
||||||
(ident, actype) = self.parseBDS08(shortdata, longdata)
|
if subtype == 4: #ident packet
|
||||||
#select model based on actype
|
(ident, actype) = self.parseBDS08(shortdata, longdata)
|
||||||
self.callsigns[icao24] = [ident, actype]
|
#select model based on actype
|
||||||
|
self.callsigns[icao24] = [ident, actype]
|
||||||
|
|
||||||
elif 5 <= subtype <= 8: #BDS0,6 pos
|
elif 5 <= subtype <= 8: #BDS0,6 pos
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata)
|
||||||
if(decoded_lat is not None):
|
|
||||||
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
||||||
self.update(icao24)
|
self.update(icao24)
|
||||||
|
|
||||||
elif 9 <= subtype <= 18: #BDS0,5 pos
|
elif 9 <= subtype <= 18: #BDS0,5 pos
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata)
|
||||||
if(decoded_lat is not None):
|
|
||||||
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
||||||
self.update(icao24)
|
self.update(icao24)
|
||||||
|
|
||||||
elif subtype == 19: #velocity
|
elif subtype == 19: #velocity
|
||||||
subsubtype = (longdata >> 48) & 0x07
|
subsubtype = (longdata >> 48) & 0x07
|
||||||
if subsubtype == 0:
|
if subsubtype == 0:
|
||||||
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(shortdata, longdata)
|
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(shortdata, longdata)
|
||||||
elif subsubtype == 1:
|
elif subsubtype == 1:
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata)
|
[velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata)
|
||||||
turnrate = 0
|
turnrate = 0
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
self.velocities[icao24] = [velocity, heading, vert_spd, turnrate]
|
self.velocities[icao24] = [velocity, heading, vert_spd, turnrate]
|
||||||
|
|
||||||
|
except ADSBError:
|
||||||
|
pass
|
||||||
|
|
||||||
def update(self, icao24):
|
def update(self, icao24):
|
||||||
#check to see that ICAO24 appears in all three records and that the data looks valid
|
#check to see that ICAO24 appears in all three records and that the data looks valid
|
||||||
|
@ -25,6 +25,7 @@ from string import split, join
|
|||||||
from altitude import decode_alt
|
from altitude import decode_alt
|
||||||
import cpr
|
import cpr
|
||||||
import math
|
import math
|
||||||
|
from modes_exceptions import *
|
||||||
|
|
||||||
class modes_parse:
|
class modes_parse:
|
||||||
def __init__(self, mypos):
|
def __init__(self, mypos):
|
||||||
@ -32,9 +33,6 @@ class modes_parse:
|
|||||||
self.cpr = cpr.cpr_decoder(self.my_location)
|
self.cpr = cpr.cpr_decoder(self.my_location)
|
||||||
|
|
||||||
def parse0(self, shortdata):
|
def parse0(self, shortdata):
|
||||||
# shortdata = long(shortdata, 16)
|
|
||||||
#parity = long(parity)
|
|
||||||
|
|
||||||
vs = bool(shortdata >> 26 & 0x1) #ground sensor -- airborne when 0
|
vs = bool(shortdata >> 26 & 0x1) #ground sensor -- airborne when 0
|
||||||
cc = bool(shortdata >> 25 & 0x1) #crosslink capability, binary
|
cc = bool(shortdata >> 25 & 0x1) #crosslink capability, binary
|
||||||
sl = shortdata >> 21 & 0x07 #operating sensitivity of onboard TCAS system. 0 means no TCAS sensitivity reported, 1-7 give TCAS sensitivity
|
sl = shortdata >> 21 & 0x07 #operating sensitivity of onboard TCAS system. 0 means no TCAS sensitivity reported, 1-7 give TCAS sensitivity
|
||||||
@ -46,7 +44,6 @@ class modes_parse:
|
|||||||
return [vs, cc, sl, ri, altitude]
|
return [vs, cc, sl, ri, altitude]
|
||||||
|
|
||||||
def parse4(self, shortdata):
|
def parse4(self, shortdata):
|
||||||
# shortdata = long(shortdata, 16)
|
|
||||||
fs = shortdata >> 24 & 0x07 #flight status: 0 is airborne normal, 1 is ground normal, 2 is airborne alert, 3 is ground alert, 4 is alert SPI, 5 is normal SPI
|
fs = shortdata >> 24 & 0x07 #flight status: 0 is airborne normal, 1 is ground normal, 2 is airborne alert, 3 is ground alert, 4 is alert SPI, 5 is normal SPI
|
||||||
dr = shortdata >> 19 & 0x1F #downlink request: 0 means no req, bit 0 is Comm-B msg rdy bit, bit 1 is TCAS info msg rdy, bit 2 is Comm-B bcast #1 msg rdy, bit2+bit0 is Comm-B bcast #2 msg rdy,
|
dr = shortdata >> 19 & 0x1F #downlink request: 0 means no req, bit 0 is Comm-B msg rdy bit, bit 1 is TCAS info msg rdy, bit 2 is Comm-B bcast #1 msg rdy, bit2+bit0 is Comm-B bcast #2 msg rdy,
|
||||||
#bit2+bit1 is TCAS info and Comm-B bcast #1 msg rdy, bit2+bit1+bit0 is TCAS info and Comm-B bcast #2 msg rdy, 8-15 N/A, 16-31 req to send N-15 segments
|
#bit2+bit1 is TCAS info and Comm-B bcast #1 msg rdy, bit2+bit1+bit0 is TCAS info and Comm-B bcast #2 msg rdy, 8-15 N/A, 16-31 req to send N-15 segments
|
||||||
@ -59,7 +56,6 @@ class modes_parse:
|
|||||||
|
|
||||||
|
|
||||||
def parse5(self, shortdata):
|
def parse5(self, shortdata):
|
||||||
# shortdata = long(shortdata, 16)
|
|
||||||
fs = shortdata >> 24 & 0x07 #flight status: 0 is airborne normal, 1 is ground normal, 2 is airborne alert, 3 is ground alert, 4 is alert SPI, 5 is normal SPI
|
fs = shortdata >> 24 & 0x07 #flight status: 0 is airborne normal, 1 is ground normal, 2 is airborne alert, 3 is ground alert, 4 is alert SPI, 5 is normal SPI
|
||||||
dr = shortdata >> 19 & 0x1F #downlink request: 0 means no req, bit 0 is Comm-B msg rdy bit, bit 1 is TCAS info msg rdy, bit 2 is Comm-B bcast #1 msg rdy, bit2+bit0 is Comm-B bcast #2 msg rdy,
|
dr = shortdata >> 19 & 0x1F #downlink request: 0 means no req, bit 0 is Comm-B msg rdy bit, bit 1 is TCAS info msg rdy, bit 2 is Comm-B bcast #1 msg rdy, bit2+bit0 is Comm-B bcast #2 msg rdy,
|
||||||
#bit2+bit1 is TCAS info and Comm-B bcast #1 msg rdy, bit2+bit1+bit0 is TCAS info and Comm-B bcast #2 msg rdy, 8-15 N/A, 16-31 req to send N-15 segments
|
#bit2+bit1 is TCAS info and Comm-B bcast #1 msg rdy, bit2+bit1+bit0 is TCAS info and Comm-B bcast #2 msg rdy, 8-15 N/A, 16-31 req to send N-15 segments
|
||||||
@ -68,7 +64,6 @@ class modes_parse:
|
|||||||
return [fs, dr, um]
|
return [fs, dr, um]
|
||||||
|
|
||||||
def parse11(self, shortdata, ecc):
|
def parse11(self, shortdata, ecc):
|
||||||
# shortdata = long(shortdata, 16)
|
|
||||||
interrogator = ecc & 0x0F
|
interrogator = ecc & 0x0F
|
||||||
|
|
||||||
ca = shortdata >> 13 & 0x3F #capability
|
ca = shortdata >> 13 & 0x3F #capability
|
||||||
@ -114,9 +109,6 @@ class modes_parse:
|
|||||||
msg = ""
|
msg = ""
|
||||||
for i in range(0, 8):
|
for i in range(0, 8):
|
||||||
msg += self.charmap( longdata >> (42-6*i) & 0x3F)
|
msg += self.charmap( longdata >> (42-6*i) & 0x3F)
|
||||||
|
|
||||||
#retstr = "Type 17 subtype 04 (ident) from " + "%x" % icao24 + " with data " + msg
|
|
||||||
|
|
||||||
return (msg, catstring)
|
return (msg, catstring)
|
||||||
|
|
||||||
def charmap(self, d):
|
def charmap(self, d):
|
||||||
@ -155,8 +147,6 @@ class modes_parse:
|
|||||||
encoded_lat = (longdata >> 17) & 0x1FFFF
|
encoded_lat = (longdata >> 17) & 0x1FFFF
|
||||||
cpr_format = (longdata >> 34) & 1
|
cpr_format = (longdata >> 34) & 1
|
||||||
|
|
||||||
# enc_alt = (longdata >> 36) & 0x0FFF
|
|
||||||
|
|
||||||
altitude = 0
|
altitude = 0
|
||||||
|
|
||||||
[decoded_lat, decoded_lon, rnge, bearing] = self.cpr.decode(icao24, encoded_lat, encoded_lon, cpr_format, 1)
|
[decoded_lat, decoded_lon, rnge, bearing] = self.cpr.decode(icao24, encoded_lat, encoded_lon, cpr_format, 1)
|
||||||
@ -189,8 +179,6 @@ class modes_parse:
|
|||||||
if heading < 0:
|
if heading < 0:
|
||||||
heading += 360
|
heading += 360
|
||||||
|
|
||||||
#retstr = "Type 17 subtype 09-0 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd
|
|
||||||
|
|
||||||
return [velocity, heading, vert_spd, turn_rate]
|
return [velocity, heading, vert_spd, turn_rate]
|
||||||
|
|
||||||
def parseBDS09_1(self, shortdata, longdata):
|
def parseBDS09_1(self, shortdata, longdata):
|
||||||
@ -232,7 +220,5 @@ class modes_parse:
|
|||||||
if heading < 0:
|
if heading < 0:
|
||||||
heading += 360
|
heading += 360
|
||||||
|
|
||||||
#retstr = "Type 17 subtype 09-1 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd
|
|
||||||
|
|
||||||
return [velocity, heading, vert_spd]
|
return [velocity, heading, vert_spd]
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright 2010 Nick Foster
|
# Copyright 2010, 2012 Nick Foster
|
||||||
#
|
#
|
||||||
# This file is part of gr-air-modes
|
# This file is part of gr-air-modes
|
||||||
#
|
#
|
||||||
@ -19,10 +19,10 @@
|
|||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
import time, os, sys
|
import time, os, sys
|
||||||
from string import split, join
|
from string import split, join
|
||||||
import modes_parse
|
import modes_parse
|
||||||
|
from modes_exceptions import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class modes_output_print(modes_parse.modes_parse):
|
class modes_output_print(modes_parse.modes_parse):
|
||||||
@ -40,29 +40,32 @@ class modes_output_print(modes_parse.modes_parse):
|
|||||||
|
|
||||||
msgtype = int(msgtype)
|
msgtype = int(msgtype)
|
||||||
|
|
||||||
output = None;
|
#TODO this is suspect
|
||||||
|
|
||||||
if msgtype == 0:
|
|
||||||
output = self.print0(shortdata, ecc)
|
|
||||||
elif msgtype == 4:
|
|
||||||
output = self.print4(shortdata, ecc)
|
|
||||||
elif msgtype == 5:
|
|
||||||
output = self.print5(shortdata, ecc)
|
|
||||||
elif msgtype == 11:
|
|
||||||
output = self.print11(shortdata, ecc)
|
|
||||||
elif msgtype == 17:
|
|
||||||
output = self.print17(shortdata, longdata)
|
|
||||||
else:
|
|
||||||
output = "No handler for message type " + str(msgtype) + " from %x" % ecc
|
|
||||||
|
|
||||||
if reference == 0.0:
|
if reference == 0.0:
|
||||||
refdb = -150.0
|
refdb = -150.0
|
||||||
else:
|
else:
|
||||||
refdb = 10.0*math.log10(reference)
|
refdb = 10.0*math.log10(reference)
|
||||||
|
output = "(%.0f %.10f) " % (refdb, timestamp);
|
||||||
|
|
||||||
if output is not None:
|
try:
|
||||||
output = "(%.0f %.10f) " % (refdb, timestamp) + output
|
if msgtype == 0:
|
||||||
print output
|
output += self.print0(shortdata, ecc)
|
||||||
|
elif msgtype == 4:
|
||||||
|
output += self.print4(shortdata, ecc)
|
||||||
|
elif msgtype == 5:
|
||||||
|
output += self.print5(shortdata, ecc)
|
||||||
|
elif msgtype == 11:
|
||||||
|
output += self.print11(shortdata, ecc)
|
||||||
|
elif msgtype == 17:
|
||||||
|
output += self.print17(shortdata, longdata)
|
||||||
|
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
|
||||||
|
|
||||||
def print0(self, shortdata, ecc):
|
def print0(self, shortdata, ecc):
|
||||||
[vs, cc, sl, ri, altitude] = self.parse0(shortdata)
|
[vs, cc, sl, ri, altitude] = self.parse0(shortdata)
|
||||||
|
@ -24,6 +24,7 @@ import time, os, sys, socket
|
|||||||
from string import split, join
|
from string import split, join
|
||||||
import modes_parse
|
import modes_parse
|
||||||
from datetime import *
|
from datetime import *
|
||||||
|
from modes_exceptions import *
|
||||||
|
|
||||||
class modes_output_sbs1(modes_parse.modes_parse):
|
class modes_output_sbs1(modes_parse.modes_parse):
|
||||||
def __init__(self, mypos):
|
def __init__(self, mypos):
|
||||||
@ -61,14 +62,15 @@ class modes_output_sbs1(modes_parse.modes_parse):
|
|||||||
return self._aircraft_id_count
|
return self._aircraft_id_count
|
||||||
|
|
||||||
def output(self, msg):
|
def output(self, msg):
|
||||||
sbs1_msg = self.parse(msg)
|
try:
|
||||||
if sbs1_msg is not None:
|
sbs1_msg = self.parse(msg)
|
||||||
for conn in self._conns[:]: #iterate over a copy of the list
|
for conn in self._conns[:]: #iterate over a copy of the list
|
||||||
try:
|
conn.send(sbs1_msg)
|
||||||
conn.send(sbs1_msg)
|
except socket.error:
|
||||||
except socket.error:
|
self._conns.remove(conn)
|
||||||
self._conns.remove(conn)
|
print "Connections: ", len(self._conns)
|
||||||
print "Connections: ", len(self._conns)
|
except ADSBError:
|
||||||
|
pass
|
||||||
|
|
||||||
def add_pending_conns(self):
|
def add_pending_conns(self):
|
||||||
try:
|
try:
|
||||||
|
@ -23,6 +23,7 @@ import time, os, sys
|
|||||||
from string import split, join
|
from string import split, join
|
||||||
import modes_parse
|
import modes_parse
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from modes_exceptions import *
|
||||||
|
|
||||||
class modes_output_sql(modes_parse.modes_parse):
|
class modes_output_sql(modes_parse.modes_parse):
|
||||||
def __init__(self, mypos, filename):
|
def __init__(self, mypos, filename):
|
||||||
@ -58,12 +59,14 @@ class modes_output_sql(modes_parse.modes_parse):
|
|||||||
self.db.close()
|
self.db.close()
|
||||||
|
|
||||||
def output(self, message):
|
def output(self, message):
|
||||||
query = self.make_insert_query(message)
|
try:
|
||||||
if query is not None:
|
query = self.make_insert_query(message)
|
||||||
c = self.db.cursor()
|
c = self.db.cursor()
|
||||||
c.execute(query)
|
c.execute(query)
|
||||||
c.close()
|
c.close()
|
||||||
self.db.commit() #not sure if i have to do this
|
self.db.commit()
|
||||||
|
except ADSBError:
|
||||||
|
pass
|
||||||
|
|
||||||
def make_insert_query(self, message):
|
def make_insert_query(self, message):
|
||||||
#assembles a SQL query tailored to our database
|
#assembles a SQL query tailored to our database
|
||||||
|
Loading…
Reference in New Issue
Block a user