X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosTelemetryIterable.java;h=a1b253321fde593eb2f11238b1f7e420ca7f6f41;hb=da2c920b9f3378d5a18551e008c1da5dace1e0ef;hp=a71ab8726d0dce64bf1b746e0e13e61e444c84b3;hpb=3fbefb3eea981d34a09496cf8abf0119de2e35bf;p=fw%2Faltos diff --git a/altosui/AltosTelemetryIterable.java b/altosui/AltosTelemetryIterable.java index a71ab872..a1b25332 100644 --- a/altosui/AltosTelemetryIterable.java +++ b/altosui/AltosTelemetryIterable.java @@ -22,18 +22,26 @@ import java.util.*; import java.text.*; public class AltosTelemetryIterable extends AltosRecordIterable { - LinkedList records; + TreeSet records; public Iterator iterator () { return records.iterator(); } + boolean has_gps = false; + boolean has_accel = false; + boolean has_ignite = false; + public boolean has_gps() { return has_gps; } + public boolean has_accel() { return has_accel; } + public boolean has_ignite() { return has_ignite; }; + public AltosTelemetryIterable (FileInputStream input) { boolean saw_boost = false; int current_tick = 0; int boost_tick = 0; - records = new LinkedList (); + AltosRecord previous = null; + records = new TreeSet (); try { for (;;) { @@ -42,14 +50,14 @@ public class AltosTelemetryIterable extends AltosRecordIterable { break; } try { - AltosTelemetry record = new AltosTelemetry(line); + AltosRecord record = AltosTelemetry.parse(line, previous); if (record == null) break; if (records.isEmpty()) { current_tick = record.tick; } else { - int tick = record.tick | (current_tick & ~ 0xffff); - if (tick < current_tick - 0x1000) + int tick = record.tick; + while (tick < current_tick - 0x1000) tick += 0x10000; current_tick = tick; record.tick = current_tick; @@ -59,17 +67,36 @@ public class AltosTelemetryIterable extends AltosRecordIterable { saw_boost = true; boost_tick = record.tick; } - records.add(record); + if (record.accel != AltosRecord.MISSING) + has_accel = true; + if (record.gps != null) + has_gps = true; + if (record.main != AltosRecord.MISSING) + has_ignite = true; + if (previous != null && previous.tick != record.tick) + records.add(previous); + previous = record; } catch (ParseException pe) { System.out.printf("parse exception %s\n", pe.getMessage()); } catch (AltosCRCException ce) { - System.out.printf("crc error\n"); } } } catch (IOException io) { System.out.printf("io exception\n"); } + if (previous != null) + records.add(previous); + + /* Adjust all tick counts to match expected eeprom values, + * which starts with a 16-bit tick count 16 samples before boost + */ + + int tick_adjust = (boost_tick - 16) & 0xffff0000; + for (AltosRecord r : this) + r.tick -= tick_adjust; + boost_tick -= tick_adjust; + /* adjust all tick counts to be relative to boost time */ for (AltosRecord r : this) r.time = (r.tick - boost_tick) / 100.0;