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.
18 package org.altusmetrum.altoslib_1;
21 import java.util.concurrent.*;
23 public class AltosIgnite {
28 public final static int None = 0;
29 public final static int Apogee = 1;
30 public final static int Main = 2;
32 public final static int Unknown = 0;
33 public final static int Ready = 1;
34 public final static int Active = 2;
35 public final static int Open = 3;
37 private void start_link() throws InterruptedException, TimeoutException {
43 private void stop_link() throws InterruptedException {
59 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);
84 private int status(String status_name) {
85 if (status_name.equals("unknown"))
87 if (status_name.equals("ready"))
89 if (status_name.equals("active"))
91 if (status_name.equals("open"))
96 public int status(int igniter) throws InterruptedException, TimeoutException {
100 //string_ref status_name = new string_ref();
105 String line = link.get_reply(5000);
107 throw new TimeoutException();
108 String[] items = line.split("\\s+");
110 if (items.length < 4)
113 if (!items[0].equals("Igniter:"))
116 if (!items[2].equals("Status:"))
119 if (items[1].equals("drogue")) {
120 if (igniter == Apogee)
121 status = status(items[3]);
122 } else if (items[1].equals("main")) {
124 status = status(items[3]);
134 public static String status_string(int status) {
136 case Unknown: return "Unknown";
137 case Ready: return "Ready";
138 case Active: return "Active";
139 case Open: return "Open";
140 default: return "Unknown";
144 public void fire(int igniter) {
151 link.printf("i DoIt main\n");
154 link.printf("i DoIt drogue\n");
157 } catch (InterruptedException ie) {
158 } catch (TimeoutException te) {
162 } catch (InterruptedException ie) {
167 public void close() {
170 } catch (InterruptedException ie) {
176 public AltosIgnite(AltosLink in_link, boolean in_remote)
177 throws FileNotFoundException, TimeoutException, InterruptedException {