altosui: Add igniter ground testing code
authorKeith Packard <keithp@keithp.com>
Fri, 19 Nov 2010 07:41:30 +0000 (15:41 +0800)
committerKeith Packard <keithp@keithp.com>
Fri, 19 Nov 2010 07:54:37 +0000 (15:54 +0800)
Not yet hooked up, but the UI is finished.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosIgnite.java [new file with mode: 0644]
ao-tools/altosui/AltosIgniteUI.java [new file with mode: 0644]
ao-tools/altosui/AltosUI.java
ao-tools/altosui/Makefile.am

diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java
new file mode 100644 (file)
index 0000000..5c27e8f
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+import java.io.*;
+
+public class AltosIgnite {
+       AltosDevice     device;
+       AltosSerial     serial;
+       boolean         remote;
+       final static int        None = 0;
+       final static int        Apogee = 1;
+       final static int        Main = 2;
+
+       final static int        Unknown = 0;
+       final static int        Ready = 1;
+       final static int        Active = 2;
+       final static int        Open = 3;
+
+       private void start_serial() throws InterruptedException {
+               if (remote) {
+                       serial.set_channel(AltosPreferences.channel(device.getSerial()));
+                       serial.set_callsign(AltosPreferences.callsign());
+                       serial.printf("~\np\n");
+                       serial.flush_input();
+               }
+       }
+
+       private void stop_serial() throws InterruptedException {
+               if (serial == null)
+                       return;
+               if (remote) {
+                       serial.printf("~");
+                       serial.flush_output();
+               }
+       }
+
+       class string_ref {
+               String  value;
+
+               public String get() {
+                       return value;
+               }
+               public void set(String i) {
+                       value = i;
+               }
+               public string_ref() {
+                       value = null;
+               }
+       }
+
+       private boolean get_string(String line, String label, string_ref s) {
+               if (line.startsWith(label)) {
+                       String  quoted = line.substring(label.length()).trim();
+
+                       if (quoted.startsWith("\""))
+                               quoted = quoted.substring(1);
+                       if (quoted.endsWith("\""))
+                               quoted = quoted.substring(0,quoted.length()-1);
+                       s.set(quoted);
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       private int status(String status_name) {
+               if (status_name.equals("unknown"))
+                       return Unknown;
+               if (status_name.equals("ready"))
+                       return Ready;
+               if (status_name.equals("active"))
+                       return Active;
+               if (status_name.equals("open"))
+                       return Open;
+               return Unknown;
+       }
+
+       public int status(int igniter) {
+               int status = Unknown;
+               if (serial == null)
+                       return status;
+               string_ref status_name = new string_ref();
+               try {
+                       start_serial();
+                       serial.printf("t\n");
+                       for (;;) {
+                               String line = serial.get_reply();
+                               if (get_string(line, "Igniter: drogue Status: ", status_name))
+                                       if (igniter == Apogee)
+                                               status = status(status_name.get());
+                               if (get_string(line, "Igniter:   main Status: ", status_name)) {
+                                       if (igniter == Main)
+                                               status = status(status_name.get());
+                                       break;
+                               }
+                       }
+               } catch (InterruptedException ie) {
+               } finally {
+                       try {
+                               stop_serial();
+                       } catch (InterruptedException ie) {
+                       }
+               }
+               return status;
+       }
+
+       public void fire(int igniter) {
+               if (serial == null)
+                       return;
+               try {
+                       start_serial();
+                       switch (igniter) {
+                       case Main:
+                               serial.printf("i DoIt main\n");
+                               break;
+                       case Apogee:
+                               serial.printf("i DoIt drogue\n");
+                               break;
+                       }
+               } catch (InterruptedException ie) {
+               } finally {
+                       try {
+                               stop_serial();
+                       } catch (InterruptedException ie) {
+                       }
+               }
+       }
+
+       public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
+
+               device = in_device;
+               serial = null;
+//             serial = new AltosSerial(device);
+               remote = false;
+
+//             if (!device.matchProduct(AltosDevice.product_telemetrum))
+//                     remote = true;
+       }
+}
\ No newline at end of file
diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java
new file mode 100644 (file)
index 0000000..62da413
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.table.*;
+import javax.swing.event.*;
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+
+public class AltosIgniteUI
+       extends JDialog
+       implements ActionListener
+{
+       JFrame          owner;
+       JLabel          label;
+       JRadioButton    apogee;
+       JRadioButton    main;
+       JToggleButton   arm;
+       JButton         fire;
+       javax.swing.Timer       timer;
+
+       final static int        timeout = 1 * 1000;
+
+       int             time_remaining;
+
+       void set_arm_text() {
+               if (arm.isSelected())
+                       arm.setText(String.format("%d", time_remaining));
+               else
+                       arm.setText("Arm");
+       }
+
+       void start_timer() {
+               time_remaining = 10;
+               set_arm_text();
+               timer.restart();
+       }
+
+       void stop_timer() {
+               time_remaining = 0;
+               arm.setSelected(false);
+               arm.setEnabled(false);
+               fire.setEnabled(false);
+               timer.stop();
+               set_arm_text();
+       }
+
+       void cancel () {
+               apogee.setSelected(false);
+               main.setSelected(false);
+               fire.setEnabled(false);
+               stop_timer();
+       }
+
+       void tick_timer() {
+               --time_remaining;
+               if (time_remaining <= 0)
+                       cancel();
+               else
+                       set_arm_text();
+       }
+
+       void fire() {
+               if (arm.isEnabled() && arm.isSelected() && time_remaining > 0) {
+                       int     igniter = AltosIgnite.None;
+                       if (apogee.isSelected() && !main.isSelected())
+                               igniter = AltosIgnite.Apogee;
+                       else if (main.isSelected() && !apogee.isSelected())
+                               igniter = AltosIgnite.Main;
+                       System.out.printf ("fire %d\n", igniter);
+                       cancel();
+               }
+       }
+
+       public void actionPerformed(ActionEvent e) {
+               String cmd = e.getActionCommand();
+               if (cmd.equals("apogee") || cmd.equals("main")) {
+                       stop_timer();
+                       arm.setEnabled(true);
+               }
+
+               if (cmd.equals("apogee") && apogee.isSelected())
+                       main.setSelected(false);
+               if (cmd.equals("main") && main.isSelected())
+                       apogee.setSelected(false);
+
+               if (cmd.equals("arm")) {
+                       if (arm.isSelected()) {
+                               fire.setEnabled(true);
+                               start_timer();
+                       } else
+                               cancel();
+               }
+               if (cmd.equals("fire"))
+                       fire();
+               if (cmd.equals("tick"))
+                       tick_timer();
+       }
+
+       public AltosIgniteUI(JFrame in_owner) {
+               Container               pane = getContentPane();
+               GridBagConstraints      c = new GridBagConstraints();
+               Insets                  i = new Insets(4,4,4,4);
+
+               timer = new javax.swing.Timer(timeout, this);
+               timer.setActionCommand("tick");
+
+               owner = in_owner;
+
+               pane.setLayout(new GridBagLayout());
+
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.CENTER;
+               c.insets = i;
+               c.weightx = 1;
+               c.weighty = 1;
+
+               c.gridx = 0;
+               c.gridy = 0;
+               c.gridwidth = 2;
+               label = new JLabel ("Fire Igniter");
+               pane.add(label, c);
+
+               c.gridx = 0;
+               c.gridy = 1;
+               c.gridwidth = 1;
+               apogee = new JRadioButton ("Apogee");
+               pane.add(apogee, c);
+               apogee.addActionListener(this);
+               apogee.setActionCommand("apogee");
+
+               c.gridx = 1;
+               c.gridy = 1;
+               c.gridwidth = 1;
+               main = new JRadioButton ("Main");
+               pane.add(main, c);
+               main.addActionListener(this);
+               main.setActionCommand("main");
+
+               c.gridx = 0;
+               c.gridy = 2;
+               c.gridwidth = 1;
+               arm = new JToggleButton ("Arm");
+               pane.add(arm, c);
+               arm.addActionListener(this);
+               arm.setActionCommand("arm");
+               arm.setEnabled(false);
+
+               c.gridx = 1;
+               c.gridy = 2;
+               c.gridwidth = 1;
+               fire = new JButton ("Fire");
+               fire.setEnabled(false);
+               pane.add(fire, c);
+               fire.addActionListener(this);
+               fire.setActionCommand("fire");
+
+               pack();
+               setLocationRelativeTo(owner);
+               setVisible(true);
+       }
+}
\ No newline at end of file
index bedf24598c2bd29406dcf304dc093176b3073e49..5e9566f076ab6e994cf581ae00007be8f3a1185a 100644 (file)
@@ -125,40 +125,47 @@ public class AltosUI extends JFrame {
                                                Replay();
                                        }
                                });
                                                Replay();
                                        }
                                });
-               b = addButton(0, 1, "Graph Data");
+               b = addButton(3, 0, "Graph Data");
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                GraphData();
                                        }
                                });
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                GraphData();
                                        }
                                });
-               b = addButton(1, 1, "Export Data");
+               b = addButton(4, 0, "Export Data");
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                ExportData();
                                        }
                                });
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                ExportData();
                                        }
                                });
-               b = addButton(2, 1, "Configure TeleMetrum");
+               b = addButton(0, 1, "Configure TeleMetrum");
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                ConfigureTeleMetrum();
                                        }
                                });
 
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                ConfigureTeleMetrum();
                                        }
                                });
 
-               b = addButton(0, 2, "Configure AltosUI");
+               b = addButton(1, 1, "Configure AltosUI");
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        ConfigureAltosUI();
                                }
                        });
 
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        ConfigureAltosUI();
                                }
                        });
 
-               b = addButton(1, 2, "Flash Image");
+               b = addButton(2, 1, "Flash Image");
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        FlashImage();
                                }
                        });
 
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        FlashImage();
                                }
                        });
 
-               b = addButton(2, 2, "Quit");
+               b = addButton(3, 1, "Fire Igniter");
+               b.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       FireIgniter();
+                               }
+                       });
+
+               b = addButton(4, 1, "Quit");
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        System.exit(0);
                b.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        System.exit(0);
@@ -215,6 +222,10 @@ public class AltosUI extends JFrame {
                new AltosFlashUI(AltosUI.this);
        }
 
                new AltosFlashUI(AltosUI.this);
        }
 
+       void FireIgniter() {
+               new AltosIgniteUI(AltosUI.this);
+       }
+
        /*
         * Replay a flight from telemetry data
         */
        /*
         * Replay a flight from telemetry data
         */
index 8d0fe16eca2ec78e32f57e5b5b3b0806c7b6ac39..25977b12e338717ca6b34325ba36c8d899fd60b4 100644 (file)
@@ -40,6 +40,8 @@ altosui_JAVA = \
        AltosGreatCircle.java \
        AltosHexfile.java \
        Altos.java \
        AltosGreatCircle.java \
        AltosHexfile.java \
        Altos.java \
+       AltosIgnite.java \
+       AltosIgniteUI.java \
        AltosInfoTable.java \
        AltosKML.java \
        AltosLanded.java \
        AltosInfoTable.java \
        AltosKML.java \
        AltosLanded.java \