From: Keith Packard Date: Thu, 20 Jun 2024 22:35:38 +0000 (-0700) Subject: altoslib: Check for negative tick wrap when importing flight records X-Git-Tag: 1.9.19~1^2~14^2 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=3bc1ab0046c4dbebbde8557d3a1f45707aaefa42;p=fw%2Faltos altoslib: Check for negative tick wrap when importing flight records 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 --- diff --git a/altoslib/AltosCalData.java b/altoslib/AltosCalData.java index c90534a9..53e3b8fb 100644 --- a/altoslib/AltosCalData.java +++ b/altoslib/AltosCalData.java @@ -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; diff --git a/altoslib/AltosEepromRecordSet.java b/altoslib/AltosEepromRecordSet.java index 8f3fa459..f0819a81 100644 --- a/altoslib/AltosEepromRecordSet.java +++ b/altoslib/AltosEepromRecordSet.java @@ -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;