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.*;
24 public class AltosLaunch {
27 boolean serial_started;
32 final static int Unknown = -1;
33 final static int Good = 0;
34 final static int Bad = 1;
39 private void start_serial() throws InterruptedException {
40 serial_started = true;
43 private void stop_serial() throws InterruptedException {
46 serial_started = false;
57 public void set(String i) {
65 private boolean get_string(String line, String label, string_ref s) {
66 if (line.startsWith(label)) {
67 String quoted = line.substring(label.length()).trim();
69 if (quoted.startsWith("\""))
70 quoted = quoted.substring(1);
71 if (quoted.endsWith("\""))
72 quoted = quoted.substring(0,quoted.length()-1);
80 public boolean status() throws InterruptedException, TimeoutException {
84 string_ref status_name = new string_ref();
86 serial.printf("l %d %d\n", launcher_serial, launcher_channel);
88 String line = serial.get_reply(20000);
90 throw new TimeoutException();
91 if (get_string(line, "Rssi: ", status_name)) {
93 rssi = Altos.fromdec(status_name.get());
94 } catch (NumberFormatException ne) {
97 } else if (get_string(line, "Armed: ", status_name)) {
99 String status = status_name.get();
100 if (status.startsWith("igniter good"))
102 else if (status.startsWith("igniter bad"))
107 } else if (get_string(line, "Disarmed: ", status_name)) {
109 if (status_name.get().startsWith("igniter good"))
111 else if (status_name.get().startsWith("igniter bad"))
116 } else if (get_string(line, "Error ", status_name)) {
131 public static String status_string(int status) {
146 serial.printf("a %d %d\n", launcher_serial, launcher_channel);
147 serial.flush_output();
148 } catch (InterruptedException ie) {
152 } catch (InterruptedException ie) {
162 serial.printf("i %d %d\n", launcher_serial, launcher_channel);
163 serial.flush_output();
164 } catch (InterruptedException ie) {
168 } catch (InterruptedException ie) {
173 public void close() {
176 } catch (InterruptedException ie) {
182 public void set_frame(Frame frame) {
183 serial.set_frame(frame);
186 public void set_remote(int in_serial, int in_channel) {
187 launcher_serial = in_serial;
188 launcher_channel = in_channel;
191 public AltosLaunch(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
194 serial = new AltosSerial(device);