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.
21 import java.util.concurrent.*;
23 import org.altusmetrum.altosuilib_1.*;
25 public class AltosLaunch {
28 boolean serial_started;
33 final static int Unknown = -1;
34 final static int Good = 0;
35 final static int Bad = 1;
40 private void start_serial() throws InterruptedException {
41 serial_started = true;
44 private void stop_serial() throws InterruptedException {
47 serial_started = false;
58 public void set(String i) {
66 private boolean get_string(String line, String label, string_ref s) {
67 if (line.startsWith(label)) {
68 String quoted = line.substring(label.length()).trim();
70 if (quoted.startsWith("\""))
71 quoted = quoted.substring(1);
72 if (quoted.endsWith("\""))
73 quoted = quoted.substring(0,quoted.length()-1);
81 public boolean status() throws InterruptedException, TimeoutException {
85 string_ref status_name = new string_ref();
87 serial.printf("l %d %d\n", launcher_serial, launcher_channel);
89 String line = serial.get_reply(20000);
91 throw new TimeoutException();
92 if (get_string(line, "Rssi: ", status_name)) {
94 rssi = Altos.fromdec(status_name.get());
95 } catch (NumberFormatException ne) {
98 } else if (get_string(line, "Armed: ", status_name)) {
100 String status = status_name.get();
101 if (status.startsWith("igniter good"))
103 else if (status.startsWith("igniter bad"))
108 } else if (get_string(line, "Disarmed: ", status_name)) {
110 if (status_name.get().startsWith("igniter good"))
112 else if (status_name.get().startsWith("igniter bad"))
117 } else if (get_string(line, "Error ", status_name)) {
132 public static String status_string(int status) {
147 serial.printf("a %d %d\n", launcher_serial, launcher_channel);
148 serial.flush_output();
149 } catch (InterruptedException ie) {
153 } catch (InterruptedException ie) {
163 serial.printf("i %d %d\n", launcher_serial, launcher_channel);
164 serial.flush_output();
165 } catch (InterruptedException ie) {
169 } catch (InterruptedException ie) {
174 public void close() {
177 } catch (InterruptedException ie) {
183 public void set_frame(Frame frame) {
184 serial.set_frame(frame);
187 public void set_remote(int in_serial, int in_channel) {
188 launcher_serial = in_serial;
189 launcher_channel = in_channel;
192 public AltosLaunch(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
195 serial = new AltosSerial(device);