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 3a17144..47df375 100644 (file)
@@ -42,4 +42,6 @@ public class AltosFlightReader {
        void save_telemetry() { }
 
        void update(AltosState state) throws InterruptedException { }
+
+       File backing_file() { return null; }
 }
index e38142f..e644b0b 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 {
-               this(iterable, "");
+               this(iterable, new File(""));
        }
 }
index c31e02b..f0626e7 100644 (file)
@@ -210,7 +210,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                descent = new AltosDescent();
                pane.add("Descent", descent);
 
-               landed = new AltosLanded();
+               landed = new AltosLanded(reader);
                pane.add("Landed", landed);
 
                flightInfo = new AltosInfoTable();
index d5c8e43..47aca29 100644 (file)
@@ -28,7 +28,7 @@ import java.text.*;
 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;
@@ -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);
+               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();
 
+               reader = in_reader;
+
                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);
+
+               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 6157a65..a5f1830 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,6 +55,10 @@ class AltosLog implements Runnable {
                }
        }
 
+       File file() {
+               return file;
+       }
+
        boolean open (AltosRecord telem) throws IOException {
                AltosFile       a = new AltosFile(telem);
 
@@ -69,6 +74,7 @@ class AltosLog implements Runnable {
                                }
                        }
                        log_file.flush();
+                       file = a;
                }
                return log_file != null;
        }
index 4e5e1d9..eed56cf 100644 (file)
@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 
 public class AltosReplayReader extends AltosFlightReader {
        Iterator<AltosRecord>   iterator;
+       File    file;
 
        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));
        }
 
-       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;
-               name = in_name;
+               file = in_file;
+               name = file.getName();
        }
 }
index 6abe95d..1f327a6 100644 (file)
@@ -69,6 +69,10 @@ class AltosTelemetryReader extends AltosFlightReader {
                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;
index fefe74e..62e612e 100644 (file)
@@ -276,7 +276,7 @@ public class AltosUI extends JFrame {
                AltosRecordIterable iterable = chooser.runDialog();
                if (iterable != null) {
                        AltosFlightReader reader = new AltosReplayReader(iterable.iterator(),
-                                                                        chooser.filename());
+                                                                        chooser.file());
                        new AltosFlightUI(voice, reader);
                }
        }
@@ -310,7 +310,11 @@ public class AltosUI extends JFrame {
                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() {
@@ -427,7 +431,7 @@ public class AltosUI extends JFrame {
                        } 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;