X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosEepromDownload.java;h=280414f8e9a32d5b81906ec50a7fd6b73c527519;hp=74912ed4bac7218b8d9a2462360e4e8c1acc32dc;hb=06b1fc72c8a694b3295262f1e0b50e8c88c53585;hpb=17e20a6d2dab1f4bd1375bfd9e1c5230ee2c1119 diff --git a/altoslib/AltosEepromDownload.java b/altoslib/AltosEepromDownload.java index 74912ed4..280414f8 100644 --- a/altoslib/AltosEepromDownload.java +++ b/altoslib/AltosEepromDownload.java @@ -16,13 +16,61 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_13; import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; +class AltosEepromNameData extends AltosDataListener { + AltosGPS gps = null; + + public void set_rssi(int rssi, int status) { } + public void set_received_time(long received_time) { } + + public void set_acceleration(double accel) { } + public void set_pressure(double pa) { } + public void set_thrust(double N) { } + + public void set_temperature(double deg_c) { } + public void set_battery_voltage(double volts) { } + + public void set_apogee_voltage(double volts) { } + public void set_main_voltage(double volts) { } + + public void set_gps(AltosGPS gps) { + super.set_gps(gps); + if (gps != null && + gps.year != AltosLib.MISSING && + gps.month != AltosLib.MISSING && + gps.day != AltosLib.MISSING) { + this.gps = gps; + } + } + + public boolean done() { + if (gps == null) + return false; + return true; + } + + public void set_gyro(double roll, double pitch, double yaw) { } + public void set_accel_ground(double along, double across, double through) { } + public void set_accel(double along, double across, double through) { } + public void set_mag(double along, double across, double through) { } + public void set_pyro_voltage(double volts) { } + public void set_igniter_voltage(double[] voltage) { } + public void set_pyro_fired(int pyro_mask) { } + public void set_companion(AltosCompanion companion) { } + public void set_kalman(double height, double speed, double acceleration) { } + public void set_orient(double new_orient) { } + + public AltosEepromNameData(AltosCalData cal_data) { + super(cal_data); + } +} + public class AltosEepromDownload implements Runnable { AltosLink link; @@ -45,11 +93,11 @@ public class AltosEepromDownload implements Runnable { gps.day != AltosLib.MISSING; } - private AltosFile MakeFile(int serial, int flight, AltosState state) throws IOException { + private AltosFile MakeFile(int serial, int flight, AltosEepromNameData name_data) throws IOException { AltosFile eeprom_name; - if (has_gps_date(state)) { - AltosGPS gps = state.gps; + if (name_data.gps != null) { + AltosGPS gps = name_data.gps; eeprom_name = new AltosFile(gps.year, gps.month, gps.day, serial, flight, "eeprom"); } else @@ -134,44 +182,65 @@ 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 * doesn't need to work; we'll still save the data using * a less accurate name. */ - AltosEepromRecordSet set = new AltosEepromRecordSet(eeprom); - - AltosState state = new AltosState(); + AltosEepromRecordSet set = new AltosEepromRecordSet(eeprom); + AltosEepromNameData name_data = new AltosEepromNameData(set.cal_data()); - for (AltosState s : set) { - state = s; - if (state.gps != null) + for (AltosEepromRecord record : set.ordered) { + record.provide_data(name_data, set.cal_data()); + if (name_data.done()) break; } - AltosFile f = MakeFile(flights.config_data.serial, log.flight, state); + AltosFile f = MakeFile(flights.config_data.serial, log.flight, name_data); + + log.set_file(f); + + boolean do_write = true; + + if (f.exists()) + do_write = monitor.check_overwrite(f); - monitor.set_filename(f.toString()); + if (do_write) { + FileWriter w = new FileWriter(f); - 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); @@ -179,16 +248,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,