From 0093d5b368669e0c324f8d9dfcd2f004de85ee5c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 12 Nov 2013 14:37:57 +0900 Subject: [PATCH 1/1] altosui, altoslib: Move eeprom download code to altoslib This should make adding eeprom downloading to altosdroid easier Signed-off-by: Keith Packard --- .../AltosEepromDownload.java | 39 +++++++++---------- {altosui => altoslib}/AltosEepromList.java | 21 +++++----- altoslib/Makefile.am | 4 +- altosui/Makefile.am | 2 - altosuilib/Makefile.am | 2 +- 5 files changed, 33 insertions(+), 35 deletions(-) rename {altosui => altoslib}/AltosEepromDownload.java (87%) rename {altosui => altoslib}/AltosEepromList.java (88%) diff --git a/altosui/AltosEepromDownload.java b/altoslib/AltosEepromDownload.java similarity index 87% rename from altosui/AltosEepromDownload.java rename to altoslib/AltosEepromDownload.java index 6ce420d3..542defee 100644 --- a/altosui/AltosEepromDownload.java +++ b/altoslib/AltosEepromDownload.java @@ -15,17 +15,16 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_2.*; public class AltosEepromDownload implements Runnable { - AltosSerial serial_line; + AltosLink link; boolean remote; Thread eeprom_thread; AltosEepromMonitor monitor; @@ -79,7 +78,7 @@ public class AltosEepromDownload implements Runnable { boolean start; void LogEeprom(AltosEeprom r) throws IOException { - if (r.cmd != Altos.AO_LOG_INVALID) { + if (r.cmd != AltosLib.AO_LOG_INVALID) { String line = r.string(); if (eeprom_file != null) eeprom_file.write(line); @@ -114,7 +113,7 @@ public class AltosEepromDownload implements Runnable { if (state.state != AltosLib.ao_flight_invalid && state.state <= AltosLib.ao_flight_landed) { - if (state.state > Altos.ao_flight_pad) + if (state.state > AltosLib.ao_flight_pad) want_file = true; if (state.state == AltosLib.ao_flight_landed) done = true; @@ -161,19 +160,19 @@ public class AltosEepromDownload implements Runnable { block - state_block, block - log.start_block); - AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block); + AltosEepromChunk eechunk = new AltosEepromChunk(link, block, block == log.start_block); /* * Guess what kind of data is there if the device * didn't tell us */ - if (log_format == Altos.AO_LOG_FORMAT_UNKNOWN) { + if (log_format == AltosLib.AO_LOG_FORMAT_UNKNOWN) { if (block == log.start_block) { - if (eechunk.data(0) == Altos.AO_LOG_FLIGHT) - log_format = Altos.AO_LOG_FORMAT_FULL; + if (eechunk.data(0) == AltosLib.AO_LOG_FLIGHT) + log_format = AltosLib.AO_LOG_FORMAT_FULL; else - log_format = Altos.AO_LOG_FORMAT_TINY; + log_format = AltosLib.AO_LOG_FORMAT_TINY; } } @@ -190,7 +189,7 @@ public class AltosEepromDownload implements Runnable { try { boolean failed = false; if (remote) - serial_line.start_remote(); + link.start_remote(); for (AltosEepromLog log : flights) { parse_exception = null; @@ -207,33 +206,33 @@ public class AltosEepromDownload implements Runnable { monitor.show_message(String.format("Flight %d download error\n%s\nValid log data saved", log.flight, parse_exception.getMessage()), - serial_line.device.toShortString(), + link.name, AltosEepromMonitor.WARNING_MESSAGE); } } success = !failed; } catch (IOException ee) { monitor.show_message(ee.getLocalizedMessage(), - serial_line.device.toShortString(), + link.name, AltosEepromMonitor.ERROR_MESSAGE); } catch (InterruptedException ie) { monitor.show_message(String.format("Connection to \"%s\" interrupted", - serial_line.device.toShortString()), + link.name), "Connection Interrupted", AltosEepromMonitor.ERROR_MESSAGE); } catch (TimeoutException te) { monitor.show_message(String.format("Connection to \"%s\" failed", - serial_line.device.toShortString()), + link.name), "Connection Failed", AltosEepromMonitor.ERROR_MESSAGE); } finally { if (remote) { try { - serial_line.stop_remote(); + link.stop_remote(); } catch (InterruptedException ie) { } } - serial_line.flush_output(); + link.flush_output(); } monitor.done(success); } @@ -244,17 +243,17 @@ public class AltosEepromDownload implements Runnable { } public AltosEepromDownload(AltosEepromMonitor given_monitor, - AltosSerial given_serial_line, + AltosLink given_link, boolean given_remote, AltosEepromList given_flights) { monitor = given_monitor; - serial_line = given_serial_line; + link = given_link; remote = given_remote; flights = given_flights; success = false; - monitor.set_states(Altos.ao_flight_boost, Altos.ao_flight_landed); + monitor.set_states(AltosLib.ao_flight_boost, AltosLib.ao_flight_landed); monitor.set_thread(eeprom_thread); monitor.start(); diff --git a/altosui/AltosEepromList.java b/altoslib/AltosEepromList.java similarity index 88% rename from altosui/AltosEepromList.java rename to altoslib/AltosEepromList.java index 258c421a..763bd1e2 100644 --- a/altosui/AltosEepromList.java +++ b/altoslib/AltosEepromList.java @@ -15,13 +15,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_2.*; /* * Temporary structure to hold the list of stored flights; @@ -46,15 +45,15 @@ class AltosEepromFlight { */ public class AltosEepromList extends ArrayList { - AltosConfigData config_data; + public AltosConfigData config_data; - public AltosEepromList (AltosSerial serial_line, boolean remote) + public AltosEepromList (AltosLink link, boolean remote) throws IOException, InterruptedException, TimeoutException { try { if (remote) - serial_line.start_remote(); - config_data = new AltosConfigData (serial_line); + link.start_remote(); + config_data = new AltosConfigData (link); // if (config_data.serial == 0) // throw new IOException("no serial number found"); @@ -66,9 +65,9 @@ public class AltosEepromList extends ArrayList { * command which will list the region of storage * occupied by each available flight */ - serial_line.printf("l\n"); + link.printf("l\n"); for (;;) { - String line = serial_line.get_reply(5000); + String line = link.get_reply(5000); if (line == null) throw new TimeoutException(); if (line.contains("done")) @@ -106,13 +105,13 @@ public class AltosEepromList extends ArrayList { * firmware, this will also extract the flight number. */ for (AltosEepromFlight flight : flights) { - add(new AltosEepromLog(config_data, serial_line, + add(new AltosEepromLog(config_data, link, flight.flight, flight.start, flight.end)); } } finally { if (remote) - serial_line.stop_remote(); - serial_line.flush_output(); + link.stop_remote(); + link.flush_output(); } } } \ No newline at end of file diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 2cf7b63d..6d3f3fc4 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -1,4 +1,4 @@ -AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation +AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation -source 6 JAVAROOT=bin @@ -34,11 +34,13 @@ altoslib_JAVA = \ AltosDebug.java \ AltosEeprom.java \ AltosEepromChunk.java \ + AltosEepromDownload.java \ AltosEepromFile.java \ AltosEepromTM.java \ AltosEepromTm.java \ AltosEepromHeader.java \ AltosEepromIterable.java \ + AltosEepromList.java \ AltosEepromLog.java \ AltosEepromMega.java \ AltosEepromMetrum2.java \ diff --git a/altosui/Makefile.am b/altosui/Makefile.am index b51f8112..e103d289 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -34,8 +34,6 @@ altosui_JAVA = \ AltosDeviceUIDialog.java \ AltosDisplayThread.java \ AltosEepromDelete.java \ - AltosEepromDownload.java \ - AltosEepromList.java \ AltosEepromManage.java \ AltosEepromMonitorUI.java \ AltosEepromSelect.java \ diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index 0cd2aaea..5e19e00f 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -1,4 +1,4 @@ -AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation +AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation -source 6 JAVAROOT=bin -- 2.30.2