altosui: Deal with telem data that goes backwards in time
authorKeith Packard <keithp@keithp.com>
Sun, 9 Oct 2011 16:55:04 +0000 (10:55 -0600)
committerKeith Packard <keithp@keithp.com>
Sun, 9 Oct 2011 17:09:11 +0000 (11:09 -0600)
The new telemetry stuff can send packets with older timestamps, so
sort telem packets read from disk to create an in-order record of the flight.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosRecord.java
altosui/AltosTelemetryIterable.java
altosui/AltosTelemetryRecordRaw.java

index ce6d86ab5294a1fb96538df6a72af6e181e4118a..486c96b2e232d93e7f30fc29e210d02c4dd69a3f 100644 (file)
@@ -22,7 +22,7 @@ import java.text.*;
 import java.util.HashMap;
 import java.io.*;
 
-public class AltosRecord {
+public class AltosRecord implements Comparable <AltosRecord> {
        final static int        MISSING = 0x7fffffff;
 
        static final int        seen_flight = 1;
@@ -243,6 +243,10 @@ public class AltosRecord {
                return null;
        }
 
+       public int compareTo(AltosRecord o) {
+               return tick - o.tick;
+       }
+
        public AltosRecord(AltosRecord old) {
                version = old.version;
                seen = old.seen;
index 1a31b3652e23745c6b2b41a4068c613c6fdf4cd1..278cbfb75b9e2e28ebceff7aa5f0621f84c60cb2 100644 (file)
@@ -22,7 +22,7 @@ import java.util.*;
 import java.text.*;
 
 public class AltosTelemetryIterable extends AltosRecordIterable {
-       LinkedList<AltosRecord> records;
+       TreeSet<AltosRecord>    records;
 
        public Iterator<AltosRecord> iterator () {
                return records.iterator();
@@ -41,7 +41,7 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
                int     boost_tick = 0;
 
                AltosRecord     previous = null;
-               records = new LinkedList<AltosRecord> ();
+               records = new TreeSet<AltosRecord> ();
 
                try {
                        for (;;) {
@@ -56,8 +56,8 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
                                        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;
index 39b2ba0772a2d3efdf56d897023ce5bd3718402c..fb2b495cdb2e281792bff6784b14c48fd9338edd 100644 (file)
@@ -143,11 +143,9 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
 
        public AltosRecord update_state(AltosRecord previous) {
                AltosRecord     next;
-               if (previous != null) {
+               if (previous != null)
                        next = new AltosRecord(previous);
-                       while (tick < previous.tick)
-                               tick += 65536;
-               } else
+               else
                        next = new AltosRecord();
                next.serial = serial;
                next.tick = tick;