altosui: Fix telemetry file reader to handle tick count wrapping
authorKeith Packard <keithp@keithp.com>
Fri, 10 Sep 2010 05:30:48 +0000 (22:30 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Sep 2010 05:31:52 +0000 (22:31 -0700)
The telemetry reader was ignoring tick count wrapping, so you'd see
time go backwards in jumps. Not useful.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosTelemetryReader.java

index fdedbde279345499e1ac926104478ade2106fa24..ae9682ab323ccb43a45e31959dbdec9c88fcca30 100644 (file)
@@ -41,6 +41,7 @@ public class AltosTelemetryReader extends AltosReader {
 
        public AltosTelemetryReader (FileInputStream input) {
                boolean saw_boost = false;
+               int     current_tick = 0;
 
                records = new LinkedList<AltosRecord> ();
 
@@ -51,9 +52,20 @@ public class AltosTelemetryReader extends AltosReader {
                                        break;
                                }
                                try {
+                                       System.out.printf("%s\n", line);
                                        AltosTelemetry record = new AltosTelemetry(line);
                                        if (record == null)
                                                break;
+                                       if (records.isEmpty()) {
+                                               current_tick = record.tick;
+                                       } else {
+                                               int tick = record.tick | (current_tick & ~ 0xffff);
+                                               if (tick < current_tick - 0x1000)
+                                                       tick += 0x10000;
+                                               current_tick = tick;
+                                               record.tick = current_tick;
+                                       }
+                                       System.out.printf("\tRSSI %d tick %d\n", record.rssi, record.tick);
                                        if (!saw_boost && record.state >= Altos.ao_flight_boost)
                                        {
                                                saw_boost = true;