AltosEepromMonitor monitor;
int flight;
+ int serial;
int year, month, day;
boolean want_file;
FileWriter eeprom_file;
ActionListener listener;
boolean success;
ParseException parse_exception;
+ String extension;
private void FlushPending() throws IOException {
for (String s : flights.config_data) {
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) {
}
}
+ 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) {
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;
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 {
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;
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;
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);
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()),
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
* 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 {
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 {
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;
}
}
}
--- /dev/null
+/*
+ * 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);
+ }
+}
AltosEepromMonitor.java \
AltosEepromIterable.java \
AltosEepromRecord.java \
+ AltosEepromTeleScience.java \
AltosEepromSelect.java \
AltosFile.java \
AltosFlash.java \