2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.util.concurrent.*;
23 import java.awt.event.*;
25 import javax.swing.filechooser.FileNameExtensionFilter;
26 import javax.swing.table.*;
27 import javax.swing.event.*;
28 import org.altusmetrum.AltosLib.*;
30 public class AltosIgnite {
34 boolean serial_started;
35 final static int None = 0;
36 final static int Apogee = 1;
37 final static int Main = 2;
39 final static int Unknown = 0;
40 final static int Ready = 1;
41 final static int Active = 2;
42 final static int Open = 3;
44 private void start_serial() throws InterruptedException, TimeoutException {
45 serial_started = true;
47 serial.start_remote();
50 private void stop_serial() throws InterruptedException {
53 serial_started = false;
66 public void set(String i) {
74 private boolean get_string(String line, String label, string_ref s) {
75 if (line.startsWith(label)) {
76 String quoted = line.substring(label.length()).trim();
78 if (quoted.startsWith("\""))
79 quoted = quoted.substring(1);
80 if (quoted.endsWith("\""))
81 quoted = quoted.substring(0,quoted.length()-1);
89 private int status(String status_name) {
90 if (status_name.equals("unknown"))
92 if (status_name.equals("ready"))
94 if (status_name.equals("active"))
96 if (status_name.equals("open"))
101 public int status(int igniter) throws InterruptedException, TimeoutException {
102 int status = Unknown;
105 string_ref status_name = new string_ref();
108 serial.printf("t\n");
110 String line = serial.get_reply(5000);
112 throw new TimeoutException();
113 if (get_string(line, "Igniter: drogue Status: ", status_name))
114 if (igniter == Apogee)
115 status = status(status_name.get());
116 if (get_string(line, "Igniter: main Status: ", status_name)) {
118 status = status(status_name.get());
128 public static String status_string(int status) {
130 case Unknown: return "Unknown";
131 case Ready: return "Ready";
132 case Active: return "Active";
133 case Open: return "Open";
134 default: return "Unknown";
138 public void fire(int igniter) {
145 serial.printf("i DoIt main\n");
148 serial.printf("i DoIt drogue\n");
151 } catch (InterruptedException ie) {
152 } catch (TimeoutException te) {
156 } catch (InterruptedException ie) {
161 public void close() {
164 } catch (InterruptedException ie) {
170 public void set_frame(Frame frame) {
171 serial.set_frame(frame);
174 public AltosIgnite(AltosDevice in_device)
175 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
178 serial = new AltosSerial(device);
181 if (!device.matchProduct(Altos.product_telemetrum))