altoslib: Provide consistent cal_data from idle and replay readers
authorKeith Packard <keithp@keithp.com>
Sun, 28 May 2017 06:33:07 +0000 (23:33 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 28 May 2017 06:33:07 +0000 (23:33 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosIdleReader.java
altoslib/AltosReplayReader.java

index 49d0cf61cd3f73338e3049a4ab4b7b8c11f937e8..3307cf2646a47587f20fbe24886129c46732bdf5 100644 (file)
@@ -25,6 +25,7 @@ import java.util.concurrent.*;
 public class AltosIdleReader extends AltosFlightReader {
        AltosLink       link;
        boolean         remote;
+       AltosCalData    cal_data = null;
        AltosState      state = null;
        AltosIdleFetch  fetch;
        long            next_millis;
@@ -44,6 +45,19 @@ public class AltosIdleReader extends AltosFlightReader {
                return link.reply_abort;
        }
 
+       public AltosCalData cal_data() {
+               if (cal_data == null) {
+                       try {
+                               cal_data = new AltosCalData(link.config_data());
+                       } catch (InterruptedException ie) {
+                       } catch (TimeoutException te) {
+                       }
+                       if (cal_data == null)
+                               cal_data = new AltosCalData();
+               }
+               return cal_data;
+       }
+
        public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
                boolean worked = false;
                boolean aborted = false;
@@ -57,7 +71,7 @@ public class AltosIdleReader extends AltosFlightReader {
                        try {
                                start_link();
                                if (state == null)
-                                       state = new AltosState(new AltosCalData(link.config_data()));
+                                       state = new AltosState(cal_data());
                                fetch.provide_data(state, state.cal_data);
                                if (!link.has_error && !link.reply_abort)
                                        worked = true;
index 2117bc878c6fc2e23cb9fcb6eb741f6eb5c8996f..a26d1e84373d313f4e660ace1deab6c0d3c1b0b7 100644 (file)
@@ -107,6 +107,10 @@ public class AltosReplayReader extends AltosFlightReader {
        Thread          t;
        int             reads;
 
+       public AltosCalData cal_data() {
+               return replay.state.cal_data;
+       }
+
        public AltosState read() {
                switch (reads) {
                case 0: