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;
40 serial.start_remote();
43 private void stop_serial() throws InterruptedException {
46 serial_started = false;
59 public void set(String i) {
67 private boolean get_string(String line, String label, string_ref s) {
68 if (line.startsWith(label)) {
69 String quoted = line.substring(label.length()).trim();
71 if (quoted.startsWith("\""))
72 quoted = quoted.substring(1);
73 if (quoted.endsWith("\""))
74 quoted = quoted.substring(0,quoted.length()-1);
82 private int status(String status_name) {
83 if (status_name.equals("unknown"))
85 if (status_name.equals("ready"))
87 if (status_name.equals("active"))
89 if (status_name.equals("open"))
94 public int status(int igniter) throws InterruptedException, TimeoutException {
98 string_ref status_name = new string_ref();
100 serial.printf("t\n");
102 String line = serial.get_reply(5000);
104 throw new TimeoutException();
105 if (get_string(line, "Igniter: drogue Status: ", status_name))
106 if (igniter == Apogee)
107 status = status(status_name.get());
108 if (get_string(line, "Igniter: main Status: ", status_name)) {
110 status = status(status_name.get());
118 public String status_string(int status) {
120 case Unknown: return "Unknown";
121 case Ready: return "Ready";
122 case Active: return "Active";
123 case Open: return "Open";
124 default: return "Unknown";
128 public void fire(int igniter) {
135 serial.printf("i DoIt main\n");
138 serial.printf("i DoIt drogue\n");
141 } catch (InterruptedException ie) {
145 } catch (InterruptedException ie) {
150 public void close() {
153 } catch (InterruptedException ie) {
159 public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
162 serial = new AltosSerial(device);
165 if (!device.matchProduct(AltosDevice.product_telemetrum))