X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosEepromDownload.java;h=a3c15112318c7cae3c4503ba3ce1d50849190c95;hp=8a2053ecd4a8ae809a293354dd220e8cec1ca778;hb=HEAD;hpb=222158581887b5f9e8b9843d14321c313fa023fa diff --git a/altoslib/AltosEepromDownload.java b/altoslib/AltosEepromDownload.java index 8a2053ec..a3c15112 100644 --- a/altoslib/AltosEepromDownload.java +++ b/altoslib/AltosEepromDownload.java @@ -16,7 +16,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_14; import java.io.*; import java.util.*; @@ -26,6 +26,8 @@ import java.util.concurrent.*; class AltosEepromNameData extends AltosDataListener { AltosGPS gps = null; + boolean avoid_duplicate_files = false; + public void set_rssi(int rssi, int status) { } public void set_received_time(long received_time) { } @@ -39,7 +41,12 @@ class AltosEepromNameData extends AltosDataListener { public void set_apogee_voltage(double volts) { } public void set_main_voltage(double volts) { } - public void set_gps(AltosGPS gps) { + public void set_avoid_duplicate_files() { + avoid_duplicate_files = true; + } + + public void set_gps(AltosGPS gps, boolean set_location, boolean set_sats) { + super.set_gps(gps, set_location, set_sats); if (gps != null && gps.year != AltosLib.MISSING && gps.month != AltosLib.MISSING && @@ -64,6 +71,7 @@ class AltosEepromNameData extends AltosDataListener { public void set_companion(AltosCompanion companion) { } public void set_kalman(double height, double speed, double acceleration) { } public void set_orient(double new_orient) { } + public void set_motor_pressure(double motor_pressure) { } public AltosEepromNameData(AltosCalData cal_data) { super(cal_data); @@ -95,12 +103,19 @@ public class AltosEepromDownload implements Runnable { private AltosFile MakeFile(int serial, int flight, AltosEepromNameData name_data) throws IOException { AltosFile eeprom_name; - if (name_data.gps != null) { - AltosGPS gps = name_data.gps; - eeprom_name = new AltosFile(gps.year, gps.month, gps.day, - serial, flight, "eeprom"); - } else - eeprom_name = new AltosFile(serial, flight, "eeprom"); + for (;;) { + if (name_data.gps != null) { + AltosGPS gps = name_data.gps; + eeprom_name = new AltosFile(gps.year, gps.month, gps.day, + serial, flight, "eeprom"); + } else + eeprom_name = new AltosFile(serial, flight, "eeprom"); + if (!name_data.avoid_duplicate_files) + break; + if (!eeprom_name.exists()) + break; + flight++; + } return eeprom_name; } @@ -181,7 +196,7 @@ public class AltosEepromDownload implements Runnable { } /* Construct our internal representation of the eeprom data */ - AltosEepromNew eeprom = new AltosEepromNew(flights.config_data, data); + AltosEeprom eeprom = new AltosEeprom(flights.config_data, data); /* Now see if we can't actually parse the resulting * file to generate a better filename. Note that this @@ -199,25 +214,47 @@ public class AltosEepromDownload implements Runnable { AltosFile f = MakeFile(flights.config_data.serial, log.flight, name_data); - monitor.set_filename(f.toString()); + log.set_file(f); + + boolean do_write = true; + + if (f.exists()) + do_write = monitor.check_overwrite(f); - FileWriter w = new FileWriter(f); + if (do_write) { + FileWriter w = new FileWriter(f); + + eeprom.write(w); + w.close(); + } + + if (eeprom.errors != 0) + throw new ParseException(String.format("%d CRC Errors", eeprom.errors), 0); + } + + static String label(int flight) { + if (flight < 0) + return "Corrupt"; + else + return "Flight"; + } - eeprom.write(w); - w.close(); + static int flight(int flight) { + if (flight < 0) + return -flight; + return flight; } public void run () { boolean success = false; try { - boolean failed = false; if (remote) link.start_remote(); for (AltosEepromLog log : flights) { parse_errors = null; - if (log.selected) { + if (log.download_selected) { monitor.reset(); try { CaptureLog(log); @@ -225,16 +262,16 @@ public class AltosEepromDownload implements Runnable { LogError(e.getMessage()); } } + success = true; if (parse_errors != null) { - failed = true; - monitor.show_message(String.format("Flight %d download error. Valid log data saved\n%s", - log.flight, + monitor.show_message(String.format("%s %d download error. Valid log data saved\n%s", + label(log.flight), + flight(log.flight), parse_errors), link.name, AltosEepromMonitor.WARNING_MESSAGE); } } - success = !failed; } catch (IOException ee) { monitor.show_message(ee.getLocalizedMessage(), link.name,