altoslib: Add receiver serial to telem file names
authorKeith Packard <keithp@keithp.com>
Fri, 6 Sep 2013 23:54:07 +0000 (16:54 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 6 Sep 2013 23:54:07 +0000 (16:54 -0700)
Makes it easy to record telemetry from multiple sites and compare them later.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosFile.java
altoslib/AltosLog.java
altoslib/AltosState.java

index 9802f883edbcb9ad8a26962b8f2f05e2bd2bdfbe..f39c3962a3f42b7e56dd2510a9c05dee871ff2b6 100644 (file)
@@ -24,15 +24,35 @@ public class AltosFile extends File {
 
        static String number(int n) {
                if (n == AltosLib.MISSING)
-                       return "unk";
+                       return "unkn";
                else
-                       return String.format("%03d", n);
+                       return String.format("%04d", n);
        }
 
-       public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
+       static String receiver(int receiver) {
+               if (receiver == AltosLib.MISSING)
+                       return "";
+               return String.format("-via-%04d", receiver);
+       }
+
+       public AltosFile(int year, int month, int day, int serial, int flight, int receiver, String extension) {
                super (AltosPreferences.logdir(),
-                      String.format("%04d-%02d-%02d-serial-%s-flight-%s.%s",
-                                    year, month, day, number(serial), number(flight), extension));
+                      String.format("%04d-%02d-%02d-serial-%s-flight-%s%s.%s",
+                                    year, month, day, number(serial), number(flight), receiver(receiver), extension));
+       }
+
+       public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
+               this(year, month, day, serial, flight, AltosLib.MISSING, extension);
+       }
+
+       public AltosFile(int serial, int flight, int receiver, String extension) {
+               this(Calendar.getInstance().get(Calendar.YEAR),
+                    Calendar.getInstance().get(Calendar.MONTH) + 1,
+                    Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
+                    serial,
+                    flight,
+                    receiver,
+                    extension);
        }
 
        public AltosFile(int serial, int flight, String extension) {
@@ -41,10 +61,11 @@ public class AltosFile extends File {
                     Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
                     serial,
                     flight,
+                    AltosLib.MISSING,
                     extension);
        }
 
        public AltosFile(AltosState state) {
-               this(state.serial, state.flight, "telem");
+               this(state.serial, state.flight, state.receiver_serial, "telem");
        }
 }
index ed59ef713eb44cd1a27c58e9cbbdefe5157a81b2..015d9f65aa13ad28ef3aadef04bcf044becabf12 100644 (file)
@@ -18,8 +18,8 @@
 package org.altusmetrum.altoslib_2;
 
 import java.io.*;
-import java.text.ParseException;
-import java.util.concurrent.LinkedBlockingQueue;
+import java.text.*;
+import java.util.concurrent.*;
 
 /*
  * This creates a thread to capture telemetry data and write it to
@@ -31,9 +31,11 @@ public class AltosLog implements Runnable {
        LinkedBlockingQueue<String>     pending_queue;
        int                             serial;
        int                             flight;
+       int                             receiver_serial;
        FileWriter                      log_file;
        Thread                          log_thread;
        AltosFile                       file;
+       AltosLink                       link;
 
        private void close_log_file() {
                if (log_file != null) {
@@ -78,17 +80,16 @@ public class AltosLog implements Runnable {
 
        public void run () {
                try {
-                       AltosState      state = null;
+                       AltosState      state = new AltosState();
+                       AltosConfigData receiver_config = link.config_data();
+                       state.set_receiver_serial(receiver_config.serial);
                        for (;;) {
                                AltosLine       line = input_queue.take();
                                if (line.line == null)
                                        continue;
                                try {
                                        AltosTelemetry  telem = AltosTelemetry.parse(line.line);
-                                       if (state != null)
-                                               state = state.clone();
-                                       else
-                                               state = new AltosState();
+                                       state = state.clone();
                                        telem.update_state(state);
                                        if (state.serial != serial || state.flight != flight || log_file == null)
                                        {
@@ -109,6 +110,7 @@ public class AltosLog implements Runnable {
                                        pending_queue.put(line.line);
                        }
                } catch (InterruptedException ie) {
+               } catch (TimeoutException te) {
                } catch (IOException ie) {
                }
                close();
@@ -120,6 +122,7 @@ public class AltosLog implements Runnable {
                link.add_monitor(input_queue);
                serial = -1;
                flight = -1;
+               this.link = link;
                log_file = null;
                log_thread = new Thread(this);
                log_thread.start();
index 422590573459b3829366f6a37dc3e88601bd132d..5a805fc6bf6864b75a146b64a411746583084c48 100644 (file)
@@ -269,6 +269,7 @@ public class AltosState implements Cloneable {
        public int      state;
        public int      flight;
        public int      serial;
+       public int      receiver_serial;
        public boolean  landed;
        public boolean  ascent; /* going up? */
        public boolean  boost;  /* under power */
@@ -604,6 +605,7 @@ public class AltosState implements Cloneable {
 
                log_format = AltosLib.MISSING;
                serial = AltosLib.MISSING;
+               receiver_serial = AltosLib.MISSING;
 
                baro = null;
                companion = null;
@@ -725,6 +727,7 @@ public class AltosState implements Cloneable {
 
                log_format = old.log_format;
                serial = old.serial;
+               receiver_serial = old.receiver_serial;
 
                baro = old.baro;
                companion = old.companion;
@@ -847,6 +850,11 @@ public class AltosState implements Cloneable {
                }
        }
 
+       public void set_receiver_serial(int serial) {
+               if (serial != AltosLib.MISSING)
+                       receiver_serial = serial;
+       }
+
        public int rssi() {
                if (rssi == AltosLib.MISSING)
                        return 0;