altoslib: Reset transient AltosCalData values before processing data
[fw/altos] / altoslib / AltosIdleReader.java
index 5903c96815f03feb12adbbb1667085a8bb2eed38..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,15 +45,23 @@ 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;
 
-               if (state == null)
-                       state = new AltosState();
-               else
-                       state = state.clone();
-
                long    delay = next_millis - System.currentTimeMillis();
 
                if (delay > 0)
@@ -61,7 +70,9 @@ public class AltosIdleReader extends AltosFlightReader {
                try {
                        try {
                                start_link();
-                               fetch.update_state(state);
+                               if (state == null)
+                                       state = new AltosState(cal_data());
+                               fetch.provide_data(state, state.cal_data);
                                if (!link.has_error && !link.reply_abort)
                                        worked = true;
                        } catch (TimeoutException te) {