Automatically update pod state from PodInfoFaultEvent

This commit is contained in:
Bart Sopers 2020-08-26 21:58:54 +02:00
parent 908c666d5f
commit ff72b0d474
11 changed files with 136 additions and 84 deletions

View file

@ -24,7 +24,7 @@ public class DeactivatePodAction implements OmnipodAction<StatusResponse> {
@Override @Override
public StatusResponse execute(OmnipodRileyLinkCommunicationManager communicationService) { public StatusResponse execute(OmnipodRileyLinkCommunicationManager communicationService) {
if (!podStateManager.isSuspended() && !podStateManager.hasFaultEvent()) { if (!podStateManager.isSuspended() && !podStateManager.isPodFaulted()) {
try { try {
communicationService.executeAction(new CancelDeliveryAction(podStateManager, communicationService.executeAction(new CancelDeliveryAction(podStateManager,
EnumSet.allOf(DeliveryType.class), acknowledgementBeep)); EnumSet.allOf(DeliveryType.class), acknowledgementBeep));

View file

@ -30,7 +30,9 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, podStateManager.isPodInitialized() ? podStateManager.getPodProgressStatus() : null); throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, podStateManager.isPodInitialized() ? podStateManager.getPodProgressStatus() : null);
} }
if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PRIMING)) { if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PRIMING)) {
service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podStateManager); // FaultConfigCommand sets internal pod variables to effectively disable $6x faults which occur more often with a 0 TBR
service.executeDisableTab5Sub16And17FaultConfigCommand(communicationService, podStateManager);
service.executeFinishSetupReminderAlertCommand(communicationService, podStateManager); service.executeFinishSetupReminderAlertCommand(communicationService, podStateManager);
return service.executePrimeBolusCommand(communicationService, podStateManager); return service.executePrimeBolusCommand(communicationService, podStateManager);
} else if (podStateManager.getPodProgressStatus().equals(PodProgressStatus.PRIMING)) { } else if (podStateManager.getPodProgressStatus().equals(PodProgressStatus.PRIMING)) {

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.OmnipodRileyLin
public class PrimeService { public class PrimeService {
public StatusResponse executeDisableTab5Sub16FaultConfigCommand(OmnipodRileyLinkCommunicationManager communicationService, PodStateManager podStateManager) { public StatusResponse executeDisableTab5Sub16And17FaultConfigCommand(OmnipodRileyLinkCommunicationManager communicationService, PodStateManager podStateManager) {
FaultConfigCommand faultConfigCommand = new FaultConfigCommand(podStateManager.getCurrentNonce(), (byte) 0x00, (byte) 0x00); FaultConfigCommand faultConfigCommand = new FaultConfigCommand(podStateManager.getCurrentNonce(), (byte) 0x00, (byte) 0x00);
OmnipodMessage faultConfigMessage = new OmnipodMessage(podStateManager.getAddress(), OmnipodMessage faultConfigMessage = new OmnipodMessage(podStateManager.getAddress(),
Collections.singletonList(faultConfigCommand), podStateManager.getMessageNumber()); Collections.singletonList(faultConfigCommand), podStateManager.getMessageNumber());

View file

@ -13,7 +13,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.Message
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
public class StatusResponse extends MessageBlock { public class StatusResponse extends MessageBlock implements StatusUpdatableResponse {
private static final int MESSAGE_LENGTH = 10; private static final int MESSAGE_LENGTH = 10;
private final DeliveryStatus deliveryStatus; private final DeliveryStatus deliveryStatus;
@ -22,9 +22,9 @@ public class StatusResponse extends MessageBlock {
private final Double reservoirLevel; private final Double reservoirLevel;
private final int ticksDelivered; private final int ticksDelivered;
private final double insulinDelivered; private final double insulinDelivered;
private final double insulinNotDelivered; private final double bolusNotDelivered;
private final byte podMessageCounter; private final byte podMessageCounter;
private final AlertSet alerts; private final AlertSet unacknowledgedAlerts;
public StatusResponse(byte[] encodedData) { public StatusResponse(byte[] encodedData) {
if (encodedData.length < MESSAGE_LENGTH) { if (encodedData.length < MESSAGE_LENGTH) {
@ -45,8 +45,8 @@ public class StatusResponse extends MessageBlock {
insulinDelivered = OmnipodConstants.POD_PULSE_SIZE * ticksDelivered; insulinDelivered = OmnipodConstants.POD_PULSE_SIZE * ticksDelivered;
podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf); podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf);
insulinNotDelivered = OmnipodConstants.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5])); bolusNotDelivered = OmnipodConstants.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5]));
alerts = new AlertSet((byte) (((encodedData[6] & 0x7f) << 1) | (ByteUtil.convertUnsignedByteToInt(encodedData[7]) >>> 7))); unacknowledgedAlerts = new AlertSet((byte) (((encodedData[6] & 0x7f) << 1) | (ByteUtil.convertUnsignedByteToInt(encodedData[7]) >>> 7)));
double reservoirValue = (((encodedData[8] & 0x3) << 8) + ByteUtil.convertUnsignedByteToInt(encodedData[9])) * OmnipodConstants.POD_PULSE_SIZE; double reservoirValue = (((encodedData[8] & 0x3) << 8) + ByteUtil.convertUnsignedByteToInt(encodedData[9])) * OmnipodConstants.POD_PULSE_SIZE;
if (reservoirValue > OmnipodConstants.MAX_RESERVOIR_READING) { if (reservoirValue > OmnipodConstants.MAX_RESERVOIR_READING) {
@ -61,40 +61,40 @@ public class StatusResponse extends MessageBlock {
return MessageBlockType.STATUS_RESPONSE; return MessageBlockType.STATUS_RESPONSE;
} }
public DeliveryStatus getDeliveryStatus() { @Override public DeliveryStatus getDeliveryStatus() {
return deliveryStatus; return deliveryStatus;
} }
public PodProgressStatus getPodProgressStatus() { @Override public PodProgressStatus getPodProgressStatus() {
return podProgressStatus; return podProgressStatus;
} }
public Duration getTimeActive() { @Override public Duration getTimeActive() {
return timeActive; return timeActive;
} }
public Double getReservoirLevel() { @Override public Double getReservoirLevel() {
return reservoirLevel; return reservoirLevel;
} }
public int getTicksDelivered() { @Override public int getTicksDelivered() {
return ticksDelivered; return ticksDelivered;
} }
public double getInsulinDelivered() { @Override public double getInsulinDelivered() {
return insulinDelivered; return insulinDelivered;
} }
public double getInsulinNotDelivered() { @Override public double getBolusNotDelivered() {
return insulinNotDelivered; return bolusNotDelivered;
} }
public byte getPodMessageCounter() { @Override public byte getPodMessageCounter() {
return podMessageCounter; return podMessageCounter;
} }
public AlertSet getAlerts() { @Override public AlertSet getUnacknowledgedAlerts() {
return alerts; return unacknowledgedAlerts;
} }
@Override public byte[] getRawData() { @Override public byte[] getRawData() {
@ -109,17 +109,18 @@ public class StatusResponse extends MessageBlock {
return stream.toByteArray(); return stream.toByteArray();
} }
@Override @Override public String toString() {
public String toString() {
return "StatusResponse{" + return "StatusResponse{" +
"deliveryStatus=" + deliveryStatus + "deliveryStatus=" + deliveryStatus +
", podProgressStatus=" + podProgressStatus + ", podProgressStatus=" + podProgressStatus +
", timeActive=" + timeActive + ", timeActive=" + timeActive +
", reservoirLevel=" + reservoirLevel + ", reservoirLevel=" + reservoirLevel +
", ticksDelivered=" + ticksDelivered +
", insulinDelivered=" + insulinDelivered + ", insulinDelivered=" + insulinDelivered +
", insulinNotDelivered=" + insulinNotDelivered + ", bolusNotDelivered=" + bolusNotDelivered +
", podMessageCounter=" + podMessageCounter + ", podMessageCounter=" + podMessageCounter +
", alerts=" + alerts + ", unacknowledgedAlerts=" + unacknowledgedAlerts +
", encodedData=" + ByteUtil.shortHexStringWithoutSpaces(encodedData) +
'}'; '}';
} }
} }

View file

@ -0,0 +1,27 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response;
import org.joda.time.Duration;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
public interface StatusUpdatableResponse {
DeliveryStatus getDeliveryStatus();
PodProgressStatus getPodProgressStatus();
Duration getTimeActive();
Double getReservoirLevel();
int getTicksDelivered();
double getInsulinDelivered();
double getBolusNotDelivered();
byte getPodMessageCounter();
AlertSet getUnacknowledgedAlerts();
}

View file

@ -2,7 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.mes
import org.joda.time.Duration; import org.joda.time.Duration;
import java.util.Arrays;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusUpdatableResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.FaultEventCode;
@ -11,18 +14,19 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.Omnipod
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
public class PodInfoFaultEvent extends PodInfo { public class PodInfoFaultEvent extends PodInfo implements StatusUpdatableResponse {
private static final int MINIMUM_MESSAGE_LENGTH = 21; private static final int MINIMUM_MESSAGE_LENGTH = 21;
private final PodProgressStatus podProgressStatus; private final PodProgressStatus podProgressStatus;
private final DeliveryStatus deliveryStatus; private final DeliveryStatus deliveryStatus;
private final double insulinNotDelivered; private final double bolusNotDelivered;
private final byte podMessageCounter; private final byte podMessageCounter;
private final double totalInsulinDelivered; private final int ticksDelivered;
private final double insulinDelivered;
private final FaultEventCode faultEventCode; private final FaultEventCode faultEventCode;
private final Duration faultEventTime; private final Duration faultEventTime;
private final Double reservoirLevel; private final Double reservoirLevel;
private final Duration timeSinceActivation; private final Duration timeActive;
private final AlertSet unacknowledgedAlerts; private final AlertSet unacknowledgedAlerts;
private final boolean faultAccessingTables; private final boolean faultAccessingTables;
private final LogEventErrorCode logEventErrorType; private final LogEventErrorCode logEventErrorType;
@ -41,9 +45,10 @@ public class PodInfoFaultEvent extends PodInfo {
podProgressStatus = PodProgressStatus.fromByte(encodedData[1]); podProgressStatus = PodProgressStatus.fromByte(encodedData[1]);
deliveryStatus = DeliveryStatus.fromByte(encodedData[2]); deliveryStatus = DeliveryStatus.fromByte(encodedData[2]);
insulinNotDelivered = OmnipodConstants.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[3], encodedData[4]); bolusNotDelivered = OmnipodConstants.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[3], encodedData[4]);
podMessageCounter = encodedData[5]; podMessageCounter = encodedData[5];
totalInsulinDelivered = OmnipodConstants.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[6], encodedData[7]); ticksDelivered = ByteUtil.toInt(encodedData[6], encodedData[7]);
insulinDelivered = OmnipodConstants.POD_PULSE_SIZE * ticksDelivered;
faultEventCode = FaultEventCode.fromByte(encodedData[8]); faultEventCode = FaultEventCode.fromByte(encodedData[8]);
int minutesSinceActivation = ByteUtil.toInt(encodedData[9], encodedData[10]); int minutesSinceActivation = ByteUtil.toInt(encodedData[9], encodedData[10]);
@ -62,7 +67,7 @@ public class PodInfoFaultEvent extends PodInfo {
} }
int minutesActive = ByteUtil.toInt(encodedData[13], encodedData[14]); int minutesActive = ByteUtil.toInt(encodedData[13], encodedData[14]);
timeSinceActivation = Duration.standardMinutes(minutesActive); timeActive = Duration.standardMinutes(minutesActive);
unacknowledgedAlerts = new AlertSet(encodedData[15]); unacknowledgedAlerts = new AlertSet(encodedData[15]);
faultAccessingTables = encodedData[16] == 0x02; faultAccessingTables = encodedData[16] == 0x02;
@ -79,24 +84,28 @@ public class PodInfoFaultEvent extends PodInfo {
return PodInfoType.FAULT_EVENT; return PodInfoType.FAULT_EVENT;
} }
public PodProgressStatus getPodProgressStatus() { @Override public PodProgressStatus getPodProgressStatus() {
return podProgressStatus; return podProgressStatus;
} }
public DeliveryStatus getDeliveryStatus() { @Override public DeliveryStatus getDeliveryStatus() {
return deliveryStatus; return deliveryStatus;
} }
public double getInsulinNotDelivered() { @Override public double getBolusNotDelivered() {
return insulinNotDelivered; return bolusNotDelivered;
} }
public byte getPodMessageCounter() { @Override public byte getPodMessageCounter() {
return podMessageCounter; return podMessageCounter;
} }
public double getTotalInsulinDelivered() { @Override public int getTicksDelivered() {
return totalInsulinDelivered; return ticksDelivered;
}
@Override public double getInsulinDelivered() {
return insulinDelivered;
} }
public FaultEventCode getFaultEventCode() { public FaultEventCode getFaultEventCode() {
@ -107,15 +116,15 @@ public class PodInfoFaultEvent extends PodInfo {
return faultEventTime; return faultEventTime;
} }
public Double getReservoirLevel() { @Override public Double getReservoirLevel() {
return reservoirLevel; return reservoirLevel;
} }
public Duration getTimeSinceActivation() { @Override public Duration getTimeActive() {
return timeSinceActivation; return timeActive;
} }
public AlertSet getUnacknowledgedAlerts() { @Override public AlertSet getUnacknowledgedAlerts() {
return unacknowledgedAlerts; return unacknowledgedAlerts;
} }
@ -147,18 +156,18 @@ public class PodInfoFaultEvent extends PodInfo {
return unknownValue; return unknownValue;
} }
@Override @Override public String toString() {
public String toString() {
return "PodInfoFaultEvent{" + return "PodInfoFaultEvent{" +
"podProgressStatus=" + podProgressStatus + "podProgressStatus=" + podProgressStatus +
", deliveryStatus=" + deliveryStatus + ", deliveryStatus=" + deliveryStatus +
", insulinNotDelivered=" + insulinNotDelivered + ", bolusNotDelivered=" + bolusNotDelivered +
", podMessageCounter=" + podMessageCounter + ", podMessageCounter=" + podMessageCounter +
", totalInsulinDelivered=" + totalInsulinDelivered + ", ticksDelivered=" + ticksDelivered +
", insulinDelivered=" + insulinDelivered +
", faultEventCode=" + faultEventCode + ", faultEventCode=" + faultEventCode +
", faultEventTime=" + faultEventTime + ", faultEventTime=" + faultEventTime +
", reservoirLevel=" + reservoirLevel + ", reservoirLevel=" + reservoirLevel +
", timeSinceActivation=" + timeSinceActivation + ", timeActive=" + timeActive +
", unacknowledgedAlerts=" + unacknowledgedAlerts + ", unacknowledgedAlerts=" + unacknowledgedAlerts +
", faultAccessingTables=" + faultAccessingTables + ", faultAccessingTables=" + faultAccessingTables +
", logEventErrorType=" + logEventErrorType + ", logEventErrorType=" + logEventErrorType +
@ -166,7 +175,7 @@ public class PodInfoFaultEvent extends PodInfo {
", receiverLowGain=" + receiverLowGain + ", receiverLowGain=" + receiverLowGain +
", radioRSSI=" + radioRSSI + ", radioRSSI=" + radioRSSI +
", podProgressStatusAtTimeOfFirstLoggedFaultEvent=" + podProgressStatusAtTimeOfFirstLoggedFaultEvent + ", podProgressStatusAtTimeOfFirstLoggedFaultEvent=" + podProgressStatusAtTimeOfFirstLoggedFaultEvent +
", unknownValue=" + ByteUtil.shortHexString(unknownValue) + ", unknownValue=" + Arrays.toString(unknownValue) +
'}'; '}';
} }
} }

View file

@ -340,7 +340,7 @@ public class OmnipodManager {
} }
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
// Substract units not delivered in case of a Pod failure // Substract units not delivered in case of a Pod failure
unitsNotDelivered = ex.getFaultEvent().getInsulinNotDelivered(); unitsNotDelivered = ex.getFaultEvent().getBolusNotDelivered();
aapsLogger.debug(LTag.PUMPCOMM, "Caught PodFaultException in bolus completion verification", ex); aapsLogger.debug(LTag.PUMPCOMM, "Caught PodFaultException in bolus completion verification", ex);
break; break;
@ -374,9 +374,9 @@ public class OmnipodManager {
try { try {
StatusResponse statusResponse = cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep); StatusResponse statusResponse = cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep);
discardActiveBolusData(statusResponse.getInsulinNotDelivered()); discardActiveBolusData(statusResponse.getBolusNotDelivered());
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
discardActiveBolusData(ex.getFaultEvent().getInsulinNotDelivered()); discardActiveBolusData(ex.getFaultEvent().getBolusNotDelivered());
throw ex; throw ex;
} finally { } finally {
logCommandExecutionFinished("cancelBolus"); logCommandExecutionFinished("cancelBolus");

View file

@ -19,7 +19,7 @@ import java.util.function.Supplier;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusUpdatableResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoFaultEvent; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoFaultEvent;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSlot;
@ -57,7 +57,7 @@ public abstract class PodStateManager {
} }
/** /**
* @return true if we have a Pod state (which at least contains an ddress), indicating it is legal to call getters on PodStateManager * @return true if we have a Pod state (which at least contains an address), indicating it is legal to call getters on PodStateManager
*/ */
public final boolean hasPodState() { public final boolean hasPodState() {
return podState != null; return podState != null;
@ -88,6 +88,13 @@ public abstract class PodStateManager {
return isPodInitialized() && getPodProgressStatus().isRunning(); return isPodInitialized() && getPodProgressStatus().isRunning();
} }
/**
* @return true if the Pod is initialized and a Fault Event has occurred
*/
public final boolean isPodFaulted() {
return isPodInitialized() && podState.getPodProgressStatus().equals(PodProgressStatus.FAULT_EVENT_OCCURRED);
}
/** /**
* @return true if we have a Pod state and the Pod is dead, meaning it is either in a fault state or activation time has been exceeded or it is deactivated * @return true if we have a Pod state and the Pod is dead, meaning it is either in a fault state or activation time has been exceeded or it is deactivated
*/ */
@ -214,10 +221,15 @@ public abstract class PodStateManager {
setSafe(() -> podState.setLastFailedCommunication(dateTime)); setSafe(() -> podState.setLastFailedCommunication(dateTime));
} }
public final DateTime getLastUpdatedFromStatusResponse() { public final DateTime getLastUpdatedFromResponse() {
return getSafe(() -> podState.getLastUpdatedFromStatusResponse()); return getSafe(() -> podState.getLastUpdatedFromResponse());
} }
/**
* @return true if the Pod State contains a fault event. Is the Pod state does not contain
* a fault event, this does NOT necessarily mean that the Pod is not faulted. For a reliable
* indication on whether or not the pod is faulted, see {@link #isPodFaulted() isPodFaulted()}
*/
public final boolean hasFaultEvent() { public final boolean hasFaultEvent() {
return podState != null && podState.getFaultEvent() != null; return podState != null && podState.getFaultEvent() != null;
} }
@ -374,7 +386,7 @@ public abstract class PodStateManager {
/** /**
* Does not automatically store pod state in order to decrease I/O load * Does not automatically store pod state in order to decrease I/O load
*/ */
public final void updateFromStatusResponse(StatusResponse statusResponse) { public final void updateFromResponse(StatusUpdatableResponse statusResponse) {
setSafe(() -> { setSafe(() -> {
if (podState.getActivatedAt() == null) { if (podState.getActivatedAt() == null) {
DateTime activatedAtCalculated = getTime().minus(statusResponse.getTimeActive()); DateTime activatedAtCalculated = getTime().minus(statusResponse.getTimeActive());
@ -387,12 +399,12 @@ public abstract class PodStateManager {
} }
podState.setSuspended(statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED); podState.setSuspended(statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
podState.setActiveAlerts(statusResponse.getAlerts()); podState.setActiveAlerts(statusResponse.getUnacknowledgedAlerts());
podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus()); podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus());
podState.setReservoirLevel(statusResponse.getReservoirLevel()); podState.setReservoirLevel(statusResponse.getReservoirLevel());
podState.setTotalTicksDelivered(statusResponse.getTicksDelivered()); podState.setTotalTicksDelivered(statusResponse.getTicksDelivered());
podState.setPodProgressStatus(statusResponse.getPodProgressStatus()); podState.setPodProgressStatus(statusResponse.getPodProgressStatus());
podState.setLastUpdatedFromStatusResponse(DateTime.now()); podState.setLastUpdatedFromResponse(DateTime.now());
}); });
} }
@ -475,7 +487,7 @@ public abstract class PodStateManager {
private int messageNumber; private int messageNumber;
private DateTime lastSuccessfulCommunication; private DateTime lastSuccessfulCommunication;
private DateTime lastFailedCommunication; private DateTime lastFailedCommunication;
private DateTime lastUpdatedFromStatusResponse; private DateTime lastUpdatedFromResponse;
private DateTimeZone timeZone; private DateTimeZone timeZone;
private DateTime activatedAt; private DateTime activatedAt;
private DateTime expiresAt; private DateTime expiresAt;
@ -567,12 +579,12 @@ public abstract class PodStateManager {
this.lastFailedCommunication = lastFailedCommunication; this.lastFailedCommunication = lastFailedCommunication;
} }
DateTime getLastUpdatedFromStatusResponse() { DateTime getLastUpdatedFromResponse() {
return lastUpdatedFromStatusResponse; return lastUpdatedFromResponse;
} }
void setLastUpdatedFromStatusResponse(DateTime lastUpdatedFromStatusResponse) { void setLastUpdatedFromResponse(DateTime lastUpdatedFromResponse) {
this.lastUpdatedFromStatusResponse = lastUpdatedFromStatusResponse; this.lastUpdatedFromResponse = lastUpdatedFromResponse;
} }
DateTimeZone getTimeZone() { DateTimeZone getTimeZone() {
@ -734,12 +746,13 @@ public abstract class PodStateManager {
", messageNumber=" + messageNumber + ", messageNumber=" + messageNumber +
", lastSuccessfulCommunication=" + lastSuccessfulCommunication + ", lastSuccessfulCommunication=" + lastSuccessfulCommunication +
", lastFailedCommunication=" + lastFailedCommunication + ", lastFailedCommunication=" + lastFailedCommunication +
", lastUpdatedFromStatusResponse=" + lastUpdatedFromStatusResponse + ", lastUpdatedFromResponse=" + lastUpdatedFromResponse +
", timeZone=" + timeZone + ", timeZone=" + timeZone +
", activatedAt=" + activatedAt + ", activatedAt=" + activatedAt +
", expiresAt=" + expiresAt + ", expiresAt=" + expiresAt +
", faultEvent=" + faultEvent + ", faultEvent=" + faultEvent +
", reservoirLevel=" + reservoirLevel + ", reservoirLevel=" + reservoirLevel +
", totalTicksDelivered=" + totalTicksDelivered +
", suspended=" + suspended + ", suspended=" + suspended +
", nonceState=" + nonceState + ", nonceState=" + nonceState +
", podProgressStatus=" + podProgressStatus + ", podProgressStatus=" + podProgressStatus +

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.mess
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodPacket; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodPacket;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.DeactivatePodCommand; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.DeactivatePodCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.ErrorResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.ErrorResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusUpdatableResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoFaultEvent; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoFaultEvent;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.MessageBlockType;
@ -125,8 +125,8 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication
aapsLogger.debug(LTag.PUMPBTCOMM, "Received response from the Pod [responseMessageBlock={}]", responseMessageBlock); aapsLogger.debug(LTag.PUMPBTCOMM, "Received response from the Pod [responseMessageBlock={}]", responseMessageBlock);
if (responseMessageBlock instanceof StatusResponse) { if (responseMessageBlock instanceof StatusUpdatableResponse) {
podStateManager.updateFromStatusResponse((StatusResponse) responseMessageBlock); podStateManager.updateFromResponse((StatusUpdatableResponse) responseMessageBlock);
} }
if (responseClass.isInstance(responseMessageBlock)) { if (responseClass.isInstance(responseMessageBlock)) {

View file

@ -48,8 +48,8 @@ public class StatusResponseTest {
assertEquals(1201, statusResponse.getTicksDelivered()); assertEquals(1201, statusResponse.getTicksDelivered());
assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001);
assertEquals(0, statusResponse.getAlerts().getAlertSlots().size()); assertEquals(0, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertArrayEquals(ByteUtil.fromHexString("1d180258f80000146fff"), statusResponse.getRawData()); assertArrayEquals(ByteUtil.fromHexString("1d180258f80000146fff"), statusResponse.getRawData());
} }
@ -66,9 +66,9 @@ public class StatusResponseTest {
assertEquals(3134, statusResponse.getTicksDelivered()); assertEquals(3134, statusResponse.getTicksDelivered());
assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(13, statusResponse.getPodMessageCounter()); assertEquals(13, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001);
assertEquals(1, statusResponse.getAlerts().getAlertSlots().size()); assertEquals(1, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertEquals(AlertSlot.SLOT3, statusResponse.getAlerts().getAlertSlots().get(0)); assertEquals(AlertSlot.SLOT3, statusResponse.getUnacknowledgedAlerts().getAlertSlots().get(0));
assertArrayEquals(ByteUtil.fromHexString("1d19061f6800044295e8"), statusResponse.getRawData()); assertArrayEquals(ByteUtil.fromHexString("1d19061f6800044295e8"), statusResponse.getRawData());
} }
@ -79,13 +79,13 @@ public class StatusResponseTest {
StatusResponse statusResponse = new StatusResponse(bytes); StatusResponse statusResponse = new StatusResponse(bytes);
assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(OmnipodConstants.POD_PULSE_SIZE * 1023, statusResponse.getBolusNotDelivered(), 0.000001);
assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001);
assertEquals(8191, statusResponse.getTicksDelivered()); assertEquals(8191, statusResponse.getTicksDelivered());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001);
assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(8, statusResponse.getAlerts().getAlertSlots().size()); assertEquals(8, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertArrayEquals(ByteUtil.fromHexString("1d11ffffffffffffffff"), statusResponse.getRawData()); assertArrayEquals(ByteUtil.fromHexString("1d11ffffffffffffffff"), statusResponse.getRawData());
} }
@ -101,7 +101,7 @@ public class StatusResponseTest {
assertEquals(2589, statusResponse.getTicksDelivered()); assertEquals(2589, statusResponse.getTicksDelivered());
assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001); assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001);
assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001); assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001);
assertEquals(2.2, statusResponse.getInsulinNotDelivered(), 0.0001); assertEquals(2.2, statusResponse.getBolusNotDelivered(), 0.0001);
assertEquals(9, statusResponse.getPodMessageCounter()); assertEquals(9, statusResponse.getPodMessageCounter());
assertArrayEquals(ByteUtil.fromHexString("1d19050ec82c08376f98"), statusResponse.getRawData()); assertArrayEquals(ByteUtil.fromHexString("1d19050ec82c08376f98"), statusResponse.getRawData());

View file

@ -22,12 +22,12 @@ public class PodInfoFaultEventTest {
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoFaultEvent.getPodProgressStatus()); assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoFaultEvent.getPodProgressStatus());
assertEquals(DeliveryStatus.NORMAL, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.NORMAL, podInfoFaultEvent.getDeliveryStatus());
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getBolusNotDelivered(), 0.000001);
assertEquals(0x0a, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x0a, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventCode.NO_FAULTS, podInfoFaultEvent.getFaultEventCode()); assertEquals(FaultEventCode.NO_FAULTS, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.ZERO.isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.ZERO.isEqual(podInfoFaultEvent.getFaultEventTime()));
assertNull(podInfoFaultEvent.getReservoirLevel()); assertNull(podInfoFaultEvent.getReservoirLevel());
assertTrue(Duration.standardSeconds(8100).isEqual(podInfoFaultEvent.getTimeSinceActivation())); assertTrue(Duration.standardSeconds(8100).isEqual(podInfoFaultEvent.getTimeActive()));
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoFaultEvent.isFaultAccessingTables()); assertFalse(podInfoFaultEvent.isFaultAccessingTables());
assertEquals(LogEventErrorCode.NONE, podInfoFaultEvent.getLogEventErrorType()); assertEquals(LogEventErrorCode.NONE, podInfoFaultEvent.getLogEventErrorType());
@ -42,12 +42,12 @@ public class PodInfoFaultEventTest {
assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus()); assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getBolusNotDelivered(), 0.000001);
assertEquals(0x09, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x09, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventCode.PRIME_OPEN_COUNT_TOO_LOW, podInfoFaultEvent.getFaultEventCode()); assertEquals(FaultEventCode.PRIME_OPEN_COUNT_TOO_LOW, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardSeconds(60).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardSeconds(60).isEqual(podInfoFaultEvent.getFaultEventTime()));
assertNull(podInfoFaultEvent.getReservoirLevel()); assertNull(podInfoFaultEvent.getReservoirLevel());
assertTrue(Duration.standardSeconds(60).isEqual(podInfoFaultEvent.getTimeSinceActivation())); assertTrue(Duration.standardSeconds(60).isEqual(podInfoFaultEvent.getTimeActive()));
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoFaultEvent.isFaultAccessingTables()); assertFalse(podInfoFaultEvent.isFaultAccessingTables());
assertEquals(LogEventErrorCode.NONE, podInfoFaultEvent.getLogEventErrorType()); assertEquals(LogEventErrorCode.NONE, podInfoFaultEvent.getLogEventErrorType());
@ -62,8 +62,8 @@ public class PodInfoFaultEventTest {
assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoFaultEvent.getPodProgressStatus()); assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoFaultEvent.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
assertEquals(101.7, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(101.7, podInfoFaultEvent.getInsulinDelivered(), 0.000001);
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getBolusNotDelivered(), 0.000001);
assertEquals(0x04, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x04, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventCode.BASAL_OVER_INFUSION_PULSE, podInfoFaultEvent.getFaultEventCode()); assertEquals(FaultEventCode.BASAL_OVER_INFUSION_PULSE, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(2559).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(2559).isEqual(podInfoFaultEvent.getFaultEventTime()));
@ -82,8 +82,8 @@ public class PodInfoFaultEventTest {
assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus()); assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(11.8, podInfoFaultEvent.getInsulinDelivered(), 0.000001);
assertEquals(0.05, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0.05, podInfoFaultEvent.getBolusNotDelivered(), 0.000001);
assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode()); assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime()));
@ -102,8 +102,8 @@ public class PodInfoFaultEventTest {
assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus()); assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(11.8, podInfoFaultEvent.getInsulinDelivered(), 0.000001);
assertEquals(3276.75, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); // Insane and will not happen, but this verifies that we convert it to an unsigned int assertEquals(3276.75, podInfoFaultEvent.getBolusNotDelivered(), 0.000001); // Insane and will not happen, but this verifies that we convert it to an unsigned int
assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode()); assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime()));