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.*;
29 public class AltosLaunch {
32 boolean serial_started;
37 final static int Unknown = -1;
38 final static int Good = 0;
39 final static int Bad = 1;
44 private void start_serial() throws InterruptedException {
45 serial_started = true;
48 private void stop_serial() throws InterruptedException {
51 serial_started = false;
62 public void set(String i) {
70 private boolean get_string(String line, String label, string_ref s) {
71 if (line.startsWith(label)) {
72 String quoted = line.substring(label.length()).trim();
74 if (quoted.startsWith("\""))
75 quoted = quoted.substring(1);
76 if (quoted.endsWith("\""))
77 quoted = quoted.substring(0,quoted.length()-1);
85 public boolean status() throws InterruptedException, TimeoutException {
89 string_ref status_name = new string_ref();
91 serial.printf("l %d %d\n", launcher_serial, launcher_channel);
93 String line = serial.get_reply(20000);
95 throw new TimeoutException();
96 if (get_string(line, "Rssi: ", status_name)) {
98 rssi = Altos.fromdec(status_name.get());
99 } catch (NumberFormatException ne) {
102 } else if (get_string(line, "Armed: ", status_name)) {
104 String status = status_name.get();
105 if (status.startsWith("igniter good"))
107 else if (status.startsWith("igniter bad"))
112 } else if (get_string(line, "Disarmed: ", status_name)) {
114 if (status_name.get().startsWith("igniter good"))
116 else if (status_name.get().startsWith("igniter bad"))
121 } else if (get_string(line, "Error ", status_name)) {
136 public static String status_string(int status) {
151 serial.printf("a %d %d\n", launcher_serial, launcher_channel);
152 serial.flush_output();
153 } catch (InterruptedException ie) {
157 } catch (InterruptedException ie) {
167 serial.printf("i %d %d\n", launcher_serial, launcher_channel);
168 serial.flush_output();
169 } catch (InterruptedException ie) {
173 } catch (InterruptedException ie) {
178 public void close() {
181 } catch (InterruptedException ie) {
187 public void set_frame(Frame frame) {
188 serial.set_frame(frame);
191 public void set_remote(int in_serial, int in_channel) {
192 launcher_serial = in_serial;
193 launcher_channel = in_channel;
196 public AltosLaunch(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
199 serial = new AltosSerial(device);