mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
AndroidGCS: After terminating the telemetry connection make sure to close the
TCP socket or the android system will keep it active and block reconnections.
This commit is contained in:
parent
5670a958a8
commit
e359b96b09
@ -1,5 +1,6 @@
|
|||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ public class OPTelemetryService extends Service {
|
|||||||
case MSG_DISCONNECT:
|
case MSG_DISCONNECT:
|
||||||
Toast.makeText(getApplicationContext(), "Disconnect requested", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Disconnect requested", Toast.LENGTH_SHORT).show();
|
||||||
terminate = true;
|
terminate = true;
|
||||||
|
activeTelem.interrupt();
|
||||||
try {
|
try {
|
||||||
activeTelem.join();
|
activeTelem.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -123,6 +125,10 @@ public class OPTelemetryService extends Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the service starts. It creates a thread to handle messages (e.g. connect and disconnect)
|
||||||
|
* and based on the stored preference will send itself a connect signal if needed.
|
||||||
|
*/
|
||||||
public void startup() {
|
public void startup() {
|
||||||
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
@ -193,6 +199,9 @@ public class OPTelemetryService extends Service {
|
|||||||
mServiceHandler.sendMessage(msg);
|
mServiceHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used by other processes to get a handle to the object manager
|
||||||
|
*/
|
||||||
public interface TelemTask {
|
public interface TelemTask {
|
||||||
public UAVObjectManager getObjectManager();
|
public UAVObjectManager getObjectManager();
|
||||||
};
|
};
|
||||||
@ -314,8 +323,14 @@ public class OPTelemetryService extends Service {
|
|||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop");
|
if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop");
|
||||||
while( !terminate ) {
|
while( !terminate ) {
|
||||||
|
try {
|
||||||
if( !uavTalk.processInputStream() )
|
if( !uavTalk.processInputStream() )
|
||||||
break;
|
break;
|
||||||
|
} catch (IOException e) {
|
||||||
|
// This occurs when they communication stream fails
|
||||||
|
toastMessage("Connection dropped");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
|
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
|
||||||
}
|
}
|
||||||
@ -384,10 +399,28 @@ public class OPTelemetryService extends Service {
|
|||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop");
|
if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop");
|
||||||
while( !terminate ) {
|
while( !terminate ) {
|
||||||
|
try {
|
||||||
if( !uavTalk.processInputStream() )
|
if( !uavTalk.processInputStream() )
|
||||||
break;
|
break;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
toastMessage("TCP Stream interrupted");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Looper.myLooper().quit();
|
||||||
|
|
||||||
|
// Shut down all the attached
|
||||||
|
mon.stopMonitor();
|
||||||
|
mon = null;
|
||||||
|
tel.stopTelemetry();
|
||||||
|
tel = null;
|
||||||
|
|
||||||
|
// Finally close the stream if it is still open
|
||||||
|
tcp.disconnect();
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
|
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
|
||||||
|
toastMessage("TCP Thread finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user