danar connection improvement
This commit is contained in:
parent
a7d3dca752
commit
7d4260b36f
1 changed files with 18 additions and 13 deletions
|
@ -183,7 +183,7 @@ public class ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (isConnected() || isConnecting()) {
|
while (isConnected() || isConnecting()) {
|
||||||
if (Config.logDanaBTComm)
|
if (Config.logDanaBTComm)
|
||||||
log.debug("already connected from: " + from);
|
log.debug("already connected/connecting from: " + from);
|
||||||
waitMsec(3000);
|
waitMsec(3000);
|
||||||
}
|
}
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
||||||
|
@ -205,15 +205,20 @@ public class ExecutionService extends Service {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
waitMsec(1000);
|
waitMsec(1000);
|
||||||
}
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (mSerialIOThread != null) {
|
if (mSerialIOThread != null) {
|
||||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||||
|
}
|
||||||
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
|
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTED, 0));
|
||||||
|
if (!getPumpStatus()) {
|
||||||
|
mSerialIOThread.disconnect("getPumpStatus failed");
|
||||||
|
waitMsec(3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
}
|
||||||
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTED, 0));
|
if (!isConnected()) {
|
||||||
getPumpStatus();
|
|
||||||
} else {
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
@ -254,7 +259,7 @@ public class ExecutionService extends Service {
|
||||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getPumpStatus() {
|
private boolean getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MsgStatus statusMsg = new MsgStatus();
|
MsgStatus statusMsg = new MsgStatus();
|
||||||
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
|
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
|
||||||
|
@ -291,8 +296,7 @@ public class ExecutionService extends Service {
|
||||||
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
||||||
waitMsec(10 * 1000);
|
waitMsec(10 * 1000);
|
||||||
log.debug("getPumpStatus failed");
|
log.debug("getPumpStatus failed");
|
||||||
connect("getPumpStatus fail");
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
|
@ -314,8 +318,9 @@ public class ExecutionService extends Service {
|
||||||
danaRPump.lastConnection = now;
|
danaRPump.lastConnection = now;
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
MainApp.bus().post(new EventDanaRNewStatus());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("err", e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasal(int percent, int durationInHours) {
|
public boolean tempBasal(int percent, int durationInHours) {
|
||||||
|
|
Loading…
Reference in a new issue