optimize keepalive pump connection
This commit is contained in:
parent
da26ea5995
commit
6bee16919e
|
@ -37,7 +37,7 @@
|
|||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -22,7 +22,7 @@ public class Constants {
|
|||
public static final int hoursToKeepInDatabase = 72;
|
||||
public static final int daysToKeepHistoryInDatabase = 30;
|
||||
|
||||
public static final long keepAliveMsecs = 30 * 60 * 1000L;
|
||||
public static final long keepAliveMsecs = 5 * 60 * 1000L;
|
||||
|
||||
public static final long remoteBolusMinDistance = 15 * 60 * 1000L;
|
||||
}
|
||||
|
|
|
@ -734,6 +734,16 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
if (mExecutionService != null) mExecutionService.connect(from);
|
||||
}
|
||||
|
||||
public static boolean isConnected() {
|
||||
if (mExecutionService != null) return mExecutionService.isConnected();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isConnecting() {
|
||||
if (mExecutionService != null) return mExecutionService.isConnecting();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
JSONObject pump = new JSONObject();
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ExecutionService extends Service {
|
|||
private DanaRPump danaRPump;
|
||||
private Treatment bolusingTreatment = null;
|
||||
|
||||
private static Object connectionInProgress = new Object();
|
||||
private static Boolean connectionInProgress = false;
|
||||
|
||||
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
|
@ -166,10 +166,14 @@ public class ExecutionService extends Service {
|
|||
log.debug("EventAppExit finished");
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
public boolean isConnected() {
|
||||
return mRfcommSocket != null && mRfcommSocket.isConnected();
|
||||
}
|
||||
|
||||
public boolean isConnecting() {
|
||||
return connectionInProgress;
|
||||
}
|
||||
|
||||
public void connect(String from) {
|
||||
if (isConnected()) {
|
||||
if (Config.logDanaBTComm)
|
||||
|
@ -178,6 +182,7 @@ public class ExecutionService extends Service {
|
|||
}
|
||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
||||
synchronized (connectionInProgress) {
|
||||
connectionInProgress = true;
|
||||
mWakeLock.acquire();
|
||||
getBTSocketForSelectedPump();
|
||||
if (mRfcommSocket == null || mBTDevice == null)
|
||||
|
@ -205,6 +210,7 @@ public class ExecutionService extends Service {
|
|||
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
|
||||
log.error("Pump connection timed out");
|
||||
}
|
||||
connectionInProgress = false;
|
||||
mWakeLock.release();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import android.os.PowerManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
|
@ -38,13 +40,15 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
log.debug("KeepAlive received");
|
||||
final DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
|
||||
if (Config.DANAR && danaRFragment.isEnabled(PluginBase.PUMP)) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
danaRFragment.doConnect("KeepAlive"); // TODO: only if if last conn > 30 min
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
if (danaRFragment.getDanaRPump().lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime() && !danaRFragment.isConnected() && !danaRFragment.isConnecting()) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
danaRFragment.doConnect("KeepAlive"); // TODO: only if if last conn > 30 min
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
wl.release();
|
||||
|
|
Loading…
Reference in a new issue