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 AltosEepromDelete implements Runnable {
34 AltosEepromList flights;
36 AltosSerial serial_line;
39 ActionListener listener;
42 private void DeleteLog (AltosEepromLog log)
43 throws IOException, InterruptedException, TimeoutException {
45 if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) {
47 /* Devices with newer firmware can erase the
48 * flash blocks containing each flight
50 serial_line.flush_input();
51 serial_line.printf("d %d\n", log.flight);
53 /* It can take a while to erase the flash... */
54 String line = serial_line.get_reply(20000);
56 throw new TimeoutException();
57 if (line.equals("Erased"))
59 if (line.startsWith("No such"))
60 throw new IOException(line);
65 private void show_error_internal(String message, String title) {
66 JOptionPane.showMessageDialog(frame,
69 JOptionPane.ERROR_MESSAGE);
72 private void show_error(String in_message, String in_title) {
73 final String message = in_message;
74 final String title = in_title;
75 Runnable r = new Runnable() {
78 show_error_internal(message, title);
79 } catch (Exception ex) {
83 SwingUtilities.invokeLater(r);
90 serial_line.start_remote();
92 for (AltosEepromLog log : flights) {
98 } catch (IOException ee) {
99 show_error (ee.getLocalizedMessage(),
100 serial_line.device.toShortString());
101 } catch (InterruptedException ie) {
102 } catch (TimeoutException te) {
103 show_error (String.format("Connection to \"%s\" failed",
104 serial_line.device.toShortString()),
105 "Connection Failed");
109 serial_line.stop_remote();
110 } catch (InterruptedException ie) {
112 serial_line.flush_output();
116 if (listener != null) {
117 Runnable r = new Runnable() {
120 listener.actionPerformed(new ActionEvent(this,
123 } catch (Exception ex) {
127 SwingUtilities.invokeLater(r);
131 public void start() {
132 eeprom_thread = new Thread(this);
133 eeprom_thread.start();
136 public void addActionListener(ActionListener l) {
140 public AltosEepromDelete(JFrame given_frame,
141 AltosSerial given_serial_line,
142 boolean given_remote,
143 AltosEepromList given_flights) {
145 serial_line = given_serial_line;
146 remote = given_remote;
147 flights = given_flights;