altoslib: Add set_config_data to AltosState
[fw/altos] / altoslib / AltosState.java
index 15cf7d641b0f68a3248de98c443096579fe5938b..8c3f93f0c0e9481930dcbf195be0a2e02c118c74 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -1387,7 +1388,7 @@ public class AltosState implements Cloneable {
        public void set_ms5607(AltosMs5607 ms5607) {
                baro = ms5607;
 
-               if (baro != null) {
+               if (baro != null && baro.pa != AltosLib.MISSING && baro.cc != AltosLib.MISSING) {
                        set_pressure(baro.pa);
                        set_temperature(baro.cc / 100.0);
                }
@@ -1520,6 +1521,23 @@ public class AltosState implements Cloneable {
                temp_gps = null;
        }
 
+       public void set_config_data(AltosConfigData config_data) {
+               if (config_data.callsign != null)
+                       set_callsign(config_data.callsign);
+               if (config_data.accel_cal_plus != AltosLib.MISSING &&
+                   config_data.accel_cal_minus != AltosLib.MISSING)
+                       set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
+               if (config_data.product != null)
+                       set_product(config_data.product);
+               if (config_data.log_format != AltosLib.MISSING)
+                       set_log_format(config_data.log_format);
+               if (config_data.serial != AltosLib.MISSING)
+                       set_serial(config_data.serial);
+               AltosMs5607 ms5607 = new AltosMs5607(config_data);
+               if (ms5607.valid_config())
+                       set_ms5607(ms5607);
+       }
+
        public AltosState clone() {
                AltosState s = new AltosState();
                s.copy(this);