Fix disconnect routine
This commit is contained in:
parent
cc364a0cec
commit
4d213eae7d
1 changed files with 19 additions and 14 deletions
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.ReadParameterBlockMessage;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.ReadParameterBlockMessage;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration.CloseConfigurationWriteSessionMessage;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration.CloseConfigurationWriteSessionMessage;
|
||||||
|
@ -262,16 +263,16 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
||||||
if (!connectionRequests.contains(lock)) return;
|
if (!connectionRequests.contains(lock)) return;
|
||||||
connectionRequests.remove(lock);
|
connectionRequests.remove(lock);
|
||||||
if (connectionRequests.size() == 0) {
|
if (connectionRequests.size() == 0) {
|
||||||
//TODO: Make adjustable
|
if (state == InsightState.RECOVERING) {
|
||||||
log.info("Last connection lock released, will disconnect in 5 seconds");
|
|
||||||
if (recoveryTimer != null) {
|
|
||||||
recoveryTimer.interrupt();
|
recoveryTimer.interrupt();
|
||||||
recoveryTimer = null;
|
recoveryTimer = null;
|
||||||
setState(InsightState.DISCONNECTED);
|
setState(InsightState.DISCONNECTED);
|
||||||
} else {
|
cleanup();
|
||||||
|
} else if (state != InsightState.DISCONNECTED) {
|
||||||
long disconnectTimeout = SP.getInt("insight_disconnect_delay", 5);
|
long disconnectTimeout = SP.getInt("insight_disconnect_delay", 5);
|
||||||
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
||||||
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
||||||
|
log.info("Last connection lock released, will disconnect " + disconnectTimeout + " seconds");
|
||||||
disconnectTimer = DelayedActionThread.runDelayed("Disconnect Timer", disconnectTimeout * 1000, this::disconnect);
|
disconnectTimer = DelayedActionThread.runDelayed("Disconnect Timer", disconnectTimeout * 1000, this::disconnect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,10 +327,11 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
||||||
}
|
}
|
||||||
log.info("Exception occurred: " + e.getClass().getSimpleName());
|
log.info("Exception occurred: " + e.getClass().getSimpleName());
|
||||||
if (pairingDataStorage.isPaired()) {
|
if (pairingDataStorage.isPaired()) {
|
||||||
setState(InsightState.RECOVERING);
|
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);
|
||||||
cleanup();
|
cleanup();
|
||||||
messageQueue.completeActiveRequest(e);
|
messageQueue.completeActiveRequest(e);
|
||||||
messageQueue.completePendingRequests(e);
|
messageQueue.completePendingRequests(e);
|
||||||
|
if (connectionRequests.size() != 0) {
|
||||||
if (!(e instanceof ConnectionFailedException)) {
|
if (!(e instanceof ConnectionFailedException)) {
|
||||||
connect();
|
connect();
|
||||||
} else {
|
} else {
|
||||||
|
@ -338,9 +340,12 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
||||||
recoveryDuration = Math.max(recoveryDuration, 0);
|
recoveryDuration = Math.max(recoveryDuration, 0);
|
||||||
recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration * 1000, () -> {
|
recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration * 1000, () -> {
|
||||||
recoveryTimer = null;
|
recoveryTimer = null;
|
||||||
connect();
|
synchronized (InsightConnectionService.this) {
|
||||||
|
if (!Thread.currentThread().isInterrupted()) connect();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setState(InsightState.NOT_PAIRED);
|
setState(InsightState.NOT_PAIRED);
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
Loading…
Reference in a new issue