diff options
-rw-r--r-- | altosui/AltosEepromBlock.java | 24 | ||||
-rw-r--r-- | altosui/AltosEepromDownload.java | 13 | ||||
-rw-r--r-- | altosui/AltosEepromList.java | 103 | ||||
-rw-r--r-- | altosui/AltosEepromLog.java | 98 | ||||
-rw-r--r-- | altosui/AltosEepromRecord.java | 6 | ||||
-rw-r--r-- | altosui/AltosSerial.java | 10 | ||||
-rw-r--r-- | altosui/Makefile.am | 2 |
7 files changed, 247 insertions, 9 deletions
diff --git a/altosui/AltosEepromBlock.java b/altosui/AltosEepromBlock.java index 0c1a4a92..f223f3fb 100644 --- a/altosui/AltosEepromBlock.java +++ b/altosui/AltosEepromBlock.java @@ -38,6 +38,12 @@ public class AltosEepromBlock extends ArrayList<AltosEepromRecord> { int state; boolean has_date; int year, month, day; + boolean has_lat; + double lat; + boolean has_lon; + double lon; + boolean has_time; + int hour, minute, second; public AltosEepromBlock (AltosSerial serial_line, int block) throws TimeoutException, InterruptedException { int addr; @@ -46,6 +52,9 @@ public class AltosEepromBlock extends ArrayList<AltosEepromRecord> { has_flight = false; has_state = false; has_date = false; + has_lat = false; + has_lon = false; + has_time = false; serial_line.printf("e %x\n", block); for (addr = 0; !done && addr < 0x100;) { try { @@ -70,7 +79,20 @@ public class AltosEepromBlock extends ArrayList<AltosEepromRecord> { day = (r.b & 0xff); has_date = true; } - + if (r.cmd == Altos.AO_LOG_GPS_TIME) { + hour = (r.a & 0xff); + minute = (r.a >> 8); + second = (r.b & 0xff); + has_time = true; + } + if (r.cmd == Altos.AO_LOG_GPS_LAT) { + lat = (double) (r.a | (r.b << 16)) / 1e7; + has_lat = true; + } + if (r.cmd == Altos.AO_LOG_GPS_LON) { + lon = (double) (r.a | (r.b << 16)) / 1e7; + has_lon = true; + } if (r.cmd == Altos.AO_LOG_STATE && r.a == Altos.ao_flight_landed) done = true; add(addr / 8, r); diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 9a748710..ca31fdcf 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -161,11 +161,12 @@ public class AltosEepromDownload implements Runnable { int start_block, end_block; public void run () { - if (remote) { - serial_line.set_radio(); - serial_line.printf("p\nE 0\n"); - serial_line.flush_input(); - } + try { + new AltosEepromList(serial_line, remote); + } catch (Exception ee) { } + + if (remote) + serial_line.start_remote(); try { CaptureLog(start_block, end_block); @@ -179,7 +180,7 @@ public class AltosEepromDownload implements Runnable { "Connection Failed"); } if (remote) - serial_line.printf("~"); + serial_line.stop_remote(); monitor.done(); serial_line.flush_output(); serial_line.close(); diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java new file mode 100644 index 00000000..ac4a29de --- /dev/null +++ b/altosui/AltosEepromList.java @@ -0,0 +1,103 @@ +/* + * 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.*; + +import libaltosJNI.*; + +class AltosEepromFlight { + int flight; + int start; + int end; + + public AltosEepromFlight(int in_flight, int in_start, int in_end) { + flight = in_flight; + start = in_start; + end = in_end; + } +} + +public class AltosEepromList extends ArrayList<AltosEepromLog> { + AltosConfigData config_data; + + public AltosEepromList (AltosSerial serial_line, boolean remote) throws IOException, InterruptedException, TimeoutException { + try { + if (remote) + serial_line.start_remote(); + config_data = new AltosConfigData (serial_line); + if (config_data.serial == 0) + throw new IOException("no serial number found"); + + ArrayList<AltosEepromFlight> flights = new ArrayList<AltosEepromFlight>(); + if (config_data.flight_log_max != 0) { + serial_line.printf("l\n"); + for (;;) { + String line = serial_line.get_reply(5000); + if (line == null) + throw new TimeoutException(); + if (line.contains("done")) + break; + if (line.contains("Syntax")) + continue; + String[] tokens = line.split("\\s+"); + System.out.printf("got line %s (%d tokens)\n", line, tokens.length); + if (tokens.length < 6) + break; + + int flight = -1, start = -1, end = -1; + try { + if (tokens[0].equals("flight")) + flight = AltosParse.parse_int(tokens[1]); + if (tokens[2].equals("start")) + start = AltosParse.parse_hex(tokens[3]); + if (tokens[4].equals("end")) + end = AltosParse.parse_hex(tokens[5]); + System.out.printf("parsed flight %d %x %x\n", flight, start, end); + if (flight > 0 && start >= 0 && end > 0) + flights.add(new AltosEepromFlight(flight, start, end)); + } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); } + } + } else { + flights.add(new AltosEepromFlight(0, 0, 0xfff)); + } + for (AltosEepromFlight flight : flights) { + System.out.printf("Scanning flight %d %x %x\n", flight.flight, flight.start, flight.end); + add(new AltosEepromLog(serial_line, config_data.serial, + flight.start, flight.end)); + } + } finally { + if (remote) + serial_line.stop_remote(); + serial_line.flush_output(); + } + for (int i = 0; i < size(); i++) { + AltosEepromLog l = get(i); + System.out.printf("Found flight %d at %x - %x\n", l.flight, l.start_block, l.end_block); + } + } +}
\ No newline at end of file diff --git a/altosui/AltosEepromLog.java b/altosui/AltosEepromLog.java new file mode 100644 index 00000000..36289b42 --- /dev/null +++ b/altosui/AltosEepromLog.java @@ -0,0 +1,98 @@ +/* + * 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.*; + +import libaltosJNI.*; + +public class AltosEepromLog { + int serial; + boolean has_flight; + int flight; + int start_block; + int end_block; + + boolean has_gps; + int year, month, day; + int hour, minute, second; + double lat, lon; + + public AltosEepromLog(AltosSerial serial_line, int in_serial, + int in_start_block, int in_end_block) + throws InterruptedException, TimeoutException { + + int block; + boolean has_date = false, has_time = false, has_lat = false, has_lon = false; + + start_block = in_start_block; + end_block = in_end_block; + serial = in_serial; + + 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++) { + AltosEepromBlock eeblock = new AltosEepromBlock(serial_line, block); + if (eeblock.has_flight) { + flight = eeblock.flight; + has_flight = true; + } + if (eeblock.has_date) { + year = eeblock.year; + month = eeblock.month; + day = eeblock.day; + has_date = true; + } + if (eeblock.has_time) { + hour = eeblock.hour; + minute = eeblock.minute; + second = eeblock.second; + has_time = true; + } + if (eeblock.has_lat) { + lat = eeblock.lat; + has_lat = true; + } + if (eeblock.has_lon) { + lon = eeblock.lon; + has_lon = true; + } + if (has_date && has_time && has_lat && has_lon) + has_gps = true; + if (has_gps && has_flight) + break; + } + System.out.printf("Serial %d start block %d end block %d\n", + serial, start_block, end_block); + if (has_flight) + System.out.printf("Flight %d\n", flight); + if (has_gps) + System.out.printf("%d-%d-%d %d:%02d:%02d Lat %f Lon %f\n", + year, month, day, hour, minute, second, lat, lon); + } +} diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java index e61a7159..584a04b7 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/AltosEepromRecord.java @@ -65,8 +65,10 @@ public class AltosEepromRecord { throw new TimeoutException(); int[] values = ParseHex(line); - if (values == null) - throw new ParseException(String.format("invalid line %s", line), 0); + if (values == null || values.length < 9) { + System.out.printf("invalid line %s", line); + throw new ParseException(String.format("inalid line %s", line), 0); + } if (values[0] != (addr & 0xff)) throw new ParseException(String.format("data address out of sync at 0x%x", addr), 0); diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index b19143e5..6dce6f3d 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -242,6 +242,16 @@ public class AltosSerial implements Runnable { } } + public void start_remote() { + set_radio(); + printf("p\nE 0\n"); + flush_input(); + } + + public void stop_remote() { + printf ("~"); + } + public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { device = in_device; line = ""; diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 8cdd64cc..58d23787 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -29,6 +29,8 @@ altosui_JAVA = \ AltosDisplayThread.java \ AltosEepromBlock.java \ AltosEepromDownload.java \ + AltosEepromList.java \ + AltosEepromLog.java \ AltosEepromMonitor.java \ AltosEepromIterable.java \ AltosEepromRecord.java \ |