diff options
| -rw-r--r-- | altosui/AltosEepromDownload.java | 95 | ||||
| -rw-r--r-- | altosui/AltosEepromList.java | 4 | ||||
| -rw-r--r-- | altosui/AltosEepromLog.java | 65 | ||||
| -rw-r--r-- | altosui/AltosEepromTeleScience.java | 64 | ||||
| -rw-r--r-- | altosui/Makefile.am | 1 | 
5 files changed, 188 insertions, 41 deletions
diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 417aab00..6112a3b1 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -39,6 +39,7 @@ public class AltosEepromDownload implements Runnable {  	AltosEepromMonitor	monitor;  	int			flight; +	int			serial;  	int			year, month, day;  	boolean			want_file;  	FileWriter		eeprom_file; @@ -48,6 +49,7 @@ public class AltosEepromDownload implements Runnable {  	ActionListener		listener;  	boolean			success;  	ParseException		parse_exception; +	String			extension;  	private void FlushPending() throws IOException {  		for (String s : flights.config_data) { @@ -64,10 +66,13 @@ public class AltosEepromDownload implements Runnable {  			return;  		if (force || (flight != 0 && want_file)) {  			AltosFile		eeprom_name; + +			if (extension == null) +				extension = "data";  			if (year != 0 && month != 0 && day != 0) -				eeprom_name = new AltosFile(year, month, day, flights.config_data.serial, flight, "eeprom"); +				eeprom_name = new AltosFile(year, month, day, serial, flight, extension);  			else -				eeprom_name = new AltosFile(flights.config_data.serial, flight, "eeprom"); +				eeprom_name = new AltosFile(serial, flight, extension);  			eeprom_file = new FileWriter(eeprom_name);  			if (eeprom_file != null) { @@ -89,18 +94,29 @@ public class AltosEepromDownload implements Runnable {  		}  	} +	void set_serial(int in_serial) { +		serial = in_serial; +		monitor.set_serial(serial); +	} + +	void set_flight(int in_flight) { +		flight = in_flight; +		monitor.set_flight(flight); +	} +		  	boolean			done;  	int			state;  	void CaptureFull(AltosEepromChunk eechunk) throws IOException {  		boolean	any_valid = false; + +		extension = "eeprom"; +		set_serial(flights.config_data.serial);  		for (int i = 0; i < eechunk.chunk_size && !done; i += AltosEepromRecord.record_length) {  			try {  				AltosEepromRecord r = new AltosEepromRecord(eechunk, i); -				if (r.cmd == Altos.AO_LOG_FLIGHT) { -					flight = r.b; -					monitor.set_flight(flight); -				} +				if (r.cmd == Altos.AO_LOG_FLIGHT) +					set_flight(r.b);  				/* Monitor state transitions to update display */  				if (r.cmd == Altos.AO_LOG_STATE && r.a <= Altos.ao_flight_landed) { @@ -137,6 +153,8 @@ public class AltosEepromDownload implements Runnable {  	void CaptureTiny (AltosEepromChunk eechunk) throws IOException {  		boolean any_valid = false; +		extension = "eeprom"; +		set_serial(flights.config_data.serial);  		for (int i = 0; i < eechunk.data.length && !done; i += 2) {  			int			v = eechunk.data16(i);  			AltosEepromRecord	r; @@ -144,8 +162,7 @@ public class AltosEepromDownload implements Runnable {  			if (i == 0 && start) {  				tiny_tick = 0;  				start = false; -				flight = v; -				monitor.set_flight(flight); +				set_flight(v);  				r = new AltosEepromRecord(Altos.AO_LOG_FLIGHT, tiny_tick, 0, v);  				any_valid = true;  			} else { @@ -181,6 +198,56 @@ public class AltosEepromDownload implements Runnable {  			done = true;  	} +	void LogTeleScience(AltosEepromTeleScience r) throws IOException { +		if (r.type != Altos.AO_LOG_INVALID) { +			String log_line = String.format("%c %4x %4x %d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", +							r.type, r.tick, r.tm_tick, r.tm_state, +							r.data[0], r.data[1], r.data[2], r.data[3],  +							r.data[4], r.data[5], r.data[6], r.data[7],  +							r.data[8], r.data[9], r.data[10], r.data[11]); +			if (eeprom_file != null) +				eeprom_file.write(log_line); +			else +				eeprom_pending.add(log_line); +		} +	} +	 +	boolean	telescience_start; + +	void CaptureTeleScience (AltosEepromChunk eechunk) throws IOException { +		boolean	any_valid = false; + +		extension = "science"; +		for (int i = 0; i < eechunk.chunk_size && !done; i += AltosEepromTeleScience.record_length) { +			try { +				AltosEepromTeleScience r = new AltosEepromTeleScience(eechunk, i); +				if (r.type == AltosEepromTeleScience.AO_LOG_TELESCIENCE_START) { +					if (telescience_start) { +						done = true; +						break; +					} +					set_serial(r.data[0]); +					set_flight(r.data[1]); +					telescience_start = true; +				} else { +					if (!telescience_start) +						break; +				} +				state = r.tm_state; +				want_file =true; +				any_valid = true; +				LogTeleScience(r); +			} catch (ParseException pe) { +				if (parse_exception == null) +					parse_exception = pe; +			} +		} + +		CheckFile(false); +		if (!any_valid) +			done = true; +	} +  	void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException {  		int			block, state_block = 0;  		int			log_format = flights.config_data.log_format; @@ -202,7 +269,6 @@ public class AltosEepromDownload implements Runnable {  		eeprom_pending = new LinkedList<String>();  		/* Set serial number in the monitor dialog window */ -		monitor.set_serial(flights.config_data.serial);  		/* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */  		state = 0; state_block = log.start_block; @@ -227,11 +293,21 @@ public class AltosEepromDownload implements Runnable {  			switch (log_format) {  			case Altos.AO_LOG_FORMAT_FULL: +				extension = "eeprom";  				CaptureFull(eechunk);  				break;  			case Altos.AO_LOG_FORMAT_TINY: +				extension = "eeprom";  				CaptureTiny(eechunk);  				break; +//			case Altos.AO_LOG_FORMAT_TELEMETRY: +//				extension = "telem"; +//				CaptureTelemetry(eechunk); +//				break; +			case Altos.AO_LOG_FORMAT_TELESCIENCE: +				extension = "science"; +				CaptureTeleScience(eechunk); +				break;  			}  		}  		CheckFile(true); @@ -290,6 +366,7 @@ public class AltosEepromDownload implements Runnable {  				     serial_line.device.toShortString(),  				     JOptionPane.ERROR_MESSAGE);  		} catch (InterruptedException ie) { +			System.out.printf("download interrupted\n");  		} catch (TimeoutException te) {  			show_message(String.format("Connection to \"%s\" failed",  						   serial_line.device.toShortString()), diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java index 185fec91..da4b1166 100644 --- a/altosui/AltosEepromList.java +++ b/altosui/AltosEepromList.java @@ -67,7 +67,7 @@ public class AltosEepromList extends ArrayList<AltosEepromLog> {  			ArrayList<AltosEepromFlight> flights = new ArrayList<AltosEepromFlight>(); -			if (config_data.flight_log_max != 0) { +			if (config_data.flight_log_max != 0 || config_data.log_format != 0) {  				/* Devices with newer firmware will support the 'l'  				 * command which will list the region of storage @@ -113,7 +113,7 @@ public class AltosEepromList extends ArrayList<AltosEepromLog> {  			 * firmware, this will also extract the flight number.  			 */  			for (AltosEepromFlight flight : flights) { -				add(new AltosEepromLog(serial_line, config_data.serial, +				add(new AltosEepromLog(config_data, serial_line,  						       flight.flight, flight.start, flight.end));  			}  		} finally { diff --git a/altosui/AltosEepromLog.java b/altosui/AltosEepromLog.java index 0cf420d9..be2549cb 100644 --- a/altosui/AltosEepromLog.java +++ b/altosui/AltosEepromLog.java @@ -46,7 +46,8 @@ public class AltosEepromLog {  	boolean		download;  	boolean		delete; -	public AltosEepromLog(AltosSerial serial_line, int in_serial, +	public AltosEepromLog(AltosConfigData config_data, +			      AltosSerial serial_line,  			      int in_flight, int in_start_block,  			      int in_end_block)  		throws InterruptedException, TimeoutException { @@ -54,51 +55,55 @@ public class AltosEepromLog {  		int		block;  		boolean		has_date = false; +		flight = in_flight; +		if (flight != 0) +			has_flight = true;  		start_block = in_start_block;  		end_block = in_end_block; -		serial = in_serial; +		serial = config_data.serial;  		/*  		 * By default, request that every log be downloaded but not deleted  		 */  		download = true;  		delete = false; +  		/* -		 * Only look in the first two blocks so that this -		 * process doesn't take a long time +		 * Look in TeleMetrum log data for date  		 */ -		if (in_end_block > in_start_block + 2) -			in_end_block = in_start_block + 2; +		if (config_data.log_format == Altos.AO_LOG_FORMAT_UNKNOWN || +		    config_data.log_format == Altos.AO_LOG_FORMAT_FULL) +		{ +			/* +			 * Only look in the first two blocks so that this +			 * process doesn't take a long time +			 */ +			if (in_end_block > in_start_block + 2) +				in_end_block = in_start_block + 2; -		for (block = in_start_block; block < in_end_block; block++) { -			AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block); +			for (block = in_start_block; block < in_end_block; block++) { +				AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block); -			if (block == in_start_block) { -				if (eechunk.data16(0) == in_flight) { -					flight = in_flight; -					has_flight = true; -					break; -				} -			} -			for (int i = 0; i < eechunk.chunk_size; i += AltosEepromRecord.record_length) { -				try { -					AltosEepromRecord r = new AltosEepromRecord(eechunk, i); +				for (int i = 0; i < eechunk.chunk_size; i += AltosEepromRecord.record_length) { +					try { +						AltosEepromRecord r = new AltosEepromRecord(eechunk, i); -					if (r.cmd == Altos.AO_LOG_FLIGHT) { -						flight = r.b; -						has_flight = true; -					} -					if (r.cmd == Altos.AO_LOG_GPS_DATE) { -						year = 2000 + (r.a & 0xff); -						month = (r.a >> 8) & 0xff; -						day = (r.b & 0xff); -						has_date = true; +						if (r.cmd == Altos.AO_LOG_FLIGHT) { +							flight = r.b; +							has_flight = true; +						} +						if (r.cmd == Altos.AO_LOG_GPS_DATE) { +							year = 2000 + (r.a & 0xff); +							month = (r.a >> 8) & 0xff; +							day = (r.b & 0xff); +							has_date = true; +						} +					} catch (ParseException pe) {  					} -				} catch (ParseException pe) {  				} +				if (has_date && has_flight) +					break;  			} -			if (has_date && has_flight) -				break;  		}  	}  } diff --git a/altosui/AltosEepromTeleScience.java b/altosui/AltosEepromTeleScience.java new file mode 100644 index 00000000..ee1840b0 --- /dev/null +++ b/altosui/AltosEepromTeleScience.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2011 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.*; + +public class AltosEepromTeleScience { +	int	type; +	int	tick; +	int	tm_state; +	int	tm_tick; +	int[]	data; +	boolean	valid; + +	static final int AO_LOG_TELESCIENCE_START = 's'; +	static final int AO_LOG_TELESCIENCE_DATA = 'd'; + +	static final int	max_data = 12; +	static final int	record_length = 32; + +	public AltosEepromTeleScience (AltosEepromChunk chunk, int start) throws ParseException { +		type = chunk.data(start); + +		valid = !chunk.erased(start, record_length); +		if (valid) { +			if (AltosConvert.checksum(chunk.data, start, record_length) != 0) +				throw new ParseException(String.format("invalid checksum at 0x%x", +								       chunk.address + start), 0); +		} else { +			type = Altos.AO_LOG_INVALID; +		} + +		tick = chunk.data16(start+2); +		tm_tick = chunk.data16(start+4); +		tm_state = chunk.data(start+6); +		data = new int[max_data]; +		for (int i = 0; i < max_data; i++) +			data[i] = chunk.data16(start + 8 + i * 2); +	} +} diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 83510352..e4986ba5 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -45,6 +45,7 @@ altosui_JAVA = \  	AltosEepromMonitor.java \  	AltosEepromIterable.java \  	AltosEepromRecord.java \ +	AltosEepromTeleScience.java \  	AltosEepromSelect.java \  	AltosFile.java \  	AltosFlash.java \  | 
