X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosLog.java;h=dd147d21adb960818ff3d26423f7c5e48816ba36;hp=2c241771be6c3b3d95b6f8792a973a4ad84636ac;hb=7a50837ea0d92db3f469f197ec8210aee22aa143;hpb=e5ef42c2b22c6639d90631dbbb588f9fd2494385 diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index 2c241771..dd147d21 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -22,8 +22,6 @@ import java.lang.*; import java.util.*; import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosSerial; -import altosui.AltosFile; /* * This creates a thread to capture telemetry data and write it to @@ -31,16 +29,29 @@ import altosui.AltosFile; */ class AltosLog implements Runnable { - LinkedBlockingQueue input_queue; + LinkedBlockingQueue input_queue; LinkedBlockingQueue pending_queue; int serial; int flight; FileWriter log_file; Thread log_thread; - void close() throws IOException { - if (log_file != null) - log_file.close(); + private void close_log_file() { + if (log_file != null) { + try { + log_file.close(); + } catch (IOException io) { + } + log_file = null; + } + } + + void close() { + close_log_file(); + if (log_thread != null) { + log_thread.interrupt(); + log_thread = null; + } } boolean open (AltosTelemetry telem) throws IOException { @@ -64,11 +75,13 @@ class AltosLog implements Runnable { public void run () { try { for (;;) { - String line = input_queue.take(); + AltosLine line = input_queue.take(); + if (line.line == null) + continue; try { - AltosTelemetry telem = new AltosTelemetry(line); + AltosTelemetry telem = new AltosTelemetry(line.line); if (telem.serial != serial || telem.flight != flight || log_file == null) { - close(); + close_log_file(); serial = telem.serial; flight = telem.flight; open(telem); @@ -77,24 +90,21 @@ class AltosLog implements Runnable { } catch (AltosCRCException ce) { } if (log_file != null) { - log_file.write(line); + log_file.write(line.line); log_file.write('\n'); log_file.flush(); } else - pending_queue.put(line); + pending_queue.put(line.line); } } catch (InterruptedException ie) { } catch (IOException ie) { } - try { - close(); - } catch (IOException ie) { - } + close(); } public AltosLog (AltosSerial s) { pending_queue = new LinkedBlockingQueue (); - input_queue = new LinkedBlockingQueue (); + input_queue = new LinkedBlockingQueue (); s.add_monitor(input_queue); serial = -1; flight = -1;