altoslib: Move temp GPS API from cal_data to data_listener
authorKeith Packard <keithp@keithp.com>
Sun, 22 Oct 2017 19:04:09 +0000 (14:04 -0500)
committerKeith Packard <keithp@keithp.com>
Sun, 22 Oct 2017 19:04:09 +0000 (14:04 -0500)
This makes the API more consistent, and means that the listener is
responsible for mangaing the temp gps state. In particular, the
AltosDataListener set_gps API now calls the cal_data function.

Signed-off-by: Keith Packard <keithp@keithp.com>
13 files changed:
altoslib/AltosCalData.java
altoslib/AltosDataListener.java
altoslib/AltosEepromDownload.java
altoslib/AltosEepromRecord.java
altoslib/AltosEepromRecordFull.java
altoslib/AltosEepromRecordMega.java
altoslib/AltosEepromRecordMetrum.java
altoslib/AltosFlightListener.java [deleted file]
altoslib/AltosFlightSeries.java
altoslib/AltosReplayReader.java
altoslib/AltosState.java
altoslib/AltosTelemetryLocation.java
altoslib/AltosTelemetrySatellite.java

index 7415d5ad6584e54c4594fe44c21ef5588529c537..fdea5e214948da1bdad80f60ad43cc8c9fde0475 100644 (file)
@@ -199,7 +199,6 @@ public class AltosCalData {
                tick = AltosLib.MISSING;
                prev_tick = AltosLib.MISSING;
                temp_gps = null;
-               prev_gps = null;
                temp_gps_sat_tick = AltosLib.MISSING;
                accel = AltosLib.MISSING;
        }
@@ -244,11 +243,14 @@ public class AltosCalData {
 
        public double           gps_pad_altitude = AltosLib.MISSING;
 
-       public void set_gps(AltosGPS gps) {
-               if ((state != AltosLib.MISSING && state < AltosLib.ao_flight_boost) || gps_pad == null)
-                       gps_pad = gps;
-               if (gps_pad_altitude == AltosLib.MISSING && gps.alt != AltosLib.MISSING)
-                       gps_pad_altitude = gps.alt;
+       public void set_cal_gps(AltosGPS gps) {
+               if (gps.locked && gps.nsat >= 4) {
+                       if ((state != AltosLib.MISSING && state < AltosLib.ao_flight_boost) || gps_pad == null)
+                               gps_pad = gps;
+                       if (gps_pad_altitude == AltosLib.MISSING && gps.alt != AltosLib.MISSING)
+                               gps_pad_altitude = gps.alt;
+               }
+               temp_gps = null;
        }
 
        /*
@@ -256,33 +258,24 @@ public class AltosCalData {
         * object and then deliver the result atomically to the listener
         */
        AltosGPS                temp_gps = null;
-       AltosGPS                prev_gps = null;
        int                     temp_gps_sat_tick = AltosLib.MISSING;
 
-       public AltosGPS temp_gps() {
+       public AltosGPS temp_cal_gps() {
                return temp_gps;
        }
 
-       public void reset_temp_gps() {
-               if (temp_gps != null) {
-                       if (temp_gps.locked && temp_gps.nsat >= 4)
-                               set_gps(temp_gps);
-                       prev_gps = temp_gps;
-                       temp_gps = null;
-               }
+       public void reset_temp_cal_gps() {
+               if (temp_gps != null)
+                       set_cal_gps(temp_gps);
        }
 
-       public boolean gps_pending() {
+       public boolean cal_gps_pending() {
                return temp_gps != null;
        }
 
-       public AltosGPS make_temp_gps(int tick, boolean sats) {
-               if (temp_gps == null) {
-                       if (prev_gps != null)
-                               temp_gps = prev_gps.clone();
-                       else
-                               temp_gps = new AltosGPS();
-               }
+       public AltosGPS make_temp_cal_gps(int tick, boolean sats) {
+               if (temp_gps == null)
+                       temp_gps = new AltosGPS();
                if (sats) {
                        if (tick != temp_gps_sat_tick)
                                temp_gps.cc_gps_sat = null;
index 359d04c932008993238474a14266bb0ce5ca241a..9a1e1465fbb19aa39781f33904ce7f09ac65c1ed 100644 (file)
@@ -111,7 +111,18 @@ public abstract class AltosDataListener {
        public abstract void set_apogee_voltage(double volts);
        public abstract void set_main_voltage(double volts);
 
-       public abstract void set_gps(AltosGPS gps);
+       public void set_gps(AltosGPS gps) {
+               AltosCalData cal_data = cal_data();
+               cal_data.set_cal_gps(gps);
+       }
+
+       public AltosGPS make_temp_gps(boolean sats) {
+               return cal_data().make_temp_cal_gps(tick(), sats);
+       }
+
+       public AltosGPS temp_gps() {
+               return cal_data().temp_cal_gps();
+       }
 
        public abstract void set_orient(double orient);
        public abstract void set_gyro(double roll, double pitch, double yaw);
index 33f0dd177997104e1bd1f8e8eabf0e2d8aff1fd2..3df8a5b475e22b13cb1d75d938f5ee1fe6a5cc51 100644 (file)
@@ -40,6 +40,7 @@ class AltosEepromNameData extends AltosDataListener {
        public void set_main_voltage(double volts) { }
 
        public void set_gps(AltosGPS gps) {
+               super.set_gps(gps);
                if (gps != null &&
                    gps.year != AltosLib.MISSING &&
                    gps.month != AltosLib.MISSING &&
index e937c3d0c4bfff99c1ed9a58fc3c1723b63ad696..12519e6b91c1b47beff90c731765e9646c4b9ec1 100644 (file)
@@ -90,11 +90,9 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>
 
                /* Flush any pending GPS changes */
                if (!AltosLib.is_gps_cmd(cmd())) {
-                       AltosGPS gps = cal_data.temp_gps();
-                       if (gps != null) {
+                       AltosGPS gps = listener.temp_gps();
+                       if (gps != null)
                                listener.set_gps(gps);
-                               cal_data.reset_temp_gps();
-                       }
                }
        }
 
index 32df957841e19e978cc8c2892b9bda7a856de535..7e92d35377bc1912d5a8363d80d82bc370dd838f 100644 (file)
@@ -53,7 +53,7 @@ public class AltosEepromRecordFull extends AltosEepromRecord {
                        listener.set_state(data16(0));
                        break;
                case AltosLib.AO_LOG_GPS_TIME:
-                       gps = cal_data.make_temp_gps(tick(),false);
+                       gps = listener.make_temp_gps(false);
 
                        gps.hour = data8(0);
                        gps.minute = data8(1);
@@ -67,29 +67,29 @@ public class AltosEepromRecordFull extends AltosEepromRecord {
                                AltosLib.AO_GPS_NUM_SAT_SHIFT;
                        break;
                case AltosLib.AO_LOG_GPS_LAT:
-                       gps = cal_data.make_temp_gps(tick(),false);
+                       gps = listener.make_temp_gps(false);
 
                        int lat32 = data32(0);
                        gps.lat = (double) lat32 / 1e7;
                        break;
                case AltosLib.AO_LOG_GPS_LON:
-                       gps = cal_data.make_temp_gps(tick(),false);
+                       gps = listener.make_temp_gps(false);
 
                        int lon32 = data32(0);
                        gps.lon = (double) lon32 / 1e7;
                        break;
                case AltosLib.AO_LOG_GPS_ALT:
-                       gps = cal_data.make_temp_gps(tick(),false);
+                       gps = listener.make_temp_gps(false);
                        gps.alt = data16(0);
                        break;
                case AltosLib.AO_LOG_GPS_SAT:
-                       gps = cal_data.make_temp_gps(tick(),true);
+                       gps = listener.make_temp_gps(true);
                        int svid = data16(0);
                        int c_n0 = data16(2);
                        gps.add_sat(svid, c_n0);
                        break;
                case AltosLib.AO_LOG_GPS_DATE:
-                       gps = cal_data.make_temp_gps(tick(),false);
+                       gps = listener.make_temp_gps(false);
                        gps.year = data8(0) + 2000;
                        gps.month = data8(1);
                        gps.day = data8(2);
index ad3e23fdfeeefcbc258354f5941dd6d5c35013b9..ea5aff5c83a7ba70de64cb591c7adfd6d1c98042 100644 (file)
@@ -188,7 +188,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                        listener.set_pyro_fired(pyro());
                        break;
                case AltosLib.AO_LOG_GPS_TIME:
-                       gps = cal_data.make_temp_gps(tick(), false);
+                       gps = listener.make_temp_gps(false);
                        gps.lat = latitude() / 1e7;
                        gps.lon = longitude() / 1e7;
 
@@ -231,7 +231,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                        }
                        break;
                case AltosLib.AO_LOG_GPS_SAT:
-                       gps = cal_data.make_temp_gps(tick(), true);
+                       gps = listener.make_temp_gps(true);
 
                        int n = nsat();
                        if (n > max_sat)
index 3da50544b2a56db660c619faf16cde1156e1c728..888a06cca2fbe02316525f6a01f7e10428ee4168 100644 (file)
@@ -91,7 +91,7 @@ public class AltosEepromRecordMetrum extends AltosEepromRecord {
                        listener.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
                        break;
                case AltosLib.AO_LOG_GPS_POS:
-                       gps = cal_data.make_temp_gps(tick(), false);
+                       gps = listener.make_temp_gps(false);
                        gps.lat = latitude() / 1e7;
                        gps.lon = longitude() / 1e7;
                        if (config_data().altitude_32())
@@ -100,7 +100,7 @@ public class AltosEepromRecordMetrum extends AltosEepromRecord {
                                gps.alt = altitude_low();
                        break;
                case AltosLib.AO_LOG_GPS_TIME:
-                       gps = cal_data.make_temp_gps(tick(), false);
+                       gps = listener.make_temp_gps(false);
 
                        gps.hour = hour();
                        gps.minute = minute();
@@ -119,7 +119,7 @@ public class AltosEepromRecordMetrum extends AltosEepromRecord {
                        gps.pdop = pdop() / 10.0;
                        break;
                case AltosLib.AO_LOG_GPS_SAT:
-                       gps = cal_data.make_temp_gps(tick(), true);
+                       gps = listener.make_temp_gps(true);
 
                        int n = nsat();
                        for (int i = 0; i < n; i++)
diff --git a/altoslib/AltosFlightListener.java b/altoslib/AltosFlightListener.java
deleted file mode 100644 (file)
index d61831a..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright © 2017 Keith Packard <keithp@keithp.com>
- *
- * 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, 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
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- */
-
-package org.altusmetrum.altoslib_12;
-
-public abstract class AltosFlightListener {
-
-       public int      flight;
-       public int      serial;
-       public int      tick;
-       public int      boost_tick;
-       public int      state;
-
-       public double   accel_plus_g;
-       public double   accel_minus_g;
-       public double   accel;
-
-       public double   ground_pressure;
-       public double   ground_altitude;
-
-       AltosGPS        temp_gps;
-       int             temp_gps_sat_tick;
-       int             gps_sequence;
-
-       /* AltosEepromRecord */
-       public void set_boost_tick(int boost_tick) {
-               if (boost_tick != AltosLib.MISSING)
-                       this.boost_tick = boost_tick;
-       }
-
-       public void set_tick(int tick) {
-               if (tick != AltosLib.MISSING)
-                       this.tick = tick;
-       }
-
-       public double time() {
-               if (tick == AltosLib.MISSING)
-                       return AltosLib.MISSING;
-               if (boost_tick != AltosLib.MISSING)
-                       return (tick - boost_tick) / 100.0;
-               else
-                       return tick / 100.0;
-       }
-
-       public double boost_time() {
-               if (boost_tick == AltosLib.MISSING)
-                       return AltosLib.MISSING;
-               return boost_tick / 100.0;
-       }
-
-       public abstract void set_rssi(int rssi, int status);
-       public abstract void set_received_time(long received_time);
-
-       /* AltosEepromRecordFull */
-
-       public void set_serial(int serial) {
-               if (serial != AltosLib.MISSING)
-                       this.serial = serial;
-       }
-
-       public void set_state(int state) {
-               if (state != AltosLib.MISSING)
-                       this.state = state;
-       }
-
-       public int state() { return state; }
-
-       public abstract void set_ground_accel(double ground_accel);
-       public void set_flight(int flight) {
-               if (flight != AltosLib.MISSING)
-                       this.flight = flight;
-       }
-       public int flight() {
-               return flight;
-       }
-
-       public abstract void set_accel(double accel);
-       public abstract void set_acceleration(double accel);
-       public abstract void set_accel_g(double accel_plus_g, double accel_minus_g);
-       public abstract void set_pressure(double pa);
-       public abstract void set_thrust(double N);
-
-       public abstract void set_temperature(double deg_c);
-       public abstract void set_battery_voltage(double volts);
-
-       public abstract void set_apogee_voltage(double volts);
-       public abstract void set_main_voltage(double volts);
-
-       public void set_temp_gps() {
-               temp_gps = null;
-       }
-
-       public boolean gps_pending() {
-               return temp_gps != null;
-       }
-
-       public AltosGPS make_temp_gps(boolean sats) {
-               if (temp_gps == null) {
-                       temp_gps = new AltosGPS();
-               }
-               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_ground_pressure(double ground_pressure) {
-               if (ground_pressure != AltosLib.MISSING) {
-                       this.ground_pressure = ground_pressure;
-                       this.ground_altitude = AltosConvert.pressure_to_altitude(ground_pressure);
-               }
-       }
-
-       public abstract void set_accel_ground(double along, double across, double through);
-       public abstract void set_gyro_zero(double roll, double pitch, double yaw);
-       public abstract void check_imu_wrap(AltosIMU imu);
-       public abstract void set_imu(AltosIMU imu);
-       public abstract void set_mag(AltosMag mag);
-       public abstract void set_pyro_voltage(double volts);
-       public abstract void set_igniter_voltage(double[] voltage);
-       public abstract void set_pyro_fired(int pyro_mask);
-
-       public void copy(AltosFlightListener old) {
-               flight = old.flight;
-               serial = old.serial;
-               tick = old.tick;
-               boost_tick = old.boost_tick;
-               accel_plus_g = old.accel_plus_g;
-               accel_minus_g = old.accel_minus_g;
-               ground_pressure = old.ground_pressure;
-               ground_altitude = old.ground_altitude;
-               temp_gps = old.temp_gps;
-               temp_gps_sat_tick = old.temp_gps_sat_tick;
-       }
-
-       public void init() {
-               flight = AltosLib.MISSING;
-               serial = AltosLib.MISSING;
-               tick = AltosLib.MISSING;
-               boost_tick = AltosLib.MISSING;
-               accel_plus_g = AltosLib.MISSING;
-               accel_minus_g = AltosLib.MISSING;
-               accel = AltosLib.MISSING;
-               ground_pressure = AltosLib.MISSING;
-               ground_altitude = AltosLib.MISSING;
-               temp_gps = null;
-               temp_gps_sat_tick = AltosLib.MISSING;
-       }
-}
index 2eaf80330d4d4b6b8b6c087981e0da599d1c6824..d130d3adcfa6ae6ca41f38da645c060fbf046b41 100644 (file)
@@ -532,6 +532,7 @@ public class AltosFlightSeries extends AltosDataListener {
        public static final String gps_hdop_name = "GPS Horizontal Dilution of Precision";
 
        public void set_gps(AltosGPS gps) {
+               super.set_gps(gps);
                if (gps_series == null)
                        gps_series = new ArrayList<AltosGPSTimeValue>();
                gps_series.add(new AltosGPSTimeValue(time(), gps));
index 24b425b78a2bc797f93cf77bdd6b405d1d318f58..7ce4197b6af41ad68c21fcc4a7d5a8d69344a611 100644 (file)
@@ -70,7 +70,7 @@ class AltosReplay extends AltosDataListener implements Runnable {
        public void set_apogee_voltage(double volts) { state.set_apogee_voltage(volts); }
        public void set_main_voltage(double volts) { state.set_main_voltage(volts); }
 
-       public void set_gps(AltosGPS gps) { state.set_gps(gps); }
+       public void set_gps(AltosGPS gps) { super.set_gps(gps); state.set_gps(gps); }
 
        public void set_orient(double orient) { state.set_orient(orient); }
        public void set_gyro(double roll, double pitch, double yaw) { state.set_gyro(roll, pitch, yaw); }
index 54c7009451232bd43651b4028d31450622474c27..68097faf8bb6b589d600b61adfd4d9e6ae0b4df3 100644 (file)
@@ -887,6 +887,7 @@ public class AltosState extends AltosDataListener {
        }
 
        public void set_gps(AltosGPS gps) {
+               super.set_gps(gps);
                if (gps != null) {
                        this.gps = gps;
                        update_gps();
index f4366e33a3116ada1f71104dc4854dce701e1cad..e2925a58c165caf6e534b4c729b8996547e56ff0 100644 (file)
@@ -54,7 +54,7 @@ public class AltosTelemetryLocation extends AltosTelemetryStandard {
 
                AltosCalData    cal_data = listener.cal_data();
 
-               AltosGPS        gps = cal_data.make_temp_gps(tick(), false);
+               AltosGPS        gps = listener.make_temp_gps(false);
 
                int flags = flags();
                gps.nsat = flags & 0xf;
@@ -77,12 +77,7 @@ public class AltosTelemetryLocation extends AltosTelemetryStandard {
                        gps.ground_speed = ground_speed() * 1.0e-2;
                        gps.course = course() * 2;
                        gps.climb_rate = climb_rate() * 1.0e-2;
-
-                       if (gps.nsat >= 4)
-                               cal_data.set_gps(gps);
                }
                listener.set_gps(gps);
-               cal_data.set_gps(gps);
-               cal_data.reset_temp_gps();
        }
 }
index 60bc4a51db41ba15cbb4ddcc1a1333094b6239bc..0965df9fec8df6c3c42a96267c1b9d0512fd2ff1 100644 (file)
@@ -49,10 +49,9 @@ public class AltosTelemetrySatellite extends AltosTelemetryStandard {
 
                AltosCalData    cal_data = listener.cal_data();
 
-               AltosGPS        gps = cal_data.make_temp_gps(tick(), true);
+               AltosGPS        gps = listener.make_temp_gps(true);
 
                gps.cc_gps_sat = sats();
                listener.set_gps(gps);
-               cal_data.reset_temp_gps();
        }
 }