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.
22 import java.util.concurrent.*;
24 import org.altusmetrum.altosuilib_14.*;
26 public class AltosLaunch {
29 boolean serial_started;
34 final static int Unknown = -1;
35 final static int Good = 0;
36 final static int Bad = 1;
41 private void start_serial() throws InterruptedException {
42 serial_started = true;
45 private void stop_serial() throws InterruptedException {
48 serial_started = false;
59 public void set(String i) {
67 private boolean get_string(String line, String label, string_ref s) {
68 if (line.startsWith(label)) {
69 String quoted = line.substring(label.length()).trim();
71 if (quoted.startsWith("\""))
72 quoted = quoted.substring(1);
73 if (quoted.endsWith("\""))
74 quoted = quoted.substring(0,quoted.length()-1);
82 public boolean status() throws InterruptedException, TimeoutException {
86 string_ref status_name = new string_ref();
88 serial.printf("l %d %d\n", launcher_serial, launcher_channel);
90 String line = serial.get_reply(20000);
92 throw new TimeoutException();
93 if (get_string(line, "Rssi: ", status_name)) {
95 rssi = (int) Altos.fromdec(status_name.get());
96 } catch (NumberFormatException ne) {
99 } else if (get_string(line, "Armed: ", status_name)) {
101 String status = status_name.get();
102 if (status.startsWith("igniter good"))
104 else if (status.startsWith("igniter bad"))
109 } else if (get_string(line, "Disarmed: ", status_name)) {
111 if (status_name.get().startsWith("igniter good"))
113 else if (status_name.get().startsWith("igniter bad"))
118 } else if (get_string(line, "Error ", status_name)) {
133 public static String status_string(int status) {
148 serial.printf("a %d %d\n", launcher_serial, launcher_channel);
149 serial.flush_output();
150 } catch (InterruptedException ie) {
154 } catch (InterruptedException ie) {
164 serial.printf("i %d %d\n", launcher_serial, launcher_channel);
165 serial.flush_output();
166 } catch (InterruptedException ie) {
170 } catch (InterruptedException ie) {
175 public void close() {
178 } catch (InterruptedException ie) {
184 public void set_frame(Frame frame) {
185 serial.set_frame(frame);
188 public void set_remote(int in_serial, int in_channel) {
189 launcher_serial = in_serial;
190 launcher_channel = in_channel;
193 public AltosLaunch(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
196 serial = new AltosSerial(device);