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 public class AltosIgnite {
27 boolean serial_started;
28 final static int None = 0;
29 final static int Apogee = 1;
30 final static int Main = 2;
32 final static int Unknown = 0;
33 final static int Ready = 1;
34 final static int Active = 2;
35 final static int Open = 3;
37 private void start_serial() throws InterruptedException {
38 serial_started = true;
41 serial.printf("p\nE 0\n");
46 private void stop_serial() throws InterruptedException {
49 serial_started = false;
54 serial.flush_output();
64 public void set(String i) {
72 private boolean get_string(String line, String label, string_ref s) {
73 if (line.startsWith(label)) {
74 String quoted = line.substring(label.length()).trim();
76 if (quoted.startsWith("\""))
77 quoted = quoted.substring(1);
78 if (quoted.endsWith("\""))
79 quoted = quoted.substring(0,quoted.length()-1);
87 private int status(String status_name) {
88 if (status_name.equals("unknown"))
90 if (status_name.equals("ready"))
92 if (status_name.equals("active"))
94 if (status_name.equals("open"))
99 public int status(int igniter) throws InterruptedException, TimeoutException {
100 int status = Unknown;
103 string_ref status_name = new string_ref();
105 serial.printf("t\n");
107 String line = serial.get_reply(5000);
109 throw new TimeoutException();
110 if (get_string(line, "Igniter: drogue Status: ", status_name))
111 if (igniter == Apogee)
112 status = status(status_name.get());
113 if (get_string(line, "Igniter: main Status: ", status_name)) {
115 status = status(status_name.get());
123 public String status_string(int status) {
125 case Unknown: return "Unknown";
126 case Ready: return "Ready";
127 case Active: return "Active";
128 case Open: return "Open";
129 default: return "Unknown";
133 public void fire(int igniter) {
140 serial.printf("i DoIt main\n");
143 serial.printf("i DoIt drogue\n");
146 } catch (InterruptedException ie) {
150 } catch (InterruptedException ie) {
155 public void close() {
158 } catch (InterruptedException ie) {
164 public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
167 serial = new AltosSerial(device);
170 if (!device.matchProduct(AltosDevice.product_telemetrum))