Properly decode non-nonce error responses and some renaming/cleanup

This commit is contained in:
Bart Sopers 2020-04-27 22:30:51 +02:00
parent 9a5cd3c902
commit ed1efe8944
16 changed files with 104 additions and 108 deletions

View file

@ -32,7 +32,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Err
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.ErrorResponseType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
@ -125,7 +124,7 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
} else { } else {
if (responseMessageBlock.getType() == MessageBlockType.ERROR_RESPONSE) { if (responseMessageBlock.getType() == MessageBlockType.ERROR_RESPONSE) {
ErrorResponse error = (ErrorResponse) responseMessageBlock; ErrorResponse error = (ErrorResponse) responseMessageBlock;
if (error.getErrorResponseType() == ErrorResponseType.BAD_NONCE) { if (error.getErrorResponseCode() == ErrorResponse.ERROR_RESPONSE_CODE_BAD_NONCE) {
podState.resyncNonce(error.getNonceSearchKey(), message.getSentNonce(), message.getSequenceNumber()); podState.resyncNonce(error.getNonceSearchKey(), message.getSentNonce(), message.getSequenceNumber());
if (automaticallyResyncNonce) { if (automaticallyResyncNonce) {
message.resyncNonce(podState.getCurrentNonce()); message.resyncNonce(podState.getCurrentNonce());
@ -133,7 +132,7 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
throw new NonceOutOfSyncException(); throw new NonceOutOfSyncException();
} }
} else { } else {
throw new PodReturnedErrorResponseException((ErrorResponse) responseMessageBlock); throw new PodReturnedErrorResponseException(error);
} }
} else if (responseMessageBlock.getType() == MessageBlockType.POD_INFO_RESPONSE && ((PodInfoResponse) responseMessageBlock).getSubType() == PodInfoType.FAULT_EVENT) { } else if (responseMessageBlock.getType() == MessageBlockType.POD_INFO_RESPONSE && ((PodInfoResponse) responseMessageBlock).getSubType() == PodInfoType.FAULT_EVENT) {
PodInfoFaultEvent faultEvent = ((PodInfoResponse) responseMessageBlock).getPodInfo(); PodInfoFaultEvent faultEvent = ((PodInfoResponse) responseMessageBlock).getPodInfo();

View file

@ -7,7 +7,7 @@ public class PodFaultException extends OmnipodException {
private final PodInfoFaultEvent faultEvent; private final PodInfoFaultEvent faultEvent;
public PodFaultException(PodInfoFaultEvent faultEvent) { public PodFaultException(PodInfoFaultEvent faultEvent) {
super(faultEvent.getFaultEventType().toString(), true); super(faultEvent.getFaultEventCode().toString(), true);
this.faultEvent = faultEvent; this.faultEvent = faultEvent;
} }

View file

@ -7,7 +7,7 @@ public class PodReturnedErrorResponseException extends OmnipodException {
private final ErrorResponse errorResponse; private final ErrorResponse errorResponse;
public PodReturnedErrorResponseException(ErrorResponse errorResponse) { public PodReturnedErrorResponseException(ErrorResponse errorResponse) {
super("Pod returned error response: " + errorResponse.getErrorResponseType(), true); super("Pod returned error response: " + errorResponse, true);
this.errorResponse = errorResponse; this.errorResponse = errorResponse;
} }

View file

@ -2,14 +2,19 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response;
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.comm.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.ErrorResponseType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
public class ErrorResponse extends MessageBlock { public class ErrorResponse extends MessageBlock {
public static final byte ERROR_RESPONSE_CODE_BAD_NONCE = (byte) 0x14;
private static final int MESSAGE_LENGTH = 5; private static final int MESSAGE_LENGTH = 5;
private final ErrorResponseType errorResponseType; private final byte errorResponseCode;
private final int nonceSearchKey; private Integer nonceSearchKey; // only valid for BAD_NONCE
private FaultEventCode faultEventCode; // valid for all but BAD_NONCE
private PodProgressStatus podProgressStatus; // valid for all but BAD_NONCE
public ErrorResponse(byte[] encodedData) { public ErrorResponse(byte[] encodedData) {
if (encodedData.length < MESSAGE_LENGTH) { if (encodedData.length < MESSAGE_LENGTH) {
@ -17,14 +22,14 @@ public class ErrorResponse extends MessageBlock {
} }
this.encodedData = ByteUtil.substring(encodedData, 2, MESSAGE_LENGTH - 2); this.encodedData = ByteUtil.substring(encodedData, 2, MESSAGE_LENGTH - 2);
ErrorResponseType errorResponseType = null; errorResponseCode = encodedData[2];
try {
errorResponseType = ErrorResponseType.fromByte(encodedData[2]);
} catch (IllegalArgumentException ex) {
}
this.errorResponseType = errorResponseType; if (this.errorResponseCode == ERROR_RESPONSE_CODE_BAD_NONCE) {
this.nonceSearchKey = ByteUtil.makeUnsignedShort((int) encodedData[3], (int) encodedData[4]); nonceSearchKey = ByteUtil.makeUnsignedShort(encodedData[3], encodedData[4]);
} else {
faultEventCode = FaultEventCode.fromByte(encodedData[3]);
podProgressStatus = PodProgressStatus.fromByte(encodedData[4]);
}
} }
@Override @Override
@ -32,19 +37,29 @@ public class ErrorResponse extends MessageBlock {
return MessageBlockType.ERROR_RESPONSE; return MessageBlockType.ERROR_RESPONSE;
} }
public ErrorResponseType getErrorResponseType() { public byte getErrorResponseCode() {
return errorResponseType; return errorResponseCode;
} }
public int getNonceSearchKey() { public FaultEventCode getFaultEventCode() {
return faultEventCode;
}
public PodProgressStatus getPodProgressStatus() {
return podProgressStatus;
}
public Integer getNonceSearchKey() {
return nonceSearchKey; return nonceSearchKey;
} }
@Override @Override
public String toString() { public String toString() {
return "ErrorResponse{" + return "ErrorResponse{" +
"errorResponseType=" + errorResponseType + "errorResponseCode=" + errorResponseCode +
", nonceSearchKey=" + nonceSearchKey + ", nonceSearchKey=" + nonceSearchKey +
", faultEventCode=" + faultEventCode +
", podProgressStatus=" + podProgressStatus +
'}'; '}';
} }
} }

View file

@ -31,20 +31,20 @@ public class StatusResponse extends MessageBlock {
} }
this.encodedData = ByteUtil.substring(encodedData, 1, MESSAGE_LENGTH - 1); this.encodedData = ByteUtil.substring(encodedData, 1, MESSAGE_LENGTH - 1);
this.deliveryStatus = DeliveryStatus.fromByte((byte) (ByteUtil.convertUnsignedByteToInt(encodedData[1]) >>> 4)); deliveryStatus = DeliveryStatus.fromByte((byte) (ByteUtil.convertUnsignedByteToInt(encodedData[1]) >>> 4));
this.podProgressStatus = PodProgressStatus.fromByte((byte) (encodedData[1] & 0x0F)); podProgressStatus = PodProgressStatus.fromByte((byte) (encodedData[1] & 0x0F));
int minutes = ((encodedData[7] & 0x7F) << 6) | ((encodedData[8] & 0xFC) >>> 2); int minutes = ((encodedData[7] & 0x7F) << 6) | ((encodedData[8] & 0xFC) >>> 2);
this.timeActive = Duration.standardMinutes(minutes); timeActive = Duration.standardMinutes(minutes);
int highInsulinBits = (encodedData[2] & 0xF) << 9; int highInsulinBits = (encodedData[2] & 0xF) << 9;
int middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1; int middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1;
int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7; int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7;
this.insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits); insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits);
this.podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf); podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf);
this.insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5])); insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5]));
this.alerts = new AlertSet((byte) (((encodedData[6] & 0x7f) << 1) | (ByteUtil.convertUnsignedByteToInt(encodedData[7]) >>> 7))); alerts = new AlertSet((byte) (((encodedData[6] & 0x7f) << 1) | (ByteUtil.convertUnsignedByteToInt(encodedData[7]) >>> 7)));
double reservoirValue = (((encodedData[8] & 0x3) << 8) + ByteUtil.convertUnsignedByteToInt(encodedData[9])) * OmnipodConst.POD_PULSE_SIZE; double reservoirValue = (((encodedData[8] & 0x3) << 8) + ByteUtil.convertUnsignedByteToInt(encodedData[9])) * OmnipodConst.POD_PULSE_SIZE;
if (reservoirValue > OmnipodConst.MAX_RESERVOIR_READING) { if (reservoirValue > OmnipodConst.MAX_RESERVOIR_READING) {
@ -94,7 +94,7 @@ public class StatusResponse extends MessageBlock {
public byte[] getRawData() { public byte[] getRawData() {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
try { try {
stream.write(this.getType().getValue()); stream.write(getType().getValue());
stream.write(encodedData); stream.write(encodedData);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -34,18 +34,18 @@ public class VersionResponse extends MessageBlock {
throw new IllegalArgumentException("Unrecognized VersionResponse message length: " + length); throw new IllegalArgumentException("Unrecognized VersionResponse message length: " + length);
} }
this.podProgressStatus = PodProgressStatus.fromByte(truncatedData[7]); podProgressStatus = PodProgressStatus.fromByte(truncatedData[7]);
this.pmVersion = new FirmwareVersion(truncatedData[0], truncatedData[1], truncatedData[2]); pmVersion = new FirmwareVersion(truncatedData[0], truncatedData[1], truncatedData[2]);
this.piVersion = new FirmwareVersion(truncatedData[3], truncatedData[4], truncatedData[5]); piVersion = new FirmwareVersion(truncatedData[3], truncatedData[4], truncatedData[5]);
this.lot = ByteUtil.toInt((int) truncatedData[8], (int) truncatedData[9], lot = ByteUtil.toInt((int) truncatedData[8], (int) truncatedData[9],
(int) truncatedData[10], (int) truncatedData[11], ByteUtil.BitConversion.BIG_ENDIAN); (int) truncatedData[10], (int) truncatedData[11], ByteUtil.BitConversion.BIG_ENDIAN);
this.tid = ByteUtil.toInt((int) truncatedData[12], (int) truncatedData[13], tid = ByteUtil.toInt((int) truncatedData[12], (int) truncatedData[13],
(int) truncatedData[14], (int) truncatedData[15], ByteUtil.BitConversion.BIG_ENDIAN); (int) truncatedData[14], (int) truncatedData[15], ByteUtil.BitConversion.BIG_ENDIAN);
int indexIncrementor = extraByte ? 1 : 0; int indexIncrement = extraByte ? 1 : 0;
this.address = ByteUtil.toInt((int) truncatedData[16 + indexIncrementor], (int) truncatedData[17 + indexIncrementor], address = ByteUtil.toInt((int) truncatedData[16 + indexIncrement], (int) truncatedData[17 + indexIncrement],
(int) truncatedData[18 + indexIncrementor], (int) truncatedData[19 + indexIncrementor], ByteUtil.BitConversion.BIG_ENDIAN); (int) truncatedData[18 + indexIncrement], (int) truncatedData[19 + indexIncrement], ByteUtil.BitConversion.BIG_ENDIAN);
} }
@Override @Override

View file

@ -7,12 +7,12 @@ import java.util.Collections;
import java.util.List; import java.util.List;
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.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
public class PodInfoDataLog extends PodInfo { public class PodInfoDataLog extends PodInfo {
private static final int MINIMUM_MESSAGE_LENGTH = 8; private static final int MINIMUM_MESSAGE_LENGTH = 8;
private final FaultEventType faultEventType; private final FaultEventCode faultEventCode;
private final Duration timeFaultEvent; private final Duration timeFaultEvent;
private final Duration timeSinceActivation; private final Duration timeSinceActivation;
private final byte dataChunkSize; private final byte dataChunkSize;
@ -26,7 +26,7 @@ public class PodInfoDataLog extends PodInfo {
throw new IllegalArgumentException("Not enough data"); throw new IllegalArgumentException("Not enough data");
} }
faultEventType = FaultEventType.fromByte(encodedData[1]); faultEventCode = FaultEventCode.fromByte(encodedData[1]);
timeFaultEvent = Duration.standardMinutes(ByteUtil.toInt(encodedData[2], encodedData[3])); timeFaultEvent = Duration.standardMinutes(ByteUtil.toInt(encodedData[2], encodedData[3]));
timeSinceActivation = Duration.standardMinutes(ByteUtil.toInt(encodedData[4], encodedData[5])); timeSinceActivation = Duration.standardMinutes(ByteUtil.toInt(encodedData[4], encodedData[5]));
dataChunkSize = encodedData[6]; dataChunkSize = encodedData[6];
@ -45,8 +45,8 @@ public class PodInfoDataLog extends PodInfo {
return PodInfoType.DATA_LOG; return PodInfoType.DATA_LOG;
} }
public FaultEventType getFaultEventType() { public FaultEventCode getFaultEventCode() {
return faultEventType; return faultEventCode;
} }
public Duration getTimeFaultEvent() { public Duration getTimeFaultEvent() {
@ -72,7 +72,7 @@ public class PodInfoDataLog extends PodInfo {
@Override @Override
public String toString() { public String toString() {
return "PodInfoDataLog{" + return "PodInfoDataLog{" +
"faultEventType=" + faultEventType + "faultEventCode=" + faultEventCode +
", timeFaultEvent=" + timeFaultEvent + ", timeFaultEvent=" + timeFaultEvent +
", timeSinceActivation=" + timeSinceActivation + ", timeSinceActivation=" + timeSinceActivation +
", dataChunkSize=" + dataChunkSize + ", dataChunkSize=" + dataChunkSize +

View file

@ -3,12 +3,12 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.po
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
public class PodInfoFaultAndInitializationTime extends PodInfo { public class PodInfoFaultAndInitializationTime extends PodInfo {
private static final int MINIMUM_MESSAGE_LENGTH = 17; private static final int MINIMUM_MESSAGE_LENGTH = 17;
private final FaultEventType faultEventType; private final FaultEventCode faultEventCode;
private final Duration timeFaultEvent; private final Duration timeFaultEvent;
private final DateTime initializationTime; private final DateTime initializationTime;
@ -19,7 +19,7 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
throw new IllegalArgumentException("Not enough data"); throw new IllegalArgumentException("Not enough data");
} }
faultEventType = FaultEventType.fromByte(encodedData[1]); faultEventCode = FaultEventCode.fromByte(encodedData[1]);
timeFaultEvent = Duration.standardMinutes(((encodedData[2] & 0b1) << 8) + encodedData[3]); timeFaultEvent = Duration.standardMinutes(((encodedData[2] & 0b1) << 8) + encodedData[3]);
// We ignore time zones here because we don't keep the time zone in which the pod was initially set up // We ignore time zones here because we don't keep the time zone in which the pod was initially set up
// Which is fine because we don't use the initialization time for anything important anyway // Which is fine because we don't use the initialization time for anything important anyway
@ -31,8 +31,8 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
return PodInfoType.FAULT_AND_INITIALIZATION_TIME; return PodInfoType.FAULT_AND_INITIALIZATION_TIME;
} }
public FaultEventType getFaultEventType() { public FaultEventCode getFaultEventCode() {
return faultEventType; return faultEventCode;
} }
public Duration getTimeFaultEvent() { public Duration getTimeFaultEvent() {
@ -46,7 +46,7 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
@Override @Override
public String toString() { public String toString() {
return "PodInfoFaultAndInitializationTime{" + return "PodInfoFaultAndInitializationTime{" +
"faultEventType=" + faultEventType + "faultEventCode=" + faultEventCode +
", timeFaultEvent=" + timeFaultEvent + ", timeFaultEvent=" + timeFaultEvent +
", initializationTime=" + initializationTime + ", initializationTime=" + initializationTime +
'}'; '}';

View file

@ -5,7 +5,7 @@ import org.joda.time.Duration;
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.defs.AlertSet; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.LogEventErrorCode; import info.nightscout.androidaps.plugins.pump.omnipod.defs.LogEventErrorCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
@ -19,7 +19,7 @@ public class PodInfoFaultEvent extends PodInfo {
private final double insulinNotDelivered; private final double insulinNotDelivered;
private final byte podMessageCounter; private final byte podMessageCounter;
private final double totalInsulinDelivered; private final double totalInsulinDelivered;
private final FaultEventType faultEventType; 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 timeSinceActivation;
@ -44,7 +44,7 @@ public class PodInfoFaultEvent extends PodInfo {
insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[3], encodedData[4]); insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[3], encodedData[4]);
podMessageCounter = encodedData[5]; podMessageCounter = encodedData[5];
totalInsulinDelivered = OmnipodConst.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[6], encodedData[7]); totalInsulinDelivered = OmnipodConst.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[6], encodedData[7]);
faultEventType = FaultEventType.fromByte(encodedData[8]); faultEventCode = FaultEventCode.fromByte(encodedData[8]);
int minutesSinceActivation = ByteUtil.toInt(encodedData[9], encodedData[10]); int minutesSinceActivation = ByteUtil.toInt(encodedData[9], encodedData[10]);
if (minutesSinceActivation == 0xffff) { if (minutesSinceActivation == 0xffff) {
@ -99,8 +99,8 @@ public class PodInfoFaultEvent extends PodInfo {
return totalInsulinDelivered; return totalInsulinDelivered;
} }
public FaultEventType getFaultEventType() { public FaultEventCode getFaultEventCode() {
return faultEventType; return faultEventCode;
} }
public Duration getFaultEventTime() { public Duration getFaultEventTime() {
@ -155,7 +155,7 @@ public class PodInfoFaultEvent extends PodInfo {
", insulinNotDelivered=" + insulinNotDelivered + ", insulinNotDelivered=" + insulinNotDelivered +
", podMessageCounter=" + podMessageCounter + ", podMessageCounter=" + podMessageCounter +
", totalInsulinDelivered=" + totalInsulinDelivered + ", totalInsulinDelivered=" + totalInsulinDelivered +
", faultEventType=" + faultEventType + ", faultEventCode=" + faultEventCode +
", faultEventTime=" + faultEventTime + ", faultEventTime=" + faultEventTime +
", reservoirLevel=" + reservoirLevel + ", reservoirLevel=" + reservoirLevel +
", timeSinceActivation=" + timeSinceActivation + ", timeSinceActivation=" + timeSinceActivation +

View file

@ -1,24 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
public enum ErrorResponseType {
BAD_NONCE((byte) 0x14);
private byte value;
ErrorResponseType(byte value) {
this.value = value;
}
public static ErrorResponseType fromByte(byte value) {
for (ErrorResponseType type : values()) {
if (type.value == value) {
return type;
}
}
throw new IllegalArgumentException("Unknown ErrorResponseType: " + value);
}
public byte getValue() {
return value;
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs;
import java.util.Locale; import java.util.Locale;
public enum FaultEventType { public enum FaultEventCode {
NO_FAULTS((byte) 0x00), NO_FAULTS((byte) 0x00),
FAILED_FLASH_ERASE((byte) 0x01), FAILED_FLASH_ERASE((byte) 0x01),
FAILED_FLASH_STORE((byte) 0x02), FAILED_FLASH_STORE((byte) 0x02),
@ -124,17 +124,17 @@ public enum FaultEventType {
private byte value; private byte value;
FaultEventType(byte value) { FaultEventCode(byte value) {
this.value = value; this.value = value;
} }
public static FaultEventType fromByte(byte value) { public static FaultEventCode fromByte(byte value) {
for (FaultEventType type : values()) { for (FaultEventCode type : values()) {
if (type.value == value) { if (type.value == value) {
return type; return type;
} }
} }
throw new IllegalArgumentException("Unknown FaultEventType: " + value); throw new IllegalArgumentException("Unknown FaultEventCode: " + value);
} }
public byte getValue() { public byte getValue() {

View file

@ -43,7 +43,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.pod
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
@ -330,7 +330,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (delegate.getPodState().hasFaultEvent()) { if (delegate.getPodState().hasFaultEvent()) {
showPodFaultErrorDialog(delegate.getPodState().getFaultEvent().getFaultEventType(), R.raw.urgentalarm); showPodFaultErrorDialog(delegate.getPodState().getFaultEvent().getFaultEventCode(), R.raw.urgentalarm);
} }
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered); return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered);
@ -346,7 +346,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventType(), null); showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventCode(), null);
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
@ -624,9 +624,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} else if (ex instanceof NotEnoughDataException) { } else if (ex instanceof NotEnoughDataException) {
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data); comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
} else if (ex instanceof PodFaultException) { } else if (ex instanceof PodFaultException) {
FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType(); FaultEventCode faultEventCode = ((PodFaultException) ex).getFaultEvent().getFaultEventCode();
showPodFaultErrorDialog(faultEventType, R.raw.urgentalarm); showPodFaultErrorDialog(faultEventCode, R.raw.urgentalarm);
comment = createPodFaultErrorMessage(faultEventType); comment = createPodFaultErrorMessage(faultEventCode);
} else if (ex instanceof PodReturnedErrorResponseException) { } else if (ex instanceof PodReturnedErrorResponseException) {
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response); comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
} else { } else {
@ -646,10 +646,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
return comment; return comment;
} }
private String createPodFaultErrorMessage(FaultEventType faultEventType) { private String createPodFaultErrorMessage(FaultEventCode faultEventCode) {
String comment; String comment;
comment = getStringResource(R.string.omnipod_driver_error_pod_fault, comment = getStringResource(R.string.omnipod_driver_error_pod_fault,
ByteUtil.convertUnsignedByteToInt(faultEventType.getValue()), faultEventType.name()); ByteUtil.convertUnsignedByteToInt(faultEventCode.getValue()), faultEventCode.name());
return comment; return comment;
} }
@ -657,8 +657,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
RxBus.INSTANCE.send(event); RxBus.INSTANCE.send(event);
} }
private void showPodFaultErrorDialog(FaultEventType faultEventType, Integer sound) { private void showPodFaultErrorDialog(FaultEventCode faultEventCode, Integer sound) {
showErrorDialog(createPodFaultErrorMessage(faultEventType), sound); showErrorDialog(createPodFaultErrorMessage(faultEventCode), sound);
} }
private void showErrorDialog(String message, Integer sound) { private void showErrorDialog(String message, Integer sound) {

View file

@ -3,7 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response;
import org.junit.Test; import org.junit.Test;
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.defs.ErrorResponseType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -33,14 +34,19 @@ public class ErrorResponseTest {
byte[] encodedData = ByteUtil.fromHexString("060314fa92"); byte[] encodedData = ByteUtil.fromHexString("060314fa92");
ErrorResponse errorResponse = new ErrorResponse(encodedData); ErrorResponse errorResponse = new ErrorResponse(encodedData);
assertEquals(ErrorResponseType.BAD_NONCE, errorResponse.getErrorResponseType()); assertEquals(ErrorResponse.ERROR_RESPONSE_CODE_BAD_NONCE, errorResponse.getErrorResponseCode());
// TODO add assertion one nonce search key (obtain captures first) // TODO add assertion on nonce search key (obtain captures first)
assertNull(errorResponse.getFaultEventCode());
assertNull(errorResponse.getPodProgressStatus());
} }
@Test @Test
public void testUnknownError() { public void testOtherError() {
ErrorResponse errorResponse = new ErrorResponse(ByteUtil.fromHexString("060307fa92")); ErrorResponse errorResponse = new ErrorResponse(ByteUtil.fromHexString("0603101308"));
assertEquals(0x10, errorResponse.getErrorResponseCode());
assertEquals(FaultEventCode.MESSAGE_LENGTH_TOO_LONG, errorResponse.getFaultEventCode());
assertEquals(PodProgressStatus.RUNNING_ABOVE_FIFTY_UNITS, errorResponse.getPodProgressStatus());
assertNull(errorResponse.getErrorResponseType()); assertNull(errorResponse.getNonceSearchKey());
} }
} }

View file

@ -4,7 +4,7 @@ import org.joda.time.Duration;
import org.junit.Test; import org.junit.Test;
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.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -14,7 +14,7 @@ public class PodInfoDataLogTest {
public void testDecoding() { public void testDecoding() {
PodInfoDataLog podInfoDataLog = new PodInfoDataLog(ByteUtil.fromHexString("030100010001043c"), 8); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift PodInfoDataLog podInfoDataLog = new PodInfoDataLog(ByteUtil.fromHexString("030100010001043c"), 8); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
assertEquals(FaultEventType.FAILED_FLASH_ERASE, podInfoDataLog.getFaultEventType()); assertEquals(FaultEventCode.FAILED_FLASH_ERASE, podInfoDataLog.getFaultEventCode());
assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeFaultEvent())); assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeFaultEvent()));
assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeSinceActivation())); assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeSinceActivation()));
assertEquals(4, podInfoDataLog.getDataChunkSize()); assertEquals(4, podInfoDataLog.getDataChunkSize());

View file

@ -5,7 +5,7 @@ import org.joda.time.Duration;
import org.junit.Test; import org.junit.Test;
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.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -15,7 +15,7 @@ public class PodInfoFaultAndInitializationTimeTest {
public void testDecoding() { public void testDecoding() {
PodInfoFaultAndInitializationTime podInfoFaultAndInitializationTime = new PodInfoFaultAndInitializationTime(ByteUtil.fromHexString("059200010000000000000000091912170e")); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift PodInfoFaultAndInitializationTime podInfoFaultAndInitializationTime = new PodInfoFaultAndInitializationTime(ByteUtil.fromHexString("059200010000000000000000091912170e")); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
assertEquals(FaultEventType.BAD_PUMP_REQ_2_STATE, podInfoFaultAndInitializationTime.getFaultEventType()); assertEquals(FaultEventCode.BAD_PUMP_REQ_2_STATE, podInfoFaultAndInitializationTime.getFaultEventCode());
assertTrue(Duration.standardMinutes(1).isEqual(podInfoFaultAndInitializationTime.getTimeFaultEvent())); assertTrue(Duration.standardMinutes(1).isEqual(podInfoFaultAndInitializationTime.getTimeFaultEvent()));
DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime(); DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime();

View file

@ -5,7 +5,7 @@ import org.junit.Test;
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.defs.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.LogEventErrorCode; import info.nightscout.androidaps.plugins.pump.omnipod.defs.LogEventErrorCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
@ -24,7 +24,7 @@ public class PodInfoFaultEventTest {
assertEquals(DeliveryStatus.NORMAL, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.NORMAL, podInfoFaultEvent.getDeliveryStatus());
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
assertEquals(0x0a, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x0a, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventType.NO_FAULTS, podInfoFaultEvent.getFaultEventType()); 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.getTimeSinceActivation()));
@ -44,7 +44,7 @@ public class PodInfoFaultEventTest {
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
assertEquals(0x09, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x09, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventType.PRIME_OPEN_COUNT_TOO_LOW, podInfoFaultEvent.getFaultEventType()); 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.getTimeSinceActivation()));
@ -65,7 +65,7 @@ public class PodInfoFaultEventTest {
assertEquals(101.7, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(101.7, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001);
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
assertEquals(0x04, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x04, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventType.BASAL_OVER_INFUSION_PULSE, podInfoFaultEvent.getFaultEventType()); assertEquals(FaultEventCode.BASAL_OVER_INFUSION_PULSE, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(2559).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(2559).isEqual(podInfoFaultEvent.getFaultEventTime()));
assertNull(podInfoFaultEvent.getReservoirLevel()); assertNull(podInfoFaultEvent.getReservoirLevel());
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
@ -85,7 +85,7 @@ public class PodInfoFaultEventTest {
assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001);
assertEquals(0.05, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); assertEquals(0.05, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter()); assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter());
assertEquals(FaultEventType.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventType()); assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime()));
assertNull(podInfoFaultEvent.getReservoirLevel()); assertNull(podInfoFaultEvent.getReservoirLevel());
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
@ -105,7 +105,7 @@ public class PodInfoFaultEventTest {
assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 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.getInsulinNotDelivered(), 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(FaultEventType.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventType()); assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime())); assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime()));
assertNull(podInfoFaultEvent.getReservoirLevel()); assertNull(podInfoFaultEvent.getReservoirLevel());
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());