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;
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) {
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();
103 String line = link.get_reply(5000);
105 throw new TimeoutException();
106 String[] items = line.split("\\s+");
108 if (items.length < 4)
111 if (!items[0].equals("Igniter:"))
114 if (!items[2].equals("Status:"))
117 if (items[1].equals("drogue")) {
118 if (igniter == Apogee)
119 status = status(items[3]);
120 } else if (items[1].equals("main")) {
122 status = status(items[3]);
132 public static String status_string(int status) {
134 case Unknown: return "Unknown";
135 case Ready: return "Ready";
136 case Active: return "Active";
137 case Open: return "Open";
138 default: return "Unknown";
142 public void fire(int igniter) {
149 link.printf("i DoIt main\n");
152 link.printf("i DoIt drogue\n");
155 } catch (InterruptedException ie) {
156 } catch (TimeoutException te) {
160 } catch (InterruptedException ie) {
165 public void close() {
168 } catch (InterruptedException ie) {
174 public AltosIgnite(AltosLink in_link, boolean in_remote)
175 throws FileNotFoundException, TimeoutException, InterruptedException {