Various fixes for stability.

This commit is contained in:
Nick Foster 2010-10-24 19:00:10 -07:00
parent a2aad97f5b
commit 4b3a225f7b
4 changed files with 35 additions and 31 deletions

View File

@ -48,7 +48,10 @@ cpr_format = (longdata >> 34) & 1
enc_alt = (longdata >> 36) & 0x0FFF enc_alt = (longdata >> 36) & 0x0FFF
[cpr_lat, cpr_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, 1)
print "Subtype: %i\nEncoded longitude: %x\nEncoded latitude: %x\nCPR format: %i\nEncoded altitude: %x\n" % (subtype, encoded_lon, encoded_lat, cpr_format, enc_alt,) print "Subtype: %i\nEncoded longitude: %x\nEncoded latitude: %x\nCPR format: %i\nEncoded altitude: %x\n" % (subtype, encoded_lon, encoded_lat, cpr_format, enc_alt,)
print "Pos: %.6f %.6f" % (cpr_lat, cpr_lon)
#print "First argument is order %i, second %i" % ((evendata >> 34) & 1, (odddata >> 34) & 1,) #print "First argument is order %i, second %i" % ((evendata >> 34) & 1, (odddata >> 34) & 1,)

View File

@ -27,13 +27,13 @@ import math, time
#this implements CPR position decoding. #this implements CPR position decoding.
latz = 15 latz = 15
nbits = 17
my_lat = 37.76225 #update these later!
my_lon = -122.44254
#ER
#my_lat = 37.40889176297184
#my_lon = -122.07765340805054
def nbits(surface):
return 17
# if surface == 1:
# return 19
# else:
# return 17
def nz(ctype): def nz(ctype):
return 4 * latz - ctype return 4 * latz - ctype
@ -69,7 +69,7 @@ def dlon(declat_in, ctype, surface):
def decode_lat(enclat, ctype, my_lat, surface): def decode_lat(enclat, ctype, my_lat, surface):
tmp1 = dlat(ctype, surface) tmp1 = dlat(ctype, surface)
tmp2 = float(enclat) / (2**nbits) tmp2 = float(enclat) / (2**nbits(surface))
j = math.floor(my_lat/tmp1) + math.floor(0.5 + (mod(my_lat, tmp1) / tmp1) - tmp2) j = math.floor(my_lat/tmp1) + math.floor(0.5 + (mod(my_lat, tmp1) / tmp1) - tmp2)
# print "dlat gives " + "%.6f " % tmp1 + "with j = " + "%.6f " % j + " and tmp2 = " + "%.6f" % tmp2 + " given enclat " + "%x" % enclat # print "dlat gives " + "%.6f " % tmp1 + "with j = " + "%.6f " % j + " and tmp2 = " + "%.6f" % tmp2 + " given enclat " + "%x" % enclat
@ -77,7 +77,7 @@ def decode_lat(enclat, ctype, my_lat, surface):
def decode_lon(declat, enclon, ctype, my_lon, surface): def decode_lon(declat, enclon, ctype, my_lon, surface):
tmp1 = dlon(declat, ctype, surface) tmp1 = dlon(declat, ctype, surface)
tmp2 = float(enclon) / (2.0**nbits) tmp2 = float(enclon) / (2.0**nbits(surface))
m = math.floor(my_lon / tmp1) + math.floor(0.5 + (mod(my_lon, tmp1) / tmp1) - tmp2) m = math.floor(my_lon / tmp1) + math.floor(0.5 + (mod(my_lon, tmp1) / tmp1) - tmp2)
# print "dlon gives " + "%.6f " % tmp1 + "with m = " + "%.6f " % m + " and tmp2 = " + "%.6f" % tmp2 + " given enclon " + "%x" % enclon # print "dlon gives " + "%.6f " % tmp1 + "with m = " + "%.6f " % m + " and tmp2 = " + "%.6f" % tmp2 + " given enclon " + "%x" % enclon
@ -94,8 +94,6 @@ def cpr_resolve_local(my_location, encoded_location, ctype, surface):
[my_lat, my_lon] = my_location [my_lat, my_lon] = my_location
[enclat, enclon] = encoded_location [enclat, enclon] = encoded_location
decoded_lat = decode_lat(enclat, ctype, my_lat, surface) decoded_lat = decode_lat(enclat, ctype, my_lat, surface)
decoded_lon = decode_lon(decoded_lat, enclon, ctype, my_lon, surface) decoded_lon = decode_lon(decoded_lat, enclon, ctype, my_lon, surface)
@ -113,12 +111,12 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface): #ok this is consid
#print "Even position: %x, %x\nOdd position: %x, %x" % (evenpos[0], evenpos[1], oddpos[0], oddpos[1],) #print "Even position: %x, %x\nOdd position: %x, %x" % (evenpos[0], evenpos[1], oddpos[0], oddpos[1],)
j = math.floor(((59*evenpos[0] - 60*oddpos[0])/2**nbits) + 0.5) #latitude index j = math.floor(((59*evenpos[0] - 60*oddpos[0])/2**nbits(surface)) + 0.5) #latitude index
#print "Latitude index: %i" % j #should be 6, getting 5? #print "Latitude index: %i" % j #should be 6, getting 5?
rlateven = dlateven * (mod(j, 60)+evenpos[0]/2**nbits) rlateven = dlateven * (mod(j, 60)+evenpos[0]/2**nbits(surface))
rlatodd = dlatodd * (mod(j, 59)+ oddpos[0]/2**nbits) rlatodd = dlatodd * (mod(j, 59)+ oddpos[0]/2**nbits(surface))
#print "Rlateven: %f\nRlatodd: %f" % (rlateven, rlatodd,) #print "Rlateven: %f\nRlatodd: %f" % (rlateven, rlatodd,)
@ -140,7 +138,7 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface): #ok this is consid
#print "ni is %i" % ni #print "ni is %i" % ni
m = math.floor(((evenpos[1]*(nlthing-1)-oddpos[1]*(nlthing))/2**nbits)+0.5) #longitude index, THIS LINE IS CORRECT m = math.floor(((evenpos[1]*(nlthing-1)-oddpos[1]*(nlthing))/2**nbits(surface))+0.5) #longitude index, THIS LINE IS CORRECT
#print "m is %f" % m #should be -16 #print "m is %f" % m #should be -16
@ -149,7 +147,7 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface): #ok this is consid
else: else:
enclon = oddpos[1] enclon = oddpos[1]
rlon = dl * (mod(ni+m, ni)+enclon/2**nbits) rlon = dl * (mod(ni+m, ni)+enclon/2**nbits(surface))
if rlon > 180: if rlon > 180:
rlon = rlon - 360.0 rlon = rlon - 360.0
@ -210,7 +208,7 @@ def cpr_decode(my_location, icao24, encoded_lat, encoded_lon, cpr_format, evenli
#print "debug: icao %x not found. attempting local decode." % icao24 #print "debug: icao %x not found. attempting local decode." % icao24
[local_lat, local_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, surface) #try local decoding [local_lat, local_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, surface) #try local decoding
# print "debug: local resolve gives %.6f, %.6f" % (local_lat, local_lon) # print "debug: local resolve gives %.6f, %.6f" % (local_lat, local_lon)
[rnge, bearing] = range_bearing([my_lat, my_lon], [local_lat, local_lon]) [rnge, bearing] = range_bearing(my_location, [local_lat, local_lon])
if rnge < validrange: #if the local decoding can be guaranteed valid if rnge < validrange: #if the local decoding can be guaranteed valid
#print "debug: range < 180nm, position valid." #print "debug: range < 180nm, position valid."
lkplist[icao24] = [local_lat, local_lon, time.time()] #update the local position for next time lkplist[icao24] = [local_lat, local_lon, time.time()] #update the local position for next time
@ -233,7 +231,7 @@ def cpr_decode(my_location, icao24, encoded_lat, encoded_lon, cpr_format, evenli
#print "settled on position: %.6f, %.6f" % (decoded_lat, decoded_lon,) #print "settled on position: %.6f, %.6f" % (decoded_lat, decoded_lon,)
if decoded_lat is not None: if decoded_lat is not None:
[rnge, bearing] = range_bearing([my_lat, my_lon], [decoded_lat, decoded_lon]) [rnge, bearing] = range_bearing(my_location, [decoded_lat, decoded_lon])
else: else:
rnge = None rnge = None
bearing = None bearing = None

View File

@ -115,6 +115,12 @@ class modes_kml(threading.Thread):
trackstr += " %f, %f, %f" % (pos[4], pos[3], pos[2]*0.3048) trackstr += " %f, %f, %f" % (pos[4], pos[3], pos[2]*0.3048)
trackstr = string.lstrip(trackstr) trackstr = string.lstrip(trackstr)
else:
alt = 0
metric_alt = 0
lat = 0
lon = 0
trackstr = str("")
#now get metadata #now get metadata
q = "select ident from ident where icao=%i" % icao q = "select ident from ident where icao=%i" % icao

View File

@ -40,7 +40,7 @@ class modes_output_print(modes_parse.modes_parse):
msgtype = int(msgtype) msgtype = int(msgtype)
output = str("") output = None;
if msgtype == 0: if msgtype == 0:
output = self.print0(shortdata, parity, ecc) output = self.print0(shortdata, parity, ecc)
@ -55,14 +55,13 @@ class modes_output_print(modes_parse.modes_parse):
else: else:
output = "No handler for message type " + str(msgtype) + " from " + str(ecc) output = "No handler for message type " + str(msgtype) + " from " + str(ecc)
if reference == 0.0:
if reference == 0: refdb = 0.0
refdb = 0
else: else:
refdb = 10.0*math.log10(reference) refdb = 10.0*math.log10(reference)
if output is not None:
output = "(%.0f) " % (refdb) + output output = "(%.0f) " % (refdb) + output
print output print output
def print0(self, shortdata, parity, ecc): def print0(self, shortdata, parity, ecc):
@ -135,9 +134,7 @@ class modes_output_print(modes_parse.modes_parse):
elif subtype >= 5 and subtype <= 8: elif subtype >= 5 and subtype <= 8:
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata, parity, ecc) [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata, parity, ecc)
if decoded_lat==0: #no unambiguously valid position available if decoded_lat is not None:
retstr = ""
else:
retstr = "Type 17 subtype 06 (surface report) from " + "%x" % icao24 + " at (" + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ") (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")" retstr = "Type 17 subtype 06 (surface report) from " + "%x" % icao24 + " at (" + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ") (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")"
elif subtype >= 9 and subtype <= 18: elif subtype >= 9 and subtype <= 18:
@ -160,8 +157,8 @@ class modes_output_print(modes_parse.modes_parse):
retstr = "Type 17 subtype 09-1 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd retstr = "Type 17 subtype 09-1 (track report) from " + "%x" % icao24 + " with velocity " + "%.0f" % velocity + "kt heading " + "%.0f" % heading + " VS " + "%.0f" % vert_spd
else: else:
retstr = "BDS09 subtype " + str(subsubtype) + " not implemented" retstr = "Type 17 subtype 09-%i" % (subsubtype) + " not implemented"
else: else:
retstr = "Type 17, subtype " + str(subtype) + " not implemented" retstr = "Type 17 subtype " + str(subtype) + " not implemented"
return retstr return retstr