Merge branch 'omnipod_eros' of https://github.com/AAPS-Omnipod/AndroidAPS into omnipod_eros

This commit is contained in:
Andy Rozman 2019-11-30 12:17:39 +00:00
commit f84149afa4
35 changed files with 312 additions and 122 deletions

View file

@ -26,10 +26,14 @@ 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;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.NonceResyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodReturnedErrorResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalResponseException;
/**
* Created by andy on 6/29/18.
@ -112,12 +116,12 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
podState.setFaultEvent(faultEvent);
throw new PodFaultException(faultEvent);
} else {
throw new OmnipodException("Unexpected response type: " + responseMessageBlock.toString());
throw new IllegalResponseException(responseClass.getSimpleName(), responseMessageBlock.getType());
}
}
}
throw new OmnipodException("Nonce resync failed");
throw new NonceResyncException();
}
private MessageBlock transportMessages(PodState podState, OmnipodMessage message, Integer addressOverride, Integer ackAddressOverride) {
@ -139,15 +143,17 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
firstPacket = false;
try {
response = exchangePackets(podState, packet);
} catch (OmnipodException ex) {
throw ex;
} catch (Exception ex) {
throw new OmnipodException("Failed to exchange packets", ex);
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
}
//We actually ignore (ack) responses if it is not last packet to send
}
if (response.getPacketType() == PacketType.ACK) {
podState.increasePacketNumber(1);
throw new OmnipodException("Received ack instead of real response");
throw new IllegalPacketTypeException(null, PacketType.ACK);
}
OmnipodMessage receivedMessage = null;
@ -158,15 +164,19 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
} catch (NotEnoughDataException ex) {
// Message is (probably) not complete yet
OmnipodPacket ackForCon = createAckPacket(podState, packetAddress, ackAddressOverride);
try {
OmnipodPacket conPacket = exchangePackets(podState, ackForCon, 3, 40);
if (conPacket.getPacketType() != PacketType.CON) {
throw new OmnipodException("Received a non-con packet type: " + conPacket.getPacketType());
throw new IllegalPacketTypeException(PacketType.CON, conPacket.getPacketType());
}
receivedMessageData = ByteUtil.concat(receivedMessageData, conPacket.getEncodedMessage());
} catch (RileyLinkCommunicationException ex2) {
throw new OmnipodException("RileyLink communication failed", ex2);
} catch (OmnipodException ex2) {
throw ex2;
} catch (Exception ex2) {
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex2);
}
}
}
@ -177,7 +187,7 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
List<MessageBlock> messageBlocks = receivedMessage.getMessageBlocks();
if (messageBlocks.size() == 0) {
throw new OmnipodException("Not enough data");
throw new NotEnoughDataException(receivedMessageData);
} else if (messageBlocks.size() > 1) {
LOG.error("received more than one message block: " + messageBlocks.toString());
}
@ -206,32 +216,34 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
quiet = true;
} else {
LOG.debug("Ignoring exception in ackUntilQuiet: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
LOG.debug("Ignoring exception in ackUntilQuiet: " + ex.getClass().getSimpleName() + ": " + ex.getErrorCode() + ": " + ex.getMessage());
}
} catch (Exception ex) {
LOG.debug("Ignoring exception in ackUntilQuiet: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
}
podState.increasePacketNumber(1);
}
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet) throws RileyLinkCommunicationException {
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet) {
return exchangePackets(podState, packet, 0, 333, 9000, 127);
}
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet, int repeatCount, int preambleExtensionMilliseconds) throws RileyLinkCommunicationException {
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet, int repeatCount, int preambleExtensionMilliseconds) {
return exchangePackets(podState, packet, repeatCount, 333, 9000, preambleExtensionMilliseconds);
}
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet, int repeatCount, int responseTimeoutMilliseconds, int exchangeTimeoutMilliseconds, int preambleExtensionMilliseconds) throws RileyLinkCommunicationException {
private OmnipodPacket exchangePackets(PodState podState, OmnipodPacket packet, int repeatCount, int responseTimeoutMilliseconds, int exchangeTimeoutMilliseconds, int preambleExtensionMilliseconds) {
long timeoutTime = System.currentTimeMillis() + exchangeTimeoutMilliseconds;
while (System.currentTimeMillis() < timeoutTime) {
OmnipodPacket response = null;
try {
response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
} catch (Exception ex) {
} catch (RileyLinkCommunicationException ex) {
LOG.debug("Ignoring exception in exchangePackets: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
} catch (Exception ex) {
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
}
if (response == null || !response.isValid()) {
continue;
@ -246,6 +258,6 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
podState.increasePacketNumber(2);
return response;
}
throw new OmnipodException("Timeout when trying to exchange packets");
throw new CommunicationException(CommunicationException.Type.TIMEOUT);
}
}

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Sta
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class AcknowledgeAlertsAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -15,12 +16,12 @@ public class AcknowledgeAlertsAction implements OmnipodAction<StatusResponse> {
public AcknowledgeAlertsAction(PodSessionState podState, AlertSet alerts) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (alerts == null) {
throw new IllegalArgumentException("Alert set can not be null");
throw new ActionInitializationException("Alert set can not be null");
} else if (alerts.size() == 0) {
throw new IllegalArgumentException("Alert set can not be empty");
throw new ActionInitializationException("Alert set can not be empty");
}
this.podState = podState;
this.alerts = alerts;

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetI
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BolusDeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class BolusAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -22,10 +23,10 @@ public class BolusAction implements OmnipodAction<StatusResponse> {
public BolusAction(PodSessionState podState, double units, Duration timeBetweenPulses,
boolean acknowledgementBeep, boolean completionBeep) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (timeBetweenPulses == null) {
throw new IllegalArgumentException("Time between pulses cannot be null");
throw new ActionInitializationException("Time between pulses cannot be null");
}
this.podState = podState;
this.units = units;

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Sta
import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -17,10 +18,10 @@ public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
public CancelDeliveryAction(PodSessionState podState, EnumSet<DeliveryType> deliveryTypes,
boolean acknowledgementBeep) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (deliveryTypes == null) {
throw new IllegalArgumentException("Delivery types cannot be null");
throw new ActionInitializationException("Delivery types cannot be null");
}
this.podState = podState;
this.deliveryTypes = deliveryTypes;

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.Conf
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class ConfigureAlertsAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -14,10 +15,10 @@ public class ConfigureAlertsAction implements OmnipodAction<StatusResponse> {
public ConfigureAlertsAction(PodSessionState podState, List<AlertConfiguration> alertConfigurations) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (alertConfigurations == null) {
throw new IllegalArgumentException("Alert configurations cannot be null");
throw new ActionInitializationException("Alert configurations cannot be null");
}
this.podState = podState;
this.alertConfigurations = alertConfigurations;

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.Deac
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class DeactivatePodAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -14,7 +15,7 @@ public class DeactivatePodAction implements OmnipodAction<StatusResponse> {
public DeactivatePodAction(PodSessionState podState, boolean acknowledgementBeep) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
this.podState = podState;
this.acknowledgementBeep = acknowledgementBeep;

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.GetS
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class GetPodInfoAction implements OmnipodAction<PodInfoResponse> {
private final PodSessionState podState;
@ -12,10 +13,10 @@ public class GetPodInfoAction implements OmnipodAction<PodInfoResponse> {
public GetPodInfoAction(PodSessionState podState, PodInfoType podInfoType) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (podInfoType == null) {
throw new IllegalArgumentException("Pod info type cannot be null");
throw new ActionInitializationException("Pod info type cannot be null");
}
this.podState = podState;
this.podInfoType = podInfoType;

View file

@ -5,13 +5,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.GetS
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class GetStatusAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
public GetStatusAction(PodSessionState podState) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
this.podState = podState;
}

View file

@ -9,6 +9,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Sta
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalSetupProgressException;
public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(InsertCannulaAction.class);
@ -19,13 +21,13 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
public InsertCannulaAction(InsertCannulaService insertCannulaService, PodSessionState podState, BasalSchedule initialBasalSchedule) {
if (insertCannulaService == null) {
throw new IllegalArgumentException("Insert cannula service cannot be null");
throw new ActionInitializationException("Insert cannula service cannot be null");
}
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (initialBasalSchedule == null) {
throw new IllegalArgumentException("Initial basal schedule cannot be null");
throw new ActionInitializationException("Initial basal schedule cannot be null");
}
this.service = insertCannulaService;
this.podState = podState;
@ -45,7 +47,7 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
@Override
public StatusResponse execute(OmnipodCommunicationService communicationService) {
if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalStateException("Pod should be primed first");
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, podState.getSetupProgress());
}
if (podState.getSetupProgress().isBefore(SetupProgress.INITIAL_BASAL_SCHEDULE_SET)) {
@ -67,7 +69,7 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
updateCannulaInsertionStatus(podState, statusResponse);
return statusResponse;
} else {
throw new IllegalStateException("Illegal setup progress: " + podState.getSetupProgress().name());
throw new IllegalSetupProgressException(null, podState.getSetupProgress());
}
}
}

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Ver
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSetupState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class PairAction implements OmnipodAction<PodSessionState> {
private final PairService service;
@ -18,7 +19,7 @@ public class PairAction implements OmnipodAction<PodSessionState> {
public PairAction(PairService pairService, int address) {
if (pairService == null) {
throw new IllegalArgumentException("Pair service cannot be null");
throw new ActionInitializationException("Pair service cannot be null");
}
this.service = pairService;
this.address = address;

View file

@ -9,6 +9,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Sta
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalSetupProgressException;
public class PrimeAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(PrimeAction.class);
@ -18,10 +20,10 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
public PrimeAction(PrimeService primeService, PodSessionState podState) {
if (primeService == null) {
throw new IllegalArgumentException("Prime service cannot be null");
throw new ActionInitializationException("Prime service cannot be null");
}
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
this.service = primeService;
this.podState = podState;
@ -39,7 +41,7 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
@Override
public StatusResponse execute(OmnipodCommunicationService communicationService) {
if (podState.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
throw new IllegalStateException("Pod should be paired first");
throw new IllegalSetupProgressException(SetupProgress.POD_CONFIGURED, podState.getSetupProgress());
}
if (podState.getSetupProgress().isBefore(SetupProgress.STARTING_PRIME)) {
service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podState);
@ -57,7 +59,7 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
updatePrimingStatus(podState, statusResponse);
return statusResponse;
} else {
throw new IllegalStateException("Illegal setup progress: " + podState.getSetupProgress().name());
throw new IllegalSetupProgressException(null, podState.getSetupProgress());
}
}
}

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetI
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class SetBasalScheduleAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState;
@ -22,13 +23,13 @@ public class SetBasalScheduleAction implements OmnipodAction<StatusResponse> {
public SetBasalScheduleAction(PodSessionState podState, BasalSchedule basalSchedule,
boolean confidenceReminder, Duration scheduleOffset, boolean acknowledgementBeep) {
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (basalSchedule == null) {
throw new IllegalArgumentException("Basal schedule cannot be null");
throw new ActionInitializationException("Basal schedule cannot be null");
}
if (scheduleOffset == null) {
throw new IllegalArgumentException("Schedule offset cannot be null");
throw new ActionInitializationException("Schedule offset cannot be null");
}
this.podState = podState;
this.basalSchedule = basalSchedule;

View file

@ -7,6 +7,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTe
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalDeliveryStatusException;
public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
private final SetTempBasalService service;
@ -19,13 +21,13 @@ public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
public SetTempBasalAction(SetTempBasalService setTempBasalService, PodSessionState podState,
double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep) {
if (setTempBasalService == null) {
throw new IllegalArgumentException("Set temp basal service cannot be null");
throw new ActionInitializationException("Set temp basal service cannot be null");
}
if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null");
throw new ActionInitializationException("Pod state cannot be null");
}
if (duration == null) {
throw new IllegalArgumentException("Duration cannot be null");
throw new ActionInitializationException("Duration cannot be null");
}
this.service = setTempBasalService;
this.podState = podState;
@ -40,8 +42,7 @@ public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
StatusResponse statusResponse = service.cancelTempBasal(communicationService, podState);
if (statusResponse.getDeliveryStatus() != DeliveryStatus.NORMAL) {
throw new IllegalStateException("Illegal delivery status: " +
statusResponse.getDeliveryStatus().name());
throw new IllegalDeliveryStatusException(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
}
return service.executeTempBasalCommand(communicationService, podState, rate, duration,

View file

@ -11,7 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.Conf
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSetupState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class PairService {
@ -37,7 +37,7 @@ public class PairService {
message, OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress());
if (configurePodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_SUCCESS) {
throw new OmnipodException("Pairing failed, state: " + configurePodResponse.getPodProgressStatus().name());
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_SUCCESS, configurePodResponse.getPodProgressStatus());
}
return configurePodResponse;

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CrcMismatchException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.MessageDecodingException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
public class OmnipodMessage {
@ -29,7 +29,7 @@ public class OmnipodMessage {
public static OmnipodMessage decodeMessage(byte[] data) {
if (data.length < 10) {
throw new NotEnoughDataException("Not enough data");
throw new NotEnoughDataException(data);
}
int address = ByteUtil.toInt((int) data[0], (int) data[1], (int) data[2],
@ -37,21 +37,20 @@ public class OmnipodMessage {
byte b9 = data[4];
int bodyLength = ByteUtil.convertUnsignedByteToInt(data[5]);
if (data.length - 8 < bodyLength) {
throw new NotEnoughDataException("not enough data: " + ByteUtil.shortHexString(data));
throw new NotEnoughDataException(data);
}
int sequenceNumber = (((int) b9 >> 2) & 0b11111);
int crc = ByteUtil.toInt(data[data.length - 2], data[data.length - 1]);
int calculatedCrc = OmniCRC.crc16(ByteUtil.substring(data, 0, data.length - 2));
if (crc != calculatedCrc) {
throw new CrcMismatchException("CRC mismatch");
throw new CrcMismatchException(calculatedCrc, crc);
}
List<MessageBlock> blocks = decodeBlocks(ByteUtil.substring(data, 6, data.length - 6 - 2));
if (blocks == null || blocks.size() == 0) {
throw new OmnipodException("No blocks decoded");
throw new MessageDecodingException("No blocks decoded");
}
OmnipodMessage result = new OmnipodMessage(address, blocks, sequenceNumber);
return result;
return new OmnipodMessage(address, blocks, sequenceNumber);
}
private static List<MessageBlock> decodeBlocks(byte[] data) {
@ -65,7 +64,7 @@ public class OmnipodMessage {
int blockLength = block.getRawData().length;
index += blockLength;
} catch (Exception ex) {
throw new OmnipodException("Failed to decode blocks", ex);
throw new MessageDecodingException("Failed to decode blocks", ex);
}
}
@ -84,7 +83,6 @@ public class OmnipodMessage {
header = ByteUtil.concat(header, (byte) (((sequenceNumber & 0x1F) << 2) + ((encodedData.length >> 8) & 0x03)));
header = ByteUtil.concat(header, (byte) (encodedData.length & 0xFF));
encodedData = ByteUtil.concat(header, encodedData);
String myString = ByteUtil.shortHexString(encodedData);
int crc = OmniCRC.crc16(encodedData);
encodedData = ByteUtil.concat(encodedData, ByteUtil.substring(ByteUtil.getBytesFromInt(crc), 2, 2));
return encodedData;

View file

@ -4,7 +4,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMe
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CrcMismatchException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
/**
@ -26,15 +26,12 @@ public class OmnipodPacket implements RLMessage {
try {
this.packetType = PacketType.fromByte((byte) (((int) encoded[4] & 0xFF) >> 5));
} catch (IllegalArgumentException ex) {
throw new OmnipodException("Invalid packet type", ex);
throw new IllegalPacketTypeException(null, null);
}
this.sequenceNumber = (encoded[4] & 0b11111);
byte crc = OmniCRC.crc8(ByteUtil.substring(encoded, 0, encoded.length - 1));
if (crc != encoded[encoded.length - 1]) {
throw new CrcMismatchException("CRC mismatch: " +
ByteUtil.shortHexString(new byte[]{crc}) + " <> " +
ByteUtil.shortHexString(new byte[]{encoded[encoded.length - 1]}) +
" (packetType=" + packetType.name() + ",packetLength=" + encoded.length + ")");
throw new CrcMismatchException(crc, encoded[encoded.length - 1]);
}
this.encodedMessage = ByteUtil.substring(encoded, 5, encoded.length - 1 - 5);
valid = true;

View file

@ -5,6 +5,7 @@ import org.joda.time.Duration;
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.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class BolusExtraCommand extends MessageBlock {
@ -28,9 +29,9 @@ public class BolusExtraCommand extends MessageBlock {
boolean acknowledgementBeep, boolean completionBeep,
Duration programReminderInterval, Duration timeBetweenPulses) {
if (units <= 0D) {
throw new IllegalArgumentException("Units should be > 0");
throw new CommandInitializationException("Units should be > 0");
} else if (units > OmnipodConst.MAX_BOLUS) {
throw new IllegalArgumentException("Units exceeds max bolus");
throw new CommandInitializationException("Units exceeds max bolus");
}
this.units = units;
this.squareWaveUnits = squareWaveUnits;

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedu
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BolusDeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.DeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.TempBasalDeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock {
@ -50,12 +51,12 @@ public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock {
// Temp basal
public SetInsulinScheduleCommand(int nonce, double tempBasalRate, Duration duration) {
if (tempBasalRate < 0D) {
throw new IllegalArgumentException("Rate should be >= 0");
throw new CommandInitializationException("Rate should be >= 0");
} else if (tempBasalRate > OmnipodConst.MAX_BASAL_RATE) {
throw new IllegalArgumentException("Rate exceeds max basal rate");
throw new CommandInitializationException("Rate exceeds max basal rate");
}
if (duration.isLongerThan(OmnipodConst.MAX_TEMP_BASAL_DURATION)) {
throw new IllegalArgumentException("Duration exceeds max temp basal duration");
throw new CommandInitializationException("Duration exceeds max temp basal duration");
}
int pulsesPerHour = (int) Math.round(tempBasalRate / OmnipodConst.POD_PULSE_SIZE);
int pulsesPerSegment = pulsesPerHour / 2;

View file

@ -9,6 +9,7 @@ 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.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.RateEntry;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class TempBasalExtraCommand extends MessageBlock {
@ -23,12 +24,12 @@ public class TempBasalExtraCommand extends MessageBlock {
public TempBasalExtraCommand(double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep,
Duration programReminderInterval) {
if (rate < 0D) {
throw new IllegalArgumentException("Rate should be >= 0");
throw new CommandInitializationException("Rate should be >= 0");
} else if (rate > OmnipodConst.MAX_BASAL_RATE) {
throw new IllegalArgumentException("Rate exceeds max basal rate");
throw new CommandInitializationException("Rate exceeds max basal rate");
}
if (duration.isLongerThan(OmnipodConst.MAX_TEMP_BASAL_DURATION)) {
throw new IllegalArgumentException("Duration exceeds max temp basal duration");
throw new CommandInitializationException("Duration exceeds max temp basal duration");
}
this.acknowledgementBeep = acknowledgementBeep;

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class ActionInitializationException extends OmnipodException {
public ActionInitializationException(String message) {
super(message);
}
}

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class CommandInitializationException extends OmnipodException {
public CommandInitializationException(String message) {
super(message);
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class CommunicationException extends OmnipodException {
private final Type type;
public CommunicationException(Type type) {
super(type.getDescription());
this.type = type;
}
public CommunicationException(Type type, Throwable cause) {
super(type.getDescription(), cause);
this.type = type;
}
public Type getType() {
return type;
}
public enum Type {
TIMEOUT("Communication timeout"),
UNEXPECTED_EXCEPTION("Caught an unexpected Exception");
private final String description;
Type(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
}

View file

@ -1,11 +1,22 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
public class CrcMismatchException extends OmnipodException {
public CrcMismatchException(String message) {
super(message);
private final int expected;
private final int actual;
public CrcMismatchException(int expected, int actual) {
super(String.format(Locale.getDefault(), "CRC mismatch: expected %d, got %d", expected, actual));
this.expected = expected;
this.actual = actual;
}
public CrcMismatchException(String message, Throwable cause) {
super(message, cause);
public int getExpected() {
return expected;
}
public int getActual() {
return actual;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
public class IllegalDeliveryStatusException extends OmnipodException {
private final DeliveryStatus expected;
private final DeliveryStatus actual;
public IllegalDeliveryStatusException(DeliveryStatus expected, DeliveryStatus actual) {
super(String.format(Locale.getDefault(), "Illegal delivery status: %s, expected: %s", actual, expected));
this.expected = expected;
this.actual = actual;
}
public DeliveryStatus getExpected() {
return expected;
}
public DeliveryStatus getActual() {
return actual;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
public class IllegalPacketTypeException extends OmnipodException {
private final PacketType expected;
private final PacketType actual;
public IllegalPacketTypeException(PacketType expected, PacketType actual) {
super(String.format(Locale.getDefault(), "Illegal packet type: %s, expected %s",
actual, expected));
this.expected = expected;
this.actual = actual;
}
public PacketType getExpected() {
return expected;
}
public PacketType getActual() {
return actual;
}
}

View file

@ -0,0 +1,24 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
public class IllegalPodProgressException extends OmnipodException {
private final PodProgressStatus expected;
private final PodProgressStatus actual;
public IllegalPodProgressException(PodProgressStatus expected, PodProgressStatus actual) {
super(String.format(Locale.getDefault(), "Illegal setup state: %s, expected: %s", actual, expected));
this.expected = expected;
this.actual = actual;
}
public PodProgressStatus getExpected() {
return expected;
}
public PodProgressStatus getActual() {
return actual;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
public class IllegalResponseException extends OmnipodException {
private final String actualClass;
private final MessageBlockType expectedType;
public IllegalResponseException(String actualClass, MessageBlockType expectedType) {
super(String.format(Locale.getDefault(), "Illegal response type: got class of type %s " +
"for message block type %s", actualClass, expectedType));
this.actualClass = actualClass;
this.expectedType = expectedType;
}
public String getActualClass() {
return actualClass;
}
public MessageBlockType getExpectedType() {
return expectedType;
}
}

View file

@ -0,0 +1,24 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
public class IllegalSetupProgressException extends OmnipodException {
private final SetupProgress expected;
private final SetupProgress actual;
public IllegalSetupProgressException(SetupProgress expected, SetupProgress actual) {
super(String.format(Locale.getDefault(), "Illegal setup progress: %s, expected: %s", actual, expected));
this.expected = expected;
this.actual = actual;
}
public SetupProgress getExpected() {
return expected;
}
public SetupProgress getActual() {
return actual;
}
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class MessageDecodingException extends OmnipodException {
public MessageDecodingException(String message) {
super(message);
}
public MessageDecodingException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -1,13 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.ErrorResponse;
public class NonceOutOfSyncException extends PodReturnedErrorResponseException {
public NonceOutOfSyncException(ErrorResponse errorResponse) {
super(errorResponse);
}
public NonceOutOfSyncException(ErrorResponse errorResponse, Throwable cause) {
super(errorResponse, cause);
}
}

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class NonceResyncException extends OmnipodException {
public NonceResyncException() {
super("Nonce resync failed");
}
}

View file

@ -1,11 +1,16 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
public class NotEnoughDataException extends OmnipodException {
public NotEnoughDataException(String message) {
super(message);
private final byte[] data;
public NotEnoughDataException(byte[] data) {
super("Not enough data: " + ByteUtil.shortHexString(data));
this.data = data;
}
public NotEnoughDataException(String message, Throwable cause) {
super(message, cause);
public byte[] getData() {
return data;
}
}

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception;
public class OmnipodException extends RuntimeException {
public abstract class OmnipodException extends RuntimeException {
public OmnipodException(String message) {
super(message);
}

View file

@ -8,27 +8,12 @@ public class PodFaultException extends OmnipodException {
private final PodInfoFaultEvent faultEvent;
public PodFaultException(PodInfoFaultEvent faultEvent) {
super(describePodFault(faultEvent));
super(String.format(Locale.getDefault(), "Pod fault (%d): %s", faultEvent.getFaultEventCode().getValue(),
faultEvent.getFaultEventCode().toString()));
this.faultEvent = faultEvent;
}
public PodFaultException(PodInfoFaultEvent faultEvent, Throwable cause) {
super(describePodFault(faultEvent), cause);
this.faultEvent = faultEvent;
}
public static String describePodFault(PodInfoFaultEvent faultEvent) {
return String.format(Locale.getDefault(), "Pod fault (%d): %s", faultEvent.getFaultEventCode().getValue(),
faultEvent.getFaultEventCode().toString());
}
public PodInfoFaultEvent getFaultEvent() {
return faultEvent;
}
@Override
public void printStackTrace() {
System.out.println(faultEvent.toString());
super.printStackTrace();
}
}

View file

@ -6,22 +6,11 @@ public class PodReturnedErrorResponseException extends OmnipodException {
private final ErrorResponse errorResponse;
public PodReturnedErrorResponseException(ErrorResponse errorResponse) {
super("Pod returned error response");
this.errorResponse = errorResponse;
}
public PodReturnedErrorResponseException(ErrorResponse errorResponse, Throwable cause) {
super("Pod returned error response", cause);
super("Pod returned error response: " + errorResponse.getErrorResponseType());
this.errorResponse = errorResponse;
}
public ErrorResponse getErrorResponse() {
return errorResponse;
}
@Override
public void printStackTrace() {
System.out.println(errorResponse.toString());
super.printStackTrace();
}
}