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.
22 public class AltosIgnite {
26 final static int None = 0;
27 final static int Apogee = 1;
28 final static int Main = 2;
30 final static int Unknown = 0;
31 final static int Ready = 1;
32 final static int Active = 2;
33 final static int Open = 3;
35 private void start_serial() throws InterruptedException {
37 serial.set_channel(AltosPreferences.channel(device.getSerial()));
38 serial.set_callsign(AltosPreferences.callsign());
39 serial.printf("~\np\n");
44 private void stop_serial() throws InterruptedException {
49 serial.flush_output();
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 private int status(String status_name) {
83 if (status_name.equals("unknown"))
85 if (status_name.equals("ready"))
87 if (status_name.equals("active"))
89 if (status_name.equals("open"))
94 public int status(int igniter) {
98 string_ref status_name = new string_ref();
101 serial.printf("t\n");
103 String line = serial.get_reply();
104 if (get_string(line, "Igniter: drogue Status: ", status_name))
105 if (igniter == Apogee)
106 status = status(status_name.get());
107 if (get_string(line, "Igniter: main Status: ", status_name)) {
109 status = status(status_name.get());
113 } catch (InterruptedException ie) {
117 } catch (InterruptedException ie) {
123 public void fire(int igniter) {
130 serial.printf("i DoIt main\n");
133 serial.printf("i DoIt drogue\n");
136 } catch (InterruptedException ie) {
140 } catch (InterruptedException ie) {
145 public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
149 // serial = new AltosSerial(device);
152 // if (!device.matchProduct(AltosDevice.product_telemetrum))