altos: Support staging by going back to boost as needed
[fw/altos] / altosui / AltosLog.java
index dd147d21adb960818ff3d26423f7c5e48816ba36..a5f1830d89d0986149cf1bc88781dcc82296cb77 100644 (file)
@@ -35,6 +35,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 +55,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 +74,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) {
                                }