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.*;
29 public class AltosIgnite {
33 boolean serial_started;
34 final static int None = 0;
35 final static int Apogee = 1;
36 final static int Main = 2;
38 final static int Unknown = 0;
39 final static int Ready = 1;
40 final static int Active = 2;
41 final static int Open = 3;
43 private void start_serial() throws InterruptedException, TimeoutException {
44 serial_started = true;
46 serial.start_remote();
49 private void stop_serial() throws InterruptedException {
52 serial_started = false;
65 public void set(String i) {
73 private boolean get_string(String line, String label, string_ref s) {
74 if (line.startsWith(label)) {
75 String quoted = line.substring(label.length()).trim();
77 if (quoted.startsWith("\""))
78 quoted = quoted.substring(1);
79 if (quoted.endsWith("\""))
80 quoted = quoted.substring(0,quoted.length()-1);
88 private int status(String status_name) {
89 if (status_name.equals("unknown"))
91 if (status_name.equals("ready"))
93 if (status_name.equals("active"))
95 if (status_name.equals("open"))
100 public int status(int igniter) throws InterruptedException, TimeoutException {
101 int status = Unknown;
104 string_ref status_name = new string_ref();
107 serial.printf("t\n");
109 String line = serial.get_reply(5000);
111 throw new TimeoutException();
112 if (get_string(line, "Igniter: drogue Status: ", status_name))
113 if (igniter == Apogee)
114 status = status(status_name.get());
115 if (get_string(line, "Igniter: main Status: ", status_name)) {
117 status = status(status_name.get());
127 public static String status_string(int status) {
129 case Unknown: return "Unknown";
130 case Ready: return "Ready";
131 case Active: return "Active";
132 case Open: return "Open";
133 default: return "Unknown";
137 public void fire(int igniter) {
144 serial.printf("i DoIt main\n");
147 serial.printf("i DoIt drogue\n");
150 } catch (InterruptedException ie) {
151 } catch (TimeoutException te) {
155 } catch (InterruptedException ie) {
160 public void close() {
163 } catch (InterruptedException ie) {
169 public void set_frame(Frame frame) {
170 serial.set_frame(frame);
173 public AltosIgnite(AltosDevice in_device)
174 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
177 serial = new AltosSerial(device);
180 if (!device.matchProduct(Altos.product_telemetrum))