altoslib: Create new abstraction underneath AltosState for recording values
authorKeith Packard <keithp@keithp.com>
Fri, 12 May 2017 00:14:51 +0000 (17:14 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 20 May 2017 04:41:40 +0000 (21:41 -0700)
Provides a way for the graph API to see raw data values, instead of
those cooked by AltosState.

Signed-off-by: Keith Packard <keithp@keithp.com>
19 files changed:
altoslib/AltosConfigData.java
altoslib/AltosConvert.java
altoslib/AltosEepromFile.java
altoslib/AltosEepromRecord.java
altoslib/AltosEepromRecordFireTwo.java
altoslib/AltosEepromRecordFull.java
altoslib/AltosEepromRecordGps.java
altoslib/AltosEepromRecordMega.java
altoslib/AltosEepromRecordMetrum.java
altoslib/AltosEepromRecordMini.java
altoslib/AltosEepromRecordSet.java
altoslib/AltosEepromRecordTiny.java
altoslib/AltosFlightListener.java [new file with mode: 0644]
altoslib/AltosFlightSeries.java [new file with mode: 0644]
altoslib/AltosRecordSet.java [new file with mode: 0644]
altoslib/AltosRotationRate.java [new file with mode: 0644]
altoslib/AltosState.java
altoslib/AltosTimeSeries.java
altoslib/Makefile.am

index 23ab1e113cd0264ac6b883f1761740a56a8023c3..05fc2031c3bc2cd067d7d8ce2eab7eab626373d5 100644 (file)
@@ -214,6 +214,10 @@ public class AltosConfigData implements Iterable<String> {
                return r;
        }
 
+       public boolean altitude_32() {
+               return altitude_32 == 1;
+       }
+
        public int compare_version(String other) {
                int[]   me = parse_version(version);
                int[]   them = parse_version(other);
@@ -438,11 +442,11 @@ public class AltosConfigData implements Iterable<String> {
 
                if (frequency > 0) {
                        radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
-                       radio_channel = -1;
+                       radio_channel = AltosLib.MISSING;
                } else if (setting > 0) {
                        radio_setting =AltosConvert.radio_frequency_to_setting(freq,
                                                                                    radio_calibration);
-                       radio_channel = -1;
+                       radio_channel = AltosLib.MISSING;
                } else {
                        radio_channel = AltosConvert.radio_frequency_to_channel(freq);
                }
@@ -453,7 +457,7 @@ public class AltosConfigData implements Iterable<String> {
                int     setting = radio_setting;
 
                if (radio_frequency < 0 && channel < 0 && setting < 0)
-                       return -1;
+                       return AltosLib.MISSING;
 
                if (channel < 0)
                        channel = 0;
index 3489a609fc9eac2156b9c586ee23af0660a09512..a3343a4f200aad0171696a31aaa88545c282b026 100644 (file)
@@ -408,6 +408,8 @@ public class AltosConvert {
 
        public static AltosLongitude longitude = new AltosLongitude();
 
+       public static AltosRotationRate rotation_rate = new AltosRotationRate();
+
        public static String show_gs(String format, double a) {
                a = meters_to_g(a);
                format = format.concat(" g");
index 4606e78091946b84911fd0d0be7777c5b2800986..7f6299131087b61e39baa6c8e0dc2c3cc5df028f 100644 (file)
@@ -22,7 +22,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 
-public class AltosEepromFile extends AltosStateIterable {
+public class AltosEepromFile extends AltosStateIterable implements AltosRecordSet {
 
        AltosEepromRecordSet    set;
 
@@ -44,4 +44,8 @@ public class AltosEepromFile extends AltosStateIterable {
        public Iterator<AltosState> iterator() {
                return set.iterator();
        }
+
+       public void capture_series(AltosFlightSeries series) {
+               set.capture_series(series);
+       }
 }
index c0edb9526bf235a80a2c7b557054aa97e5f29f77..1f6ade66d3e5841488ac7cc0e85ded7937b846d2 100644 (file)
@@ -14,7 +14,6 @@
 
 package org.altusmetrum.altoslib_11;
 
-
 public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> {
 
        AltosEepromNew          eeprom;
@@ -65,6 +64,10 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>
                return 1;
        }
 
+       public AltosConfigData config_data() {
+               return eeprom.config_data();
+       }
+
        public int compareTo(AltosEepromRecord o) {
                int     cmd_diff = cmdi() - o.cmdi();
 
@@ -78,11 +81,11 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>
                return start - o.start;
        }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener listen) {
                if (cmd() == AltosLib.AO_LOG_FLIGHT)
-                       state.set_boost_tick(tick());
+                       listen.set_boost_tick(tick());
                else
-                       state.set_tick(tick());
+                       listen.set_tick(tick());
        }
 
        public int next_start() {
index 8c03cd5657e9eec3fd0da949c20f163c0640a216..a430bd97c86a6bae0ca7b6e534f10615e15a1e51 100644 (file)
@@ -68,7 +68,7 @@ public class AltosEepromRecordFireTwo extends AltosEepromRecord {
                return AltosConvert.lb_to_n(v * 298 * 9.807);
        }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                super.update_state(state);
 
                switch (cmd()) {
index fbb8fbd9e7ff14cd528f27f564f5a6c0d8964797..0fdfa5e73c2473c7a6184762e85934d3296273f3 100644 (file)
@@ -21,12 +21,13 @@ public class AltosEepromRecordFull extends AltosEepromRecord {
 
        public static final int two_g_default = 16294 - 15758;
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
+
                super.update_state(state);
                AltosGPS        gps;
 
                /* Flush any pending GPS changes */
-               if (state.gps_pending) {
+               if (state.gps_pending()) {
                        switch (cmd()) {
                        case AltosLib.AO_LOG_GPS_LAT:
                        case AltosLib.AO_LOG_GPS_LON:
index 1312d3ecbd18fa6774f027cdae71528bfb11eae7..4f30692ee334fa2292686cd4b533e9ce2af69ed9 100644 (file)
@@ -71,13 +71,13 @@ public class AltosEepromRecordGps extends AltosEepromRecord {
                return start - o.start;
        }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                super.update_state(state);
 
                AltosGPS        gps;
 
                /* Flush any pending RecordGps changes */
-               if (state.gps_pending) {
+               if (state.gps_pending()) {
                        switch (cmd()) {
                        case AltosLib.AO_LOG_GPS_LAT:
                        case AltosLib.AO_LOG_GPS_LON:
@@ -93,7 +93,7 @@ public class AltosEepromRecordGps extends AltosEepromRecord {
 
                switch (cmd()) {
                case AltosLib.AO_LOG_FLIGHT:
-                       if (state.flight == AltosLib.MISSING) {
+                       if (state.flight() == AltosLib.MISSING) {
                                state.set_boost_tick(tick());
                                state.set_flight(flight());
                        }
index 1c6d1aee90a39747f976d3c73ca60da7e47b93d2..3c5f60b31170c036060f902247c352c4177aa5b0 100644 (file)
@@ -109,12 +109,12 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
        private int svid(int n) { return data8(2 + n * 2); }
        private int c_n(int n) { return data8(2 + n * 2 + 1); }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                super.update_state(state);
                AltosGPS        gps;
 
                /* Flush any pending GPS changes */
-               if (state.gps_pending) {
+               if (state.gps_pending()) {
                        switch (cmd()) {
                        case AltosLib.AO_LOG_GPS_LAT:
                        case AltosLib.AO_LOG_GPS_LON:
@@ -186,7 +186,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                        gps.lat = latitude() / 1e7;
                        gps.lon = longitude() / 1e7;
 
-                       if (state.altitude_32())
+                       if (config_data().altitude_32())
                                gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
                        else
                                gps.alt = altitude_low();
@@ -208,7 +208,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                        gps.ground_speed = ground_speed() * 1.0e-2;
                        gps.course = course() * 2;
                        gps.climb_rate = climb_rate() * 1.0e-2;
-                       if (state.compare_version("1.4.9") >= 0) {
+                       if (config_data().compare_version("1.4.9") >= 0) {
                                gps.pdop = pdop() / 10.0;
                                gps.hdop = hdop() / 10.0;
                                gps.vdop = vdop() / 10.0;
index c11b6aacf7e49a5084e0ff5f53f365111efee3e8..6d516ebbe93cbb58081694ea5f48e71a65d0ce47 100644 (file)
@@ -65,13 +65,13 @@ public class AltosEepromRecordMetrum extends AltosEepromRecord {
        public int svid(int n) { return data8(2 + n * 2); }
        public int c_n(int n) { return data8(2 + n * 2 + 1); }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                super.update_state(state);
 
                AltosGPS        gps;
 
                /* Flush any pending GPS changes */
-               if (state.gps_pending) {
+               if (state.gps_pending()) {
                        switch (cmd()) {
                        case AltosLib.AO_LOG_GPS_POS:
                        case AltosLib.AO_LOG_GPS_LAT:
@@ -111,7 +111,7 @@ public class AltosEepromRecordMetrum extends AltosEepromRecord {
                        gps = state.make_temp_gps(false);
                        gps.lat = latitude() / 1e7;
                        gps.lon = longitude() / 1e7;
-                       if (state.altitude_32())
+                       if (config_data().altitude_32())
                                gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
                        else
                                gps.alt = altitude_low();
index f0fc61ad236147b9ece79f60a95dacac9b2b4ce5..dedf4bda7555872783e921ebfa48c91040eb222b 100644 (file)
@@ -62,7 +62,7 @@ public class AltosEepromRecordMini extends AltosEepromRecord {
                return -1;
        }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                super.update_state(state);
 
                switch (cmd()) {
index 911b90b9f9f471f5c26167eeb8ad93a7cc347629..653a1305c934b97262550f60cb49354b1125d13b 100644 (file)
@@ -17,7 +17,7 @@ package org.altusmetrum.altoslib_11;
 import java.io.*;
 import java.util.*;
 
-public class AltosEepromRecordSet implements Iterable<AltosState> {
+public class AltosEepromRecordSet implements Iterable<AltosState>, AltosRecordSet {
        AltosEepromNew                  eeprom;
        TreeSet<AltosEepromRecord>      ordered;
        AltosState                      start_state;
@@ -52,6 +52,13 @@ public class AltosEepromRecordSet implements Iterable<AltosState> {
                return new RecordIterator();
        }
 
+       public void capture_series(AltosFlightSeries series) {
+               series.set_config_data(eeprom.config_data());
+               for (AltosEepromRecord record : ordered) {
+                       record.update_state(series);
+               }
+       }
+
        public AltosEepromRecordSet(AltosEepromNew eeprom) {
                this.eeprom = eeprom;
 
index fda6ddff8db063848dd54dc13980988b7b0217a5..e70f8cdc58ee4f1da79cc7fb40ffa0c5f3089f80 100644 (file)
@@ -50,7 +50,7 @@ public class AltosEepromRecordTiny extends AltosEepromRecord {
                return tick;
        }
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosFlightListener state) {
                int value = data16(-header_length);
 
                state.set_tick(tick());
diff --git a/altoslib/AltosFlightListener.java b/altoslib/AltosFlightListener.java
new file mode 100644 (file)
index 0000000..ff5e4c3
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * 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_11;
+
+public abstract class AltosFlightListener {
+
+       int flight;
+
+       public int tick;
+       int boost_tick;
+
+       AltosGPS temp_gps;
+       int temp_gps_sat_tick;
+
+       /* 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;
+               return tick / 100.0;
+       }
+
+       public double boost_time() {
+               if (boost_tick == AltosLib.MISSING)
+                       return AltosLib.MISSING;
+               return boost_tick / 100.0;
+       }
+
+       /* AltosEepromRecordFull */
+
+       public abstract void set_state(int 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_accel_g(double accel_plus_g, double accel_minus_g);
+       public abstract void set_pressure(double pa);
+
+       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 abstract void set_ground_pressure(double 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 set_ms5607(int pres_val, int temp_val);
+       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_ignitor_voltage(double[] voltage);
+       public abstract void set_pyro_fired(int pyro_mask);
+
+       public void copy(AltosFlightListener old) {
+               flight = old.flight;
+               tick = old.tick;
+               boost_tick = old.boost_tick;
+               temp_gps = old.temp_gps;
+               temp_gps_sat_tick = old.temp_gps_sat_tick;
+       }
+
+       public void init() {
+               flight = AltosLib.MISSING;
+               tick = AltosLib.MISSING;
+               boost_tick = AltosLib.MISSING;
+               temp_gps_sat_tick = AltosLib.MISSING;
+       }
+}
diff --git a/altoslib/AltosFlightSeries.java b/altoslib/AltosFlightSeries.java
new file mode 100644 (file)
index 0000000..752aa48
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * 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_11;
+
+import java.util.*;
+
+public class AltosFlightSeries extends AltosFlightListener {
+
+       int flight;
+
+       int tick;
+       int boost_tick;
+
+       AltosGPS temp_gps;
+       int temp_gps_sat_tick;
+
+       AltosMs5607 ms5607;
+
+       public ArrayList<AltosTimeSeries> series;
+
+       /* 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;
+               return tick / 100.0;
+       }
+
+       public double boost_time() {
+               if (boost_tick == AltosLib.MISSING)
+                       return AltosLib.MISSING;
+               return boost_tick / 100.0;
+       }
+
+       public AltosTimeSeries make_series(String label, AltosUnits units) {
+               return new AltosTimeSeries(label, units);
+       }
+
+       public AltosTimeSeries add_series(String label, AltosUnits units) {
+               System.out.printf("add series %s\n", label);
+               AltosTimeSeries s = make_series(label, units);
+               series.add(s);
+               return s;
+       }
+
+       /* AltosEepromRecordFull */
+
+       AltosTimeSeries state_series;
+
+       public static final String state_name = "State";
+
+       public void set_state(int state) {
+               if (state_series == null)
+                       state_series = add_series(state_name, null);
+               state_series.add(time(), state);
+       }
+
+       public void set_flight(int flight) {
+               if (flight != AltosLib.MISSING)
+                       this.flight = flight;
+       }
+       public int flight() {
+               return flight;
+       }
+
+       AltosTimeSeries accel_series;
+
+       double accel_plus_g, accel_minus_g;
+
+       public static final String accel_name = "Accel";
+
+       public  void set_accel(double accel) {
+               if (accel_series == null)
+                       accel_series = add_series(accel_name, AltosConvert.accel);
+               double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0;
+               double counts_per_mss = counts_per_g / 9.80665;
+               double mss = (accel_plus_g - accel) / counts_per_mss;
+
+               accel_series.add(time(), mss);
+       }
+
+
+       public  void set_accel_g(double accel_plus_g, double accel_minus_g) {
+               this.accel_plus_g = accel_plus_g;
+               this.accel_minus_g = accel_minus_g;
+       }
+
+       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())
+                       this.ms5607 = ms5607;
+       }
+
+       public  void set_ground_accel(double ground_accel) {
+       }
+
+       AltosTimeSeries pressure_series;
+
+       public static final String pressure_name = "Pressure";
+
+       public  void set_pressure(double pa) {
+               if (pressure_series == null)
+                       pressure_series = add_series(pressure_name, AltosConvert.pressure);
+               pressure_series.add(time(), pa);
+       }
+
+       public  void set_temperature(double deg_c) {
+       }
+
+       public  void set_battery_voltage(double volts) {
+       }
+
+       public  void set_apogee_voltage(double volts) {
+       }
+
+       public  void set_main_voltage(double volts) {
+       }
+
+       AltosTimeSeries sats_in_view;
+       AltosTimeSeries sats_in_soln;
+       AltosTimeSeries gps_altitude;
+       AltosTimeSeries gps_ground_speed;
+       AltosTimeSeries gps_ascent_rate;
+       AltosTimeSeries gps_course;
+       AltosTimeSeries gps_speed;
+
+       public static final String sats_in_view_name = "Satellites in view";
+       public static final String sats_in_soln_name = "Satellites in solution";
+       public static final String gps_altitude_name = "GPS Altitude";
+
+       public void set_temp_gps() {
+               if (sats_in_view == null) {
+                       sats_in_view = add_series("Satellites in view", null);
+                       sats_in_soln = add_series("Satellites in solution", null);
+                       gps_altitude = add_series("GPS Altitude", AltosConvert.height);
+                       gps_ground_speed = add_series("GPS Ground Speed", AltosConvert.speed);
+                       gps_ascent_rate = add_series("GPS Ascent Rate", AltosConvert.speed);
+                       gps_course = add_series("GPS Course", null);
+                       gps_speed = add_series("GPS Speed", null);
+               }
+
+               /* XXX capture GPS data */
+               super.set_temp_gps();
+       }
+
+       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) {
+       }
+
+       public  void set_accel_ground(double along, double across, double through) {
+       }
+
+       public  void set_gyro_zero(double roll, double pitch, double yaw) {
+       }
+
+       public  void set_ms5607(int pres_val, int temp_val) {
+               if (ms5607 != null) {
+                       ms5607.set(pres_val, temp_val);
+
+                       set_pressure(ms5607.pa);
+                       set_temperature(ms5607.cc / 100.0);
+               }
+       }
+
+       public  void check_imu_wrap(AltosIMU imu) {
+       }
+
+       public  void set_imu(AltosIMU imu) {
+       }
+
+       public  void set_mag(AltosMag mag) {
+       }
+
+       public  void set_pyro_voltage(double volts) {
+       }
+
+       public  void set_ignitor_voltage(double[] voltage) {
+       }
+
+       public  void set_pyro_fired(int pyro_mask) {
+       }
+
+       public void init() {
+               flight = AltosLib.MISSING;
+               tick = AltosLib.MISSING;
+               boost_tick = AltosLib.MISSING;
+               temp_gps_sat_tick = AltosLib.MISSING;
+               series = new ArrayList<AltosTimeSeries>();
+       }
+
+       public void copy(AltosFlightSeries old) {
+               super.copy(old);
+       }
+
+       public AltosTimeSeries[] series() {
+               return series.toArray(new AltosTimeSeries[0]);
+       }
+
+       public AltosFlightSeries() {
+               init();
+       }
+}
diff --git a/altoslib/AltosRecordSet.java b/altoslib/AltosRecordSet.java
new file mode 100644 (file)
index 0000000..8a47233
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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_11;
+
+import java.util.*;
+
+public interface AltosRecordSet {
+       public void capture_series(AltosFlightSeries series);
+}
diff --git a/altoslib/AltosRotationRate.java b/altoslib/AltosRotationRate.java
new file mode 100644 (file)
index 0000000..c3f26f4
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_11;
+
+public class AltosRotationRate extends AltosUnits {
+
+       public double value(double p, boolean imperial_units) {
+               return p;
+       }
+
+       public double inverse(double p, boolean imperial_units) {
+               return p;
+       }
+
+       public String show_units(boolean imperial_units) {
+               return "°/sec";
+       }
+
+       public String say_units(boolean imperial_units) {
+               return "degrees per second";
+       }
+
+       public int show_fraction(int width, boolean imperial_units) {
+               return 1;
+       }
+}
index 8c3f93f0c0e9481930dcbf195be0a2e02c118c74..6aa77139d62f81f9edd47191b51640a7367ae813 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;
@@ -870,6 +868,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 +1071,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);
        }
@@ -1502,23 +1497,10 @@ 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) {
index 53c0076f5ed345d58f79b89ef4b614155f9c20c6..0ea7b3561baa6e9e6390d74d3003235f9918ffae 100644 (file)
@@ -29,6 +29,62 @@ public class AltosTimeSeries implements Iterable<AltosTimeValue> {
                return values.iterator();
        }
 
+       public void integrate(AltosTimeSeries integral) {
+               double  y = 0.0;
+               double  x = 0.0;
+               boolean start = true;
+
+               for (AltosTimeValue v : values) {
+                       if (start) {
+                               y = 0.0;
+                               x = v.x;
+                               start = false;
+                       } else {
+                               y += v.y * (v.x - x);
+                               x = v.x;
+                       }
+                       integral.add(x, y);
+               }
+       }
+
+       public void differentiate(AltosTimeSeries diff) {
+               double y = 0.0;
+               double x = 0.0;
+               boolean start = true;
+
+               for (AltosTimeValue v: values) {
+                       if (start) {
+                               y = 0.0;
+                               x = v.x;
+                               start = false;
+                       } else {
+                               double  dx = v.x - x;
+                               double  dy = v.y - y;
+
+                               x = v.x;
+                               y = v.y;
+                               if (dx != 0)
+                                       diff.add(x, dy);
+                       }
+               }
+       }
+
+       private int find_left(int i, double dt) {
+               int j;
+               double t = values.get(i).x - dt;
+               for (j = i; j > 0; j--) {
+                       if (values.get(j).x < t)
+                               break;
+               }
+               return j;
+
+       }
+
+       public void filter(AltosTimeSeries out, double width) {
+               for (int i = 0; i < values.size(); i++) {
+               }
+       }
+
        public AltosTimeSeries(String label, AltosUnits units) {
                this.label = label;
                this.units = units;
index 20b8284980ae287e8a31c7b2407a3766eaa7dc3e..1b37215c736b053fadcd0c99c956466c430f43b7 100644 (file)
@@ -35,6 +35,7 @@ altoslib_JAVA = \
        AltosCSV.java \
        AltosDebug.java \
        AltosEepromNew.java \
+       AltosRecordSet.java \
        AltosEepromRecord.java \
        AltosEepromRecordFull.java \
        AltosEepromRecordTiny.java \
@@ -54,6 +55,8 @@ altoslib_JAVA = \
        AltosFile.java \
        AltosFlash.java \
        AltosFlashListener.java \
+       AltosFlightListener.java \
+       AltosFlightSeries.java \
        AltosFlightReader.java \
        AltosFlightStats.java \
        AltosForce.java \
@@ -138,6 +141,7 @@ altoslib_JAVA = \
        AltosLocation.java \
        AltosLatitude.java \
        AltosLongitude.java \
+       AltosRotationRate.java \
        AltosPyro.java \
        AltosWriter.java \
        AltosQuaternion.java \