altosdroid: Deal with AltosState changes
authorKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 07:27:04 +0000 (00:27 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 07:27:04 +0000 (00:27 -0700)
cal data split out from altos state.
altos state needed to have no-arguments constructor for JSON code.
Also messed with voice to make it stay quiet during app startup.

Signed-off-by: Keith Packard <keithp@keithp.com>
14 files changed:
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java
altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java
altoslib/AltosDataListener.java
altoslib/AltosFlightSeries.java
altoslib/AltosFlightStats.java
altoslib/AltosMapStore.java
altoslib/AltosState.java
altoslib/AltosTelemetryFile.java
altosui/AltosGraphUI.java

index 30a949d57378cf8607c7a7a2e5a230e9c2dfb7c3..36ba03084cd931163221ed2bad6e9b1291076538 100644 (file)
@@ -54,6 +54,29 @@ import android.graphics.drawable.*;
 
 import org.altusmetrum.altoslib_11.*;
 
 
 import org.altusmetrum.altoslib_11.*;
 
+class SavedState {
+       long    received_time;
+       int     state;
+       boolean locked;
+       String  callsign;
+       int     serial;
+       int     flight;
+       int     rssi;
+
+       SavedState(AltosState state) {
+               received_time = state.received_time;
+               this.state = state.state();
+               if (state.gps != null)
+                       locked = state.gps.locked;
+               else
+                       locked = false;
+               callsign = state.cal_data.callsign;
+               serial = state.cal_data.serial;
+               flight = state.cal_data.flight;
+               rssi = state.rssi;
+       }
+}
+
 public class AltosDroid extends FragmentActivity implements AltosUnitsListener, LocationListener {
 
        // Actions sent to the telemetry server at startup time
 public class AltosDroid extends FragmentActivity implements AltosUnitsListener, LocationListener {
 
        // Actions sent to the telemetry server at startup time
@@ -114,6 +137,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
        public Location location = null;
 
 
        public Location location = null;
 
+       private AltosState      state;
+       private SavedState      saved_state;
+
        // Tabs
        TabHost         mTabHost;
        AltosViewPager  mViewPager;
        // Tabs
        TabHost         mTabHost;
        AltosViewPager  mViewPager;
@@ -123,7 +149,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
        // Timer and Saved flight state for Age calculation
        private Timer timer;
 
        // Timer and Saved flight state for Age calculation
        private Timer timer;
-       AltosState saved_state;
+
        TelemetryState  telemetry_state;
        Integer[]       serials;
 
        TelemetryState  telemetry_state;
        Integer[]       serials;
 
@@ -307,7 +333,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
                if (telemetry_state.states.containsKey(current_serial)) {
                        state = telemetry_state.states.get(current_serial);
 
                if (telemetry_state.states.containsKey(current_serial)) {
                        state = telemetry_state.states.get(current_serial);
-                       int age = state_age(state);
+                       int age = state_age(state.received_time);
                        if (age < 20)
                                aged = false;
                        if (current_serial == selected_serial)
                        if (age < 20)
                                aged = false;
                        if (current_serial == selected_serial)
@@ -322,7 +348,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
                        for (int serial : telemetry_state.states.keySet()) {
                                AltosState      existing = telemetry_state.states.get(serial);
 
                        for (int serial : telemetry_state.states.keySet()) {
                                AltosState      existing = telemetry_state.states.get(serial);
-                               int             existing_age = state_age(existing);
+                               int             existing_age = state_age(existing.received_time);
 
                                if (newest_state == null || existing_age < newest_age) {
                                        newest_state = existing;
 
                                if (newest_state == null || existing_age < newest_age) {
                                        newest_state = existing;
@@ -334,7 +360,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                state = newest_state;
                }
 
                                state = newest_state;
                }
 
-               update_ui(telemetry_state, state);
+               update_ui(telemetry_state, state, telemetry_state.quiet);
 
                start_timer();
        }
 
                start_timer();
        }
@@ -362,8 +388,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                        blend_component(a, b, r, 24, 0xff));
        }
 
                        blend_component(a, b, r, 24, 0xff));
        }
 
-       int state_age(AltosState state) {
-               return (int) ((System.currentTimeMillis() - state.received_time + 500) / 1000);
+       int state_age(long received_time) {
+               return (int) ((System.currentTimeMillis() - received_time + 500) / 1000);
        }
 
        void set_screen_on(int age) {
        }
 
        void set_screen_on(int age) {
@@ -375,7 +401,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
        void update_age() {
                if (saved_state != null) {
 
        void update_age() {
                if (saved_state != null) {
-                       int age = state_age(saved_state);
+                       int age = state_age(saved_state.received_time);
 
                        double age_scale = age / 100.0;
 
 
                        double age_scale = age / 100.0;
 
@@ -399,17 +425,19 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                }
        }
 
                }
        }
 
-       void update_ui(TelemetryState telem_state, AltosState state) {
+       void update_ui(TelemetryState telem_state, AltosState state, boolean quiet) {
+
+               this.state = state;
 
                int prev_state = AltosLib.ao_flight_invalid;
 
                AltosGreatCircle from_receiver = null;
 
                if (saved_state != null)
 
                int prev_state = AltosLib.ao_flight_invalid;
 
                AltosGreatCircle from_receiver = null;
 
                if (saved_state != null)
-                       prev_state = saved_state.state();
+                       prev_state = saved_state.state;
 
                if (state != null) {
 
                if (state != null) {
-                       set_screen_on(state_age(state));
+                       set_screen_on(state_age(state.received_time));
 
                        if (state.state() == AltosLib.ao_flight_stateless) {
                                boolean prev_locked = false;
 
                        if (state.state() == AltosLib.ao_flight_stateless) {
                                boolean prev_locked = false;
@@ -417,8 +445,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
                                if(state.gps != null)
                                        locked = state.gps.locked;
 
                                if(state.gps != null)
                                        locked = state.gps.locked;
-                               if (saved_state != null && saved_state.gps != null)
-                                       prev_locked = saved_state.gps.locked;
+                               if (saved_state != null)
+                                       prev_locked = saved_state.locked;
                                if (prev_locked != locked) {
                                        String currentTab = mTabHost.getCurrentTabTag();
                                        if (locked) {
                                if (prev_locked != locked) {
                                        String currentTab = mTabHost.getCurrentTabTag();
                                        if (locked) {
@@ -456,22 +484,22 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                                                     state.gps.alt);
                        }
 
                                                                     state.gps.alt);
                        }
 
-                       if (saved_state == null || !same_string(saved_state.callsign, state.callsign)) {
-                               mCallsignView.setText(state.callsign);
+                       if (saved_state == null || !same_string(saved_state.callsign, state.cal_data.callsign)) {
+                               mCallsignView.setText(state.cal_data.callsign);
                        }
                        }
-                       if (saved_state == null || state.serial != saved_state.serial) {
-                               if (state.serial == AltosLib.MISSING)
+                       if (saved_state == null || state.cal_data.serial != saved_state.serial) {
+                               if (state.cal_data.serial == AltosLib.MISSING)
                                        mSerialView.setText("");
                                else
                                        mSerialView.setText("");
                                else
-                                       mSerialView.setText(String.format("%d", state.serial));
+                                       mSerialView.setText(String.format("%d", state.cal_data.serial));
                        }
                        }
-                       if (saved_state == null || state.flight != saved_state.flight) {
-                               if (state.flight == AltosLib.MISSING)
+                       if (saved_state == null || state.cal_data.flight != saved_state.flight) {
+                               if (state.cal_data.flight == AltosLib.MISSING)
                                        mFlightView.setText("");
                                else
                                        mFlightView.setText("");
                                else
-                                       mFlightView.setText(String.format("%d", state.flight));
+                                       mFlightView.setText(String.format("%d", state.cal_data.flight));
                        }
                        }
-                       if (saved_state == null || state.state() != saved_state.state()) {
+                       if (saved_state == null || state.state() != saved_state.state) {
                                if (state.state() == AltosLib.ao_flight_stateless) {
                                        mStateLayout.setVisibility(View.GONE);
                                } else {
                                if (state.state() == AltosLib.ao_flight_stateless) {
                                        mStateLayout.setVisibility(View.GONE);
                                } else {
@@ -485,15 +513,16 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                else
                                        mRSSIView.setText(String.format("%d", state.rssi));
                        }
                                else
                                        mRSSIView.setText(String.format("%d", state.rssi));
                        }
+                       saved_state = new SavedState(state);
                }
 
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
                }
 
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
+               AltosDebug.debug("quiet %b\n", quiet);
                if (mAltosVoice != null)
                if (mAltosVoice != null)
-                       mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem());
+                       mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem(), quiet);
 
 
-               saved_state = state;
        }
 
        private void onTimerTick() {
        }
 
        private void onTimerTick() {
@@ -567,8 +596,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                // Display the Version
                mVersion = (TextView) findViewById(R.id.version);
                mVersion.setText("Version: " + BuildInfo.version +
                // Display the Version
                mVersion = (TextView) findViewById(R.id.version);
                mVersion.setText("Version: " + BuildInfo.version +
-                                "  Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
-                                "  (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
+                                (AltosVersion.has_google_maps_api_key() ? " maps" : "") +
+                                " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
+                                " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
 
                mCallsignView  = (TextView) findViewById(R.id.callsign_value);
                mRSSIView      = (TextView) findViewById(R.id.rssi_value);
 
                mCallsignView  = (TextView) findViewById(R.id.callsign_value);
                mRSSIView      = (TextView) findViewById(R.id.rssi_value);
@@ -703,7 +733,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                         location.getLatitude(),
                                         location.getLongitude());
 
                                         location.getLatitude(),
                                         location.getLongitude());
 
-               update_ui(telemetry_state, saved_state);
+               update_ui(telemetry_state, state, true);
        }
 
        @Override
        }
 
        @Override
@@ -1094,7 +1124,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                AltosDebug.debug("Location changed to %f,%f",
                                 location.getLatitude(),
                                 location.getLongitude());
                AltosDebug.debug("Location changed to %f,%f",
                                 location.getLatitude(),
                                 location.getLongitude());
-               update_ui(telemetry_state, saved_state);
+               update_ui(telemetry_state, state, false);
        }
 
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
 
        public void onStatusChanged(String provider, int status, Bundle extras) {
index 2e6ccb34e2227277910bbf1237392ff404980287..2fceb535fede337115dca82ea1a8feee0233123e 100644 (file)
@@ -77,7 +77,17 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend {
        }
 
        public String getString(String key, String def) {
        }
 
        public String getString(String key, String def) {
-               return prefs.getString(key, def);
+               String  ret;
+               ret = prefs.getString(key, def);
+//             AltosDebug.debug("AltosDroidPreferencesBackend get string %s:\n", key);
+//             if (ret == null)
+//                     AltosDebug.debug("      (null)\n");
+//             else {
+//                     String[] lines = ret.split("\n");
+//                     for (String l : lines)
+//                             AltosDebug.debug("        %s\n", l);
+//             }
+               return ret;
        }
 
        public byte[] getBytes(String key, byte[] def) {
        }
 
        public byte[] getBytes(String key, byte[] def) {
@@ -103,6 +113,10 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend {
        }
 
        public void putString(String key, String value) {
        }
 
        public void putString(String key, String value) {
+//             AltosDebug.debug("AltosDroidPreferencesBackend put string %s:\n", key);
+//             String[] lines = value.split("\n");
+//             for (String l : lines)
+//                     AltosDebug.debug("        %s\n", l);
                editor.putString(key, value);
        }
 
                editor.putString(key, value);
        }
 
index 76771adcfce6246ae3b57078be6ff2338f4f5a7e..3f74bbba2426853012081da4f7ca45d09591ab62 100644 (file)
@@ -164,6 +164,7 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal
                                                break;
                                        case AltosMapTile.forbidden:
                                                message = "Too many requests, try later";
                                                break;
                                        case AltosMapTile.forbidden:
                                                message = "Too many requests, try later";
+                                               AltosDebug.debug("Forbidden map response %d\n", AltosMapStore.forbidden_response);
                                                break;
                                        }
                                        if (message != null) {
                                                break;
                                        }
                                        if (message != null) {
@@ -476,11 +477,11 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal
                                if (t_state.gps != null) {
                                        AltosLatLon     latlon = new AltosLatLon(t_state.gps.lat, t_state.gps.lon);
                                        rocket.set_position(latlon, t_state.received_time);
                                if (t_state.gps != null) {
                                        AltosLatLon     latlon = new AltosLatLon(t_state.gps.lat, t_state.gps.lon);
                                        rocket.set_position(latlon, t_state.received_time);
-                                       if (state.serial == serial)
+                                       if (state.cal_data.serial == serial)
                                                there = latlon;
                                }
                                if (state != null)
                                                there = latlon;
                                }
                                if (state != null)
-                                       rocket.set_active(state.serial == serial);
+                                       rocket.set_active(state.cal_data.serial == serial);
                        }
                }
                if (receiver != null) {
                        }
                }
                if (receiver != null) {
index 811b03675d63640bb62d258ce46a6a249fa43d9d..308c50e7d182eb7f3622f1a0082c1ebebb957fcf 100644 (file)
@@ -49,6 +49,7 @@ public class AltosVoice {
        private Location        last_receiver;
        private long            last_speak_time;
        private int             last_flight_tell = TELL_FLIGHT_NONE;
        private Location        last_receiver;
        private long            last_speak_time;
        private int             last_flight_tell = TELL_FLIGHT_NONE;
+       private boolean         quiet = false;
 
        private long now() {
                return System.currentTimeMillis();
 
        private long now() {
                return System.currentTimeMillis();
@@ -80,7 +81,8 @@ public class AltosVoice {
        public synchronized void speak(String s) {
                if (!tts_enabled) return;
                last_speak_time = now();
        public synchronized void speak(String s) {
                if (!tts_enabled) return;
                last_speak_time = now();
-               tts.speak(s, TextToSpeech.QUEUE_ADD, null);
+               if (!quiet)
+                       tts.speak(s, TextToSpeech.QUEUE_ADD, null);
        }
 
        public synchronized long time_since_speak() {
        }
 
        public synchronized long time_since_speak() {
@@ -121,6 +123,8 @@ public class AltosVoice {
                if (state == null)
                        return false;
 
                if (state == null)
                        return false;
 
+               AltosDebug.debug("tell_pad lag %b ltm %d\n", last_apogee_good, last_tell_mode);
+
                if (state.apogee_voltage != AltosLib.MISSING)
                        last_apogee_good = tell_gonogo("apogee",
                                                       state.apogee_voltage >= AltosLib.ao_igniter_good,
                if (state.apogee_voltage != AltosLib.MISSING)
                        last_apogee_good = tell_gonogo("apogee",
                                                       state.apogee_voltage >= AltosLib.ao_igniter_good,
@@ -277,7 +281,9 @@ public class AltosVoice {
 
        public void tell(TelemetryState telem_state, AltosState state,
                         AltosGreatCircle from_receiver, Location receiver,
 
        public void tell(TelemetryState telem_state, AltosState state,
                         AltosGreatCircle from_receiver, Location receiver,
-                        AltosDroidTab tab) {
+                        AltosDroidTab tab, boolean quiet) {
+
+               this.quiet = quiet;
 
                boolean spoken = false;
 
 
                boolean spoken = false;
 
@@ -288,7 +294,7 @@ public class AltosVoice {
                int     tell_serial = last_tell_serial;
 
                if (state != null)
                int     tell_serial = last_tell_serial;
 
                if (state != null)
-                       tell_serial = state.serial;
+                       tell_serial = state.cal_data.serial;
 
                if (tell_serial != last_tell_serial)
                        reset_last();
 
                if (tell_serial != last_tell_serial)
                        reset_last();
index 492f7f5f4585c61dffb703c5189fd4802423bbd2..37e2df187759fa1d071a6c0ad3071c746f95a197 100644 (file)
@@ -178,10 +178,10 @@ public class TabPad extends AltosDroidTab {
                        }
                        main_lights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING);
 
                        }
                        main_lights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING);
 
-                       int num_igniter = state.ignitor_voltage == null ? 0 : state.ignitor_voltage.length;
+                       int num_igniter = state.igniter_voltage == null ? 0 : state.igniter_voltage.length;
 
                        for (int i = 0; i < 4; i++) {
 
                        for (int i = 0; i < 4; i++) {
-                               double voltage = i >= num_igniter ? AltosLib.MISSING : state.ignitor_voltage[i];
+                               double voltage = i >= num_igniter ? AltosLib.MISSING : state.igniter_voltage[i];
                                if (voltage == AltosLib.MISSING) {
                                        ignite_row[i].setVisibility(View.GONE);
                                } else {
                                if (voltage == AltosLib.MISSING) {
                                        ignite_row[i].setVisibility(View.GONE);
                                } else {
@@ -191,7 +191,7 @@ public class TabPad extends AltosDroidTab {
                                ignite_lights[i].set(voltage >= AltosLib.ao_igniter_good, voltage == AltosLib.MISSING);
                        }
 
                                ignite_lights[i].set(voltage >= AltosLib.ao_igniter_good, voltage == AltosLib.MISSING);
                        }
 
-                       if (state.flight != 0) {
+                       if (state.cal_data.flight != 0) {
                                if (state.state() <= AltosLib.ao_flight_pad)
                                        data_logging_view.setText("Ready to record");
                                else if (state.state() < AltosLib.ao_flight_landed)
                                if (state.state() <= AltosLib.ao_flight_pad)
                                        data_logging_view.setText("Ready to record");
                                else if (state.state() < AltosLib.ao_flight_landed)
@@ -201,7 +201,7 @@ public class TabPad extends AltosDroidTab {
                        } else {
                                data_logging_view.setText("Storage full");
                        }
                        } else {
                                data_logging_view.setText("Storage full");
                        }
-                       data_logging_lights.set(state.flight != 0, state.flight == AltosLib.MISSING);
+                       data_logging_lights.set(state.cal_data.flight != 0, state.cal_data.flight == AltosLib.MISSING);
 
                        if (state.gps != null) {
                                int soln = state.gps.nsat;
 
                        if (state.gps != null) {
                                int soln = state.gps.nsat;
index 34c86ce5b56e31b5d7b5cc46409297811d2353f2..45bb47328a2c9abb1cc3c41a454b28673487503b 100644 (file)
@@ -259,14 +259,15 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        private void telemetry(AltosTelemetry telem) {
                AltosState      state;
 
        private void telemetry(AltosTelemetry telem) {
                AltosState      state;
 
-               if (telemetry_state.states.containsKey(telem.serial))
-                       state = telemetry_state.states.get(telem.serial).clone();
+               if (telemetry_state.states.containsKey(telem.serial()))
+                       state = telemetry_state.states.get(telem.serial());
                else
                else
-                       state = new AltosState();
-               telem.update_state(state);
-               telemetry_state.states.put(telem.serial, state);
+                       state = new AltosState(new AltosCalData());
+               telem.provide_data(state, state.cal_data);
+               telemetry_state.states.put(telem.serial(), state);
+               telemetry_state.quiet = false;
                if (state != null) {
                if (state != null) {
-                       AltosPreferences.set_state(state);
+                       AltosPreferences.set_state(state,telem.serial());
                }
                send_to_clients();
        }
                }
                send_to_clients();
        }
@@ -615,6 +616,8 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
                telemetry_state.latest_serial = AltosPreferences.latest_state();
 
 
                telemetry_state.latest_serial = AltosPreferences.latest_state();
 
+               telemetry_state.quiet = true;
+
                AltosDebug.debug("latest serial %d\n", telemetry_state.latest_serial);
 
                for (int serial : serials) {
                AltosDebug.debug("latest serial %d\n", telemetry_state.latest_serial);
 
                for (int serial : serials) {
@@ -625,7 +628,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
                                AltosDebug.debug("recovered old state serial %d flight %d",
                                                 serial,
 
                                AltosDebug.debug("recovered old state serial %d flight %d",
                                                 serial,
-                                                saved_state.flight);
+                                                saved_state.cal_data.flight);
                                if (saved_state.gps != null)
                                        AltosDebug.debug("\tposition %f,%f",
                                                         saved_state.gps.lat,
                                if (saved_state.gps != null)
                                        AltosDebug.debug("\tposition %f,%f",
                                                         saved_state.gps.lat,
@@ -699,7 +702,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
        /* AltosIdleMonitorListener */
        public void update(AltosState state, AltosListenerState listener_state) {
 
        /* AltosIdleMonitorListener */
        public void update(AltosState state, AltosListenerState listener_state) {
-               telemetry_state.states.put(state.serial, state);
+               telemetry_state.states.put(state.cal_data.serial, state);
                telemetry_state.receiver_battery = listener_state.battery;
                send_to_clients();
        }
                telemetry_state.receiver_battery = listener_state.battery;
                send_to_clients();
        }
index 32ba12546d66c2ae9cbafbb766945f21299053ca..46b4027a94b472872af9b0b122856c219500f5bf 100644 (file)
@@ -36,6 +36,8 @@ public class TelemetryState {
        double          frequency;
        int             telemetry_rate;
 
        double          frequency;
        int             telemetry_rate;
 
+       boolean         quiet;
+
        HashMap<Integer,AltosState>     states;
 
        int             latest_serial;
        HashMap<Integer,AltosState>     states;
 
        int             latest_serial;
index 14c29d85263fc332e2ebe29f8be7bf6a22f121ec..f8d38731ea5004138ebf579d1f70e7d6d5a7881e 100644 (file)
@@ -16,9 +16,9 @@ package org.altusmetrum.altoslib_11;
 
 public abstract class AltosDataListener {
 
 
 public abstract class AltosDataListener {
 
-       public AltosCalData     cal_data;
-
-       public double   time = AltosLib.MISSING;
+       public AltosCalData     cal_data = null;
+       public double           time = AltosLib.MISSING;
+       public int              state = AltosLib.MISSING;
 
        public void set_time(double time) {
                if (time != AltosLib.MISSING)
 
        public void set_time(double time) {
                if (time != AltosLib.MISSING)
@@ -29,8 +29,6 @@ public abstract class AltosDataListener {
                return time;
        }
 
                return time;
        }
 
-       public int      state = AltosLib.MISSING;
-
        public void set_state(int state) {
                if (state != AltosLib.MISSING)
                        this.state = state;
        public void set_state(int state) {
                if (state != AltosLib.MISSING)
                        this.state = state;
@@ -67,6 +65,9 @@ public abstract class AltosDataListener {
        public abstract void set_pyro_fired(int pyro_mask);
        public abstract void set_companion(AltosCompanion companion);
 
        public abstract void set_pyro_fired(int pyro_mask);
        public abstract void set_companion(AltosCompanion companion);
 
+       public AltosDataListener() {
+       }
+
        public AltosDataListener(AltosCalData cal_data) {
                this.cal_data = cal_data;
        }
        public AltosDataListener(AltosCalData cal_data) {
                this.cal_data = cal_data;
        }
index 944cff31851a1d03cdd7fa72cfabf4db5d74b214..5cf552fcf00d178048f56fbafe3f2815b279820e 100644 (file)
@@ -216,7 +216,7 @@ public class AltosFlightSeries extends AltosDataListener {
 
        private void compute_height() {
                double ground_altitude = cal_data.ground_altitude;
 
        private void compute_height() {
                double ground_altitude = cal_data.ground_altitude;
-               if (height_series == null && ground_altitude != AltosLib.MISSING) {
+               if (height_series == null && ground_altitude != AltosLib.MISSING && altitude_series != null) {
                        height_series = add_series(height_name, AltosConvert.height);
                        for (AltosTimeValue alt : altitude_series)
                                height_series.add(alt.time, alt.value - ground_altitude);
                        height_series = add_series(height_name, AltosConvert.height);
                        for (AltosTimeValue alt : altitude_series)
                                height_series.add(alt.time, alt.value - ground_altitude);
index 9ebdb9e644a0e67bd5191d0d19bdc44977553ce0..f48e6be6077d8cb5a85b935624c92aa955362195 100644 (file)
@@ -51,21 +51,26 @@ public class AltosFlightStats {
        double landed_time(AltosFlightSeries series) {
                double  landed_state_time = AltosLib.MISSING;
 
        double landed_time(AltosFlightSeries series) {
                double  landed_state_time = AltosLib.MISSING;
 
-               for (AltosTimeValue state : series.state_series) {
-                       if (state.value == AltosLib.ao_flight_landed) {
-                               landed_state_time = state.time;
-                               break;
+               if (series.state_series != null) {
+                       for (AltosTimeValue state : series.state_series) {
+                               if (state.value == AltosLib.ao_flight_landed) {
+                                       landed_state_time = state.time;
+                                       break;
+                               }
                        }
                }
 
                        }
                }
 
-               if (landed_state_time == AltosLib.MISSING)
+               if (landed_state_time == AltosLib.MISSING && series.height_series != null)
                        landed_state_time = series.height_series.get(series.height_series.size()-1).time;
 
                double landed_height = AltosLib.MISSING;
                        landed_state_time = series.height_series.get(series.height_series.size()-1).time;
 
                double landed_height = AltosLib.MISSING;
-               for (AltosTimeValue height : series.height_series) {
-                       if (height.time >= landed_state_time) {
-                               landed_height = height.value;
-                               break;
+
+               if (series.height_series != null) {
+                       for (AltosTimeValue height : series.height_series) {
+                               if (height.time >= landed_state_time) {
+                                       landed_height = height.value;
+                                       break;
+                               }
                        }
                }
 
                        }
                }
 
@@ -76,13 +81,15 @@ public class AltosFlightStats {
 
                double  landed_time = AltosLib.MISSING;
 
 
                double  landed_time = AltosLib.MISSING;
 
-               for (AltosTimeValue height : series.height_series) {
-                       if (height.value > landed_height + 10) {
-                               above = true;
-                       } else {
-                               if (above && Math.abs(height.value - landed_height) < 2) {
-                                       above = false;
-                                       landed_time = height.time;
+               if (series.height_series != null) {
+                       for (AltosTimeValue height : series.height_series) {
+                               if (height.value > landed_height + 10) {
+                                       above = true;
+                               } else {
+                                       if (above && Math.abs(height.value - landed_height) < 2) {
+                                               above = false;
+                                               landed_time = height.time;
+                                       }
                                }
                        }
                }
                                }
                        }
                }
@@ -93,17 +100,21 @@ public class AltosFlightStats {
                double          boost_time = AltosLib.MISSING;
                double          boost_state_time = AltosLib.MISSING;
 
                double          boost_time = AltosLib.MISSING;
                double          boost_state_time = AltosLib.MISSING;
 
-               for (AltosTimeValue state : series.state_series) {
-                       if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
-                               boost_state_time = state.time;
-                               break;
+               if (series.state_series != null) {
+                       for (AltosTimeValue state : series.state_series) {
+                               if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
+                                       boost_state_time = state.time;
+                                       break;
+                               }
                        }
                }
                        }
                }
-               for (AltosTimeValue accel : series.accel_series) {
-                       if (accel.value < 1)
-                               boost_time = accel.time;
-                       if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
-                               break;
+               if (series.accel_series != null) {
+                       for (AltosTimeValue accel : series.accel_series) {
+                               if (accel.value < 1)
+                                       boost_time = accel.time;
+                               if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
+                                       break;
+                       }
                }
                return boost_time;
        }
                }
                return boost_time;
        }
@@ -136,12 +147,16 @@ public class AltosFlightStats {
 
                        if (s == AltosLib.ao_flight_boost)
                                state_start[s] = boost_time;
 
                        if (s == AltosLib.ao_flight_boost)
                                state_start[s] = boost_time;
-                       else
+                       else if (series.state_series != null)
                                state_start[s] = series.state_series.time_of(s);
                                state_start[s] = series.state_series.time_of(s);
+                       else
+                               state_start[s] = AltosLib.MISSING;
                        if (s == AltosLib.ao_flight_main)
                                state_end[s] = landed_time;
                        if (s == AltosLib.ao_flight_main)
                                state_end[s] = landed_time;
-                       else
+                       else if (series.state_series != null)
                                state_end[s] = series.state_series.time_of(s+1);
                                state_end[s] = series.state_series.time_of(s+1);
+                       else
+                               state_end[s] = AltosLib.MISSING;
 
                        if (series.speed_series != null)
                                state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
 
                        if (series.speed_series != null)
                                state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
index 7cce05a594c7eccb8008aaaca85c68357d97f76b..460c52b628ec4094a133cae4b1796dc8b3f4eee2 100644 (file)
@@ -91,6 +91,7 @@ public class AltosMapStore {
        static Object   forbidden_lock = new Object();
        static long     forbidden_time;
        static boolean  forbidden_set;
        static Object   forbidden_lock = new Object();
        static long     forbidden_time;
        static boolean  forbidden_set;
+       public static int forbidden_response;
 
        private int fetch_url() {
                URL u;
 
        private int fetch_url() {
                URL u;
@@ -116,6 +117,7 @@ public class AltosMapStore {
                                        synchronized (forbidden_lock) {
                                                forbidden_time = System.nanoTime();
                                                forbidden_set = true;
                                        synchronized (forbidden_lock) {
                                                forbidden_time = System.nanoTime();
                                                forbidden_set = true;
+                                               forbidden_response = response;
                                                return AltosMapTile.forbidden;
                                        }
                                }
                                                return AltosMapTile.forbidden;
                                        }
                                }
index d3929b8f7e047480ddcd02cef4eed0953863f26c..e5a0541e18af3d73ede2e596ae2c7d9c31cf814a 100644 (file)
@@ -43,8 +43,6 @@ public class AltosState extends AltosDataListener {
        public int      rssi;
        public int      status;
 
        public int      rssi;
        public int      status;
 
-       public double   time;
-
        class AltosValue {
                double  value;
                double  prev_value;
        class AltosValue {
                double  value;
                double  prev_value;
@@ -288,7 +286,6 @@ public class AltosState extends AltosDataListener {
                }
        }
 
                }
        }
 
-       private int     state;
        public boolean  landed;
        public boolean  ascent; /* going up? */
        public boolean  boost;  /* under power */
        public boolean  landed;
        public boolean  ascent; /* going up? */
        public boolean  boost;  /* under power */
@@ -506,23 +503,7 @@ public class AltosState extends AltosDataListener {
                pressure.set(p, time);
        }
 
                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) {
        public void set_thrust(double N) {
-               thrust.set(N, time);
        }
 
        public double baro_height() {
        }
 
        public double baro_height() {
@@ -720,15 +701,8 @@ public class AltosState extends AltosDataListener {
        public int      speak_tick;
        public double   speak_altitude;
 
        public int      speak_tick;
        public double   speak_altitude;
 
-       public String   callsign;
-       public String   firmware_version;
-
        public double   ground_accel;
 
        public double   ground_accel;
 
-       public int      log_format;
-       public int      log_space;
-       public String   product;
-
        public AltosCompanion   companion;
 
        public int      pyro_fired;
        public AltosCompanion   companion;
 
        public int      pyro_fired;
@@ -756,7 +730,6 @@ public class AltosState extends AltosDataListener {
                ground_pressure = new AltosGroundPressure();
                altitude = new AltosAltitude();
                pressure = new AltosPressure();
                ground_pressure = new AltosGroundPressure();
                altitude = new AltosAltitude();
                pressure = new AltosPressure();
-               thrust = new AltosForce();
                speed = new AltosSpeed();
                acceleration = new AltosAccel();
                orient = new AltosCValue();
                speed = new AltosSpeed();
                acceleration = new AltosAccel();
                orient = new AltosCValue();
@@ -810,15 +783,8 @@ public class AltosState extends AltosDataListener {
                speak_tick = AltosLib.MISSING;
                speak_altitude = AltosLib.MISSING;
 
                speak_tick = AltosLib.MISSING;
                speak_altitude = AltosLib.MISSING;
 
-               callsign = null;
-               firmware_version = null;
-
                ground_accel = AltosLib.MISSING;
 
                ground_accel = AltosLib.MISSING;
 
-               log_format = AltosLib.MISSING;
-               log_space = AltosLib.MISSING;
-               product = null;
-
                companion = null;
 
                pyro_fired = 0;
                companion = null;
 
                pyro_fired = 0;
@@ -1108,6 +1074,10 @@ public class AltosState extends AltosDataListener {
                this.pyro_fired = fired;
        }
 
                this.pyro_fired = fired;
        }
 
+       public AltosState() {
+               init();
+       }
+
        public AltosState (AltosCalData cal_data) {
                super(cal_data);
                init();
        public AltosState (AltosCalData cal_data) {
                super(cal_data);
                init();
index 46a5d060caf9a264335947ec26e5909aa4a251f7..40b9c9bfb85f1f25487112bae905f342bf197a7d 100644 (file)
@@ -123,6 +123,8 @@ public class AltosTelemetryFile implements AltosRecordSet {
                        cal_data.set_tick(tick);
                        if (cal_data.time() >= -1)
                                telem.provide_data(listener, cal_data);
                        cal_data.set_tick(tick);
                        if (cal_data.time() >= -1)
                                telem.provide_data(listener, cal_data);
+                       if (listener.state == AltosLib.ao_flight_landed)
+                               break;
                }
                listener.finish();
        }
                }
                listener.finish();
        }
index db0cac2ffe178b60c58cfd27595893f23d49385a..71aa0e6f9c719669ae54a56e182f85d510dc25a2 100644 (file)
@@ -46,17 +46,19 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt
                boolean                 any_gps = false;
                AltosGPSTimeValue       gtv_last = null;
 
                boolean                 any_gps = false;
                AltosGPSTimeValue       gtv_last = null;
 
-               for (AltosGPSTimeValue gtv : flight_series.gps_series) {
-                       gtv_last = gtv;
-                       AltosGPS gps = gtv.gps;
-                       if (gps != null &&
-                           gps.locked &&
-                           gps.nsat >= 4) {
-                               if (map == null)
-                                       map = new AltosUIMap();
-                               map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
-                               this.gps = gps;
-                               has_gps = true;
+               if (flight_series.gps_series != null) {
+                       for (AltosGPSTimeValue gtv : flight_series.gps_series) {
+                               gtv_last = gtv;
+                               AltosGPS gps = gtv.gps;
+                               if (gps != null &&
+                                   gps.locked &&
+                                   gps.nsat >= 4) {
+                                       if (map == null)
+                                               map = new AltosUIMap();
+                                       map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+                                       this.gps = gps;
+                                       has_gps = true;
+                               }
                        }
                }
                if (gtv_last != null) {
                        }
                }
                if (gtv_last != null) {