X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosLog.java;h=740f0be600ecd1301a2b20be9c1a31ff4265395d;hb=93305717ac4c993c88d9144d797ca64d26db97c5;hp=dd147d21adb960818ff3d26423f7c5e48816ba36;hpb=f01096c4b42f9a4720ed0414826c2a283a992545;p=fw%2Faltos diff --git a/altosui/AltosLog.java b/altosui/AltosLog.java index dd147d21..740f0be6 100644 --- a/altosui/AltosLog.java +++ b/altosui/AltosLog.java @@ -22,6 +22,7 @@ import java.lang.*; import java.util.*; import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; /* * This creates a thread to capture telemetry data and write it to @@ -35,6 +36,7 @@ class AltosLog implements Runnable { int flight; FileWriter log_file; Thread log_thread; + AltosFile file; private void close_log_file() { if (log_file != null) { @@ -54,9 +56,14 @@ class AltosLog implements Runnable { } } - boolean open (AltosTelemetry telem) throws IOException { + File file() { + return file; + } + + boolean open (AltosRecord telem) throws IOException { AltosFile a = new AltosFile(telem); + System.out.printf("open %s\n", a.toString()); log_file = new FileWriter(a, true); if (log_file != null) { while (!pending_queue.isEmpty()) { @@ -68,24 +75,29 @@ class AltosLog implements Runnable { } } log_file.flush(); + file = a; } return log_file != null; } public void run () { try { + AltosRecord previous = null; for (;;) { AltosLine line = input_queue.take(); if (line.line == null) continue; try { - AltosTelemetry telem = new AltosTelemetry(line.line); - if (telem.serial != serial || telem.flight != flight || log_file == null) { + AltosRecord telem = AltosTelemetry.parse(line.line, previous); + if (telem.serial != 0 && telem.flight != 0 && + (telem.serial != serial || telem.flight != flight || log_file == null)) + { close_log_file(); serial = telem.serial; flight = telem.flight; open(telem); } + previous = telem; } catch (ParseException pe) { } catch (AltosCRCException ce) { }