From 627b820b6e056a358a228c9558c73520ebf68eaf Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sun, 17 Oct 2010 22:17:48 -0700 Subject: [PATCH] Database inputs working. --- src/python/cpr.pyc | Bin 5836 -> 0 bytes src/python/modes_parse.py | 2 - src/python/modes_parse.pyc | Bin 5420 -> 5420 bytes src/python/modes_print.py | 1 - src/python/modes_sbs1.py | 2 +- src/python/modes_sql.py | 145 +++++++++++++++++++++---------------- src/python/uhd_modes.py | 14 +--- 7 files changed, 88 insertions(+), 76 deletions(-) delete mode 100644 src/python/cpr.pyc diff --git a/src/python/cpr.pyc b/src/python/cpr.pyc deleted file mode 100644 index 9b1ed44d354cc0a95fa40f6cb44fd3e07116463a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5836 zcmb_g&u<%P8GdIxc4EiQui9&;t3XOsY7iwfY@rf`26owMmz9wwf|a5z(Zn-xCbegh znQ4|(wpgiqK->_56Ner+aX?5QafHiW;DGoG04;w2a6sIa=Xt;JIAyzsMw@uPdB1PI zpYQiP&-c#!<=>6kx9pyXS{=Gl+Efn*zalMQy zts_APnMiXi(%I?qNiTGec3Cl_HT1GaCRawTpPd~CT^OQC`WaZ8hw&)bjKcnd%|UX* z3zHk8*bmapH0f_1pJj(}wAnvSJ`a=qM~{|~rZmOs^Tttl*E!vTF@|p~IkF|Li3KlD zY>DPzm1tqMnCxRqCM6lG<5{sR*4UOECMay}_yWIh!o83y8Q>Cm=eygvak?F{K-cAR z>@Fwa>Z0dhr4N$>uODQ@K{h(hD!50F`rfdA;k9!BAI`kQ?iZ1W)v#)I#jfLCw$&4y zN#P0BDHaQtV1GEjp4kjmi-x*mSrxV)^wIfV80jJ|JWIMP8tw)0Ct*xCiNo?*z@?is zf`O^QwFW++Elv1}MIZq0(AAp&IyN3om^d+7Du}-KcFI=upvEp({EmbeQ{d)%cST;YGhHL|=jdK$5B=@gnGlj4fZDKr1cH!Le{S z^w2Pt0Bu6A4dl>TjECMi-B!h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Lsd4p}P@ADg{<2zVnSLKM0UKAU z!I{Qnv)3Jc`7#nng>zqH!gU_0Yt>AvU`kns)> 51) & 0x1F -def sql17(shortdata, longdata, parity, ecc): - icao24 = shortdata & 0xFFFFFF - subtype = (longdata >> 51) & 0x1F + retstr = None - retstr = None + if subtype == 4: + msg = self.parseBDS08(shortdata, longdata, parity, ecc) + retstr = "INSERT OR REPLACE INTO ident (icao, ident) VALUES (" + "%i" % icao24 + ", '" + msg + "')" - if subtype == 4: - msg = parseBDS08(shortdata, longdata, parity, ecc) - retstr = "INSERT INTO plane_metadata (icao, ident) VALUES ('" + "%x" % icao24 + "', '" + msg + "') ON DUPLICATE KEY UPDATE seen=now(), ident=values(ident)" + elif subtype >= 5 and subtype <= 8: + [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata, parity, ecc) + if decoded_lat is None: #no unambiguously valid position available + retstr = None + else: + retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" - elif subtype >= 5 and subtype <= 8: - [altitude, decoded_lat, decoded_lon, rnge, bearing] = parseBDS06(shortdata, longdata, parity, ecc) - if decoded_lat is None: #no unambiguously valid position available - retstr = None - else: - retstr = "INSERT INTO plane_positions (icao, seen, alt, lat, lon) VALUES ('" + "%x" % icao24 + "', now(), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" + elif subtype >= 9 and subtype <= 18 and subtype != 15: #i'm eliminating type 15 records because they don't appear to be valid position reports. + [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata, parity, ecc) + if decoded_lat is None: #no unambiguously valid position available + retstr = None + else: + retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" - elif subtype >= 9 and subtype <= 18 and subtype != 15: #i'm eliminating type 15 records because they don't appear to be valid position reports. - [altitude, decoded_lat, decoded_lon, rnge, bearing] = parseBDS05(shortdata, longdata, parity, ecc) - if decoded_lat is None: #no unambiguously valid position available - retstr = None - else: - retstr = "INSERT INTO plane_positions (icao, seen, alt, lat, lon) VALUES ('" + "%x" % icao24 + "', now(), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" + elif subtype == 19: + subsubtype = (longdata >> 48) & 0x07 + if subsubtype == 0: + [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata, parity, ecc) + retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"; - elif subtype == 19: - subsubtype = (longdata >> 48) & 0x07 - if subsubtype == 0: - [velocity, heading, vert_spd] = parseBDS09_0(shortdata, longdata, parity, ecc) - retstr = "INSERT INTO plane_metadata (icao, seen, speed, heading, vertical) VALUES ('" + "%x" % icao24 + "', now(), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ") ON DUPLICATE KEY UPDATE seen=now(), speed=values(speed), heading=values(heading), vertical=values(vertical)" + elif subsubtype == 1: + [velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata, parity, ecc) + retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"; - elif subsubtype == 1: - [velocity, heading, vert_spd] = parseBDS09_1(shortdata, longdata, parity, ecc) - retstr = "INSERT INTO plane_metadata (icao, seen, speed, heading, vertical) VALUES ('" + "%x" % icao24 + "', now(), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ") ON DUPLICATE KEY UPDATE seen=now(), speed=values(speed), heading=values(heading), vertical=values(vertical)" + else: + print "debug (modes_sql): unknown subtype %i with data %x %x %x" % (subtype, shortdata, longdata, parity,) - else: - print "debug (modes_sql): unknown subtype %i with data %x %x %x" % (subtype, shortdata, longdata, parity,) - - - return retstr + return retstr diff --git a/src/python/uhd_modes.py b/src/python/uhd_modes.py index 0d7f104..bdf68a2 100755 --- a/src/python/uhd_modes.py +++ b/src/python/uhd_modes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python - from gnuradio import gr, gru, optfir, eng_notation, blks2, air from gnuradio import uhd from gnuradio.eng_option import eng_option @@ -8,7 +7,7 @@ import time, os, sys from string import split, join from usrpm import usrp_dbid from modes_print import modes_output_print -from modes_sql import modes_sql +from modes_sql import modes_output_sql from modes_sbs1 import modes_output_sbs1 import gnuradio.gr.gr_threading as _threading @@ -82,11 +81,6 @@ class adsb_rx_block (gr.top_block): def tune(self, freq): result = self.u.set_center_freq(freq) return result - -def post_to_sql(db, query): - if query is not None: - c = db.cursor() - c.execute(query) if __name__ == '__main__': usage = "%prog: [options] output filename" @@ -122,9 +116,7 @@ if __name__ == '__main__': updates = [] #registry of plugin update functions if options.database is True: - import pysqlite3 - #db = pysqlite3.connect(:memory:) - #here we have to initialize the database with the correct tables and relations + outputs.append(modes_output_sql().output) if options.sbs1 is True: sbs1port = modes_output_sbs1() @@ -141,7 +133,7 @@ if __name__ == '__main__': try: #the update registry is really for the SBS1 plugin -- we're looking for new TCP connections. #i think we have to do this here rather than in the output handler because otherwise connections will stack up - #until the next output + #until the next output arrives for update in updates: update()