X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FTelemetryService.java;h=1834d55b2eb1fa4bb3280803b5fbc1a283b06f21;hb=39af826ce9032e339929eb7917b1d29c87d03f69;hp=2d0ae65de8ab5fcecdc857e50feabf988ac00de9;hpb=ee656c9d41238ab2c56859a03fe6b8ce8ff2df4e;p=fw%2Faltos diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 2d0ae65d..1834d55b 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -38,14 +38,11 @@ import android.os.Messenger; import android.os.RemoteException; import android.os.Looper; import android.widget.Toast; -import android.location.Location; -import android.location.LocationManager; -import android.location.LocationListener; import android.location.Criteria; -import org.altusmetrum.altoslib_7.*; +import org.altusmetrum.altoslib_10.*; -public class TelemetryService extends Service implements LocationListener { +public class TelemetryService extends Service { static final int MSG_REGISTER_CLIENT = 1; static final int MSG_UNREGISTER_CLIENT = 2; @@ -199,13 +196,11 @@ public class TelemetryService extends Service implements LocationListener { * Messages from TelemetryReader */ case MSG_TELEMETRY: - AltosDebug.debug("MSG_TELEMETRY"); s.telemetry((AltosTelemetry) msg.obj); break; case MSG_CRC_ERROR: // forward crc error messages s.telemetry_state.crc_errors = (Integer) msg.obj; - AltosDebug.debug("MSG_CRC_ERROR"); s.send_to_clients(); break; default: @@ -226,7 +221,6 @@ public class TelemetryService extends Service implements LocationListener { telem.update_state(state); telemetry_state.states.put(telem.serial, state); if (state != null) { - AltosDebug.debug("Save state %d", telem.serial); AltosPreferences.set_state(telem.serial, state, null); } send_to_clients(); @@ -251,7 +245,7 @@ public class TelemetryService extends Service implements LocationListener { /* On connect, send the current state to the new client */ - send_to_client(client, message()); + send_to_client(client); /* If we've got an address from a previous session, then * go ahead and try to reconnect to the device @@ -278,9 +272,9 @@ public class TelemetryService extends Service implements LocationListener { } } - private void send_to_client(Messenger client, Message m) { + private void send_to_client(Messenger client) { + Message m = message(); try { - AltosDebug.debug("Send message to client %s", client.toString()); client.send(m); } catch (RemoteException e) { AltosDebug.error("Client %s disappeared", client.toString()); @@ -289,10 +283,8 @@ public class TelemetryService extends Service implements LocationListener { } private void send_to_clients() { - Message m = message(); - AltosDebug.debug("Send message to %d clients", clients.size()); for (Messenger client : clients) - send_to_client(client, m); + send_to_client(client); } private void disconnect(boolean notify) { @@ -375,7 +367,6 @@ public class TelemetryService extends Service implements LocationListener { if (altos_link != null) { try { double voltage = altos_link.monitor_battery(); - AltosDebug.debug("update receiver voltage %g\n", voltage); telemetry_state.receiver_battery = voltage; } catch (InterruptedException ie) { } @@ -441,6 +432,12 @@ public class TelemetryService extends Service implements LocationListener { @Override public void onCreate() { + + AltosDebug.init(this); + + // Initialise preferences + AltosDroidPreferences.init(this); + // Get local Bluetooth adapter bluetooth_adapter = BluetoothAdapter.getDefaultAdapter(); @@ -484,11 +481,6 @@ public class TelemetryService extends Service implements LocationListener { telemetry_state.states.put(serial, saved_state.state); } } - - // Listen for GPS and Network position updates - LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); } @Override @@ -513,7 +505,11 @@ public class TelemetryService extends Service implements LocationListener { // Move us into the foreground. startForeground(NOTIFICATION, notification); - if (intent != null) { + /* Start bluetooth if we don't have a connection already */ + if (intent != null && + (telemetry_state.connect == TelemetryState.CONNECT_NONE || + telemetry_state.connect == TelemetryState.CONNECT_DISCONNECTED)) + { String action = intent.getAction(); if (action.equals(AltosDroid.ACTION_BLUETOOTH)) { @@ -531,9 +527,6 @@ public class TelemetryService extends Service implements LocationListener { @Override public void onDestroy() { - // Stop listening for location updates - ((LocationManager) getSystemService(Context.LOCATION_SERVICE)).removeUpdates(this); - // Stop the bluetooth Comms threads disconnect(true); @@ -548,21 +541,4 @@ public class TelemetryService extends Service implements LocationListener { public IBinder onBind(Intent intent) { return messenger.getBinder(); } - - - public void onLocationChanged(Location location) { - telemetry_state.location = location; - AltosDebug.debug("location changed"); - send_to_clients(); - } - - public void onStatusChanged(String provider, int status, Bundle extras) { - } - - public void onProviderEnabled(String provider) { - } - - public void onProviderDisabled(String provider) { - } - }