altoslib: Raise ParseException on invalid eeprom format
authorKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 05:03:42 +0000 (14:03 +0900)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 05:03:42 +0000 (14:03 +0900)
Make sure the user knows when data are not downloaded successfully
because the UI doesn't understand the eeprom format.

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

index 48d29e1b603e9a9d8fdf558602e226d2495d7e3a..c03fa931fdc0f230b307e97d726b4ea31570e23f 100644 (file)
@@ -62,31 +62,30 @@ public class AltosEepromChunk {
                return true;
        }
 
                return true;
        }
 
-       public AltosEeprom eeprom(int offset, int log_format, AltosState state) {
+       public AltosEeprom eeprom(int offset, int log_format, AltosState state) throws ParseException {
                AltosEeprom     eeprom = null;
                AltosEeprom     eeprom = null;
-               try {
-                       switch (log_format) {
-                       case AltosLib.AO_LOG_FORMAT_FULL:
-                               eeprom = new AltosEepromTM(this, offset);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TINY:
-                               eeprom = new AltosEepromTm(this, offset, state);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMETRY:
-                       case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMEGA:
-                               eeprom = new AltosEepromMega(this, offset);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
-                               eeprom = new AltosEepromMetrum2(this, offset);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMINI:
-                       case AltosLib.AO_LOG_FORMAT_EASYMINI:
-                               eeprom = new AltosEepromMini(this, offset);
-                               break;
-                       }
-               } catch (ParseException e) {
+               switch (log_format) {
+               case AltosLib.AO_LOG_FORMAT_FULL:
+                       eeprom = new AltosEepromTM(this, offset);
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TINY:
+                       eeprom = new AltosEepromTm(this, offset, state);
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMETRY:
+               case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMEGA:
+                       eeprom = new AltosEepromMega(this, offset);
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
+                       eeprom = new AltosEepromMetrum2(this, offset);
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMINI:
+               case AltosLib.AO_LOG_FORMAT_EASYMINI:
+                       eeprom = new AltosEepromMini(this, offset);
+                       break;
+               default:
+                       throw new ParseException("unknown eeprom format " + log_format, 0);
                }
                return eeprom;
        }
                }
                return eeprom;
        }
index 6e2fd061b1cbef6afe1f6ef223a118b95a57782c..7ccf26a5e359622463b6a8799b8f768cf23eaa54 100644 (file)
@@ -92,7 +92,7 @@ public class AltosEepromDownload implements Runnable {
                }
        }
 
                }
        }
 
-       void CaptureEeprom(AltosEepromChunk eechunk, int log_format) throws IOException {
+       void CaptureEeprom(AltosEepromChunk eechunk, int log_format) throws IOException, ParseException {
                boolean any_valid = false;
                boolean got_flight = false;
 
                boolean any_valid = false;
                boolean got_flight = false;
 
@@ -138,7 +138,7 @@ public class AltosEepromDownload implements Runnable {
                CheckFile(false);
        }
        
                CheckFile(false);
        }
        
-       void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException {
+       void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException, ParseException {
                int                     block, state_block = 0;
                int                     log_format = flights.config_data.log_format;
 
                int                     block, state_block = 0;
                int                     log_format = flights.config_data.log_format;
 
@@ -222,7 +222,11 @@ public class AltosEepromDownload implements Runnable {
                                parse_exception = null;
                                if (log.selected) {
                                        monitor.reset();
                                parse_exception = null;
                                if (log.selected) {
                                        monitor.reset();
-                                       CaptureLog(log);
+                                       try {
+                                               CaptureLog(log);
+                                       } catch (ParseException e) {
+                                               parse_exception = e;
+                                       }
                                }
                                if (parse_exception != null) {
                                        failed = true;
                                }
                                if (parse_exception != null) {
                                        failed = true;