add thrust as a graphable time series type
[fw/altos] / altoslib / AltosState.java
index fd2684db4c0ce6b06aa9392476b294a97ceb692d..846bda42dd834f454c8dc225de5bc4a42a44643f 100644 (file)
@@ -24,7 +24,7 @@ package org.altusmetrum.altoslib_11;
 
 import java.io.*;
 
-public class AltosState implements Cloneable {
+public class AltosState extends AltosFlightListener implements Cloneable {
 
        public static final int set_position = 1;
        public static final int set_gps = 2;
@@ -43,9 +43,7 @@ public class AltosState implements Cloneable {
        public double   time;
        public double   prev_time;
        public double   time_change;
-       public int      tick;
        private int     prev_tick;
-       public int      boost_tick;
 
        class AltosValue {
                double  value;
@@ -515,6 +513,25 @@ public class AltosState implements Cloneable {
                pressure.set(p, time);
        }
 
+       class AltosForce extends AltosValue {
+               void set(double p, double time) {
+                       super.set(p, time);
+               }
+
+               AltosForce() {
+                       super();
+               }
+       }
+       private AltosForce      thrust;
+
+       public double thrust() {
+               return thrust.value();
+       }
+
+       public void set_thrust(double N) {
+               thrust.set(N, time);
+       }
+
        public double baro_height() {
                double a = altitude();
                double g = ground_altitude();
@@ -762,6 +779,7 @@ public class AltosState implements Cloneable {
                ground_pressure = new AltosGroundPressure();
                altitude = new AltosAltitude();
                pressure = new AltosPressure();
+               thrust = new AltosForce();
                speed = new AltosSpeed();
                acceleration = new AltosAccel();
                orient = new AltosCValue();
@@ -870,6 +888,8 @@ public class AltosState implements Cloneable {
                        return;
                }
 
+               super.copy(old);
+
                received_time = old.received_time;
                time = old.time;
                time_change = old.time_change;
@@ -1071,11 +1091,6 @@ public class AltosState implements Cloneable {
                }
        }
 
-       public void set_boost_tick(int boost_tick) {
-               if (boost_tick != AltosLib.MISSING)
-                       this.boost_tick = boost_tick;
-       }
-
        public String state_name() {
                return AltosLib.state_name(state);
        }
@@ -1388,7 +1403,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);
                }
@@ -1502,23 +1517,27 @@ public class AltosState implements Cloneable {
                return tick != AltosLib.MISSING && serial != AltosLib.MISSING;
        }
 
-       public AltosGPS make_temp_gps(boolean sats) {
-               if (temp_gps == null) {
-                       temp_gps = new AltosGPS(gps);
-               }
-               gps_pending = true;
-               if (sats) {
-                       if (tick != temp_gps_sat_tick)
-                               temp_gps.cc_gps_sat = null;
-                       temp_gps_sat_tick = tick;
-               }
-               return temp_gps;
-       }
-
        public void set_temp_gps() {
                set_gps(temp_gps, gps_sequence + 1);
                gps_pending = false;
-               temp_gps = null;
+               super.set_temp_gps();
+       }
+
+       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() {