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_11;
22 import java.util.concurrent.*;
24 public class AltosIgnite {
27 boolean close_on_exit;
29 boolean have_npyro = false;
31 AltosConfigData config_data;
33 public final static String None = null;
34 public final static String Apogee = "drogue";
35 public final static String Main = "main";
37 public final static int Unknown = 0;
38 public final static int Ready = 1;
39 public final static int Active = 2;
40 public final static int Open = 3;
42 private void start_link() throws InterruptedException, TimeoutException {
48 private void stop_link() throws InterruptedException {
64 public void set(String i) {
73 private boolean get_string(String line, String label, string_ref s) {
74 if (line.startsWith(label)) {
75 String quoted = line.substring(label.length()).trim();
77 if (quoted.startsWith("\""))
78 quoted = quoted.substring(1);
79 if (quoted.endsWith("\""))
80 quoted = quoted.substring(0,quoted.length()-1);
89 private int map_status(String status_name) {
90 if (status_name.equals("unknown"))
92 if (status_name.equals("ready"))
94 if (status_name.equals("active"))
96 if (status_name.equals("open"))
101 private void get_npyro() throws InterruptedException, TimeoutException {
102 if (config_data == null)
103 config_data = new AltosConfigData(link);
104 if (config_data != null)
105 npyro = config_data.npyro;
111 public int npyro() throws InterruptedException, TimeoutException {
120 public HashMap<String,Integer> status() throws InterruptedException, TimeoutException {
121 HashMap<String,Integer> status = new HashMap<String,Integer>();
129 String last_igniter = Main;
131 last_igniter = String.format("%d", npyro - 1);
135 String line = link.get_reply(5000);
137 throw new TimeoutException();
138 String[] items = line.split("\\s+");
140 if (items.length < 4)
143 if (!items[0].equals("Igniter:"))
146 if (!items[2].equals("Status:"))
149 status.put(items[1], map_status(items[3]));
151 if (items[1].equals(last_igniter))
160 public static String status_string(int status) {
162 case Unknown: return "Unknown";
163 case Ready: return "Ready";
164 case Active: return "Active";
165 case Open: return "Open";
166 default: return "Unknown";
170 public void fire(String igniter) throws InterruptedException {
175 link.printf("i DoIt %s\n", igniter);
176 } catch (TimeoutException te) {
182 public void close() throws InterruptedException {
189 public AltosIgnite(AltosLink in_link, boolean in_remote, boolean in_close_on_exit) {
192 close_on_exit = in_close_on_exit;
195 public AltosIgnite(AltosLink in_link, boolean in_remote) {
196 this(in_link, in_remote, true);