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;
31 public final static String None = null;
32 public final static String Apogee = "drogue";
33 public final static String Main = "main";
35 public final static int Unknown = 0;
36 public final static int Ready = 1;
37 public final static int Active = 2;
38 public final static int Open = 3;
40 private void start_link() throws InterruptedException, TimeoutException {
46 private void stop_link() throws InterruptedException {
62 public void set(String i) {
71 private boolean get_string(String line, String label, string_ref s) {
72 if (line.startsWith(label)) {
73 String quoted = line.substring(label.length()).trim();
75 if (quoted.startsWith("\""))
76 quoted = quoted.substring(1);
77 if (quoted.endsWith("\""))
78 quoted = quoted.substring(0,quoted.length()-1);
87 private int map_status(String status_name) {
88 if (status_name.equals("unknown"))
90 if (status_name.equals("ready"))
92 if (status_name.equals("active"))
94 if (status_name.equals("open"))
99 private void get_npyro() throws InterruptedException, TimeoutException {
100 AltosConfigData config_data = link.config_data();
101 npyro = config_data.npyro;
105 public int npyro() throws InterruptedException, TimeoutException {
114 public HashMap<String,Integer> status() throws InterruptedException, TimeoutException {
115 HashMap<String,Integer> status = new HashMap<String,Integer>();
123 String last_igniter = Main;
125 last_igniter = String.format("%d", npyro - 1);
129 String line = link.get_reply(5000);
131 throw new TimeoutException();
132 String[] items = line.split("\\s+");
134 if (items.length < 4)
137 if (!items[0].equals("Igniter:"))
140 if (!items[2].equals("Status:"))
143 status.put(items[1], map_status(items[3]));
145 if (items[1].equals(last_igniter))
154 public static String status_string(int status) {
156 case Unknown: return "Unknown";
157 case Ready: return "Ready";
158 case Active: return "Active";
159 case Open: return "Open";
160 default: return "Unknown";
164 public void fire(String igniter) throws InterruptedException {
169 link.printf("i DoIt %s\n", igniter);
170 } catch (TimeoutException te) {
176 public void close() throws InterruptedException {
182 public AltosIgnite(AltosLink in_link, boolean in_remote)
183 throws FileNotFoundException, TimeoutException, InterruptedException {