optimize keepalive pump connection
This commit is contained in:
parent
da26ea5995
commit
6bee16919e
5 changed files with 31 additions and 11 deletions
|
@ -37,7 +37,7 @@
|
||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class Constants {
|
||||||
public static final int hoursToKeepInDatabase = 72;
|
public static final int hoursToKeepInDatabase = 72;
|
||||||
public static final int daysToKeepHistoryInDatabase = 30;
|
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;
|
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);
|
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
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
JSONObject pump = new JSONObject();
|
JSONObject pump = new JSONObject();
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class ExecutionService extends Service {
|
||||||
private DanaRPump danaRPump;
|
private DanaRPump danaRPump;
|
||||||
private Treatment bolusingTreatment = null;
|
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");
|
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");
|
log.debug("EventAppExit finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return mRfcommSocket != null && mRfcommSocket.isConnected();
|
return mRfcommSocket != null && mRfcommSocket.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConnecting() {
|
||||||
|
return connectionInProgress;
|
||||||
|
}
|
||||||
|
|
||||||
public void connect(String from) {
|
public void connect(String from) {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (Config.logDanaBTComm)
|
if (Config.logDanaBTComm)
|
||||||
|
@ -178,6 +182,7 @@ public class ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
||||||
synchronized (connectionInProgress) {
|
synchronized (connectionInProgress) {
|
||||||
|
connectionInProgress = true;
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
getBTSocketForSelectedPump();
|
getBTSocketForSelectedPump();
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
if (mRfcommSocket == null || mBTDevice == null)
|
||||||
|
@ -205,6 +210,7 @@ public class ExecutionService extends Service {
|
||||||
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
|
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
|
||||||
log.error("Pump connection timed out");
|
log.error("Pump connection timed out");
|
||||||
}
|
}
|
||||||
|
connectionInProgress = false;
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import android.os.PowerManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainActivity;
|
import info.nightscout.androidaps.MainActivity;
|
||||||
|
@ -38,6 +40,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
log.debug("KeepAlive received");
|
log.debug("KeepAlive received");
|
||||||
final DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
|
final DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
|
||||||
if (Config.DANAR && danaRFragment.isEnabled(PluginBase.PUMP)) {
|
if (Config.DANAR && danaRFragment.isEnabled(PluginBase.PUMP)) {
|
||||||
|
if (danaRFragment.getDanaRPump().lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime() && !danaRFragment.isConnected() && !danaRFragment.isConnecting()) {
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -46,6 +49,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wl.release();
|
wl.release();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue