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.*;
30 import org.altusmetrum.AltosLib.*;
34 public class AltosEepromDelete implements Runnable {
35 AltosEepromList flights;
37 AltosSerial serial_line;
40 ActionListener listener;
43 private void DeleteLog (AltosEepromLog log)
44 throws IOException, InterruptedException, TimeoutException {
46 if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) {
48 /* Devices with newer firmware can erase the
49 * flash blocks containing each flight
51 serial_line.flush_input();
52 serial_line.printf("d %d\n", log.flight);
54 /* It can take a while to erase the flash... */
55 String line = serial_line.get_reply(20000);
57 throw new TimeoutException();
58 if (line.equals("Erased"))
60 if (line.startsWith("No such"))
61 throw new IOException(line);
66 private void show_error_internal(String message, String title) {
67 JOptionPane.showMessageDialog(frame,
70 JOptionPane.ERROR_MESSAGE);
73 private void show_error(String in_message, String in_title) {
74 final String message = in_message;
75 final String title = in_title;
76 Runnable r = new Runnable() {
79 show_error_internal(message, title);
80 } catch (Exception ex) {
84 SwingUtilities.invokeLater(r);
91 serial_line.start_remote();
93 for (AltosEepromLog log : flights) {
99 } catch (IOException ee) {
100 show_error (ee.getLocalizedMessage(),
101 serial_line.device.toShortString());
102 } catch (InterruptedException ie) {
103 } catch (TimeoutException te) {
104 show_error (String.format("Connection to \"%s\" failed",
105 serial_line.device.toShortString()),
106 "Connection Failed");
110 serial_line.stop_remote();
111 } catch (InterruptedException ie) {
113 serial_line.flush_output();
117 if (listener != null) {
118 Runnable r = new Runnable() {
121 listener.actionPerformed(new ActionEvent(this,
124 } catch (Exception ex) {
128 SwingUtilities.invokeLater(r);
132 public void start() {
133 eeprom_thread = new Thread(this);
134 eeprom_thread.start();
137 public void addActionListener(ActionListener l) {
141 public AltosEepromDelete(JFrame given_frame,
142 AltosSerial given_serial_line,
143 boolean given_remote,
144 AltosEepromList given_flights) {
146 serial_line = given_serial_line;
147 remote = given_remote;
148 flights = given_flights;