From 9e1487b1a5db0afd1d23c86d82c60b1c1a62aab0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 10 Aug 2011 14:08:21 -0700 Subject: [PATCH] altosui: Add a 'Graph Flight' button to the 'landed' tab This lets you see the results of a flight as soon as the rocket lands using the telemetry data. Signed-off-by: Keith Packard --- altosui/AltosFlightReader.java | 2 ++ altosui/AltosFlightStats.java | 6 ++-- altosui/AltosFlightUI.java | 2 +- altosui/AltosLanded.java | 59 +++++++++++++++++++++++++++++-- altosui/AltosLog.java | 6 ++++ altosui/AltosReplayReader.java | 8 +++-- altosui/AltosTelemetryReader.java | 4 +++ altosui/AltosUI.java | 10 ++++-- 8 files changed, 86 insertions(+), 11 deletions(-) diff --git a/altosui/AltosFlightReader.java b/altosui/AltosFlightReader.java index 3a171444..47df375d 100644 --- a/altosui/AltosFlightReader.java +++ b/altosui/AltosFlightReader.java @@ -42,4 +42,6 @@ public class AltosFlightReader { void save_telemetry() { } void update(AltosState state) throws InterruptedException { } + + File backing_file() { return null; } } diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index e38142f0..e644b0ba 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -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("")); } } diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index c31e02bf..f0626e7c 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -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(); diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index d5c8e434..47aca29d 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -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); } } diff --git a/altosui/AltosLog.java b/altosui/AltosLog.java index 6157a656..a5f1830d 100644 --- a/altosui/AltosLog.java +++ b/altosui/AltosLog.java @@ -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; } diff --git a/altosui/AltosReplayReader.java b/altosui/AltosReplayReader.java index 4e5e1d93..eed56cff 100644 --- a/altosui/AltosReplayReader.java +++ b/altosui/AltosReplayReader.java @@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosReplayReader extends AltosFlightReader { Iterator 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 in_iterator, String in_name) { + public File backing_file() { return file; } + + public AltosReplayReader(Iterator in_iterator, File in_file) { iterator = in_iterator; - name = in_name; + file = in_file; + name = file.getName(); } } diff --git a/altosui/AltosTelemetryReader.java b/altosui/AltosTelemetryReader.java index 6abe95d8..1f327a67 100644 --- a/altosui/AltosTelemetryReader.java +++ b/altosui/AltosTelemetryReader.java @@ -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; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index fefe74e8..62e612ed 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -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; -- 2.30.2