summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-09-27 18:52:30 -0700
committerKeith Packard <keithp@keithp.com>2010-09-27 18:52:30 -0700
commit803203197e51e71e9c77b3610047fd5bf9a56c56 (patch)
treebce2aa1967673f46fba447fdb98c4911f203bf3a
parentfe7eba2e4af36cf29d8dc2378ac6985be04f68c6 (diff)
altosui: Deal with eeprom dates going backwards across wrap
eeprom timestamps can go backwards as the GPS time stamps are recorded when the first GPS character is received, but not placed into the eeprom log until the last GPS packet is complete. If this happens at the same time the tick count is wrapping, then the tick count will wrap backwards across the 0 boundary causing time to jump forwards. Fix this by letting time go backwards across the tick boundary, which requires that we know when the first 'real' tick is read from the eeprom file. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao-tools/altosui/AltosEepromIterable.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java
index d4ac3f3e..2f1e7e90 100644
--- a/ao-tools/altosui/AltosEepromIterable.java
+++ b/ao-tools/altosui/AltosEepromIterable.java
@@ -44,15 +44,19 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable<AltosOr
public int index;
- public AltosOrderedRecord(String line, int in_index, int prev_tick)
+ public AltosOrderedRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid)
throws ParseException {
super(line);
- int new_tick = tick | (prev_tick & ~0xffff);
- if (new_tick < prev_tick) {
- if (prev_tick - new_tick > 0x8000)
- new_tick += 0x10000;
+ if (prev_tick_valid) {
+ tick |= (prev_tick & ~0xffff);
+ if (tick < prev_tick) {
+ if (prev_tick - tick > 0x8000)
+ tick += 0x10000;
+ } else {
+ if (tick - prev_tick > 0x8000)
+ tick -= 0x10000;
+ }
}
- tick = new_tick;
index = in_index;
}
@@ -340,7 +344,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
int index = 0;
int prev_tick = 0;
-
+ boolean prev_tick_valid = false;
boolean missing_time = false;
try {
@@ -348,12 +352,14 @@ public class AltosEepromIterable extends AltosRecordIterable {
String line = AltosRecord.gets(input);
if (line == null)
break;
- AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick);
+ AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid);
if (record == null)
break;
if (record.cmd == Altos.AO_LOG_INVALID)
continue;
prev_tick = record.tick;
+ if (record.cmd < Altos.AO_LOG_CONFIG_VERSION)
+ prev_tick_valid = true;
if (record.cmd == Altos.AO_LOG_FLIGHT) {
flight_record = record;
continue;