altosui: Display eeprom parsing errors to user
authorKeith Packard <keithp@keithp.com>
Sat, 19 Feb 2011 09:06:01 +0000 (01:06 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 19 Feb 2011 09:11:53 +0000 (01:11 -0800)
When reading the eeprom, any parsing errors (most likely bad
checksums) indicate some kind of problem with either the hardware or
the flight software. Display these to the user and do not erase the
flight.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosEepromBlock.java
altosui/AltosEepromDownload.java

index 11438df8bf536d40ccc7061a002bf6852b3353c7..d59fd39e2bdf9b67951dd67e2a3e3a924966a861 100644 (file)
@@ -44,6 +44,7 @@ public class AltosEepromBlock extends ArrayList<AltosEepromRecord> {
        double  lon;
        boolean has_time;
        int     hour, minute, second;
        double  lon;
        boolean has_time;
        int     hour, minute, second;
+       ParseException  parse_exception = null;
 
        public AltosEepromBlock (AltosSerial serial_line, int block) throws TimeoutException, InterruptedException {
                int     addr;
 
        public AltosEepromBlock (AltosSerial serial_line, int block) throws TimeoutException, InterruptedException {
                int     addr;
@@ -100,6 +101,8 @@ public class AltosEepromBlock extends ArrayList<AltosEepromRecord> {
                        } catch (ParseException pe) {
                                AltosEepromRecord       r = new AltosEepromRecord(Altos.AO_LOG_INVALID,
                                                                                  0, 0, 0);
                        } catch (ParseException pe) {
                                AltosEepromRecord       r = new AltosEepromRecord(Altos.AO_LOG_INVALID,
                                                                                  0, 0, 0);
+                               if (parse_exception == null)
+                                       parse_exception = pe;
                                if (!done)
                                        add(addr/8, r);
                        }
                                if (!done)
                                        add(addr/8, r);
                        }
index f1abd50cd21b07ecf9dabc03259d1a9b5cfb8fdb..1da94a6769ca191a0b5e6eefa0149003e44a307d 100644 (file)
@@ -47,6 +47,7 @@ public class AltosEepromDownload implements Runnable {
        AltosEepromList         flights;
        ActionListener          listener;
        boolean                 success;
        AltosEepromList         flights;
        ActionListener          listener;
        boolean                 success;
+       ParseException          parse_exception;
 
        private void FlushPending() throws IOException {
                for (String s : flights.config_data) {
 
        private void FlushPending() throws IOException {
                for (String s : flights.config_data) {
@@ -128,17 +129,22 @@ public class AltosEepromDownload implements Runnable {
                                        state = eeblock.state;
                        }
 
                                        state = eeblock.state;
                        }
 
+                       if (parse_exception == null && eeblock.parse_exception != null)
+                               parse_exception = eeblock.parse_exception;
+
                        CheckFile(false);
 
                        for (record = 0; record < eeblock.size(); record++) {
                                AltosEepromRecord r = eeblock.get(record);
 
                        CheckFile(false);
 
                        for (record = 0; record < eeblock.size(); record++) {
                                AltosEepromRecord r = eeblock.get(record);
 
-                               String log_line = String.format("%c %4x %4x %4x\n",
-                                                               r.cmd, r.tick, r.a, r.b);
-                               if (eeprom_file != null)
-                                       eeprom_file.write(log_line);
-                               else
-                                       eeprom_pending.add(log_line);
+                               if (r.cmd != Altos.AO_LOG_INVALID) {
+                                       String log_line = String.format("%c %4x %4x %4x\n",
+                                                                       r.cmd, r.tick, r.a, r.b);
+                                       if (eeprom_file != null)
+                                               eeprom_file.write(log_line);
+                                       else
+                                               eeprom_pending.add(log_line);
+                               }
                        }
                }
                CheckFile(true);
                        }
                }
                CheckFile(true);
@@ -148,20 +154,21 @@ public class AltosEepromDownload implements Runnable {
                }
        }
 
                }
        }
 
-       private void show_error_internal(String message, String title) {
+       private void show_message_internal(String message, String title, int message_type) {
                JOptionPane.showMessageDialog(frame,
                                              message,
                                              title,
                JOptionPane.showMessageDialog(frame,
                                              message,
                                              title,
-                                             JOptionPane.ERROR_MESSAGE);
+                                             message_type);
        }
 
        }
 
-       private void show_error(String in_message, String in_title) {
+       private void show_message(String in_message, String in_title, int in_message_type) {
                final String message = in_message;
                final String title = in_title;
                final String message = in_message;
                final String title = in_title;
+               final int message_type = in_message_type;
                Runnable r = new Runnable() {
                                public void run() {
                                        try {
                Runnable r = new Runnable() {
                                public void run() {
                                        try {
-                                               show_error_internal(message, title);
+                                               show_message_internal(message, title, message_type);
                                        } catch (Exception ex) {
                                        }
                                }
                                        } catch (Exception ex) {
                                        }
                                }
@@ -174,21 +181,33 @@ public class AltosEepromDownload implements Runnable {
                        serial_line.start_remote();
 
                try {
                        serial_line.start_remote();
 
                try {
+                       boolean failed = false;
                        for (AltosEepromLog log : flights) {
                        for (AltosEepromLog log : flights) {
+                               parse_exception = null;
                                if (log.download) {
                                        monitor.reset();
                                        CaptureLog(log);
                                }
                                if (log.download) {
                                        monitor.reset();
                                        CaptureLog(log);
                                }
+                               if (parse_exception != null) {
+                                       failed = true;
+                                       show_message(String.format("Flight %d download error\n%s\nValid log data saved",
+                                                                  log.flight,
+                                                                  parse_exception.getMessage()),
+                                                    serial_line.device.toShortString(),
+                                                    JOptionPane.WARNING_MESSAGE);
+                               }
                        }
                        }
-                       success = true;
+                       success = !failed;
                } catch (IOException ee) {
                } catch (IOException ee) {
-                       show_error (serial_line.device.toShortString(),
-                                   ee.getLocalizedMessage());
+                       show_message(ee.getLocalizedMessage(),
+                                    serial_line.device.toShortString(),
+                                    JOptionPane.ERROR_MESSAGE);
                } catch (InterruptedException ie) {
                } catch (TimeoutException te) {
                } catch (InterruptedException ie) {
                } catch (TimeoutException te) {
-                       show_error (String.format("Connection to \"%s\" failed",
-                                                 serial_line.device.toShortString()),
-                                   "Connection Failed");
+                       show_message(String.format("Connection to \"%s\" failed",
+                                                  serial_line.device.toShortString()),
+                                    "Connection Failed",
+                                    JOptionPane.ERROR_MESSAGE);
                }
                if (remote)
                        serial_line.stop_remote();
                }
                if (remote)
                        serial_line.stop_remote();