X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosReplayReader.java;h=a26d1e84373d313f4e660ace1deab6c0d3c1b0b7;hp=fb8432e7e8049ed0132763d18a27c1520fcb8940;hb=78b4bf77fca96bef2cce443ad4c9544ae83f0acc;hpb=2e82051a6aaaccf1e8a242f9c8141e4167e652d2 diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index fb8432e7..a26d1e84 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -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,49 @@ 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 AltosCalData cal_data() { + return replay.state.cal_data; + } 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 +143,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);