Better exception handling in sql.py

This commit is contained in:
Nick Foster 2013-05-30 01:06:53 -07:00
parent 4216b96262
commit 33874893b7
3 changed files with 13 additions and 20 deletions

View File

@ -107,8 +107,7 @@ def main():
#updates.append(sbs1port.add_pending_conns) #updates.append(sbs1port.add_pending_conns)
tb.run() tb.run()
tb._pubsub.done.set() tb.cleanup()
tb._pubsub.finished.wait(0.2)
if printer is not None: if printer is not None:
printer.done.set() printer.done.set()
@ -117,6 +116,5 @@ def main():
sqldb.done = True sqldb.done = True
#sqldb.join() #sqldb.join()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -198,3 +198,7 @@ class modes_radio (gr.top_block):
print "Rate is %i" % (options.rate,) print "Rate is %i" % (options.rate,)
def cleanup(self):
self._pubsub.done.set()
self._pubsub.finished.wait(0.2)

View File

@ -115,8 +115,6 @@ class output_sql(air_modes.parse, threading.Thread):
data = air_modes.modes_reply(long(data, 16)) data = air_modes.modes_reply(long(data, 16))
ecc = long(ecc, 16) ecc = long(ecc, 16)
# reference = float(reference) # reference = float(reference)
query = None query = None
msgtype = data["df"] msgtype = data["df"]
if msgtype == 17: if msgtype == 17:
@ -128,36 +126,29 @@ class output_sql(air_modes.parse, threading.Thread):
icao24 = data["aa"] icao24 = data["aa"]
bdsreg = data["me"].get_type() bdsreg = data["me"].get_type()
retstr = None
if bdsreg == 0x08: if bdsreg == 0x08:
(msg, typename) = self.parseBDS08(data) (msg, typename) = self.parseBDS08(data)
retstr = "INSERT OR REPLACE INTO ident (icao, ident) VALUES (" + "%i" % icao24 + ", '" + msg + "')" return "INSERT OR REPLACE INTO ident (icao, ident) VALUES (" + "%i" % icao24 + ", '" + msg + "')"
elif bdsreg == 0x06: elif bdsreg == 0x06:
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data) [ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
altitude = 0 altitude = 0
if decoded_lat is None: #no unambiguously valid position available if decoded_lat is None: #no unambiguously valid position available
retstr = None raise CPRNoPositionError
else: else:
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" return "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
elif bdsreg == 0x05: elif bdsreg == 0x05:
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data) [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
if decoded_lat is None: #no unambiguously valid position available if decoded_lat is None: #no unambiguously valid position available
retstr = None raise CPRNoPositionError
else: else:
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")" return "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
elif bdsreg == 0x09: elif bdsreg == 0x09:
subtype = data["bds09"].get_type() subtype = data["bds09"].get_type()
if subtype == 0: if subtype == 0:
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data) [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 + ")" return "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"
elif subtype == 1: elif subtype == 1:
[velocity, heading, vert_spd] = self.parseBDS09_1(data) [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 + ")" return "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"
else: else:
retstr = None raise NoHandlerError
return retstr