Database inputs working.
This commit is contained in:
parent
468cb726cb
commit
627b820b6e
Binary file not shown.
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import time, os, sys
|
import time, os, sys
|
||||||
from string import split, join
|
from string import split, join
|
||||||
from altitude import decode_alt
|
from altitude import decode_alt
|
||||||
|
Binary file not shown.
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import time, os, sys
|
import time, os, sys
|
||||||
from string import split, join
|
from string import split, join
|
||||||
import modes_parse
|
import modes_parse
|
||||||
|
@ -10,7 +10,7 @@ class modes_output_sbs1(modes_parse.modes_parse):
|
|||||||
self._s.listen(1)
|
self._s.listen(1)
|
||||||
self._s.setblocking(0) #nonblocking
|
self._s.setblocking(0) #nonblocking
|
||||||
self._conns = [] #list of active connections
|
self._conns = [] #list of active connections
|
||||||
|
|
||||||
def output(self, msg):
|
def output(self, msg):
|
||||||
sbs1_msg = self.parse(msg)
|
sbs1_msg = self.parse(msg)
|
||||||
if sbs1_msg is not None:
|
if sbs1_msg is not None:
|
||||||
|
@ -1,84 +1,107 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import time, os, sys
|
import time, os, sys
|
||||||
from string import split, join
|
from string import split, join
|
||||||
from modes_parse import *
|
import modes_parse
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
def modes_sql(message):
|
class modes_output_sql(modes_parse.modes_parse):
|
||||||
|
def __init__(self):
|
||||||
|
#create the database
|
||||||
|
self.db = sqlite3.connect(':memory:') #RAM-based database, no persistence
|
||||||
|
#now execute a schema to create the tables you need
|
||||||
|
c = self.db.cursor()
|
||||||
|
query = """CREATE TABLE "positions" (
|
||||||
|
"icao" INTEGER KEY NOT NULL,
|
||||||
|
"seen" TEXT NOT NULL,
|
||||||
|
"alt" INTEGER,
|
||||||
|
"lat" REAL,
|
||||||
|
"lon" REAL
|
||||||
|
);"""
|
||||||
|
c.execute(query)
|
||||||
|
query = """CREATE TABLE "vectors" (
|
||||||
|
"icao" INTEGER KEY NOT NULL,
|
||||||
|
"seen" TEXT NOT NULL,
|
||||||
|
"speed" REAL,
|
||||||
|
"heading" REAL,
|
||||||
|
"vertical" REAL
|
||||||
|
);"""
|
||||||
|
c.execute(query)
|
||||||
|
query = """CREATE TABLE "ident" (
|
||||||
|
"icao" INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
"ident" TEXT NOT NULL
|
||||||
|
);"""
|
||||||
|
c.execute(query)
|
||||||
|
c.close()
|
||||||
|
|
||||||
#assembles a MySQLdb query tailored to Owen's database
|
def __del__(self):
|
||||||
#this version ignores anything that isn't Type 17 for now, because we just don't care
|
self.db.close()
|
||||||
|
|
||||||
[msgtype, shortdata, longdata, parity, ecc, reference] = message.split()
|
def output(self, message):
|
||||||
|
query = self.make_query(message)
|
||||||
|
if query is not None:
|
||||||
|
c = self.db.cursor()
|
||||||
|
c.execute(query)
|
||||||
|
c.close()
|
||||||
|
self.db.commit() #not sure if i have to do this
|
||||||
|
|
||||||
|
def make_query(self, message):
|
||||||
|
#assembles a SQL query tailored to our database
|
||||||
|
#this version ignores anything that isn't Type 17 for now, because we just don't care
|
||||||
|
[msgtype, shortdata, longdata, parity, ecc, reference] = message.split()
|
||||||
|
|
||||||
shortdata = long(shortdata, 16)
|
shortdata = long(shortdata, 16)
|
||||||
longdata = long(longdata, 16)
|
longdata = long(longdata, 16)
|
||||||
parity = long(parity, 16)
|
parity = long(parity, 16)
|
||||||
ecc = long(ecc, 16)
|
ecc = long(ecc, 16)
|
||||||
# reference = float(reference)
|
# reference = float(reference)
|
||||||
|
|
||||||
msgtype = int(msgtype)
|
msgtype = int(msgtype)
|
||||||
|
|
||||||
query = None
|
query = None
|
||||||
|
|
||||||
# if msgtype == 0:
|
if msgtype == 17:
|
||||||
# query = sql0(shortdata, parity, ecc)
|
query = self.sql17(shortdata, longdata, parity, ecc)
|
||||||
# elif msgtype == 4:
|
|
||||||
# query = sql4(shortdata, parity, ecc)
|
|
||||||
# elif msgtype == 5:
|
|
||||||
# query = sql5(shortdata, parity, ecc)
|
|
||||||
# elif msgtype == 11:
|
|
||||||
# query = sql11(shortdata, parity, ecc)
|
|
||||||
# elif msgtype == 17:
|
|
||||||
if msgtype == 17:
|
|
||||||
query = sql17(shortdata, longdata, parity, ecc)
|
|
||||||
# elif msgtype == 20:
|
|
||||||
# output = parse20(shortdata, longdata, parity, ecc)
|
|
||||||
# else:
|
|
||||||
#output = "No handler for message type " + str(msgtype) + " from " + str(ecc)
|
|
||||||
|
|
||||||
# output = "(%.0f) " % float(reference) + output
|
return query
|
||||||
|
|
||||||
return query
|
def sql17(self, shortdata, longdata, parity, ecc):
|
||||||
|
icao24 = shortdata & 0xFFFFFF
|
||||||
|
subtype = (longdata >> 51) & 0x1F
|
||||||
|
|
||||||
def sql17(shortdata, longdata, parity, ecc):
|
retstr = None
|
||||||
icao24 = shortdata & 0xFFFFFF
|
|
||||||
subtype = (longdata >> 51) & 0x1F
|
|
||||||
|
|
||||||
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:
|
elif subtype >= 5 and subtype <= 8:
|
||||||
msg = parseBDS08(shortdata, longdata, parity, ecc)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata, parity, ecc)
|
||||||
retstr = "INSERT INTO plane_metadata (icao, ident) VALUES ('" + "%x" % icao24 + "', '" + msg + "') ON DUPLICATE KEY UPDATE seen=now(), ident=values(ident)"
|
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:
|
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] = parseBDS06(shortdata, longdata, parity, ecc)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata, parity, ecc)
|
||||||
if decoded_lat is None: #no unambiguously valid position available
|
if decoded_lat is None: #no unambiguously valid position available
|
||||||
retstr = None
|
retstr = None
|
||||||
else:
|
else:
|
||||||
retstr = "INSERT INTO plane_positions (icao, seen, alt, lat, lon) VALUES ('" + "%x" % icao24 + "', now(), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
|
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.
|
elif subtype == 19:
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = parseBDS05(shortdata, longdata, parity, ecc)
|
subsubtype = (longdata >> 48) & 0x07
|
||||||
if decoded_lat is None: #no unambiguously valid position available
|
if subsubtype == 0:
|
||||||
retstr = None
|
[velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata, parity, ecc)
|
||||||
else:
|
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")";
|
||||||
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:
|
elif subsubtype == 1:
|
||||||
subsubtype = (longdata >> 48) & 0x07
|
[velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata, parity, ecc)
|
||||||
if subsubtype == 0:
|
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")";
|
||||||
[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:
|
else:
|
||||||
[velocity, heading, vert_spd] = parseBDS09_1(shortdata, longdata, parity, ecc)
|
print "debug (modes_sql): unknown subtype %i with data %x %x %x" % (subtype, shortdata, longdata, parity,)
|
||||||
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:
|
return retstr
|
||||||
print "debug (modes_sql): unknown subtype %i with data %x %x %x" % (subtype, shortdata, longdata, parity,)
|
|
||||||
|
|
||||||
|
|
||||||
return retstr
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from gnuradio import gr, gru, optfir, eng_notation, blks2, air
|
from gnuradio import gr, gru, optfir, eng_notation, blks2, air
|
||||||
from gnuradio import uhd
|
from gnuradio import uhd
|
||||||
from gnuradio.eng_option import eng_option
|
from gnuradio.eng_option import eng_option
|
||||||
@ -8,7 +7,7 @@ import time, os, sys
|
|||||||
from string import split, join
|
from string import split, join
|
||||||
from usrpm import usrp_dbid
|
from usrpm import usrp_dbid
|
||||||
from modes_print import modes_output_print
|
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
|
from modes_sbs1 import modes_output_sbs1
|
||||||
import gnuradio.gr.gr_threading as _threading
|
import gnuradio.gr.gr_threading as _threading
|
||||||
|
|
||||||
@ -82,11 +81,6 @@ class adsb_rx_block (gr.top_block):
|
|||||||
def tune(self, freq):
|
def tune(self, freq):
|
||||||
result = self.u.set_center_freq(freq)
|
result = self.u.set_center_freq(freq)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def post_to_sql(db, query):
|
|
||||||
if query is not None:
|
|
||||||
c = db.cursor()
|
|
||||||
c.execute(query)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
usage = "%prog: [options] output filename"
|
usage = "%prog: [options] output filename"
|
||||||
@ -122,9 +116,7 @@ if __name__ == '__main__':
|
|||||||
updates = [] #registry of plugin update functions
|
updates = [] #registry of plugin update functions
|
||||||
|
|
||||||
if options.database is True:
|
if options.database is True:
|
||||||
import pysqlite3
|
outputs.append(modes_output_sql().output)
|
||||||
#db = pysqlite3.connect(:memory:)
|
|
||||||
#here we have to initialize the database with the correct tables and relations
|
|
||||||
|
|
||||||
if options.sbs1 is True:
|
if options.sbs1 is True:
|
||||||
sbs1port = modes_output_sbs1()
|
sbs1port = modes_output_sbs1()
|
||||||
@ -141,7 +133,7 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
#the update registry is really for the SBS1 plugin -- we're looking for new TCP connections.
|
#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
|
#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:
|
for update in updates:
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user