detect broken communication during bolusing
This commit is contained in:
parent
42b581ec29
commit
ecd787bdb3
4 changed files with 23 additions and 12 deletions
|
@ -371,8 +371,8 @@ public class ExecutionService extends Service {
|
||||||
public boolean bolus(Double amount, int carbs, Treatment t) {
|
public boolean bolus(Double amount, int carbs, Treatment t) {
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
MsgBolusStart start = new MsgBolusStart(amount);
|
MsgBolusStart start = new MsgBolusStart(amount);
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(MainApp.bus(), amount, t);
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
MsgBolusStop stop = new MsgBolusStop(MainApp.bus(), amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
connect("bolus");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
@ -391,6 +391,11 @@ public class ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
|
if (progress.lastReceive != 0 && (new Date().getTime() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||||
|
stop.stopped = true;
|
||||||
|
stop.forced = true;
|
||||||
|
log.debug("Communication stopped");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
bolusingTreatment = null;
|
bolusingTreatment = null;
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.squareup.otto.Bus;
|
||||||
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.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -13,27 +15,28 @@ import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProg
|
||||||
|
|
||||||
public class MsgBolusProgress extends MessageBase {
|
public class MsgBolusProgress extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(MsgBolusProgress.class);
|
private static Logger log = LoggerFactory.getLogger(MsgBolusProgress.class);
|
||||||
private static Bus bus = null;
|
|
||||||
|
|
||||||
private static Treatment t;
|
private static Treatment t;
|
||||||
private static double amount;
|
private static double amount;
|
||||||
|
|
||||||
|
public static long lastReceive = 0;
|
||||||
public int progress = -1;
|
public int progress = -1;
|
||||||
|
|
||||||
public MsgBolusProgress() {
|
public MsgBolusProgress() {
|
||||||
SetCommand(0x0202);
|
SetCommand(0x0202);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgBolusProgress(Bus bus, double amount, Treatment t) {
|
public MsgBolusProgress(double amount, Treatment t) {
|
||||||
this();
|
this();
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.t = t;
|
this.t = t;
|
||||||
this.bus = bus;
|
lastReceive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(byte[] bytes) {
|
public void handleMessage(byte[] bytes) {
|
||||||
progress = intFromBuff(bytes, 0, 2);
|
progress = intFromBuff(bytes, 0, 2);
|
||||||
|
lastReceive = new Date().getTime();
|
||||||
Double done = (amount * 100 - progress) / 100d;
|
Double done = (amount * 100 - progress) / 100d;
|
||||||
t.insulin = done;
|
t.insulin = done;
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
|
@ -45,6 +48,6 @@ public class MsgBolusProgress extends MessageBase {
|
||||||
log.debug("Bolus remaining: " + progress + " delivered: " + done);
|
log.debug("Bolus remaining: " + progress + " delivered: " + done);
|
||||||
}
|
}
|
||||||
|
|
||||||
bus.post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ public class MsgBolusStop extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(MsgBolusStop.class);
|
private static Logger log = LoggerFactory.getLogger(MsgBolusStop.class);
|
||||||
private static Treatment t;
|
private static Treatment t;
|
||||||
private static Double amount;
|
private static Double amount;
|
||||||
private static Bus bus = null;
|
|
||||||
|
|
||||||
public static boolean stopped = false;
|
public static boolean stopped = false;
|
||||||
public static boolean forced = false;
|
public static boolean forced = false;
|
||||||
|
@ -24,9 +23,8 @@ public class MsgBolusStop extends MessageBase {
|
||||||
stopped = false;
|
stopped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgBolusStop(Bus bus, Double amount, Treatment t) {
|
public MsgBolusStop(Double amount, Treatment t) {
|
||||||
this();
|
this();
|
||||||
this.bus = bus;
|
|
||||||
this.t = t;
|
this.t = t;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
forced = false;
|
forced = false;
|
||||||
|
@ -43,6 +41,6 @@ public class MsgBolusStop extends MessageBase {
|
||||||
} else {
|
} else {
|
||||||
bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_stoped);
|
bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_stoped);
|
||||||
}
|
}
|
||||||
bus.post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,8 +362,8 @@ public class ExecutionService extends Service {
|
||||||
public boolean bolus(Double amount, int carbs, Treatment t) {
|
public boolean bolus(Double amount, int carbs, Treatment t) {
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
MsgBolusStart start = new MsgBolusStart(amount);
|
MsgBolusStart start = new MsgBolusStart(amount);
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(MainApp.bus(), amount, t);
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
MsgBolusStop stop = new MsgBolusStop(MainApp.bus(), amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
connect("bolus");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
@ -382,6 +382,11 @@ public class ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
|
if (progress.lastReceive != 0 && (new Date().getTime() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||||
|
stop.stopped = true;
|
||||||
|
stop.forced = true;
|
||||||
|
log.debug("Communication stopped");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
bolusingTreatment = null;
|
bolusingTreatment = null;
|
||||||
|
|
Loading…
Reference in a new issue