Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altoslib / AltosState.java
index 830e95f311c19d6af0c0ef78821aa565bff55ef2..cf4fb9b030d66ca147be6af432e6304401d2d8a0 100644 (file)
  * Track flight state from telemetry or eeprom data stream
  */
 
-package org.altusmetrum.altoslib_5;
+package org.altusmetrum.altoslib_8;
 
-public class AltosState implements Cloneable {
+import java.io.*;
+
+public class AltosState implements Cloneable, Serializable {
 
        public static final int set_position = 1;
        public static final int set_gps = 2;
@@ -29,8 +31,9 @@ public class AltosState implements Cloneable {
 
        public int set;
 
+       static final double filter_len = 2.0;
        static final double ascent_filter_len = 0.5;
-       static final double descent_filter_len = 0.5;
+       static final double descent_filter_len = 5.0;
 
        /* derived data */
 
@@ -43,7 +46,7 @@ public class AltosState implements Cloneable {
        private int     prev_tick;
        public int      boost_tick;
 
-       class AltosValue {
+       class AltosValue implements Serializable{
                double  value;
                double  prev_value;
                private double  max_value;
@@ -62,8 +65,10 @@ public class AltosState implements Cloneable {
                }
 
                void set_filtered(double new_value, double time) {
-                       if (prev_value != AltosLib.MISSING)
-                               new_value = (prev_value * 15.0 + new_value) / 16.0;
+                       if (prev_value != AltosLib.MISSING) {
+                               double f = 1/Math.exp((time - prev_set_time) / filter_len);
+                               new_value = f * new_value + (1-f) * prev_value;
+                       }
                        set(new_value, time);
                }
 
@@ -179,9 +184,9 @@ public class AltosState implements Cloneable {
                }
        }
 
-       class AltosCValue {
+       class AltosCValue implements Serializable {
 
-               class AltosIValue extends AltosValue {
+               class AltosIValue extends AltosValue implements Serializable {
                        boolean can_max() {
                                return c_can_max();
                        }
@@ -312,7 +317,7 @@ public class AltosState implements Cloneable {
                ground_altitude.set_measured(a, time);
        }
 
-       class AltosGpsGroundAltitude extends AltosValue {
+       class AltosGpsGroundAltitude extends AltosValue implements Serializable {
                void set(double a, double t) {
                        super.set(a, t);
                        pad_alt = value();
@@ -336,7 +341,7 @@ public class AltosState implements Cloneable {
                gps_ground_altitude.set(a, time);
        }
 
-       class AltosGroundPressure extends AltosCValue {
+       class AltosGroundPressure extends AltosCValue implements Serializable {
                void set_filtered(double p, double time) {
                        computed.set_filtered(p, time);
                        if (!is_measured())
@@ -359,7 +364,7 @@ public class AltosState implements Cloneable {
                ground_pressure.set_measured(pressure, time);
        }
 
-       class AltosAltitude extends AltosCValue {
+       class AltosAltitude extends AltosCValue implements Serializable {
 
                private void set_speed(AltosValue v) {
                        if (!acceleration.is_measured() || !ascent)
@@ -381,7 +386,7 @@ public class AltosState implements Cloneable {
 
        private AltosAltitude   altitude;
 
-       class AltosGpsAltitude extends AltosValue {
+       class AltosGpsAltitude extends AltosValue implements Serializable {
 
                private void set_gps_height() {
                        double  a = value();
@@ -464,7 +469,7 @@ public class AltosState implements Cloneable {
                return gps_speed.max();
        }
 
-       class AltosPressure extends AltosValue {
+       class AltosPressure extends AltosValue implements Serializable {
                void set(double p, double time) {
                        super.set(p, time);
                        if (state == AltosLib.ao_flight_pad)
@@ -534,7 +539,7 @@ public class AltosState implements Cloneable {
                return AltosLib.MISSING;
        }
 
-       class AltosSpeed extends AltosCValue {
+       class AltosSpeed extends AltosCValue implements Serializable {
 
                boolean can_max() {
                        return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
@@ -588,7 +593,7 @@ public class AltosState implements Cloneable {
                return AltosLib.MISSING;
        }
 
-       class AltosAccel extends AltosCValue {
+       class AltosAccel extends AltosCValue implements Serializable {
 
                boolean can_max() {
                        return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
@@ -1038,6 +1043,10 @@ public class AltosState implements Cloneable {
                return AltosLib.state_name(state);
        }
 
+       public void set_product(String product) {
+               this.product = product;
+       }
+
        public void set_state(int state) {
                if (state != AltosLib.ao_flight_invalid) {
                        this.state = state;
@@ -1349,11 +1358,6 @@ public class AltosState implements Cloneable {
                }
        }
 
-       public void make_companion (int nchannels) {
-               if (companion == null)
-                       companion = new AltosCompanion(nchannels);
-       }
-
        public void set_companion(AltosCompanion companion) {
                this.companion = companion;
        }