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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_12;
21 import java.awt.event.*;
24 import java.util.concurrent.*;
25 import org.altusmetrum.altoslib_12.*;
27 public class AltosEepromDelete implements Runnable {
28 AltosEepromList flights;
30 AltosSerial serial_line;
33 ActionListener listener;
36 private void DeleteLog (AltosEepromLog log)
37 throws IOException, InterruptedException, TimeoutException {
39 if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) {
41 /* Devices with newer firmware can erase the
42 * flash blocks containing each flight
44 serial_line.flush_input();
45 serial_line.printf("d %d\n", log.flight);
47 /* It can take a while to erase the flash... */
48 String line = serial_line.get_reply(20000);
50 throw new TimeoutException();
51 if (line.equals("Erased"))
53 if (line.startsWith("No such"))
54 throw new IOException(line);
59 private void show_error_internal(String message, String title) {
60 JOptionPane.showMessageDialog(frame,
63 JOptionPane.ERROR_MESSAGE);
66 private void show_error(String in_message, String in_title) {
67 final String message = in_message;
68 final String title = in_title;
69 Runnable r = new Runnable() {
72 show_error_internal(message, title);
73 } catch (Exception ex) {
77 SwingUtilities.invokeLater(r);
84 serial_line.start_remote();
86 for (AltosEepromLog log : flights) {
87 if (log.delete_selected) {
92 } catch (IOException ee) {
93 show_error (ee.getLocalizedMessage(),
94 serial_line.device.toShortString());
95 } catch (InterruptedException ie) {
96 } catch (TimeoutException te) {
97 show_error (String.format("Connection to \"%s\" failed",
98 serial_line.device.toShortString()),
103 serial_line.stop_remote();
104 } catch (InterruptedException ie) {
106 serial_line.flush_output();
110 if (listener != null) {
111 Runnable r = new Runnable() {
114 listener.actionPerformed(new ActionEvent(this,
117 } catch (Exception ex) {
121 SwingUtilities.invokeLater(r);
125 public void start() {
126 eeprom_thread = new Thread(this);
127 eeprom_thread.start();
130 public void addActionListener(ActionListener l) {
134 public AltosEepromDelete(JFrame given_frame,
135 AltosSerial given_serial_line,
136 boolean given_remote,
137 AltosEepromList given_flights) {
139 serial_line = given_serial_line;
140 remote = given_remote;
141 flights = given_flights;