Improve recovery from uncertain TBR

This commit is contained in:
Bart Sopers 2020-12-08 20:46:59 +01:00
parent d49f0571b2
commit 96eb635c29
5 changed files with 23 additions and 17 deletions

View file

@ -151,7 +151,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private final Handler loopHandler = new Handler(Looper.getMainLooper());
private final Runnable statusChecker;
private boolean isSetTempBasalRunning;
private boolean isCancelTempBasalRunning;
@Inject
@ -363,11 +362,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
private void handleUncertainTbrRecovery() {
// Ignore changes in certainty during tbr commands; these are normal
if (isSetTempBasalRunning || isCancelTempBasalRunning) {
return;
}
TemporaryBasal tempBasal = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
if (podStateManager.isTempBasalRunning() && tempBasal == null) {
@ -660,13 +654,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
}
isSetTempBasalRunning = true;
PumpEnactResult result;
try {
result = executeCommand(OmnipodCommandType.SET_TEMPORARY_BASAL, () -> aapsOmnipodManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes)));
} finally {
isSetTempBasalRunning = false;
}
PumpEnactResult result = executeCommand(OmnipodCommandType.SET_TEMPORARY_BASAL, () -> aapsOmnipodManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes)));
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success);

View file

@ -6,7 +6,9 @@ import java.util.List;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.CancelDeliveryCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.GetStatusCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodCrc;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PacketType;
@ -145,6 +147,14 @@ public class OmnipodMessage {
return false;
}
public boolean isSetTempBasalMessage() {
return messageBlocks.size() >= 2 && messageBlocks.get(0).getType() == MessageBlockType.SET_INSULIN_SCHEDULE && messageBlocks.get(1).getType() == MessageBlockType.TEMP_BASAL_EXTRA;
}
public boolean isCancelTempBasalMessage() {
return messageBlocks.size() >= 1 && messageBlocks.get(0).getType() == MessageBlockType.CANCEL_DELIVERY && ((CancelDeliveryCommand) messageBlocks.get(0)).getDeliveryTypes().contains(DeliveryType.TEMP_BASAL);
}
@Override
public String toString() {
return "OmnipodMessage{" +

View file

@ -60,6 +60,10 @@ public class CancelDeliveryCommand extends NonceResyncableMessageBlock {
encode();
}
public EnumSet<DeliveryType> getDeliveryTypes() {
return deliveryTypes.clone();
}
@Override
public String toString() {
return "CancelDeliveryCommand{" +

View file

@ -21,6 +21,7 @@ import java.util.function.Supplier;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusUpdatableResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoDetailedStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress;
@ -550,7 +551,7 @@ public abstract class PodStateManager {
/**
* Does not automatically store pod state in order to decrease I/O load
*/
public final void updateFromResponse(StatusUpdatableResponse status) {
public final void updateFromResponse(StatusUpdatableResponse status, OmnipodMessage requestMessage) {
setSafe(() -> {
if (podState.getActivatedAt() == null) {
DateTime activatedAtCalculated = DateTime.now().withZone(podState.getTimeZone()).minus(status.getTimeActive());
@ -581,8 +582,11 @@ public abstract class PodStateManager {
}
if (!isTempBasalCertain) {
podState.setTempBasalCertain(true);
if (!requestMessage.isSetTempBasalMessage() // We always set TBR to uncertain before sending the set temp basal command, so this is not an actual recovery
&& !requestMessage.isCancelTempBasalMessage()) { // Delivery status changed, so we can't recover here
onUncertainTbrRecovered();
}
}
if (!isBasalCertain) {
podState.setBasalCertain(true);
}

View file

@ -129,11 +129,11 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication
aapsLogger.debug(LTag.PUMPBTCOMM, "Received response from the Pod [responseMessageBlock={}]", responseMessageBlock);
if (responseMessageBlock instanceof StatusUpdatableResponse) {
podStateManager.updateFromResponse((StatusUpdatableResponse) responseMessageBlock);
podStateManager.updateFromResponse((StatusUpdatableResponse) responseMessageBlock, message);
} else if (responseMessageBlock instanceof PodInfoResponse) {
PodInfo podInfo = ((PodInfoResponse) responseMessageBlock).getPodInfo();
if (podInfo instanceof StatusUpdatableResponse) {
podStateManager.updateFromResponse((StatusUpdatableResponse) podInfo);
podStateManager.updateFromResponse((StatusUpdatableResponse) podInfo, message);
}
}