commit
359b8401b2
8 changed files with 322 additions and 64 deletions
|
@ -56,7 +56,7 @@ public class InsightPumpAsyncAdapter {
|
|||
}
|
||||
|
||||
// blocking call to wait for result callback
|
||||
Cstatus busyWaitForCommandResult(final UUID uuid, long wait_time) {
|
||||
private Cstatus busyWaitForCommandInternal(final UUID uuid, long wait_time) {
|
||||
final PowerManager.WakeLock wl = getWakeLock("insight-wait-cmd", 60000);
|
||||
try {
|
||||
log("busy wait for command " + uuid);
|
||||
|
@ -82,25 +82,14 @@ public class InsightPumpAsyncAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
// commend field preparation for results
|
||||
String getCommandComment(final UUID uuid) {
|
||||
if (commandResults.containsKey(uuid)) {
|
||||
if (commandResults.get(uuid).success) {
|
||||
return "OK";
|
||||
} else {
|
||||
return commandResults.get(uuid).message;
|
||||
}
|
||||
} else {
|
||||
return "Unknown reference";
|
||||
}
|
||||
// wait for and then package result, cleanup and return
|
||||
Mstatus busyWaitForCommandResult(final UUID uuid, long wait_time) {
|
||||
final Mstatus mstatus = new Mstatus();
|
||||
mstatus.cstatus = busyWaitForCommandInternal(uuid, wait_time);
|
||||
mstatus.event = commandResults.get(uuid);
|
||||
commandResults.remove(uuid);
|
||||
return mstatus;
|
||||
}
|
||||
|
||||
int getResponseID(UUID uuid) {
|
||||
if (checkCommandResult(uuid) == Cstatus.SUCCESS) {
|
||||
return commandResults.get(uuid).response_id;
|
||||
} else {
|
||||
return -2; // invalid
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
|||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -32,6 +33,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
|||
import info.nightscout.androidaps.plugins.PumpInsight.connector.AbsoluteTBRTaskRunner;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusTaskRunner;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpCallback;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver;
|
||||
|
@ -51,7 +53,6 @@ import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMess
|
|||
import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage;
|
||||
import sugar.free.sightparser.handling.SingleMessageTaskRunner;
|
||||
import sugar.free.sightparser.handling.TaskRunner;
|
||||
import sugar.free.sightparser.handling.taskrunners.SetTBRTaskRunner;
|
||||
import sugar.free.sightparser.handling.taskrunners.StatusTaskRunner;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.getRecordUniqueID;
|
||||
|
@ -69,7 +70,7 @@ import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.round
|
|||
*
|
||||
*/
|
||||
|
||||
public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
||||
public class InsightPumpPlugin implements PluginBase, PumpInterface, ConstraintsInterface {
|
||||
|
||||
private static final long BUSY_WAIT_TIME = 20000;
|
||||
static Integer batteryPercent = 0;
|
||||
|
@ -202,7 +203,9 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public boolean isEnabled(int type) {
|
||||
return type == PUMP && fragmentEnabled;
|
||||
if (type == PluginBase.PUMP) return fragmentEnabled;
|
||||
else if (type == PluginBase.CONSTRAINTS) return fragmentEnabled;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -400,10 +403,11 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
if (cmd == null) {
|
||||
return pumpEnactFailure();
|
||||
}
|
||||
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
result.success = cs.success();
|
||||
if (cs.success()) {
|
||||
detailedBolusInfo.pumpId = getRecordUniqueID(async.getResponseID(cmd));
|
||||
final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
|
||||
result.success = ms.success();
|
||||
if (ms.success()) {
|
||||
detailedBolusInfo.pumpId = getRecordUniqueID(ms.getResponseID());
|
||||
}
|
||||
} else {
|
||||
result.success = true; // always true with carb only treatments
|
||||
|
@ -440,7 +444,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
final Mstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + cs);
|
||||
}
|
||||
|
||||
|
@ -450,6 +454,67 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||
absoluteRate = Helpers.roundDouble(absoluteRate, 3);
|
||||
log("Set TBR absolute: " + absoluteRate);
|
||||
final double base_basal = getBaseBasalRate();
|
||||
if (base_basal == 0) {
|
||||
log("Base basal rate appears to be zero!");
|
||||
return pumpEnactFailure();
|
||||
}
|
||||
int percent_amount = (int) Math.round(100d / base_basal * absoluteRate);
|
||||
log("Calculated requested rate: " + absoluteRate + " base rate: " + base_basal + " percentage: " + percent_amount + "%");
|
||||
percent_amount = (int) Math.round(((double) percent_amount) / 10d) * 10;
|
||||
log("Calculated final rate: " + percent_amount + "%");
|
||||
|
||||
if (percent_amount == 100) {
|
||||
return cancelTempBasal(false);
|
||||
}
|
||||
|
||||
if (percent_amount > 250) percent_amount = 250;
|
||||
|
||||
final SetTBRTaskRunner task = new SetTBRTaskRunner(connector.getServiceConnector(), percent_amount, durationInMinutes);
|
||||
final UUID cmd = aSyncTaskRunner(task, "Set TBR abs: " + absoluteRate + " " + durationInMinutes + "m");
|
||||
|
||||
if (cmd == null) {
|
||||
return pumpEnactFailure();
|
||||
}
|
||||
|
||||
Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + ms);
|
||||
|
||||
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes);
|
||||
pumpEnactResult.percent = percent_amount;
|
||||
pumpEnactResult.success = ms.success();
|
||||
pumpEnactResult.isTempCancel = percent_amount == 100; // 100% temp basal is a cancellation
|
||||
pumpEnactResult.comment = ms.getCommandComment();
|
||||
|
||||
|
||||
if (pumpEnactResult.success) {
|
||||
// create log entry
|
||||
final TemporaryBasal tempBasal = new TemporaryBasal();
|
||||
tempBasal.date = System.currentTimeMillis();
|
||||
tempBasal.isAbsolute = false;
|
||||
tempBasal.percentRate = percent_amount;
|
||||
tempBasal.durationInMinutes = durationInMinutes;
|
||||
tempBasal.source = Source.USER;
|
||||
MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal);
|
||||
}
|
||||
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Setting temp basal absolute: " + pumpEnactResult.success);
|
||||
|
||||
lastDataTime = new Date();
|
||||
|
||||
updateGui();
|
||||
|
||||
connector.requestHistorySync(5000);
|
||||
connector.tryToGetPumpStatusAgain();
|
||||
|
||||
return pumpEnactResult;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public PumpEnactResult setTempBasalAbsoluteOld(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||
absoluteRate = Helpers.roundDouble(absoluteRate, 3);
|
||||
log("Set TBR absolute: " + absoluteRate);
|
||||
|
||||
final AbsoluteTBRTaskRunner task = new AbsoluteTBRTaskRunner(connector.getServiceConnector(), absoluteRate, durationInMinutes);
|
||||
final UUID cmd = aSyncTaskRunner(task, "Set TBR abs: " + absoluteRate + " " + durationInMinutes + "m");
|
||||
|
@ -458,14 +523,14 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
return pumpEnactFailure();
|
||||
}
|
||||
|
||||
Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + cs);
|
||||
Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + ms);
|
||||
|
||||
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(false).duration(durationInMinutes);
|
||||
pumpEnactResult.absolute = absoluteRate; // TODO get converted value?
|
||||
pumpEnactResult.success = cs.success();
|
||||
pumpEnactResult.success = ms.success();
|
||||
pumpEnactResult.isTempCancel = false; // do we test this here?
|
||||
pumpEnactResult.comment = async.getCommandComment(cmd);
|
||||
pumpEnactResult.comment = ms.getCommandComment();
|
||||
|
||||
if (pumpEnactResult.success) {
|
||||
// create log entry
|
||||
|
@ -495,20 +560,28 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
|
||||
log("Set TBR %");
|
||||
|
||||
percent = (int) Math.round(((double) percent) / 10d) * 10;
|
||||
if (percent == 100) {
|
||||
// This would cause a cancel if a tbr is in progress so treat as a cancel
|
||||
return cancelTempBasal(false);
|
||||
}
|
||||
|
||||
|
||||
final UUID cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), percent, durationInMinutes), "Set TBR " + percent + "%" + " " + durationInMinutes + "m");
|
||||
|
||||
if (cmd == null) {
|
||||
return pumpEnactFailure();
|
||||
}
|
||||
|
||||
Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + cs);
|
||||
final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + ms);
|
||||
|
||||
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes);
|
||||
pumpEnactResult.percent = percent;
|
||||
pumpEnactResult.success = cs.success();
|
||||
pumpEnactResult.success = ms.success();
|
||||
pumpEnactResult.isTempCancel = percent == 100; // 100% temp basal is a cancellation
|
||||
pumpEnactResult.comment = async.getCommandComment(cmd);
|
||||
pumpEnactResult.comment = ms.getCommandComment();
|
||||
|
||||
if (pumpEnactResult.success) {
|
||||
// create log entry
|
||||
|
@ -543,9 +616,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
final UUID cmd;
|
||||
|
||||
if (fauxTBRcancel) {
|
||||
final int faux_percent = 90;
|
||||
final int faux_duration = 15;
|
||||
cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), faux_percent, 15), "Faux Cancel TBR - setting " + faux_percent + "%" + " " + faux_duration + "m");
|
||||
cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), 100, 1), "Faux Cancel TBR - setting " + "90%" + " 1m");
|
||||
} else {
|
||||
cmd = aSyncSingleCommand(new CancelTBRMessage(), "Cancel Temp Basal");
|
||||
}
|
||||
|
@ -555,7 +626,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
// TODO isn't conditional on one apparently being in progress only the history change
|
||||
boolean enacted = false;
|
||||
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
enacted = true;
|
||||
|
@ -571,7 +642,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
connector.requestHistorySync(5000);
|
||||
connector.tryToGetPumpStatusAgain();
|
||||
|
||||
return new PumpEnactResult().success(cs.success()).enacted(true).isTempCancel(true);
|
||||
return new PumpEnactResult().success(ms.success()).enacted(true).isTempCancel(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -588,12 +659,12 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
return pumpEnactFailure();
|
||||
}
|
||||
|
||||
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + cs);
|
||||
final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
log("Got command status: " + ms);
|
||||
|
||||
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).bolusDelivered(insulin).duration(durationInMinutes);
|
||||
pumpEnactResult.success = cs.success();
|
||||
pumpEnactResult.comment = async.getCommandComment(cmd);
|
||||
pumpEnactResult.success = ms.success();
|
||||
pumpEnactResult.comment = ms.getCommandComment();
|
||||
|
||||
if (pumpEnactResult.success) {
|
||||
// create log entry
|
||||
|
@ -602,7 +673,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
extendedBolus.insulin = insulin;
|
||||
extendedBolus.durationInMinutes = durationInMinutes;
|
||||
extendedBolus.source = Source.USER;
|
||||
extendedBolus.pumpId = getRecordUniqueID(async.getResponseID(cmd));
|
||||
extendedBolus.pumpId = getRecordUniqueID(ms.getResponseID());
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
}
|
||||
|
||||
|
@ -630,7 +701,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
return pumpEnactFailure();
|
||||
}
|
||||
|
||||
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
|
||||
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||
ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis());
|
||||
|
@ -646,7 +717,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
connector.requestHistorySync(5000);
|
||||
connector.tryToGetPumpStatusAgain();
|
||||
|
||||
return new PumpEnactResult().success(cs.success()).enacted(true);
|
||||
return new PumpEnactResult().success(ms.success()).enacted(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -777,12 +848,15 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
(batteryPercent < 70 ?
|
||||
(StatusItem.Highlight.BAD) : StatusItem.Highlight.NOTICE) : StatusItem.Highlight.NORMAL) : StatusItem.Highlight.GOOD));
|
||||
l.add(new StatusItem(gs(R.string.pump_reservoir_label), reservoirInUnits + "U"));
|
||||
|
||||
try {
|
||||
if (statusResult.getCurrentTBRMessage().getPercentage() != 100) {
|
||||
l.add(new StatusItem(gs(R.string.insight_active_tbr), statusResult.getCurrentTBRMessage().getPercentage() + "% " + gs(R.string.with) + " "
|
||||
+ Helpers.qs(statusResult.getCurrentTBRMessage().getLeftoverTime() - offset_minutes, 0)
|
||||
+ " " + gs(R.string.insight_min_left), StatusItem.Highlight.NOTICE));
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
// currentTBRMessage may be null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -795,9 +869,13 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
if (statusResult != null) {
|
||||
try {
|
||||
statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus1(), offset_minutes, l);
|
||||
statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus2(), offset_minutes, l);
|
||||
statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus3(), offset_minutes, l);
|
||||
} catch (NullPointerException e) {
|
||||
// getActiveBolusesMessage() may be null
|
||||
}
|
||||
}
|
||||
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||
|
@ -874,8 +952,9 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
@Override
|
||||
public void onResult(Object o) {
|
||||
log(name + " success");
|
||||
event.response_object = o;
|
||||
if (o instanceof BolusMessage) {
|
||||
event.response_id = ((BolusMessage)o).getBolusId();
|
||||
event.response_id = ((BolusMessage) o).getBolusId();
|
||||
}
|
||||
event.success = true;
|
||||
pushCallbackEvent(event);
|
||||
|
@ -911,6 +990,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
@Override
|
||||
public void onResult(Object o) {
|
||||
log(name + " success");
|
||||
event.response_object = o;
|
||||
event.success = true;
|
||||
pushCallbackEvent(event);
|
||||
}
|
||||
|
@ -936,5 +1016,59 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
|
|||
return new PumpEnactResult().success(false).enacted(false);
|
||||
}
|
||||
|
||||
// Constraints
|
||||
|
||||
@Override
|
||||
public boolean isLoopEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosedModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutosensModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSMBModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyBasalConstraints(Double absoluteRate) {
|
||||
return Math.min(absoluteRate, 25); // Maximum pump can support
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer applyBasalConstraints(Integer percentRate) {
|
||||
return Math.min(percentRate, pumpDescription.maxTempPercent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyBolusConstraints(Double insulin) {
|
||||
// TODO we could check what the current max is set on the pump and use that information here
|
||||
// Pump can be reconfigured up to 50U max
|
||||
return Math.min(insulin, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer applyCarbsConstraints(Integer carbs) {
|
||||
return carbs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyMaxIOBConstraints(Double maxIob) {
|
||||
return maxIob;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsight;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpCallback;
|
||||
|
||||
/**
|
||||
* Created by jamorham on 01/02/2018.
|
||||
*
|
||||
* Encapsulates results from commands
|
||||
*/
|
||||
|
||||
class Mstatus {
|
||||
|
||||
Cstatus cstatus = Cstatus.UNKNOWN;
|
||||
EventInsightPumpCallback event;
|
||||
|
||||
// comment field preparation for results
|
||||
String getCommandComment() {
|
||||
if (success()) {
|
||||
return "OK";
|
||||
} else {
|
||||
return (event == null) ? "EVENT DATA IS NULL - ERROR OR FIREWALL ENABLED?" : event.message;
|
||||
}
|
||||
}
|
||||
|
||||
boolean success() {
|
||||
return cstatus.success();
|
||||
}
|
||||
|
||||
int getResponseID() {
|
||||
if (success()) {
|
||||
return event.response_id;
|
||||
} else {
|
||||
return -2; // invalid
|
||||
}
|
||||
}
|
||||
|
||||
Object getResponseObject() {
|
||||
if (success()) {
|
||||
return event.response_object;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return cstatus + " " + event;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsight.connector;
|
||||
|
||||
import sugar.free.sightparser.applayer.messages.AppLayerMessage;
|
||||
import sugar.free.sightparser.applayer.messages.remote_control.ChangeTBRMessage;
|
||||
import sugar.free.sightparser.applayer.messages.remote_control.SetTBRMessage;
|
||||
import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage;
|
||||
import sugar.free.sightparser.handling.SightServiceConnector;
|
||||
import sugar.free.sightparser.handling.TaskRunner;
|
||||
|
||||
// from Tebbe - note this uses 1 minute duration to silently cancel existing TBR
|
||||
|
||||
public class SetTBRTaskRunner extends TaskRunner {
|
||||
|
||||
private int amount;
|
||||
private int duration;
|
||||
|
||||
public SetTBRTaskRunner(SightServiceConnector serviceConnector, int amount, int duration) {
|
||||
super(serviceConnector);
|
||||
this.amount = amount;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AppLayerMessage run(AppLayerMessage message) throws Exception {
|
||||
if (message == null) return new CurrentTBRMessage();
|
||||
else if (message instanceof CurrentTBRMessage) {
|
||||
if (((CurrentTBRMessage) message).getPercentage() == 100) {
|
||||
if (amount == 100) finish(amount);
|
||||
else {
|
||||
SetTBRMessage setTBRMessage = new SetTBRMessage();
|
||||
setTBRMessage.setDuration((short) duration);
|
||||
setTBRMessage.setAmount((short) amount);
|
||||
return setTBRMessage;
|
||||
}
|
||||
} else {
|
||||
if (amount == 100) {
|
||||
ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
|
||||
changeTBRMessage.setDuration((short) 1);
|
||||
changeTBRMessage.setAmount((short) 90);
|
||||
return changeTBRMessage;
|
||||
} else {
|
||||
ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
|
||||
changeTBRMessage.setDuration((short) duration);
|
||||
changeTBRMessage.setAmount((short) amount);
|
||||
return changeTBRMessage;
|
||||
}
|
||||
}
|
||||
} else if (message instanceof SetTBRMessage) finish(amount);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ public class EventInsightPumpCallback extends Event {
|
|||
public boolean success = false;
|
||||
public String message = null;
|
||||
public int response_id = -1;
|
||||
public Object response_object = null;
|
||||
|
||||
public EventInsightPumpCallback() {
|
||||
request_uuid = UUID.randomUUID();
|
||||
|
@ -20,7 +21,7 @@ public class EventInsightPumpCallback extends Event {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Event: " + request_uuid + " success: " + success + " msg: " + message;
|
||||
return "Event: " + request_uuid + " success: " + success + " msg: " + message + " Object: " + response_object;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.utils.SP;
|
||||
import sugar.free.sightparser.handling.HistoryBroadcast;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber;
|
||||
|
@ -50,9 +49,12 @@ class HistoryIntentAdapter {
|
|||
final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id);
|
||||
|
||||
// other sanity checks
|
||||
if ((pump_tbr_percent == 90) && (pump_tbr_duration <= 1)) {
|
||||
log("Not creating TBR record for faux cancel");
|
||||
} else {
|
||||
log("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id);
|
||||
logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void processDeliveredBolusIntent(Intent intent) {
|
||||
|
|
|
@ -17,10 +17,39 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
|||
|
||||
class HistoryLogAdapter {
|
||||
|
||||
private static final long MAX_TIME_DIFFERENCE = 61000;
|
||||
|
||||
private static void log(String msg) {
|
||||
android.util.Log.e("HISTORYLOG", msg);
|
||||
}
|
||||
|
||||
void createTBRrecord(Date eventDate, int percent, int duration, long record_id) {
|
||||
|
||||
final TemporaryBasal temporaryBasal = new TemporaryBasal();
|
||||
temporaryBasal.date = eventDate.getTime();
|
||||
TemporaryBasal temporaryBasal = new TemporaryBasal(eventDate.getTime());
|
||||
|
||||
final TemporaryBasal temporaryBasalFromHistory = MainApp.getConfigBuilder().getTempBasalFromHistory(eventDate.getTime());
|
||||
|
||||
if (temporaryBasalFromHistory == null) {
|
||||
log("Create new TBR: " + eventDate + " " + percent + " " + duration);
|
||||
} else {
|
||||
log("Loaded existing TBR record: " + temporaryBasalFromHistory.toString());
|
||||
if (Math.abs(eventDate.getTime() - temporaryBasalFromHistory.date) < MAX_TIME_DIFFERENCE) {
|
||||
if (temporaryBasalFromHistory.source != Source.PUMP) {
|
||||
if (temporaryBasalFromHistory.percentRate == percent) {
|
||||
log("Things seem to match: %" + percent);
|
||||
temporaryBasal = temporaryBasalFromHistory;
|
||||
MainApp.getDbHelper().delete(temporaryBasalFromHistory);
|
||||
} else {
|
||||
log("This record has different percent rates: " + temporaryBasalFromHistory.percentRate + " vs us: " + percent);
|
||||
}
|
||||
} else {
|
||||
log("This record is already a pump record!");
|
||||
}
|
||||
} else {
|
||||
log("Time difference too great! : " + (eventDate.getTime() - temporaryBasalFromHistory.date));
|
||||
}
|
||||
}
|
||||
|
||||
temporaryBasal.source = Source.PUMP;
|
||||
temporaryBasal.pumpId = record_id;
|
||||
temporaryBasal.percentRate = percent;
|
||||
|
@ -47,6 +76,8 @@ class HistoryLogAdapter {
|
|||
|
||||
//DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(eventDate.getTime());
|
||||
|
||||
// TODO do we need to do the same delete + insert that we are doing for temporary basals here too?
|
||||
|
||||
final DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.date = eventDate.getTime();
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
|
|
|
@ -890,7 +890,7 @@
|
|||
<string name="insight_upfront_with">upfront with</string>
|
||||
<string name="insight_stay_always_connected">Stay always connected</string>
|
||||
<string name="insight_use_real_tbr_cancels">Use Real TBR cancels</string>
|
||||
<string name="insight_actually_cancel_tbr_summary">Actually cancel a TBR (creates pump alarm) instead of setting 90% or 110% TBR for 15 minutes</string>
|
||||
<string name="insight_actually_cancel_tbr_summary">Actually cancel a TBR (creates pump alarm) instead of setting 90% for 1 minute</string>
|
||||
<string name="insight_history_idle">IDLE</string>
|
||||
<string name="insight_history_syncing">SYNCING</string>
|
||||
<string name="insight_history_busy">BUSY</string>
|
||||
|
|
Loading…
Reference in a new issue