altoslib,altosuilib: Bump library version numbers
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TelemetryService.java
index 7c5fde500aba3c5d3b935f28d4cdcb5c155e27c5..f976e05cdba5ba871eb5b6183b81af54c989bc9a 100644 (file)
@@ -3,7 +3,8 @@
  *
  * 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; version 2 of the License.
+ * 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
@@ -40,7 +41,7 @@ import android.os.Looper;
 import android.widget.Toast;
 import android.location.Criteria;
 
-import org.altusmetrum.altoslib_10.*;
+import org.altusmetrum.altoslib_12.*;
 
 public class TelemetryService extends Service implements AltosIdleMonitorListener {
 
@@ -129,6 +130,8 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                        case MSG_DISCONNECT:
                                AltosDebug.debug("Disconnect command received");
                                s.address = null;
+                               if (!(Boolean) msg.obj)
+                                       AltosDroidPreferences.set_active_device(null);
                                s.disconnect(true);
                                break;
                        case MSG_DELETE_SERIAL:
@@ -256,14 +259,15 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        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
-                       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) {
-                       AltosPreferences.set_state(state);
+                       AltosPreferences.set_state(state,telem.serial());
                }
                send_to_clients();
        }
@@ -612,6 +616,10 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
                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) {
                        AltosState saved_state = AltosPreferences.state(serial);
                        if (saved_state != null) {
@@ -620,7 +628,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
                                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,
@@ -628,6 +636,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                                telemetry_state.states.put(serial, saved_state);
                        } else {
                                AltosDebug.debug("Failed to recover state for %d", serial);
+                               AltosPreferences.remove_state(serial);
                        }
                }
        }
@@ -693,11 +702,15 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
        /* 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();
        }
 
        public void failed() {
        }
+
+       public void error(String reason) {
+               stop_idle_monitor();
+       }
 }