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.
20 import java.awt.event.*;
23 import java.util.concurrent.*;
24 import org.altusmetrum.altoslib_1.*;
26 public class AltosEepromDelete implements Runnable {
27 AltosEepromList flights;
29 AltosSerial serial_line;
32 ActionListener listener;
35 private void DeleteLog (AltosEepromLog log)
36 throws IOException, InterruptedException, TimeoutException {
38 if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) {
40 /* Devices with newer firmware can erase the
41 * flash blocks containing each flight
43 serial_line.flush_input();
44 serial_line.printf("d %d\n", log.flight);
46 /* It can take a while to erase the flash... */
47 String line = serial_line.get_reply(20000);
49 throw new TimeoutException();
50 if (line.equals("Erased"))
52 if (line.startsWith("No such"))
53 throw new IOException(line);
58 private void show_error_internal(String message, String title) {
59 JOptionPane.showMessageDialog(frame,
62 JOptionPane.ERROR_MESSAGE);
65 private void show_error(String in_message, String in_title) {
66 final String message = in_message;
67 final String title = in_title;
68 Runnable r = new Runnable() {
71 show_error_internal(message, title);
72 } catch (Exception ex) {
76 SwingUtilities.invokeLater(r);
83 serial_line.start_remote();
85 for (AltosEepromLog log : flights) {
91 } catch (IOException ee) {
92 show_error (ee.getLocalizedMessage(),
93 serial_line.device.toShortString());
94 } catch (InterruptedException ie) {
95 } catch (TimeoutException te) {
96 show_error (String.format("Connection to \"%s\" failed",
97 serial_line.device.toShortString()),
102 serial_line.stop_remote();
103 } catch (InterruptedException ie) {
105 serial_line.flush_output();
109 if (listener != null) {
110 Runnable r = new Runnable() {
113 listener.actionPerformed(new ActionEvent(this,
116 } catch (Exception ex) {
120 SwingUtilities.invokeLater(r);
124 public void start() {
125 eeprom_thread = new Thread(this);
126 eeprom_thread.start();
129 public void addActionListener(ActionListener l) {
133 public AltosEepromDelete(JFrame given_frame,
134 AltosSerial given_serial_line,
135 boolean given_remote,
136 AltosEepromList given_flights) {
138 serial_line = given_serial_line;
139 remote = given_remote;
140 flights = given_flights;