altoslib: Use GPS seconds as an additional sort key for TeleGPS eeprom
authorKeith Packard <keithp@keithp.com>
Thu, 12 Jun 2014 01:48:11 +0000 (18:48 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 12 Jun 2014 01:48:11 +0000 (18:48 -0700)
Long idle periods with TeleGPS can easily overflow 16 bits of tick
count. Using the GPS seconds provides an additional sort which will
span the tick wrap-around.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosEeprom.java
altoslib/AltosEepromGPS.java
altoslib/AltosEepromIterable.java

index be18ba24ec7ae83c20ca5c89043a73678658a9c4..020590ebfc0a9f667d82c67fbbfe906ea0a954d5 100644 (file)
@@ -43,6 +43,10 @@ public abstract class AltosEeprom implements AltosStateUpdate {
                return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
        }
 
+       public boolean has_seconds() { return false; }
+
+       public int seconds() { return 0; }
+
        public final static int header_length = 4;
 
        public abstract int record_length();
index 1820cd612a6ca5c5b1d76ae48fcd65db0f25866f..3c1852c0350258a1ce34830ea28895ed26e9ee53 100644 (file)
@@ -53,6 +53,17 @@ public class AltosEepromGPS extends AltosEeprom {
        public int vdop() { return data8(24); }
        public int mode() { return data8(25); }
 
+       public boolean has_seconds() { return cmd == AltosLib.AO_LOG_GPS_TIME; }
+
+       public int seconds() {
+               switch (cmd) {
+               case AltosLib.AO_LOG_GPS_TIME:
+                       return second() + 60 * (minute() + 60 * (hour() + 24 * (day() + 31 * month())));
+               default:
+                       return 0;
+               }
+       }
+
        public AltosEepromGPS (AltosEepromChunk chunk, int start) throws ParseException {
                parse_chunk(chunk, start);
        }
index 415c5b62099d87e5a1ea2ce720aa364b5b3d1099..d6832c1b91bbd30e539591fffa54c9544cb60a67 100644 (file)
@@ -38,6 +38,13 @@ class AltosEepromOrdered implements Comparable<AltosEepromOrdered> {
                if (cmd_diff != 0)
                        return cmd_diff;
 
+               if (eeprom.has_seconds() && o.eeprom.has_seconds()) {
+                       int     seconds_diff = eeprom.seconds() - o.eeprom.seconds();
+
+                       if (seconds_diff != 0)
+                               return seconds_diff;
+               }
+
                int     tick_diff = tick - o.tick;
 
                if (tick_diff != 0)
@@ -116,4 +123,4 @@ public class AltosEepromIterable implements Iterable<AltosEeprom> {
                        eeproms = new LinkedList<AltosEeprom>();
                return new AltosEepromOrderedIterator(eeproms);
        }
-}
\ No newline at end of file
+}