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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
23 import java.util.concurrent.*;
25 public class AltosIgnite {
28 boolean close_on_exit;
30 boolean have_npyro = false;
32 AltosConfigData config_data;
34 public final static String None = null;
35 public final static String Apogee = "drogue";
36 public final static String Main = "main";
38 public final static int Unknown = 0;
39 public final static int Ready = 1;
40 public final static int Active = 2;
41 public final static int Open = 3;
43 private void start_link() throws InterruptedException, TimeoutException {
49 private void stop_link() throws InterruptedException {
65 public void set(String i) {
74 private boolean get_string(String line, String label, string_ref s) {
75 if (line.startsWith(label)) {
76 String quoted = line.substring(label.length()).trim();
78 if (quoted.startsWith("\""))
79 quoted = quoted.substring(1);
80 if (quoted.endsWith("\""))
81 quoted = quoted.substring(0,quoted.length()-1);
90 private int map_status(String status_name) {
91 if (status_name.equals("unknown"))
93 if (status_name.equals("ready"))
95 if (status_name.equals("active"))
97 if (status_name.equals("open"))
102 private void get_npyro() throws InterruptedException, TimeoutException {
103 if (config_data == null)
104 config_data = new AltosConfigData(link);
105 if (config_data != null)
106 npyro = config_data.npyro;
112 public int npyro() throws InterruptedException, TimeoutException {
121 public HashMap<String,Integer> status() throws InterruptedException, TimeoutException {
122 HashMap<String,Integer> status = new HashMap<String,Integer>();
130 String last_igniter = Main;
132 last_igniter = String.format("%d", npyro - 1);
136 String line = link.get_reply(5000);
138 throw new TimeoutException();
139 String[] items = line.split("\\s+");
141 if (items.length < 4)
144 if (!items[0].equals("Igniter:"))
147 if (!items[2].equals("Status:"))
150 status.put(items[1], map_status(items[3]));
152 if (items[1].equals(last_igniter))
161 public static String status_string(int status) {
163 case Unknown: return "Unknown";
164 case Ready: return "Ready";
165 case Active: return "Active";
166 case Open: return "Open";
167 default: return "Unknown";
171 public void fire(String igniter) throws InterruptedException {
176 link.printf("i DoIt %s\n", igniter);
177 } catch (TimeoutException te) {
183 public void close() throws InterruptedException {
190 public AltosIgnite(AltosLink in_link, boolean in_remote, boolean in_close_on_exit) {
193 close_on_exit = in_close_on_exit;
196 public AltosIgnite(AltosLink in_link, boolean in_remote) {
197 this(in_link, in_remote, true);