altosui: Add a 'Graph Flight' button to the 'landed' tab
authorKeith Packard <keithp@keithp.com>
Wed, 10 Aug 2011 21:08:21 +0000 (14:08 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 10 Aug 2011 21:08:21 +0000 (14:08 -0700)
This lets you see the results of a flight as soon as the rocket lands
using the telemetry data.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosFlightReader.java
altosui/AltosFlightStats.java
altosui/AltosFlightUI.java
altosui/AltosLanded.java
altosui/AltosLog.java
altosui/AltosReplayReader.java
altosui/AltosTelemetryReader.java
altosui/AltosUI.java

index 3a171444c7e9e94a7d5bdc562279e24f38010bf7..47df375d67dc9bb62ad09e132971d652fde486b2 100644 (file)
@@ -42,4 +42,6 @@ public class AltosFlightReader {
        void save_telemetry() { }
 
        void update(AltosState state) throws InterruptedException { }
        void save_telemetry() { }
 
        void update(AltosState state) throws InterruptedException { }
+
+       File backing_file() { return null; }
 }
 }
index e38142f04de27d8c515ef0e437d5ee8f816920ef..e644b0bab73db07b6fd45bad7fc406f6ee1f6750 100644 (file)
@@ -85,11 +85,11 @@ public class AltosFlightStats {
                }
        }
 
                }
        }
 
-       public AltosFlightStats(AltosRecordIterable iterable, String filename) throws InterruptedException, IOException {
-               this(new AltosReplayReader(iterable.iterator(), filename));
+       public AltosFlightStats(AltosRecordIterable iterable, File file) throws InterruptedException, IOException {
+               this(new AltosReplayReader(iterable.iterator(), file));
        }
 
        public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
        }
 
        public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
-               this(iterable, "");
+               this(iterable, new File(""));
        }
 }
        }
 }
index c31e02bf095ad695267444027da9481e90112ed3..f0626e7ccdfae49fbd35bf35ccad01619d951f9b 100644 (file)
@@ -210,7 +210,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                descent = new AltosDescent();
                pane.add("Descent", descent);
 
                descent = new AltosDescent();
                pane.add("Descent", descent);
 
-               landed = new AltosLanded();
+               landed = new AltosLanded(reader);
                pane.add("Landed", landed);
 
                flightInfo = new AltosInfoTable();
                pane.add("Landed", landed);
 
                flightInfo = new AltosInfoTable();
index d5c8e4341cc33ad965f0fab3254383ff2075ac5a..47aca29dbeb3e48bb690e325101bd5957a3792d6 100644 (file)
@@ -28,7 +28,7 @@ import java.text.*;
 import java.util.prefs.*;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import java.util.prefs.*;
 import java.util.concurrent.LinkedBlockingQueue;
 
-public class AltosLanded extends JComponent implements AltosFlightDisplay {
+public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener {
        GridBagLayout   layout;
        Font            label_font;
        Font            value_font;
        GridBagLayout   layout;
        Font            label_font;
        Font            value_font;
@@ -214,11 +214,51 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay {
                height.show(state, crc_errors);
                speed.show(state, crc_errors);
                accel.show(state, crc_errors);
                height.show(state, crc_errors);
                speed.show(state, crc_errors);
                accel.show(state, crc_errors);
+               if (reader.backing_file() != null)
+                       graph.setEnabled(true);
        }
 
        }
 
-       public AltosLanded() {
+       JButton graph;
+       AltosFlightReader reader;
+
+       public void actionPerformed(ActionEvent e) {
+               String  cmd = e.getActionCommand();
+
+               if (cmd.equals("graph")) {
+                       File    file = reader.backing_file();
+                       if (file != null) {
+                               String  filename = file.getName();
+                               try {
+                                       AltosRecordIterable records = null;
+                                       if (filename.endsWith("eeprom")) {
+                                               FileInputStream in = new FileInputStream(file);
+                                               records = new AltosEepromIterable(in);
+                                       } else if (filename.endsWith("telem")) {
+                                               FileInputStream in = new FileInputStream(file);
+                                               records = new AltosTelemetryIterable(in);
+                                       } else {
+                                               throw new FileNotFoundException();
+                                       }
+                                       try {
+                                               new AltosGraphUI(records);
+                                       } catch (InterruptedException ie) {
+                                       } catch (IOException ie) {
+                                       }
+                               } catch (FileNotFoundException fe) {
+                                       JOptionPane.showMessageDialog(null,
+                                                                     filename,
+                                                                     "Cannot open file",
+                                                                     JOptionPane.ERROR_MESSAGE);
+                               }
+                       }
+               }
+       }
+
+       public AltosLanded(AltosFlightReader in_reader) {
                layout = new GridBagLayout();
 
                layout = new GridBagLayout();
 
+               reader = in_reader;
+
                label_font = new Font("Dialog", Font.PLAIN, 22);
                value_font = new Font("Monospaced", Font.PLAIN, 22);
                setLayout(layout);
                label_font = new Font("Dialog", Font.PLAIN, 22);
                value_font = new Font("Monospaced", Font.PLAIN, 22);
                setLayout(layout);
@@ -231,5 +271,20 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay {
                height = new Height(layout, 4);
                speed = new Speed(layout, 5);
                accel = new Accel(layout, 6);
                height = new Height(layout, 4);
                speed = new Speed(layout, 5);
                accel = new Accel(layout, 6);
+
+               graph = new JButton ("Graph Flight");
+               graph.setActionCommand("graph");
+               graph.addActionListener(this);
+               graph.setEnabled(false);
+
+               GridBagConstraints      c = new GridBagConstraints();
+
+               c.gridx = 0; c.gridy = 7;
+               c.insets = new Insets(10, 10, 10, 10);
+               c.anchor = GridBagConstraints.WEST;
+               c.weightx = 0;
+               c.weighty = 0;
+               c.fill = GridBagConstraints.VERTICAL;
+               add(graph, c);
        }
 }
        }
 }
index 6157a6567da03231d011e131da59a1690da04e5d..a5f1830d89d0986149cf1bc88781dcc82296cb77 100644 (file)
@@ -35,6 +35,7 @@ class AltosLog implements Runnable {
        int                             flight;
        FileWriter                      log_file;
        Thread                          log_thread;
        int                             flight;
        FileWriter                      log_file;
        Thread                          log_thread;
+       AltosFile                       file;
 
        private void close_log_file() {
                if (log_file != null) {
 
        private void close_log_file() {
                if (log_file != null) {
@@ -54,6 +55,10 @@ class AltosLog implements Runnable {
                }
        }
 
                }
        }
 
+       File file() {
+               return file;
+       }
+
        boolean open (AltosRecord telem) throws IOException {
                AltosFile       a = new AltosFile(telem);
 
        boolean open (AltosRecord telem) throws IOException {
                AltosFile       a = new AltosFile(telem);
 
@@ -69,6 +74,7 @@ class AltosLog implements Runnable {
                                }
                        }
                        log_file.flush();
                                }
                        }
                        log_file.flush();
+                       file = a;
                }
                return log_file != null;
        }
                }
                return log_file != null;
        }
index 4e5e1d93b7a62ffc50f6287b503e275c6e46843d..eed56cfffc58d4aeff26c113700405ebdd559349 100644 (file)
@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 
 public class AltosReplayReader extends AltosFlightReader {
        Iterator<AltosRecord>   iterator;
 
 public class AltosReplayReader extends AltosFlightReader {
        Iterator<AltosRecord>   iterator;
+       File    file;
 
        public AltosRecord read() {
                if (iterator.hasNext())
 
        public AltosRecord read() {
                if (iterator.hasNext())
@@ -50,8 +51,11 @@ public class AltosReplayReader extends AltosFlightReader {
                        Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
        }
 
                        Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
        }
 
-       public AltosReplayReader(Iterator<AltosRecord> in_iterator, String in_name) {
+       public File backing_file() { return file; }
+
+       public AltosReplayReader(Iterator<AltosRecord> in_iterator, File in_file) {
                iterator = in_iterator;
                iterator = in_iterator;
-               name = in_name;
+               file = in_file;
+               name = file.getName();
        }
 }
        }
 }
index 6abe95d8f3b917680bdc0a91317f3727c8a03eb9..1f327a67c75773bf95a6c81ec583fd554042bef7 100644 (file)
@@ -69,6 +69,10 @@ class AltosTelemetryReader extends AltosFlightReader {
                AltosPreferences.set_telemetry(device.getSerial(), telemetry);
        }
 
                AltosPreferences.set_telemetry(device.getSerial(), telemetry);
        }
 
+       File backing_file() {
+               return log.file();
+       }
+
        public AltosTelemetryReader (AltosDevice in_device)
                throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException {
                device = in_device;
        public AltosTelemetryReader (AltosDevice in_device)
                throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException {
                device = in_device;
index fefe74e82e4b2c397780134c8fcf7795a19d5442..62e612ed07d0fc9282e00e9ab0910f7951db6a6b 100644 (file)
@@ -276,7 +276,7 @@ public class AltosUI extends JFrame {
                AltosRecordIterable iterable = chooser.runDialog();
                if (iterable != null) {
                        AltosFlightReader reader = new AltosReplayReader(iterable.iterator(),
                AltosRecordIterable iterable = chooser.runDialog();
                if (iterable != null) {
                        AltosFlightReader reader = new AltosReplayReader(iterable.iterator(),
-                                                                        chooser.filename());
+                                                                        chooser.file());
                        new AltosFlightUI(voice, reader);
                }
        }
                        new AltosFlightUI(voice, reader);
                }
        }
@@ -310,7 +310,11 @@ public class AltosUI extends JFrame {
                AltosRecordIterable record_reader = chooser.runDialog();
                if (record_reader == null)
                        return;
                AltosRecordIterable record_reader = chooser.runDialog();
                if (record_reader == null)
                        return;
-               new AltosGraphUI(record_reader);
+               try {
+                       new AltosGraphUI(record_reader);
+               } catch (InterruptedException ie) {
+               } catch (IOException ie) {
+               }
        }
 
        private void ConfigureAltosUI() {
        }
 
        private void ConfigureAltosUI() {
@@ -427,7 +431,7 @@ public class AltosUI extends JFrame {
                        } else {
                                recs = new AltosTelemetryIterable(in);
                        }
                        } else {
                                recs = new AltosTelemetryIterable(in);
                        }
-                       reader = new AltosReplayReader(recs.iterator(), filename);
+                       reader = new AltosReplayReader(recs.iterator(), new File(filename));
                        AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader);
                        flight_ui.set_exit_on_close();
                        return;
                        AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader);
                        flight_ui.set_exit_on_close();
                        return;