Properly decode non-nonce error responses and some renaming/cleanup
This commit is contained in:
parent
9a5cd3c902
commit
ed1efe8944
16 changed files with 104 additions and 108 deletions
|
@ -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.podinfo.PodInfoFaultEvent;
|
||||
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.PacketType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
|
||||
|
@ -125,7 +124,7 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
|||
} else {
|
||||
if (responseMessageBlock.getType() == MessageBlockType.ERROR_RESPONSE) {
|
||||
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());
|
||||
if (automaticallyResyncNonce) {
|
||||
message.resyncNonce(podState.getCurrentNonce());
|
||||
|
@ -133,7 +132,7 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
|||
throw new NonceOutOfSyncException();
|
||||
}
|
||||
} else {
|
||||
throw new PodReturnedErrorResponseException((ErrorResponse) responseMessageBlock);
|
||||
throw new PodReturnedErrorResponseException(error);
|
||||
}
|
||||
} else if (responseMessageBlock.getType() == MessageBlockType.POD_INFO_RESPONSE && ((PodInfoResponse) responseMessageBlock).getSubType() == PodInfoType.FAULT_EVENT) {
|
||||
PodInfoFaultEvent faultEvent = ((PodInfoResponse) responseMessageBlock).getPodInfo();
|
||||
|
|
|
@ -7,7 +7,7 @@ public class PodFaultException extends OmnipodException {
|
|||
private final PodInfoFaultEvent faultEvent;
|
||||
|
||||
public PodFaultException(PodInfoFaultEvent faultEvent) {
|
||||
super(faultEvent.getFaultEventType().toString(), true);
|
||||
super(faultEvent.getFaultEventCode().toString(), true);
|
||||
this.faultEvent = faultEvent;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ public class PodReturnedErrorResponseException extends OmnipodException {
|
|||
private final ErrorResponse errorResponse;
|
||||
|
||||
public PodReturnedErrorResponseException(ErrorResponse errorResponse) {
|
||||
super("Pod returned error response: " + errorResponse.getErrorResponseType(), true);
|
||||
super("Pod returned error response: " + errorResponse, true);
|
||||
this.errorResponse = errorResponse;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.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.PodProgressStatus;
|
||||
|
||||
public class ErrorResponse extends MessageBlock {
|
||||
public static final byte ERROR_RESPONSE_CODE_BAD_NONCE = (byte) 0x14;
|
||||
|
||||
private static final int MESSAGE_LENGTH = 5;
|
||||
|
||||
private final ErrorResponseType errorResponseType;
|
||||
private final int nonceSearchKey;
|
||||
private final byte errorResponseCode;
|
||||
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) {
|
||||
if (encodedData.length < MESSAGE_LENGTH) {
|
||||
|
@ -17,14 +22,14 @@ public class ErrorResponse extends MessageBlock {
|
|||
}
|
||||
this.encodedData = ByteUtil.substring(encodedData, 2, MESSAGE_LENGTH - 2);
|
||||
|
||||
ErrorResponseType errorResponseType = null;
|
||||
try {
|
||||
errorResponseType = ErrorResponseType.fromByte(encodedData[2]);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
errorResponseCode = encodedData[2];
|
||||
|
||||
this.errorResponseType = errorResponseType;
|
||||
this.nonceSearchKey = ByteUtil.makeUnsignedShort((int) encodedData[3], (int) encodedData[4]);
|
||||
if (this.errorResponseCode == ERROR_RESPONSE_CODE_BAD_NONCE) {
|
||||
nonceSearchKey = ByteUtil.makeUnsignedShort(encodedData[3], encodedData[4]);
|
||||
} else {
|
||||
faultEventCode = FaultEventCode.fromByte(encodedData[3]);
|
||||
podProgressStatus = PodProgressStatus.fromByte(encodedData[4]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,19 +37,29 @@ public class ErrorResponse extends MessageBlock {
|
|||
return MessageBlockType.ERROR_RESPONSE;
|
||||
}
|
||||
|
||||
public ErrorResponseType getErrorResponseType() {
|
||||
return errorResponseType;
|
||||
public byte getErrorResponseCode() {
|
||||
return errorResponseCode;
|
||||
}
|
||||
|
||||
public int getNonceSearchKey() {
|
||||
public FaultEventCode getFaultEventCode() {
|
||||
return faultEventCode;
|
||||
}
|
||||
|
||||
public PodProgressStatus getPodProgressStatus() {
|
||||
return podProgressStatus;
|
||||
}
|
||||
|
||||
public Integer getNonceSearchKey() {
|
||||
return nonceSearchKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrorResponse{" +
|
||||
"errorResponseType=" + errorResponseType +
|
||||
"errorResponseCode=" + errorResponseCode +
|
||||
", nonceSearchKey=" + nonceSearchKey +
|
||||
", faultEventCode=" + faultEventCode +
|
||||
", podProgressStatus=" + podProgressStatus +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,20 +31,20 @@ public class StatusResponse extends MessageBlock {
|
|||
}
|
||||
this.encodedData = ByteUtil.substring(encodedData, 1, MESSAGE_LENGTH - 1);
|
||||
|
||||
this.deliveryStatus = DeliveryStatus.fromByte((byte) (ByteUtil.convertUnsignedByteToInt(encodedData[1]) >>> 4));
|
||||
this.podProgressStatus = PodProgressStatus.fromByte((byte) (encodedData[1] & 0x0F));
|
||||
deliveryStatus = DeliveryStatus.fromByte((byte) (ByteUtil.convertUnsignedByteToInt(encodedData[1]) >>> 4));
|
||||
podProgressStatus = PodProgressStatus.fromByte((byte) (encodedData[1] & 0x0F));
|
||||
|
||||
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 middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1;
|
||||
int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7;
|
||||
this.insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits);
|
||||
this.podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf);
|
||||
insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits);
|
||||
podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf);
|
||||
|
||||
this.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)));
|
||||
insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5]));
|
||||
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;
|
||||
if (reservoirValue > OmnipodConst.MAX_RESERVOIR_READING) {
|
||||
|
@ -94,7 +94,7 @@ public class StatusResponse extends MessageBlock {
|
|||
public byte[] getRawData() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
try {
|
||||
stream.write(this.getType().getValue());
|
||||
stream.write(getType().getValue());
|
||||
stream.write(encodedData);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -34,18 +34,18 @@ public class VersionResponse extends MessageBlock {
|
|||
throw new IllegalArgumentException("Unrecognized VersionResponse message length: " + length);
|
||||
}
|
||||
|
||||
this.podProgressStatus = PodProgressStatus.fromByte(truncatedData[7]);
|
||||
this.pmVersion = new FirmwareVersion(truncatedData[0], truncatedData[1], truncatedData[2]);
|
||||
this.piVersion = new FirmwareVersion(truncatedData[3], truncatedData[4], truncatedData[5]);
|
||||
this.lot = ByteUtil.toInt((int) truncatedData[8], (int) truncatedData[9],
|
||||
podProgressStatus = PodProgressStatus.fromByte(truncatedData[7]);
|
||||
pmVersion = new FirmwareVersion(truncatedData[0], truncatedData[1], truncatedData[2]);
|
||||
piVersion = new FirmwareVersion(truncatedData[3], truncatedData[4], truncatedData[5]);
|
||||
lot = ByteUtil.toInt((int) truncatedData[8], (int) truncatedData[9],
|
||||
(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 indexIncrementor = extraByte ? 1 : 0;
|
||||
int indexIncrement = extraByte ? 1 : 0;
|
||||
|
||||
this.address = ByteUtil.toInt((int) truncatedData[16 + indexIncrementor], (int) truncatedData[17 + indexIncrementor],
|
||||
(int) truncatedData[18 + indexIncrementor], (int) truncatedData[19 + indexIncrementor], ByteUtil.BitConversion.BIG_ENDIAN);
|
||||
address = ByteUtil.toInt((int) truncatedData[16 + indexIncrement], (int) truncatedData[17 + indexIncrement],
|
||||
(int) truncatedData[18 + indexIncrement], (int) truncatedData[19 + indexIncrement], ByteUtil.BitConversion.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,12 +7,12 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
public class PodInfoDataLog extends PodInfo {
|
||||
private static final int MINIMUM_MESSAGE_LENGTH = 8;
|
||||
private final FaultEventType faultEventType;
|
||||
private final FaultEventCode faultEventCode;
|
||||
private final Duration timeFaultEvent;
|
||||
private final Duration timeSinceActivation;
|
||||
private final byte dataChunkSize;
|
||||
|
@ -26,7 +26,7 @@ public class PodInfoDataLog extends PodInfo {
|
|||
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]));
|
||||
timeSinceActivation = Duration.standardMinutes(ByteUtil.toInt(encodedData[4], encodedData[5]));
|
||||
dataChunkSize = encodedData[6];
|
||||
|
@ -45,8 +45,8 @@ public class PodInfoDataLog extends PodInfo {
|
|||
return PodInfoType.DATA_LOG;
|
||||
}
|
||||
|
||||
public FaultEventType getFaultEventType() {
|
||||
return faultEventType;
|
||||
public FaultEventCode getFaultEventCode() {
|
||||
return faultEventCode;
|
||||
}
|
||||
|
||||
public Duration getTimeFaultEvent() {
|
||||
|
@ -72,7 +72,7 @@ public class PodInfoDataLog extends PodInfo {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "PodInfoDataLog{" +
|
||||
"faultEventType=" + faultEventType +
|
||||
"faultEventCode=" + faultEventCode +
|
||||
", timeFaultEvent=" + timeFaultEvent +
|
||||
", timeSinceActivation=" + timeSinceActivation +
|
||||
", dataChunkSize=" + dataChunkSize +
|
||||
|
|
|
@ -3,12 +3,12 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.po
|
|||
import org.joda.time.DateTime;
|
||||
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;
|
||||
|
||||
public class PodInfoFaultAndInitializationTime extends PodInfo {
|
||||
private static final int MINIMUM_MESSAGE_LENGTH = 17;
|
||||
private final FaultEventType faultEventType;
|
||||
private final FaultEventCode faultEventCode;
|
||||
private final Duration timeFaultEvent;
|
||||
private final DateTime initializationTime;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
|
|||
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]);
|
||||
// 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
|
||||
|
@ -31,8 +31,8 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
|
|||
return PodInfoType.FAULT_AND_INITIALIZATION_TIME;
|
||||
}
|
||||
|
||||
public FaultEventType getFaultEventType() {
|
||||
return faultEventType;
|
||||
public FaultEventCode getFaultEventCode() {
|
||||
return faultEventCode;
|
||||
}
|
||||
|
||||
public Duration getTimeFaultEvent() {
|
||||
|
@ -46,7 +46,7 @@ public class PodInfoFaultAndInitializationTime extends PodInfo {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "PodInfoFaultAndInitializationTime{" +
|
||||
"faultEventType=" + faultEventType +
|
||||
"faultEventCode=" + faultEventCode +
|
||||
", timeFaultEvent=" + timeFaultEvent +
|
||||
", initializationTime=" + initializationTime +
|
||||
'}';
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.joda.time.Duration;
|
|||
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.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.PodInfoType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
|
||||
|
@ -19,7 +19,7 @@ public class PodInfoFaultEvent extends PodInfo {
|
|||
private final double insulinNotDelivered;
|
||||
private final byte podMessageCounter;
|
||||
private final double totalInsulinDelivered;
|
||||
private final FaultEventType faultEventType;
|
||||
private final FaultEventCode faultEventCode;
|
||||
private final Duration faultEventTime;
|
||||
private final Double reservoirLevel;
|
||||
private final Duration timeSinceActivation;
|
||||
|
@ -44,7 +44,7 @@ public class PodInfoFaultEvent extends PodInfo {
|
|||
insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * ByteUtil.toInt(encodedData[3], encodedData[4]);
|
||||
podMessageCounter = encodedData[5];
|
||||
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]);
|
||||
if (minutesSinceActivation == 0xffff) {
|
||||
|
@ -99,8 +99,8 @@ public class PodInfoFaultEvent extends PodInfo {
|
|||
return totalInsulinDelivered;
|
||||
}
|
||||
|
||||
public FaultEventType getFaultEventType() {
|
||||
return faultEventType;
|
||||
public FaultEventCode getFaultEventCode() {
|
||||
return faultEventCode;
|
||||
}
|
||||
|
||||
public Duration getFaultEventTime() {
|
||||
|
@ -155,7 +155,7 @@ public class PodInfoFaultEvent extends PodInfo {
|
|||
", insulinNotDelivered=" + insulinNotDelivered +
|
||||
", podMessageCounter=" + podMessageCounter +
|
||||
", totalInsulinDelivered=" + totalInsulinDelivered +
|
||||
", faultEventType=" + faultEventType +
|
||||
", faultEventCode=" + faultEventCode +
|
||||
", faultEventTime=" + faultEventTime +
|
||||
", reservoirLevel=" + reservoirLevel +
|
||||
", timeSinceActivation=" + timeSinceActivation +
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum FaultEventType {
|
||||
public enum FaultEventCode {
|
||||
NO_FAULTS((byte) 0x00),
|
||||
FAILED_FLASH_ERASE((byte) 0x01),
|
||||
FAILED_FLASH_STORE((byte) 0x02),
|
||||
|
@ -124,17 +124,17 @@ public enum FaultEventType {
|
|||
|
||||
private byte value;
|
||||
|
||||
FaultEventType(byte value) {
|
||||
FaultEventCode(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static FaultEventType fromByte(byte value) {
|
||||
for (FaultEventType type : values()) {
|
||||
public static FaultEventCode fromByte(byte value) {
|
||||
for (FaultEventCode type : values()) {
|
||||
if (type.value == value) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown FaultEventType: " + value);
|
||||
throw new IllegalArgumentException("Unknown FaultEventCode: " + value);
|
||||
}
|
||||
|
||||
public byte getValue() {
|
|
@ -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.defs.AlertSlot;
|
||||
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.PodInfoType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
|
||||
|
@ -330,7 +330,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
|
||||
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);
|
||||
|
@ -346,7 +346,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
} catch (PodFaultException ex) {
|
||||
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventType(), null);
|
||||
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventCode(), null);
|
||||
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
} catch (Exception ex) {
|
||||
|
@ -624,9 +624,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
} else if (ex instanceof NotEnoughDataException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
|
||||
} else if (ex instanceof PodFaultException) {
|
||||
FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType();
|
||||
showPodFaultErrorDialog(faultEventType, R.raw.urgentalarm);
|
||||
comment = createPodFaultErrorMessage(faultEventType);
|
||||
FaultEventCode faultEventCode = ((PodFaultException) ex).getFaultEvent().getFaultEventCode();
|
||||
showPodFaultErrorDialog(faultEventCode, R.raw.urgentalarm);
|
||||
comment = createPodFaultErrorMessage(faultEventCode);
|
||||
} else if (ex instanceof PodReturnedErrorResponseException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
|
||||
} else {
|
||||
|
@ -646,10 +646,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
return comment;
|
||||
}
|
||||
|
||||
private String createPodFaultErrorMessage(FaultEventType faultEventType) {
|
||||
private String createPodFaultErrorMessage(FaultEventCode faultEventCode) {
|
||||
String comment;
|
||||
comment = getStringResource(R.string.omnipod_driver_error_pod_fault,
|
||||
ByteUtil.convertUnsignedByteToInt(faultEventType.getValue()), faultEventType.name());
|
||||
ByteUtil.convertUnsignedByteToInt(faultEventCode.getValue()), faultEventCode.name());
|
||||
return comment;
|
||||
}
|
||||
|
||||
|
@ -657,8 +657,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
RxBus.INSTANCE.send(event);
|
||||
}
|
||||
|
||||
private void showPodFaultErrorDialog(FaultEventType faultEventType, Integer sound) {
|
||||
showErrorDialog(createPodFaultErrorMessage(faultEventType), sound);
|
||||
private void showPodFaultErrorDialog(FaultEventCode faultEventCode, Integer sound) {
|
||||
showErrorDialog(createPodFaultErrorMessage(faultEventCode), sound);
|
||||
}
|
||||
|
||||
private void showErrorDialog(String message, Integer sound) {
|
||||
|
|
|
@ -3,7 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response;
|
|||
import org.junit.Test;
|
||||
|
||||
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.assertEquals;
|
||||
|
@ -33,14 +34,19 @@ public class ErrorResponseTest {
|
|||
byte[] encodedData = ByteUtil.fromHexString("060314fa92");
|
||||
|
||||
ErrorResponse errorResponse = new ErrorResponse(encodedData);
|
||||
assertEquals(ErrorResponseType.BAD_NONCE, errorResponse.getErrorResponseType());
|
||||
// TODO add assertion one nonce search key (obtain captures first)
|
||||
assertEquals(ErrorResponse.ERROR_RESPONSE_CODE_BAD_NONCE, errorResponse.getErrorResponseCode());
|
||||
// TODO add assertion on nonce search key (obtain captures first)
|
||||
assertNull(errorResponse.getFaultEventCode());
|
||||
assertNull(errorResponse.getPodProgressStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownError() {
|
||||
ErrorResponse errorResponse = new ErrorResponse(ByteUtil.fromHexString("060307fa92"));
|
||||
public void testOtherError() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.joda.time.Duration;
|
|||
import org.junit.Test;
|
||||
|
||||
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.assertTrue;
|
||||
|
@ -14,7 +14,7 @@ public class PodInfoDataLogTest {
|
|||
public void testDecoding() {
|
||||
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.getTimeSinceActivation()));
|
||||
assertEquals(4, podInfoDataLog.getDataChunkSize());
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.joda.time.Duration;
|
|||
import org.junit.Test;
|
||||
|
||||
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.assertTrue;
|
||||
|
@ -15,7 +15,7 @@ public class PodInfoFaultAndInitializationTimeTest {
|
|||
public void testDecoding() {
|
||||
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()));
|
||||
|
||||
DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime();
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
|||
|
||||
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.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.PodProgressStatus;
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class PodInfoFaultEventTest {
|
|||
assertEquals(DeliveryStatus.NORMAL, podInfoFaultEvent.getDeliveryStatus());
|
||||
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
|
||||
assertEquals(0x0a, podInfoFaultEvent.getPodMessageCounter());
|
||||
assertEquals(FaultEventType.NO_FAULTS, podInfoFaultEvent.getFaultEventType());
|
||||
assertEquals(FaultEventCode.NO_FAULTS, podInfoFaultEvent.getFaultEventCode());
|
||||
assertTrue(Duration.ZERO.isEqual(podInfoFaultEvent.getFaultEventTime()));
|
||||
assertNull(podInfoFaultEvent.getReservoirLevel());
|
||||
assertTrue(Duration.standardSeconds(8100).isEqual(podInfoFaultEvent.getTimeSinceActivation()));
|
||||
|
@ -44,7 +44,7 @@ public class PodInfoFaultEventTest {
|
|||
assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus());
|
||||
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
|
||||
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()));
|
||||
assertNull(podInfoFaultEvent.getReservoirLevel());
|
||||
assertTrue(Duration.standardSeconds(60).isEqual(podInfoFaultEvent.getTimeSinceActivation()));
|
||||
|
@ -65,7 +65,7 @@ public class PodInfoFaultEventTest {
|
|||
assertEquals(101.7, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001);
|
||||
assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
|
||||
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()));
|
||||
assertNull(podInfoFaultEvent.getReservoirLevel());
|
||||
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
|
||||
|
@ -85,7 +85,7 @@ public class PodInfoFaultEventTest {
|
|||
assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001);
|
||||
assertEquals(0.05, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001);
|
||||
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()));
|
||||
assertNull(podInfoFaultEvent.getReservoirLevel());
|
||||
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
|
||||
|
@ -105,7 +105,7 @@ public class PodInfoFaultEventTest {
|
|||
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(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()));
|
||||
assertNull(podInfoFaultEvent.getReservoirLevel());
|
||||
assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue());
|
||||
|
|
Loading…
Reference in a new issue