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 java.awt.event.*;
25 import javax.swing.filechooser.FileNameExtensionFilter;
26 import javax.swing.table.*;
27 import javax.swing.event.*;
28 import org.altusmetrum.AltosLib.*;
30 public class AltosLaunch {
33 boolean serial_started;
38 final static int Unknown = -1;
39 final static int Good = 0;
40 final static int Bad = 1;
45 private void start_serial() throws InterruptedException {
46 serial_started = true;
49 private void stop_serial() throws InterruptedException {
52 serial_started = false;
63 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);
86 public boolean status() throws InterruptedException, TimeoutException {
90 string_ref status_name = new string_ref();
92 serial.printf("l %d %d\n", launcher_serial, launcher_channel);
94 String line = serial.get_reply(20000);
96 throw new TimeoutException();
97 if (get_string(line, "Rssi: ", status_name)) {
99 rssi = Altos.fromdec(status_name.get());
100 } catch (NumberFormatException ne) {
103 } else if (get_string(line, "Armed: ", status_name)) {
105 String status = status_name.get();
106 if (status.startsWith("igniter good"))
108 else if (status.startsWith("igniter bad"))
113 } else if (get_string(line, "Disarmed: ", status_name)) {
115 if (status_name.get().startsWith("igniter good"))
117 else if (status_name.get().startsWith("igniter bad"))
122 } else if (get_string(line, "Error ", status_name)) {
137 public static String status_string(int status) {
152 serial.printf("a %d %d\n", launcher_serial, launcher_channel);
153 serial.flush_output();
154 } catch (InterruptedException ie) {
158 } catch (InterruptedException ie) {
168 serial.printf("i %d %d\n", launcher_serial, launcher_channel);
169 serial.flush_output();
170 } catch (InterruptedException ie) {
174 } catch (InterruptedException ie) {
179 public void close() {
182 } catch (InterruptedException ie) {
188 public void set_frame(Frame frame) {
189 serial.set_frame(frame);
192 public void set_remote(int in_serial, int in_channel) {
193 launcher_serial = in_serial;
194 launcher_channel = in_channel;
197 public AltosLaunch(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
200 serial = new AltosSerial(device);