altoslib: Make AltosReplayReader start synchronously enough to track states
authorKeith Packard <keithp@keithp.com>
Fri, 26 May 2017 07:51:37 +0000 (00:51 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 26 May 2017 07:51:37 +0000 (00:51 -0700)
The Altos UI needs to see 'pad' state and then 'boost' state so that
it will automatically switch tabs during the flight. When reading from
eeprom files, the only way that is going to happen is if the reader
thread waits until the UI has definitely seen 'pad' state, which we do
by simply delaying the reader thread until after that has happened.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosReplayReader.java
altoslib/AltosState.java
altosui/AltosFlightUI.java

index fb8432e7e8049ed0132763d18a27c1520fcb8940..2117bc878c6fc2e23cb9fcb6eb741f6eb5c8996f 100644 (file)
@@ -83,20 +83,8 @@ class AltosReplay extends AltosDataListener implements Runnable {
        public void set_companion(AltosCompanion companion) { state.set_companion(companion); }
 
        public void run () {
-               System.out.printf("ReplayReader running\n");
-               state = new AltosState(record_set.cal_data());
-
-               /* Tell the display that we're in pad mode */
-               state.set_state(AltosLib.ao_flight_pad);
-               semaphore.release();
-               try {
-                       Thread.sleep(100);
-               } catch (InterruptedException ie) {
-               }
-
                /* Run the flight */
                record_set.capture_series(this);
-
                /* All done, signal that it's over */
                done = true;
                semaphore.release();
@@ -104,31 +92,45 @@ class AltosReplay extends AltosDataListener implements Runnable {
 
        public AltosReplay(AltosRecordSet record_set) {
                super(record_set.cal_data());
+               state = new AltosState(record_set.cal_data());
+               this.record_set = record_set;
                try {
                        semaphore.acquire();
-               } catch (InterruptedException ie) { }
-               this.record_set = record_set;
-               Thread t = new Thread(this);
-               t.start();
+               } catch (InterruptedException ie) {
+               }
        }
 }
 
 public class AltosReplayReader extends AltosFlightReader {
        File            file;
        AltosReplay     replay;
+       Thread          t;
+       int             reads;
 
        public AltosState read() {
+               switch (reads) {
+               case 0:
+                       /* Tell the display that we're in pad mode */
+                       replay.state.set_state(AltosLib.ao_flight_pad);
+                       break;
+               case 1:
+                       t = new Thread(replay);
+                       t.start();
+                       /* fall through */
+               default:
+                       /* Wait for something to change */
+                       try {
+                               replay.semaphore.acquire();
+                       } catch (InterruptedException ie) {
+                       }
+                       break;
+               }
+               reads++;
 
                /* When done, let the display know */
                if (replay.done)
                        return null;
 
-               /* Wait for something to change */
-               try {
-                       replay.semaphore.acquire();
-               } catch (InterruptedException ie) {
-               }
-
                /* Fake out the received time */
                replay.state.set_received_time(System.currentTimeMillis());
                return replay.state;
@@ -137,12 +139,10 @@ public class AltosReplayReader extends AltosFlightReader {
        public void close (boolean interrupted) {
        }
 
-       public void update(AltosState state) throws InterruptedException {
-       }
-
        public File backing_file() { return file; }
 
        public AltosReplayReader(AltosRecordSet record_set, File in_file) {
+               reads = 0;
                file = in_file;
                name = file.getName();
                replay = new AltosReplay(record_set);
index 889aa9a319e4b9067492b716639d162754bd1b77..0716b892a1c1b97d97b8e9337195f3b79721b086 100644 (file)
@@ -705,8 +705,6 @@ public class AltosState extends AltosDataListener {
        public double   igniter_voltage[];
 
        public AltosGPS gps;
-       public AltosGPS temp_gps;
-       public int temp_gps_sat_tick;
        public boolean  gps_pending;
 
        public AltosIMU imu;
@@ -757,6 +755,7 @@ public class AltosState extends AltosDataListener {
        public void init() {
                set = 0;
 
+               System.out.printf("state init\n");
                received_time = System.currentTimeMillis();
                time = AltosLib.MISSING;
                time_change = AltosLib.MISSING;
@@ -793,8 +792,6 @@ public class AltosState extends AltosDataListener {
                kalman_acceleration = new AltosValue();
 
                gps = null;
-               temp_gps = null;
-               temp_gps_sat_tick = 0;
                gps_pending = false;
 
                imu = null;
index 23a62e958200771a14c09e452b45c442490e553c..12277f8921e193a437a002b58a16dfc8c2e7bcde 100644 (file)
@@ -147,7 +147,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                        }
                }
 
-               if (state.gps != null && state.gps.connected) {
+               if (state.gps != null) {
                        if (!has_map) {
                                pane.add("Site Map", sitemap);
                                has_map = true;