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_3;
22 import java.util.concurrent.*;
24 public class AltosIgnite {
28 boolean have_npyro = false;
30 AltosConfigData config_data;
32 public final static String None = null;
33 public final static String Apogee = "drogue";
34 public final static String Main = "main";
36 public final static int Unknown = 0;
37 public final static int Ready = 1;
38 public final static int Active = 2;
39 public final static int Open = 3;
41 private void start_link() throws InterruptedException, TimeoutException {
47 private void stop_link() throws InterruptedException {
63 public void set(String i) {
72 private boolean get_string(String line, String label, string_ref s) {
73 if (line.startsWith(label)) {
74 String quoted = line.substring(label.length()).trim();
76 if (quoted.startsWith("\""))
77 quoted = quoted.substring(1);
78 if (quoted.endsWith("\""))
79 quoted = quoted.substring(0,quoted.length()-1);
88 private int map_status(String status_name) {
89 if (status_name.equals("unknown"))
91 if (status_name.equals("ready"))
93 if (status_name.equals("active"))
95 if (status_name.equals("open"))
100 private void get_npyro() throws InterruptedException, TimeoutException {
101 if (config_data == null)
102 config_data = new AltosConfigData(link);
103 if (config_data != null)
104 npyro = config_data.npyro;
110 public int npyro() throws InterruptedException, TimeoutException {
119 public HashMap<String,Integer> status() throws InterruptedException, TimeoutException {
120 HashMap<String,Integer> status = new HashMap<String,Integer>();
128 String last_igniter = Main;
130 last_igniter = String.format("%d", npyro - 1);
134 String line = link.get_reply(5000);
136 throw new TimeoutException();
137 String[] items = line.split("\\s+");
139 if (items.length < 4)
142 if (!items[0].equals("Igniter:"))
145 if (!items[2].equals("Status:"))
148 status.put(items[1], map_status(items[3]));
150 if (items[1].equals(last_igniter))
159 public static String status_string(int status) {
161 case Unknown: return "Unknown";
162 case Ready: return "Ready";
163 case Active: return "Active";
164 case Open: return "Open";
165 default: return "Unknown";
169 public void fire(String igniter) throws InterruptedException {
174 link.printf("i DoIt %s\n", igniter);
175 } catch (TimeoutException te) {
181 public void close() throws InterruptedException {
187 public AltosIgnite(AltosLink in_link, boolean in_remote)
188 throws FileNotFoundException, TimeoutException, InterruptedException {