altosuilib: In display thread, set new state synchronously
authorKeith Packard <keithp@keithp.com>
Mon, 21 Sep 2015 05:00:36 +0000 (06:00 +0100)
committerKeith Packard <keithp@keithp.com>
Tue, 13 Oct 2015 20:54:28 +0000 (13:54 -0700)
When replaying telemetry, received_time gets set by both the
telemetry reader (when the file is initially read) and by the replay
reader (as the telemetry is processed). Because these two events are
separated by the time it takes to play the file, the second time is
the one we want for figuring out how long since the last telemetry
packet. However, if we set the global state when pulling the state out
of the telemetry reader, and then the replay reader pauses for a long
time, then the voice output thread sees the intermediate time value
and thinks that it has been a long time since the last packet was
received and reports that the rocket may have crashed.

Fix this by just holding the read state until it has been passed by
the replay reader and had the received_time set to current time.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosuilib/AltosDisplayThread.java

index a773022..fac4ad7 100644 (file)
@@ -219,12 +219,14 @@ public class AltosDisplayThread extends Thread {
                try {
                        for (;;) {
                                try {
-                                       state = reader.read();
-                                       if (state == null) {
+                                       AltosState new_state = reader.read();
+                                       if (new_state == null) {
+                                               state = null;
                                                listener_state.running = false;
                                                break;
                                        }
-                                       reader.update(state);
+                                       reader.update(new_state);
+                                       state = new_state;
                                        show_safely();
                                        told = tell();
                                        idle_thread.notice(told);