]> git.gag.com Git - fw/altos/commitdiff
altoslib: Check for negative tick wrap when importing flight records
authorKeith Packard <keithp@keithp.com>
Thu, 20 Jun 2024 22:35:38 +0000 (15:35 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 20 Jun 2024 22:35:38 +0000 (15:35 -0700)
If the tick count wraps just as boost is detected, there may be some
data records on the device with large tick values which are recorded
after the AO_FLIGHT record. Check for these in two places which manage
16-bit tick values by wrapping tick values to negative numbers in
those cases.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosCalData.java
altoslib/AltosEepromRecordSet.java

index c90534a924e4159ea62cc0a1db5575e8493a67d0..53e3b8fb6c4bbb271db9c6af215e3e9ddbaca48b 100644 (file)
@@ -202,9 +202,12 @@ public class AltosCalData {
        public void set_tick(int tick) {
                if (tick != AltosLib.MISSING) {
                        if (prev_tick != AltosLib.MISSING) {
-                               while (tick < prev_tick - 1000) {
+                               while (tick < prev_tick - 32767) {
                                        tick += 65536;
                                }
+                               while (tick > prev_tick + 32767) {
+                                       tick -= 65536;
+                               }
                        }
                        if (first_tick == AltosLib.MISSING)
                                first_tick = tick;
index 8f3fa4590e43bcecd060b1d287bf09490a7a23db..f0819a8108d9c5212697524a2290609eac0508e1 100644 (file)
@@ -138,6 +138,8 @@ public class AltosEepromRecordSet implements AltosRecordSet {
                        } else {
                                while (t < tick - 32767)
                                        t += 65536;
+                               while (t > tick + 32767)
+                                       t -= 65536;
                                tick = t;
                        }
                        record.wide_tick = tick;