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 final static int None = 0;
28 final static int Apogee = 1;
29 final static int Main = 2;
31 final static int Unknown = 0;
32 final static int Ready = 1;
33 final static int Active = 2;
34 final static int Open = 3;
36 private void start_serial() throws InterruptedException {
38 serial.set_channel(AltosPreferences.channel(device.getSerial()));
39 serial.set_callsign(AltosPreferences.callsign());
40 serial.printf("~\np\n");
45 private void stop_serial() throws InterruptedException {
50 serial.flush_output();
60 public void set(String i) {
68 private boolean get_string(String line, String label, string_ref s) {
69 if (line.startsWith(label)) {
70 String quoted = line.substring(label.length()).trim();
72 if (quoted.startsWith("\""))
73 quoted = quoted.substring(1);
74 if (quoted.endsWith("\""))
75 quoted = quoted.substring(0,quoted.length()-1);
83 private int status(String status_name) {
84 if (status_name.equals("unknown"))
86 if (status_name.equals("ready"))
88 if (status_name.equals("active"))
90 if (status_name.equals("open"))
95 public int status(int igniter) throws InterruptedException, TimeoutException {
99 string_ref status_name = new string_ref();
101 serial.printf("t\n");
103 String line = serial.get_reply(1000);
105 throw new TimeoutException();
106 if (get_string(line, "Igniter: drogue Status: ", status_name))
107 if (igniter == Apogee)
108 status = status(status_name.get());
109 if (get_string(line, "Igniter: main Status: ", status_name)) {
111 status = status(status_name.get());
119 public String status_string(int status) {
121 case Unknown: return "Unknown";
122 case Ready: return "Ready";
123 case Active: return "Active";
124 case Open: return "Open";
125 default: return "Unknown";
129 public void fire(int igniter) {
136 serial.printf("i DoIt main\n");
139 serial.printf("i DoIt drogue\n");
142 } catch (InterruptedException ie) {
146 } catch (InterruptedException ie) {
151 public void close() {
156 public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
159 serial = new AltosSerial(device);
162 if (!device.matchProduct(AltosDevice.product_telemetrum))