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 class AltosEepromFlight {
38 public AltosEepromFlight(int in_flight, int in_start, int in_end) {
45 public class AltosEepromList extends ArrayList<AltosEepromLog> {
46 AltosConfigData config_data;
48 public AltosEepromList (AltosSerial serial_line, boolean remote) throws IOException, InterruptedException, TimeoutException {
51 serial_line.start_remote();
52 config_data = new AltosConfigData (serial_line);
53 if (config_data.serial == 0)
54 throw new IOException("no serial number found");
56 ArrayList<AltosEepromFlight> flights = new ArrayList<AltosEepromFlight>();
57 if (config_data.flight_log_max != 0) {
58 serial_line.printf("l\n");
60 String line = serial_line.get_reply(5000);
62 throw new TimeoutException();
63 if (line.contains("done"))
65 if (line.contains("Syntax"))
67 String[] tokens = line.split("\\s+");
68 System.out.printf("got line %s (%d tokens)\n", line, tokens.length);
69 if (tokens.length < 6)
72 int flight = -1, start = -1, end = -1;
74 if (tokens[0].equals("flight"))
75 flight = AltosParse.parse_int(tokens[1]);
76 if (tokens[2].equals("start"))
77 start = AltosParse.parse_hex(tokens[3]);
78 if (tokens[4].equals("end"))
79 end = AltosParse.parse_hex(tokens[5]);
80 System.out.printf("parsed flight %d %x %x\n", flight, start, end);
81 if (flight > 0 && start >= 0 && end > 0)
82 flights.add(new AltosEepromFlight(flight, start, end));
83 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
86 flights.add(new AltosEepromFlight(0, 0, 0xfff));
88 for (AltosEepromFlight flight : flights) {
89 System.out.printf("Scanning flight %d %x %x\n", flight.flight, flight.start, flight.end);
90 add(new AltosEepromLog(serial_line, config_data.serial,
91 flight.start, flight.end));
95 serial_line.stop_remote();
96 serial_line.flush_output();
98 for (int i = 0; i < size(); i++) {
99 AltosEepromLog l = get(i);
100 System.out.printf("Found flight %d at %x - %x\n", l.flight, l.start_block, l.end_block);