2 * Copyright © 2011 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.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
33 public class AltosConfigData implements Iterable<String> {
35 /* Version information */
42 /* Strings returned */
43 LinkedList<String> lines;
45 /* Config information */
53 int accel_cal_plus, accel_cal_minus;
54 int radio_calibration;
58 int storage_erase_unit;
60 static String get_string(String line, String label) throws ParseException {
61 if (line.startsWith(label)) {
62 String quoted = line.substring(label.length()).trim();
64 if (quoted.startsWith("\""))
65 quoted = quoted.substring(1);
66 if (quoted.endsWith("\""))
67 quoted = quoted.substring(0,quoted.length()-1);
70 throw new ParseException("mismatch", 0);
73 static int get_int(String line, String label) throws NumberFormatException, ParseException {
74 if (line.startsWith(label)) {
75 String tail = line.substring(label.length()).trim();
76 String[] tokens = tail.split("\\s+");
77 if (tokens.length > 0)
78 return Integer.parseInt(tokens[0]);
80 throw new ParseException("mismatch", 0);
83 public Iterator<String> iterator() {
84 return lines.iterator();
87 public AltosConfigData(AltosSerial serial_line) throws InterruptedException, TimeoutException {
88 serial_line.printf("c s\nf\nv\n");
89 lines = new LinkedList<String>();
92 String line = serial_line.get_reply();
94 throw new TimeoutException();
95 if (line.contains("Syntax error"))
98 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
99 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
100 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
101 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
102 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
103 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
105 if (line.startsWith("Accel cal")) {
106 String[] bits = line.split("\\s+");
107 if (bits.length >= 6) {
108 accel_cal_plus = Integer.parseInt(bits[3]);
109 accel_cal_minus = Integer.parseInt(bits[5]);
112 } catch (Exception e) {}
113 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
114 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
115 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
116 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
117 try { version = get_string(line,"software-version"); } catch (Exception e) {}
118 try { product = get_string(line,"product"); } catch (Exception e) {}
120 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
121 try { storage_erase_unit = get_int(line, "Storage erase unit"); } catch (Exception e) {}
123 /* signals the end of the version info */
124 if (line.startsWith("software-version"))