From 43f94e923a6a87520edcbb8fb4829e6ddf708908 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 14 May 2013 00:24:53 -0700 Subject: altoslib: Use sequence numbers to track GPS updates to AltosRecord State objects now record what GPS sequence ID they have to know when the GPS data has been updated. Record objects bump the GPS sequence each time new GPS data is recorded. This way, record objects aren't modified as they're iterated over to generate the list of state objects which makes it possible to iterate multiple times and get the same resulting set of states. Signed-off-by: Keith Packard --- altoslib/AltosState.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index ccbe498d..825306be 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -54,6 +54,7 @@ public class AltosState { public double max_baro_speed; public AltosGPS gps; + public int gps_sequence; public AltosIMU imu; public AltosMag mag; @@ -133,6 +134,7 @@ public class AltosState { npad = prev_state.npad; ngps = prev_state.ngps; gps = prev_state.gps; + gps_sequence = prev_state.gps_sequence; pad_lat = prev_state.pad_lat; pad_lon = prev_state.pad_lon; pad_alt = prev_state.pad_alt; @@ -187,6 +189,7 @@ public class AltosState { npad = 0; ngps = 0; gps = null; + gps_sequence = 0; baro_speed = AltosRecord.MISSING; accel_speed = AltosRecord.MISSING; pad_alt = AltosRecord.MISSING; @@ -199,7 +202,7 @@ public class AltosState { time = tick / 100.0; - if (cur.new_gps && (state < AltosLib.ao_flight_boost)) { + if (data.gps != null && data.gps_sequence != gps_sequence && (state < AltosLib.ao_flight_boost)) { /* Track consecutive 'good' gps reports, waiting for 10 of them */ if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) @@ -226,7 +229,7 @@ public class AltosState { pad_alt = ground_altitude; } - data.new_gps = false; + gps_sequence = data.gps_sequence; gps_waiting = MIN_PAD_SAMPLES - npad; if (gps_waiting < 0) -- cgit v1.2.3