From 822b05944bef12936e00fc64fe31e3732a9336ed Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 20 Jul 2012 18:40:30 -0700 Subject: [PATCH 1/9] Fix for BDS0,9 SQL insertion. --- python/modes_sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/modes_sql.py b/python/modes_sql.py index 5ec53a4..ca9dbb6 100644 --- a/python/modes_sql.py +++ b/python/modes_sql.py @@ -117,7 +117,7 @@ class modes_output_sql(modes_parse.modes_parse): elif subtype == 19: subsubtype = (longdata >> 48) & 0x07 if subsubtype == 0: - [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata) + [velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(shortdata, longdata) retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"; elif subsubtype == 1: From 1c35ccc0e038c2613dd78f8d631d6602837ef7db Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Mon, 16 Jul 2012 14:35:43 -0700 Subject: [PATCH 2/9] How did this go so long without being fixed? Range and bearing were asymptotic due to -- get this -- degree/radian confusion. --- python/cpr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cpr.py b/python/cpr.py index 460c69b..5a0e0b9 100755 --- a/python/cpr.py +++ b/python/cpr.py @@ -158,10 +158,10 @@ def range_bearing(loc_a, loc_b): delta_lat = b_lat - a_lat delta_lon = b_lon - a_lon - avg_lat = (a_lat + b_lat) / 2.0 + avg_lat = ((a_lat + b_lat) / 2.0) * math.pi / 180 R1 = earth_radius_mi*(1.0-esquared)/pow((1.0-esquared*pow(math.sin(avg_lat),2)),1.5) - + R2 = earth_radius_mi/math.sqrt(1.0-esquared*pow(math.sin(avg_lat),2)) distance_North = R1*delta_lat From ac8a01646b2c0a53f399593bce82c0b99b2527d1 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 21 Jul 2012 11:10:15 -0700 Subject: [PATCH 3/9] Add BDS0,9-3 (air course report) to parser/printer. --- python/modes_parse.py | 15 +++++++++++++++ python/modes_print.py | 14 +++++++++++--- python/modes_sbs1.py | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/python/modes_parse.py b/python/modes_parse.py index 8e672b4..f41c83e 100644 --- a/python/modes_parse.py +++ b/python/modes_parse.py @@ -345,6 +345,21 @@ class modes_parse: return [velocity, heading, vert_spd] + def parseBDS09_3(self, data): + #3: {"sub", "icf", "ifr", "nuc", "mhs", "hdg", "ast", "spd", "vrsrc", + # "dvr", "vr", "dhd", "hd"} + mag_hdg = data["mhs"] * 360. / 1024 + vel_src = "TAS" if data["ast"] == 1 else "IAS" + vel = data["spd"] + if data["sub"] == 4: + vel *= 4 + vert_spd = float(data["vr"] - 1) * 64 + if data["dvr"] == 1: + vert_spd = 0 - vert_spd + geo_diff = float(data["hd"] - 1) * 25 + return [mag_hdg, vel_src, vel, vert_spd, geo_diff] + + def parseBDS62(self, data): eps_strings = ["NO EMERGENCY", "GENERAL EMERGENCY", "LIFEGUARD/MEDICAL", "FUEL EMERGENCY", "NO COMMUNICATIONS", "UNLAWFUL INTERFERENCE", "RESERVED", "RESERVED"] diff --git a/python/modes_print.py b/python/modes_print.py index f10c83b..e90d4f0 100644 --- a/python/modes_print.py +++ b/python/modes_print.py @@ -158,10 +158,18 @@ class modes_output_print(modes_parse.modes_parse): elif bdsreg == 0x09: subtype = data["bds09"].get_type() - if subtype == 0 or subtype == 1: - parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1 - [velocity, heading, vert_spd] = parser(data) + 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) retstr = "Type 17 BDS0,9-%i (track report) from %x with velocity %.0fkt heading %.0f VS %.0f" % (subtype, icao24, velocity, heading, vert_spd) + 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) + else: retstr = "Type 17 BDS0,9-%i from %x not implemented" % (subtype, icao24) diff --git a/python/modes_sbs1.py b/python/modes_sbs1.py index 452d008..20d6457 100644 --- a/python/modes_sbs1.py +++ b/python/modes_sbs1.py @@ -146,7 +146,7 @@ class modes_output_sbs1(modes_parse.modes_parse): def pp5(self, shortdata, ecc): # I'm not sure what to do with the identiifcation shortdata & 0x1FFF [datestr, timestr] = self.current_time() - [fs, dr, um] = self.parse5(shortdata) + [fs, dr, um, ident] = self.parse5(shortdata) aircraft_id = self.get_aircraft_id(ecc) retstr = "MSG,6,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr) return retstr + self.decode_fs(fs) + "\n" From 9b539f89428d689000476291aebe9434f881557a Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 21 Jul 2012 11:12:19 -0700 Subject: [PATCH 4/9] Fix for BDS0,9-0/1 --- python/modes_sql.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/modes_sql.py b/python/modes_sql.py index 9cf272b..88e8117 100644 --- a/python/modes_sql.py +++ b/python/modes_sql.py @@ -113,9 +113,12 @@ class modes_output_sql(modes_parse.modes_parse): elif bdsreg == 0x09: subtype = data["bds09"].get_type() - if subtype == 0 or subtype == 1: - parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1 - [velocity, heading, vert_spd] = parser(data) + if subtype == 0: + [velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data) retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")" - + elif subtype == 1: + [velocity, heading, vert_spd] = self.parseBDS09_1(data) + retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")" + else: + retstr = None return retstr From 3d69b7ff80a6437bc8bec832f09b801d4263f407 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 21 Jul 2012 11:26:49 -0700 Subject: [PATCH 5/9] Use proper scaling for dBfs --- python/modes_print.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/modes_print.py b/python/modes_print.py index e90d4f0..dd611c7 100644 --- a/python/modes_print.py +++ b/python/modes_print.py @@ -36,11 +36,10 @@ class modes_output_print(modes_parse.modes_parse): reference = float(reference) timestamp = float(timestamp) - #TODO this is suspect if reference == 0.0: refdb = -150.0 else: - refdb = 10.0*math.log10(reference) + refdb = 20.0*math.log10(reference) output = "(%.0f %.10f) " % (refdb, timestamp); try: From fa4a8be31b9f5757977b0387a86b87463ed5ea67 Mon Sep 17 00:00:00 2001 From: Dennis Real Date: Mon, 6 Aug 2012 12:08:01 -0700 Subject: [PATCH 6/9] KML generator patch to align the airplane icon w/aircraft heading. --- python/modes_kml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/modes_kml.py b/python/modes_kml.py index 046ee42..b081416 100644 --- a/python/modes_kml.py +++ b/python/modes_kml.py @@ -150,7 +150,7 @@ class modes_kml(threading.Thread, modes_output_sql): heading = 0 vertical = 0 #now generate some KML - retstr+= "\n\t\t\n\t\t\t%s\n\t\t\t#airplane\n\t\t\t\n\t\t\t\tHeading: %i
Speed: %i
Vertical speed: %i
ICAO: %x
Last seen: %s]]>\n\t\t\t
\n\t\t\t\n\t\t\t\tabsolute\n\t\t\t\t1\n\t\t\t\t%s,%s,%i\n\t\t\t\n\t\t
" % (ident, alt, heading, speed, vertical, icao[0], seen, lon, lat, metric_alt, ) + retstr+= "\n\t\t\n\t\t\t%s\n\t\t\t\n\t\t\t#airplane\n\t\t\t\n\t\t\t\tHeading: %i
Speed: %i
Vertical speed: %i
ICAO: %x
Last seen: %s]]>\n\t\t\t
\n\t\t\t\n\t\t\t\tabsolute\n\t\t\t\t1\n\t\t\t\t%s,%s,%i\n\t\t\t\n\t\t
" % (ident, heading, alt, heading, speed, vertical, icao[0], seen, lon, lat, metric_alt, ) retstr+= "\n\t\t\n\t\t\t#track\n\t\t\t\n\t\t\t\t0\n\t\t\t\tabsolute\n\t\t\t\t%s\n\t\t\t\n\t\t" % (trackstr,) From d80a76faca1516ea9cc48c1e306a57a677937513 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 7 Aug 2012 10:32:41 -0700 Subject: [PATCH 7/9] README update for new executable names. --- README | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README b/README index fda0589..c3201e4 100644 --- a/README +++ b/README @@ -65,7 +65,7 @@ Implementation of ADS-B is mandatory in European airspace as well as in Australia. North American implementation is still voluntary, with a mandate arriving in 2020 via the FAA's "NextGen" program. -The receiver uhd_modes.py is written for use with Ettus Research USRP +The receiver modes_rx is written for use with Ettus Research USRP devices, although the "RTLSDR" receivers are also supported via the Osmocom driver. In theory, any receiver which outputs complex samples at at least 2Msps should work via the file input or UDP input options, or @@ -122,10 +122,10 @@ install it on your system, generally in /usr/local/bin. ======================================================================== USAGE -The main application is uhd_modes.py. For a complete list of options, +The main application is modes_rx. For a complete list of options, run: -$ uhd_modes.py --help +$ modes_rx --help For use with Ettus UHD-compatible devices, the defaults should suffice to receive reports and print to the screen. Use the -d option to look @@ -141,7 +141,7 @@ FILES Interesting files and libraries included with the package: -* apps/uhd_modes.py: The main application. +* apps/modes_rx: The main application. * apps/get_correlated_records.py: Demonstration program for computing multilaterated time error for two unsynchronized receiver stations. * lib/air_modes_int_and_dump.cc: Unused integrate-and-dump filter for From 17b788efc7262ebae17d3ab4c46c723c45cba884 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 14 Aug 2012 09:27:34 -0700 Subject: [PATCH 8/9] Possible fix for the hang bug -- preamble could under certain circumstances consume -1, which makes Gnuradio think we're done. --- lib/air_modes_preamble.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/air_modes_preamble.cc b/lib/air_modes_preamble.cc index 8046d78..6bcf2e6 100644 --- a/lib/air_modes_preamble.cc +++ b/lib/air_modes_preamble.cc @@ -157,7 +157,7 @@ int air_modes_preamble::general_work(int noutput_items, //be sure we've got enough room in the input buffer to copy out a whole packet if(ninputs-i < 240*d_samples_per_chip) { - consume_each(i-1); + consume_each(std::max(i-1,0)); return 0; } From a6dac30fbf30c6e7ae2a0a97895dc9deea825d05 Mon Sep 17 00:00:00 2001 From: Al Brown Date: Wed, 15 Aug 2012 08:52:16 -0700 Subject: [PATCH 9/9] Fix range-ring KML for new Google Earth breakage. --- python/modes_kml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/modes_kml.py b/python/modes_kml.py index b081416..c324373 100644 --- a/python/modes_kml.py +++ b/python/modes_kml.py @@ -73,7 +73,7 @@ class modes_kml(threading.Thread, modes_output_sql): bearing = i*(2*math.pi/steps) #in radians lat_out = math.degrees(math.asin(math.sin(lat_rad)*math.cos(tmp0) + math.cos(lat_rad)*math.sin(tmp0)*math.cos(bearing))) lon_out = center_lon + math.degrees(math.atan2(math.sin(bearing)*math.sin(tmp0)*math.cos(lat_rad), math.cos(tmp0)-math.sin(lat_rad)*math.sin(math.radians(lat_out)))) - retstr += " %.8f, %.8f, 0" % (lon_out, lat_out,) + retstr += " %.8f,%.8f, 0" % (lon_out, lat_out,) retstr = string.lstrip(retstr) return retstr