Merge branch 'master' into az_map
This commit is contained in:
commit
26f7c779d7
@ -116,6 +116,18 @@ link_directories(
|
|||||||
set(GR_GR-AIR-MODES_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
|
set(GR_GR-AIR-MODES_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
|
||||||
set(GR_GR-AIR-MODES_SWIG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/swig CACHE INTERNAL "" FORCE)
|
set(GR_GR-AIR-MODES_SWIG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/swig CACHE INTERNAL "" FORCE)
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Create uninstall target
|
||||||
|
########################################################################
|
||||||
|
configure_file(
|
||||||
|
${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||||
|
@ONLY)
|
||||||
|
|
||||||
|
add_custom_target(uninstall
|
||||||
|
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||||
|
)
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Add subdirectories
|
# Add subdirectories
|
||||||
########################################################################
|
########################################################################
|
||||||
|
23
apps/get_dupes.py
Executable file
23
apps/get_dupes.py
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys, re
|
||||||
|
|
||||||
|
if __name__== '__main__':
|
||||||
|
data = sys.stdin.readlines()
|
||||||
|
icaos = []
|
||||||
|
num_icaos = 0
|
||||||
|
for line in data:
|
||||||
|
match = re.match(".*Type.*from (\w+)", line)
|
||||||
|
if match is not None:
|
||||||
|
icao = int(match.group(1), 16)
|
||||||
|
icaos.append(icao)
|
||||||
|
|
||||||
|
#get dupes
|
||||||
|
dupes = sorted([icao for icao in set(icaos) if icaos.count(icao) > 1])
|
||||||
|
count = sum([icaos.count(icao) for icao in dupes])
|
||||||
|
for icao in dupes:
|
||||||
|
print "%x" % icao
|
||||||
|
print "Found %i replies from %i non-unique aircraft, out of a total %i replies (%i likely spurious replies)." \
|
||||||
|
% (count, len(dupes), len(icaos), len(icaos)-count)
|
||||||
|
|
||||||
|
|
@ -423,23 +423,15 @@ class adsb_rx_block (gr.top_block):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
self.demod = gr.complex_to_mag()
|
self.rx_path = air_modes.rx_path(rate, options["threshold"], queue)
|
||||||
self.avg = gr.moving_average_ff(100, 1.0/100, 400)
|
|
||||||
|
|
||||||
self.preamble = air_modes.modes_preamble(int(rate), float(options["threshold"]))
|
|
||||||
self.slicer = air_modes.modes_slicer(int(rate), queue)
|
|
||||||
|
|
||||||
if use_resampler:
|
if use_resampler:
|
||||||
self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
|
self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
|
||||||
self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=4, taps=self.lpfiltcoeffs)
|
self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=4, taps=self.lpfiltcoeffs)
|
||||||
self.connect(self.u, self.resample, self.demod)
|
self.connect(self.u, self.resample, self.rx_path)
|
||||||
else:
|
else:
|
||||||
self.connect(self.u, self.demod)
|
self.connect(self.u, self.rx_path)
|
||||||
|
|
||||||
self.connect(self.demod, self.avg)
|
|
||||||
self.connect(self.demod, (self.preamble, 0))
|
|
||||||
self.connect(self.avg, (self.preamble, 1))
|
|
||||||
self.connect(self.preamble, self.slicer)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
@ -110,24 +110,14 @@ class adsb_rx_block (gr.top_block):
|
|||||||
if options.output_all :
|
if options.output_all :
|
||||||
pass_all = 1
|
pass_all = 1
|
||||||
|
|
||||||
self.demod = gr.complex_to_mag()
|
self.rx_path = air_modes.rx_path(rate, options.threshold, queue)
|
||||||
self.avg = gr.moving_average_ff(100, 1.0/100, 400)
|
|
||||||
|
|
||||||
self.preamble = air_modes.modes_preamble(rate, options.threshold)
|
|
||||||
#self.framer = air_modes.modes_framer(rate)
|
|
||||||
self.slicer = air_modes.modes_slicer(rate, queue)
|
|
||||||
|
|
||||||
if use_resampler:
|
if use_resampler:
|
||||||
self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
|
self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
|
||||||
self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=4, taps=self.lpfiltcoeffs)
|
self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=4, taps=self.lpfiltcoeffs)
|
||||||
self.connect(self.u, self.resample, self.demod)
|
self.connect(self.u, self.resample, self.rx_path)
|
||||||
else:
|
else:
|
||||||
self.connect(self.u, self.demod)
|
self.connect(self.u, self.rx_path)
|
||||||
|
|
||||||
self.connect(self.demod, self.avg)
|
|
||||||
self.connect(self.demod, (self.preamble, 0))
|
|
||||||
self.connect(self.avg, (self.preamble, 1))
|
|
||||||
self.connect((self.preamble, 0), (self.slicer, 0))
|
|
||||||
|
|
||||||
def tune(self, freq):
|
def tune(self, freq):
|
||||||
result = self.u.set_center_freq(freq, 0)
|
result = self.u.set_center_freq(freq, 0)
|
||||||
|
32
cmake/cmake_uninstall.cmake.in
Normal file
32
cmake/cmake_uninstall.cmake.in
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# http://www.vtk.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
|
||||||
|
|
||||||
|
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||||
|
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
|
||||||
|
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||||
|
|
||||||
|
FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
|
||||||
|
STRING(REGEX REPLACE "\n" ";" files "${files}")
|
||||||
|
FOREACH(file ${files})
|
||||||
|
MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
|
||||||
|
IF(EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
EXEC_PROGRAM(
|
||||||
|
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||||
|
OUTPUT_VARIABLE rm_out
|
||||||
|
RETURN_VALUE rm_retval
|
||||||
|
)
|
||||||
|
IF(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||||
|
ENDIF(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
ELSEIF(IS_SYMLINK "$ENV{DESTDIR}${file}")
|
||||||
|
EXEC_PROGRAM(
|
||||||
|
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||||
|
OUTPUT_VARIABLE rm_out
|
||||||
|
RETURN_VALUE rm_retval
|
||||||
|
)
|
||||||
|
IF(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||||
|
ENDIF(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
ELSE(EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
|
||||||
|
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
ENDFOREACH(file)
|
@ -134,7 +134,7 @@ int air_modes_slicer::work(int noutput_items,
|
|||||||
slice_result_t slice_result = slicer(in[i+j*2], in[i+j*2+1], rx_packet.reference_level);
|
slice_result_t slice_result = slicer(in[i+j*2], in[i+j*2+1], rx_packet.reference_level);
|
||||||
if(slice_result.decision) pkt_hdr += 1 << (4-j);
|
if(slice_result.decision) pkt_hdr += 1 << (4-j);
|
||||||
}
|
}
|
||||||
if(pkt_hdr == 17) rx_packet.type = Long_Packet;
|
if(pkt_hdr == 16 or pkt_hdr == 17 or pkt_hdr == 20 or pkt_hdr == 21) rx_packet.type = Long_Packet;
|
||||||
else rx_packet.type = Short_Packet;
|
else rx_packet.type = Short_Packet;
|
||||||
int packet_length = (rx_packet.type == framer_packet_type(Short_Packet)) ? 56 : 112;
|
int packet_length = (rx_packet.type == framer_packet_type(Short_Packet)) ? 56 : 112;
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ GR_PYTHON_INSTALL(
|
|||||||
parse.py
|
parse.py
|
||||||
msprint.py
|
msprint.py
|
||||||
raw_server.py
|
raw_server.py
|
||||||
|
rx_path.py
|
||||||
sbs1.py
|
sbs1.py
|
||||||
sql.py
|
sql.py
|
||||||
Quaternion.py
|
Quaternion.py
|
||||||
|
@ -51,6 +51,7 @@ from air_modes_swig import *
|
|||||||
|
|
||||||
# import any pure python here
|
# import any pure python here
|
||||||
#
|
#
|
||||||
|
from rx_path import rx_path
|
||||||
from parse import parse,modes_reply
|
from parse import parse,modes_reply
|
||||||
from msprint import output_print
|
from msprint import output_print
|
||||||
from sql import output_sql
|
from sql import output_sql
|
||||||
|
167
python/cpr.py
167
python/cpr.py
@ -26,13 +26,9 @@ from air_modes.exceptions import *
|
|||||||
#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))
|
||||||
|
|
||||||
latz = 15
|
#TODO: remove range/bearing calc from CPR decoder class. you can do this outside of the decoder.
|
||||||
|
|
||||||
def nbits(surface):
|
latz = 15
|
||||||
if surface == 1:
|
|
||||||
return 19
|
|
||||||
else:
|
|
||||||
return 17
|
|
||||||
|
|
||||||
def nz(ctype):
|
def nz(ctype):
|
||||||
return 4 * latz - ctype
|
return 4 * latz - ctype
|
||||||
@ -49,38 +45,30 @@ def dlat(ctype, surface):
|
|||||||
else:
|
else:
|
||||||
return tmp / nzcalc
|
return tmp / nzcalc
|
||||||
|
|
||||||
def nl_eo(declat_in, ctype):
|
|
||||||
return nl(declat_in) - ctype
|
|
||||||
|
|
||||||
def nl(declat_in):
|
def nl(declat_in):
|
||||||
if abs(declat_in) >= 87.0:
|
if abs(declat_in) >= 87.0:
|
||||||
return 1.0
|
return 1.0
|
||||||
return math.floor( (2.0*math.pi) * pow(math.acos(1.0- (1.0-math.cos(math.pi/(2.0*latz))) / pow( math.cos( (math.pi/180.0)*abs(declat_in) ) ,2.0) ),-1.0))
|
return math.floor( (2.0*math.pi) * math.acos(1.0- (1.0-math.cos(math.pi/(2.0*latz))) / math.cos( (math.pi/180.0)*abs(declat_in) )**2 )**-1)
|
||||||
|
|
||||||
def dlon(declat_in, ctype, surface):
|
def dlon(declat_in, ctype, surface):
|
||||||
if surface == 1:
|
if surface:
|
||||||
tmp = 90.0
|
tmp = 90.0
|
||||||
else:
|
else:
|
||||||
tmp = 360.0
|
tmp = 360.0
|
||||||
nlcalc = nl_eo(declat_in, ctype)
|
nlcalc = max(nl(declat_in)-ctype, 1)
|
||||||
if nlcalc == 0:
|
return tmp / nlcalc
|
||||||
return tmp
|
|
||||||
else:
|
|
||||||
return tmp / max(nlcalc, 1.0)
|
|
||||||
|
|
||||||
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(surface))
|
tmp2 = float(enclat) / (2**17)
|
||||||
j = math.floor(my_lat/tmp1) + math.floor(0.5 + ((my_lat % tmp1) / tmp1) - tmp2)
|
j = math.floor(my_lat/tmp1) + math.floor(0.5 + ((my_lat % tmp1) / tmp1) - tmp2)
|
||||||
# print "dlat gives " + "%.6f " % tmp1 + "with j = " + "%.6f " % j + " and tmp2 = " + "%.6f" % tmp2 + " given enclat " + "%x" % enclat
|
|
||||||
|
|
||||||
return tmp1 * (j + tmp2)
|
return tmp1 * (j + tmp2)
|
||||||
|
|
||||||
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(surface))
|
tmp2 = float(enclon) / (2**17)
|
||||||
m = math.floor(my_lon / tmp1) + math.floor(0.5 + ((my_lon % tmp1) / tmp1) - tmp2)
|
m = math.floor(my_lon / tmp1) + math.floor(0.5 + ((my_lon % tmp1) / tmp1) - tmp2)
|
||||||
# print "dlon gives " + "%.6f " % tmp1 + "with m = " + "%.6f " % m + " and tmp2 = " + "%.6f" % tmp2 + " given enclon " + "%x" % enclon
|
|
||||||
|
|
||||||
return tmp1 * (m + tmp2)
|
return tmp1 * (m + tmp2)
|
||||||
|
|
||||||
@ -93,7 +81,11 @@ def cpr_resolve_local(my_location, encoded_location, ctype, surface):
|
|||||||
|
|
||||||
return [decoded_lat, decoded_lon]
|
return [decoded_lat, decoded_lon]
|
||||||
|
|
||||||
def cpr_resolve_global(evenpos, oddpos, mostrecent, surface):
|
def cpr_resolve_global(evenpos, oddpos, mypos, mostrecent, surface):
|
||||||
|
#cannot resolve surface positions unambiguously without knowing receiver position
|
||||||
|
if surface and mypos is None:
|
||||||
|
raise CPRNoPositionError
|
||||||
|
|
||||||
dlateven = dlat(0, surface)
|
dlateven = dlat(0, surface)
|
||||||
dlatodd = dlat(1, surface)
|
dlatodd = dlat(1, surface)
|
||||||
|
|
||||||
@ -114,7 +106,6 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface):
|
|||||||
#This checks to see if the latitudes of the reports straddle a transition boundary
|
#This checks to see if the latitudes of the reports straddle a transition boundary
|
||||||
#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!"
|
|
||||||
raise CPRBoundaryStraddleError
|
raise CPRBoundaryStraddleError
|
||||||
|
|
||||||
if mostrecent == 0:
|
if mostrecent == 0:
|
||||||
@ -122,21 +113,41 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface):
|
|||||||
else:
|
else:
|
||||||
rlat = rlatodd
|
rlat = rlatodd
|
||||||
|
|
||||||
dl = dlon(rlat, mostrecent, surface)
|
#disambiguate latitude
|
||||||
nlthing = nl(rlat)
|
if surface:
|
||||||
ni = max(nlthing - mostrecent, 1)
|
if mypos[0] < 0:
|
||||||
|
rlat -= 90
|
||||||
|
|
||||||
m = math.floor(((evenpos[1]*(nlthing-1)-oddpos[1]*(nlthing))/2**17)+0.5) #longitude index
|
dl = dlon(rlat, mostrecent, surface)
|
||||||
|
nl_rlat = nl(rlat)
|
||||||
|
|
||||||
|
m = math.floor(((evenpos[1]*(nl_rlat-1)-oddpos[1]*nl_rlat)/2**17)+0.5) #longitude index
|
||||||
|
|
||||||
|
#when surface positions straddle a disambiguation boundary (90 degrees),
|
||||||
|
#surface decoding will fail. this might never be a problem in real life, but it'll fail in the
|
||||||
|
#test case. the documentation doesn't mention it.
|
||||||
|
|
||||||
if mostrecent == 0:
|
if mostrecent == 0:
|
||||||
enclon = evenpos[1]
|
enclon = evenpos[1]
|
||||||
else:
|
else:
|
||||||
enclon = oddpos[1]
|
enclon = oddpos[1]
|
||||||
|
|
||||||
rlon = dl * (((ni+m) % ni)+enclon/2**17)
|
rlon = dl * ((m % max(nl_rlat-mostrecent,1)) + enclon/2.**17)
|
||||||
|
|
||||||
|
#print "DL: %f nl: %f m: %f rlon: %f" % (dl, nl_rlat, m, rlon)
|
||||||
|
#print "evenpos: %x, oddpos: %x, mostrecent: %i" % (evenpos[1], oddpos[1], mostrecent)
|
||||||
|
|
||||||
|
if surface:
|
||||||
|
#longitudes need to be resolved to the nearest 90 degree segment to the receiver.
|
||||||
|
wat = mypos[1]
|
||||||
|
if wat < 0:
|
||||||
|
wat += 360
|
||||||
|
zone = lambda lon: 90 * (int(lon) / 90)
|
||||||
|
rlon += (zone(wat) - zone(rlon))
|
||||||
|
|
||||||
|
#limit to (-180, 180)
|
||||||
if rlon > 180:
|
if rlon > 180:
|
||||||
rlon = rlon - 360.0
|
rlon -= 360.0
|
||||||
|
|
||||||
return [rlat, rlon]
|
return [rlat, rlon]
|
||||||
|
|
||||||
@ -174,6 +185,8 @@ class cpr_decoder:
|
|||||||
self.my_location = my_location
|
self.my_location = my_location
|
||||||
self.evenlist = {}
|
self.evenlist = {}
|
||||||
self.oddlist = {}
|
self.oddlist = {}
|
||||||
|
self.evenlist_sfc = {}
|
||||||
|
self.oddlist_sfc = {}
|
||||||
|
|
||||||
def set_location(new_location):
|
def set_location(new_location):
|
||||||
self.my_location = new_location
|
self.my_location = new_location
|
||||||
@ -183,24 +196,34 @@ class cpr_decoder:
|
|||||||
for key, item in poslist.items():
|
for key, item in poslist.items():
|
||||||
if time.time() - item[2] > 10:
|
if time.time() - item[2] > 10:
|
||||||
del poslist[key]
|
del poslist[key]
|
||||||
|
for poslist in [self.evenlist_sfc, self.oddlist_sfc]:
|
||||||
|
for key, item in poslist.items():
|
||||||
|
if time.time() - item[2] > 25:
|
||||||
|
del poslist[key]
|
||||||
|
|
||||||
def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface):
|
def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface):
|
||||||
|
if surface:
|
||||||
|
oddlist = self.oddlist_sfc
|
||||||
|
evenlist = self.evenlist_sfc
|
||||||
|
else:
|
||||||
|
oddlist = self.oddlist
|
||||||
|
evenlist = self.evenlist
|
||||||
|
|
||||||
#add the info to the position reports list for global decoding
|
#add the info to the position reports list for global decoding
|
||||||
if cpr_format==1:
|
if cpr_format==1:
|
||||||
self.oddlist[icao24] = [encoded_lat, encoded_lon, time.time()]
|
oddlist[icao24] = [encoded_lat, encoded_lon, time.time()]
|
||||||
else:
|
else:
|
||||||
self.evenlist[icao24] = [encoded_lat, encoded_lon, time.time()]
|
evenlist[icao24] = [encoded_lat, encoded_lon, time.time()]
|
||||||
|
|
||||||
[decoded_lat, decoded_lon] = [None, None]
|
[decoded_lat, decoded_lon] = [None, None]
|
||||||
|
|
||||||
#okay, let's traverse the lists and weed out those entries that are older than 10 seconds
|
#okay, let's traverse the lists and weed out those entries that are older than 10 seconds
|
||||||
self.weed_poslists()
|
self.weed_poslists()
|
||||||
|
|
||||||
if (icao24 in self.evenlist) \
|
if (icao24 in evenlist) \
|
||||||
and (icao24 in self.oddlist):
|
and (icao24 in oddlist):
|
||||||
newer = (self.oddlist[icao24][2] - self.evenlist[icao24][2]) > 0 #figure out which report is newer
|
newer = (oddlist[icao24][2] - 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(evenlist[icao24][0:2], oddlist[icao24][0:2], self.my_location, newer, surface) #do a global decode
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise CPRNoPositionError
|
raise CPRNoPositionError
|
||||||
|
|
||||||
@ -215,83 +238,95 @@ class cpr_decoder:
|
|||||||
#encode CPR position
|
#encode CPR position
|
||||||
def cpr_encode(lat, lon, ctype, surface):
|
def cpr_encode(lat, lon, ctype, surface):
|
||||||
if surface is True:
|
if surface is True:
|
||||||
scalar = float(2**19)
|
scalar = 2.**19
|
||||||
else:
|
else:
|
||||||
scalar = float(2**17)
|
scalar = 2.**17
|
||||||
|
|
||||||
dlati = float(dlat(ctype, False))
|
#encode using 360 constant for segment size.
|
||||||
|
dlati = dlat(ctype, False)
|
||||||
yz = math.floor(scalar * ((lat % dlati)/dlati) + 0.5)
|
yz = math.floor(scalar * ((lat % dlati)/dlati) + 0.5)
|
||||||
rlat = dlati * ((yz / scalar) + math.floor(lat / dlati))
|
rlat = dlati * ((yz / scalar) + math.floor(lat / dlati))
|
||||||
|
|
||||||
nleo = nl_eo(rlat, ctype)
|
#encode using 360 constant for segment size.
|
||||||
if nleo == 0:
|
dloni = dlon(lat, ctype, False)
|
||||||
dloni = 360.0
|
|
||||||
else:
|
|
||||||
dloni = 360.0 / nl_eo(rlat, ctype)
|
|
||||||
|
|
||||||
xz = math.floor(scalar * ((lon % dloni)/dloni) + 0.5)
|
xz = math.floor(scalar * ((lon % dloni)/dloni) + 0.5)
|
||||||
|
|
||||||
yz = int(yz % scalar)
|
yz = int(yz) & (2**17-1)
|
||||||
xz = int(xz % scalar)
|
xz = int(xz) & (2**17-1)
|
||||||
|
|
||||||
return (yz, xz) #lat, lon
|
return (yz, xz) #lat, lon
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys, random
|
import sys, random
|
||||||
|
|
||||||
rounds = 10000
|
rounds = 10001
|
||||||
threshold = 1e-3 #0.001 deg lat/lon
|
threshold = 1e-3 #0.001 deg lat/lon
|
||||||
#this accuracy is highly dependent on latitude, since at high
|
#this accuracy is highly dependent on latitude, since at high
|
||||||
#latitudes the corresponding error in longitude is greater
|
#latitudes the corresponding error in longitude is greater
|
||||||
|
|
||||||
bs = 0
|
bs = 0
|
||||||
|
surface = False
|
||||||
|
|
||||||
|
lats = [i/(rounds/170.)-85 for i in range(0,rounds)]
|
||||||
|
lons = [i/(rounds/360.)-180 for i in range(0,rounds)]
|
||||||
|
|
||||||
for i in range(0, rounds):
|
for i in range(0, rounds):
|
||||||
decoder = cpr_decoder(None)
|
even_lat = lats[i]
|
||||||
even_lat = random.uniform(-85, 85)
|
#even_lat = random.uniform(-85, 85)
|
||||||
even_lon = random.uniform(-180,180)
|
even_lon = lons[i]
|
||||||
odd_lat = even_lat + 1e-2
|
#even_lon = random.uniform(-180, 180)
|
||||||
odd_lon = min(even_lon + 1e-2, 180)
|
odd_lat = even_lat + 1e-3
|
||||||
|
odd_lon = min(even_lon + 1e-3, 180)
|
||||||
|
decoder = cpr_decoder([odd_lat, odd_lon])
|
||||||
|
|
||||||
#encode that position
|
#encode that position
|
||||||
(evenenclat, evenenclon) = cpr_encode(even_lat, even_lon, False, False)
|
(evenenclat, evenenclon) = cpr_encode(even_lat, even_lon, False, surface)
|
||||||
(oddenclat, oddenclon) = cpr_encode(odd_lat, odd_lon, True, False)
|
(oddenclat, oddenclon) = cpr_encode(odd_lat, odd_lon, True, surface)
|
||||||
|
|
||||||
#perform a global decode
|
#try to perform a global decode -- this should fail since the decoder
|
||||||
|
#only has heard one position. need two for global decoding.
|
||||||
icao = random.randint(0, 0xffffff)
|
icao = random.randint(0, 0xffffff)
|
||||||
try:
|
try:
|
||||||
evenpos = decoder.decode(icao, evenenclat, evenenclon, False, False)
|
evenpos = decoder.decode(icao, evenenclat, evenenclon, False, surface)
|
||||||
#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")
|
||||||
except CPRNoPositionError:
|
except CPRNoPositionError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
#now try to do a real decode with the last packet's odd complement
|
||||||
|
#watch for a boundary straddle -- this isn't fatal, it just indicates
|
||||||
|
#that the even and odd reports lie on either side of a longitudinal boundary
|
||||||
|
#and so you can't get a position
|
||||||
try:
|
try:
|
||||||
(odddeclat, odddeclon, rng, brg) = decoder.decode(icao, oddenclat, oddenclon, True, False)
|
(odddeclat, odddeclon, rng, brg) = decoder.decode(icao, oddenclat, oddenclon, True, surface)
|
||||||
except CPRBoundaryStraddleError:
|
except CPRBoundaryStraddleError:
|
||||||
bs += 1
|
bs += 1
|
||||||
continue
|
continue
|
||||||
except CPRNoPositionError:
|
except CPRNoPositionError:
|
||||||
raise Exception("CPR test failure: no decode after even/odd inputs")
|
raise Exception("CPR test failure: no decode after even/odd inputs")
|
||||||
|
|
||||||
#print "Lat: %f Lon: %f" % (ac_lat, ac_lon)
|
|
||||||
|
|
||||||
if abs(odddeclat - odd_lat) > threshold or abs(odddeclon - odd_lon) > threshold:
|
if abs(odddeclat - odd_lat) > threshold or abs(odddeclon - odd_lon) > threshold:
|
||||||
print "odddeclat: %f odd_lat: %f" % (odddeclat, odd_lat)
|
print "F odddeclat: %f odd_lat: %f" % (odddeclat, odd_lat)
|
||||||
print "odddeclon: %f odd_lon: %f" % (odddeclon, odd_lon)
|
print "F odddeclon: %f odd_lon: %f" % (odddeclon, odd_lon)
|
||||||
raise Exception("CPR test failure: global decode error greater than threshold")
|
raise Exception("CPR test failure: global decode error greater than threshold")
|
||||||
|
# else:
|
||||||
|
# print "S odddeclat: %f odd_lat: %f" % (odddeclat, odd_lat)
|
||||||
|
# print "S odddeclon: %f odd_lon: %f" % (odddeclon, odd_lon)
|
||||||
|
|
||||||
nexteven_lat = odd_lat + 1e-2
|
nexteven_lat = odd_lat + 1e-3
|
||||||
nexteven_lon = min(odd_lon + 1e-2, 180)
|
nexteven_lon = min(odd_lon + 1e-3, 180)
|
||||||
|
|
||||||
(nexteven_enclat, nexteven_enclon) = cpr_encode(nexteven_lat, nexteven_lon, False, False)
|
(nexteven_enclat, nexteven_enclon) = cpr_encode(nexteven_lat, nexteven_lon, False, surface)
|
||||||
|
|
||||||
|
#try a locally-referenced decode
|
||||||
try:
|
try:
|
||||||
(evendeclat, evendeclon) = cpr_resolve_local([even_lat, even_lon], [nexteven_enclat, nexteven_enclon], False, False)
|
(evendeclat, evendeclon) = cpr_resolve_local([even_lat, even_lon], [nexteven_enclat, nexteven_enclon], False, surface)
|
||||||
except CPRNoPositionError:
|
except CPRNoPositionError:
|
||||||
raise Exception("CPR test failure: local decode failure to resolve")
|
raise Exception("CPR test failure: local decode failure to resolve")
|
||||||
|
|
||||||
|
#check to see if the positions were valid
|
||||||
if abs(evendeclat - nexteven_lat) > threshold or abs(evendeclon - nexteven_lon) > threshold:
|
if abs(evendeclat - nexteven_lat) > threshold or abs(evendeclon - nexteven_lon) > threshold:
|
||||||
|
print "F evendeclat: %f nexteven_lat: %f evenlat: %f" % (evendeclat, nexteven_lat, even_lat)
|
||||||
|
print "F evendeclon: %f nexteven_lon: %f evenlon: %f" % (evendeclon, nexteven_lon, even_lon)
|
||||||
raise Exception("CPR test failure: local decode error greater than threshold")
|
raise Exception("CPR test failure: local decode error greater than threshold")
|
||||||
|
|
||||||
print "CPR test successful. There were %i boundary straddles over %i rounds." % (bs, rounds)
|
print "CPR test successful. There were %i boundary straddles over %i rounds." % (bs, rounds)
|
||||||
|
@ -55,8 +55,8 @@ class output_print(air_modes.parse):
|
|||||||
output += self.print11(data, ecc)
|
output += self.print11(data, ecc)
|
||||||
elif msgtype == 17:
|
elif msgtype == 17:
|
||||||
output += self.print17(data)
|
output += self.print17(data)
|
||||||
elif msgtype == 20 or msgtype == 21:
|
elif msgtype == 20 or msgtype == 21 or msgtype == 16:
|
||||||
output += self.print20(data, ecc)
|
output += self.printTCAS(data, ecc)
|
||||||
else:
|
else:
|
||||||
output += "No handler for message type %i from %x (but it's in modes_parse)" % (msgtype, ecc)
|
output += "No handler for message type %i from %x (but it's in modes_parse)" % (msgtype, ecc)
|
||||||
return output
|
return output
|
||||||
@ -186,36 +186,48 @@ class output_print(air_modes.parse):
|
|||||||
|
|
||||||
return retstr
|
return retstr
|
||||||
|
|
||||||
def print20(self, data, ecc):
|
def printTCAS(self, data, ecc):
|
||||||
msgtype = data["df"]
|
msgtype = data["df"]
|
||||||
if(msgtype == 20):
|
if msgtype == 20 or msgtype == 16:
|
||||||
|
#type 16 does not have fs, dr, um but we get alt here
|
||||||
[fs, dr, um, alt] = self.parse4(data)
|
[fs, dr, um, alt] = self.parse4(data)
|
||||||
else:
|
elif msgtype == 21:
|
||||||
[fs, dr, um, ident] = self.parse5(data)
|
[fs, dr, um, ident] = self.parse5(data)
|
||||||
bds1 = data["bds1"]
|
|
||||||
bds2 = data["bds2"]
|
if msgtype == 16:
|
||||||
|
bds1 = data["vds1"]
|
||||||
|
bds2 = data["vds2"]
|
||||||
|
else:
|
||||||
|
bds1 = data["bds1"]
|
||||||
|
bds2 = data["bds2"]
|
||||||
|
|
||||||
if bds2 != 0:
|
if bds2 != 0:
|
||||||
retstr = "No handler for BDS2 == %i from %x" % (bds2, ecc)
|
retstr = "No handler in type %i for BDS2 == %i from %x" % (msgtype, bds2, ecc)
|
||||||
|
|
||||||
elif bds1 == 0:
|
elif bds1 == 0:
|
||||||
retstr = "No handler for BDS1 == 0 from %x" % ecc
|
retstr = "No handler in type %i for BDS1 == 0 from %x" % (msgtype, ecc)
|
||||||
elif bds1 == 1:
|
elif bds1 == 1:
|
||||||
retstr = "Type 20 link capability report from %x: ACS: 0x%x, BCS: 0x%x, ECS: 0x%x, continues %i" \
|
retstr = "Type %i link capability report from %x: ACS: 0x%x, BCS: 0x%x, ECS: 0x%x, continues %i" \
|
||||||
% (ecc, data["acs"], data["bcs"], data["ecs"], data["cfs"])
|
% (msgtype, ecc, data["acs"], data["bcs"], data["ecs"], data["cfs"])
|
||||||
elif bds1 == 2:
|
elif bds1 == 2:
|
||||||
retstr = "Type 20 identification from %x with text %s" % (ecc, self.parseMB_id(data))
|
retstr = "Type %i identification from %x with text %s" % (msgtype, ecc, self.parseMB_id(data))
|
||||||
elif bds2 == 3:
|
elif bds1 == 3:
|
||||||
retstr = "Type 20 TCAS report from %x: " % ecc
|
retstr = "Type %i TCAS report from %x: " % (msgtype, ecc)
|
||||||
tti = data["tti"]
|
tti = data["tti"]
|
||||||
if tti == 1:
|
if msgtype == 16:
|
||||||
(resolutions, complements, rat, mte, threat_id) = self.parseMB_TCAS_threatid(data)
|
(resolutions, complements, rat, mte) = self.parse_TCAS_CRM(data)
|
||||||
retstr += "threat ID: %x advised: %s complement: %s" % (threat_id, resolutions, complements)
|
retstr += "advised: %s complement: %s" % (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:
|
else:
|
||||||
retstr += " (no handler for TTI=%i)" % tti
|
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:
|
||||||
|
rat = 0
|
||||||
|
mte = 0
|
||||||
|
retstr += " (no handler for TTI=%i)" % tti
|
||||||
if mte == 1:
|
if mte == 1:
|
||||||
retstr += " (multiple threats)"
|
retstr += " (multiple threats)"
|
||||||
if rat == 1:
|
if rat == 1:
|
||||||
@ -223,9 +235,9 @@ class output_print(air_modes.parse):
|
|||||||
else:
|
else:
|
||||||
retstr = "No handler for BDS1 == %i from %x" % (bds1, ecc)
|
retstr = "No handler for BDS1 == %i from %x" % (bds1, ecc)
|
||||||
|
|
||||||
# if(msgtype == 20):
|
if(msgtype == 20 or msgtype == 16):
|
||||||
# retstr += " at %ift" % altitude
|
retstr += " at %ift" % alt
|
||||||
# else:
|
else:
|
||||||
# retstr += " ident %x" % ident
|
retstr += " ident %x" % ident
|
||||||
|
|
||||||
return retstr
|
return retstr
|
||||||
|
@ -193,6 +193,22 @@ class mb_reply(data_field):
|
|||||||
# "vds": (33,8), "vds1": (33,4), "vds2": (37,4)
|
# "vds": (33,8), "vds1": (33,4), "vds2": (37,4)
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
class mv_reply(data_field):
|
||||||
|
offset = 33
|
||||||
|
types = { "ara": (41,14), "mte": (60,1), "rac": (55,4), "rat": (59,1),
|
||||||
|
"vds": (33,8), "vds1": (33,4), "vds2": (37,4)
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_type(self):
|
||||||
|
vds1 = self.get_bits(33,4)
|
||||||
|
vds2 = self.get_bits(37,4)
|
||||||
|
if vds1 not in (3,) or vds2 not in (0,):
|
||||||
|
raise NoHandlerError(bds1)
|
||||||
|
return int(vds1)
|
||||||
|
|
||||||
|
def get_numbits(self):
|
||||||
|
return 56
|
||||||
|
|
||||||
#the whole Mode S packet type
|
#the whole Mode S packet type
|
||||||
class modes_reply(data_field):
|
class modes_reply(data_field):
|
||||||
types = { 0: {"df": (1,5), "vs": (6,1), "cc": (7,1), "sl": (9,3), "ri": (14,4), "ac": (20,13), "ap": (33,24)},
|
types = { 0: {"df": (1,5), "vs": (6,1), "cc": (7,1), "sl": (9,3), "ri": (14,4), "ac": (20,13), "ap": (33,24)},
|
||||||
@ -379,15 +395,16 @@ class parse:
|
|||||||
53: "DON'T TURN LEFT", 54: "DON'T TURN RIGHT"}
|
53: "DON'T TURN LEFT", 54: "DON'T TURN RIGHT"}
|
||||||
rac_bits = {55: "DON'T DESCEND", 56: "DON'T CLIMB", 57: "DON'T TURN LEFT", 58: "DON'T TURN RIGHT"}
|
rac_bits = {55: "DON'T DESCEND", 56: "DON'T CLIMB", 57: "DON'T TURN LEFT", 58: "DON'T TURN RIGHT"}
|
||||||
ara = data["ara"]
|
ara = data["ara"]
|
||||||
|
rac = data["rac"]
|
||||||
#check to see which bits are set
|
#check to see which bits are set
|
||||||
resolutions = ""
|
resolutions = ""
|
||||||
for bit, name in ara_bits:
|
for bit in ara_bits:
|
||||||
if ara & (1 << (54-bit)):
|
if ara & (1 << (54-bit)):
|
||||||
resolutions += " " + name
|
resolutions += " " + ara_bits[bit]
|
||||||
complements = ""
|
complements = ""
|
||||||
for bit, name in rac_bits:
|
for bit in rac_bits:
|
||||||
if rac & (1 << (58-bit)):
|
if rac & (1 << (58-bit)):
|
||||||
complements += " " + name
|
complements += " " + rac_bits[bit]
|
||||||
return (resolutions, complements)
|
return (resolutions, complements)
|
||||||
|
|
||||||
#rat is 1 if resolution advisory terminated <18s ago
|
#rat is 1 if resolution advisory terminated <18s ago
|
||||||
@ -404,3 +421,8 @@ class parse:
|
|||||||
(resolutions, complements) = self.parseMB_TCAS_resolutions(data)
|
(resolutions, complements) = self.parseMB_TCAS_resolutions(data)
|
||||||
threat_alt = decode_alt(data["tida"], True)
|
threat_alt = decode_alt(data["tida"], True)
|
||||||
return (resolutions, complements, data["rat"], data["mte"], threat_alt, data["tidr"], data["tidb"])
|
return (resolutions, complements, data["rat"], data["mte"], threat_alt, data["tidr"], data["tidb"])
|
||||||
|
|
||||||
|
#type 16 Coordination Reply Message
|
||||||
|
def parse_TCAS_CRM(self, data):
|
||||||
|
(resolutions, complements) = self.parseMB_TCAS_resolutions(data)
|
||||||
|
return (resolutions, complements, data["rat"], data["mte"])
|
||||||
|
50
python/rx_path.py
Normal file
50
python/rx_path.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2012 Corgan Labs
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
from gnuradio import gr
|
||||||
|
import air_modes_swig
|
||||||
|
|
||||||
|
class rx_path(gr.hier_block2):
|
||||||
|
|
||||||
|
def __init__(self, rate, threshold, queue):
|
||||||
|
gr.hier_block2.__init__(self, "modes_rx_path",
|
||||||
|
gr.io_signature(1, 1, gr.sizeof_gr_complex),
|
||||||
|
gr.io_signature(0,0,0))
|
||||||
|
|
||||||
|
self._rate = int(rate)
|
||||||
|
self._threshold = threshold
|
||||||
|
self._queue = queue
|
||||||
|
|
||||||
|
# Convert incoming I/Q baseband to amplitude
|
||||||
|
self._demod = gr.complex_to_mag()
|
||||||
|
|
||||||
|
# Establish baseline amplitude (noise, interference)
|
||||||
|
self._avg = gr.moving_average_ff(100, 1.0/100, 400) # FIXME
|
||||||
|
|
||||||
|
# Synchronize to Mode-S preamble
|
||||||
|
self._sync = air_modes_swig.modes_preamble(self._rate, self._threshold)
|
||||||
|
|
||||||
|
# Slice Mode-S bits and send to message queue
|
||||||
|
self._slicer = air_modes_swig.modes_slicer(self._rate, self._queue)
|
||||||
|
|
||||||
|
self.connect(self, self._demod, (self._sync, 0))
|
||||||
|
self.connect(self._demod, self._avg, (self._sync, 1))
|
||||||
|
self.connect(self._sync, self._slicer)
|
Loading…
Reference in New Issue
Block a user