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.PacketType;
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.state.PodState; 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.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; 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.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodReturnedErrorResponseException; 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. * Created by andy on 6/29/18.
@ -112,12 +116,12 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
podState.setFaultEvent(faultEvent); podState.setFaultEvent(faultEvent);
throw new PodFaultException(faultEvent); throw new PodFaultException(faultEvent);
} else { } 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) { private MessageBlock transportMessages(PodState podState, OmnipodMessage message, Integer addressOverride, Integer ackAddressOverride) {
@ -139,15 +143,17 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
firstPacket = false; firstPacket = false;
try { try {
response = exchangePackets(podState, packet); response = exchangePackets(podState, packet);
} catch (OmnipodException ex) {
throw ex;
} catch (Exception 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 //We actually ignore (ack) responses if it is not last packet to send
} }
if (response.getPacketType() == PacketType.ACK) { if (response.getPacketType() == PacketType.ACK) {
podState.increasePacketNumber(1); podState.increasePacketNumber(1);
throw new OmnipodException("Received ack instead of real response"); throw new IllegalPacketTypeException(null, PacketType.ACK);
} }
OmnipodMessage receivedMessage = null; OmnipodMessage receivedMessage = null;
@ -158,15 +164,19 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
} catch (NotEnoughDataException ex) { } catch (NotEnoughDataException ex) {
// Message is (probably) not complete yet // Message is (probably) not complete yet
OmnipodPacket ackForCon = createAckPacket(podState, packetAddress, ackAddressOverride); OmnipodPacket ackForCon = createAckPacket(podState, packetAddress, ackAddressOverride);
try { try {
OmnipodPacket conPacket = exchangePackets(podState, ackForCon, 3, 40); OmnipodPacket conPacket = exchangePackets(podState, ackForCon, 3, 40);
if (conPacket.getPacketType() != PacketType.CON) { 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()); receivedMessageData = ByteUtil.concat(receivedMessageData, conPacket.getEncodedMessage());
} catch (RileyLinkCommunicationException ex2) { } catch (OmnipodException ex2) {
throw new OmnipodException("RileyLink communication failed", 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(); List<MessageBlock> messageBlocks = receivedMessage.getMessageBlocks();
if (messageBlocks.size() == 0) { if (messageBlocks.size() == 0) {
throw new OmnipodException("Not enough data"); throw new NotEnoughDataException(receivedMessageData);
} else if (messageBlocks.size() > 1) { } else if (messageBlocks.size() > 1) {
LOG.error("received more than one message block: " + messageBlocks.toString()); 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())) { if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
quiet = true; quiet = true;
} else { } 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) { } 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); 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); 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); 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; long timeoutTime = System.currentTimeMillis() + exchangeTimeoutMilliseconds;
while (System.currentTimeMillis() < timeoutTime) { while (System.currentTimeMillis() < timeoutTime) {
OmnipodPacket response = null; OmnipodPacket response = null;
try { try {
response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class); 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()); 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()) { if (response == null || !response.isValid()) {
continue; continue;
@ -246,6 +258,6 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
podState.increasePacketNumber(2); podState.increasePacketNumber(2);
return response; 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.AlertSet;
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.state.PodSessionState; 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> { public class AcknowledgeAlertsAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -15,12 +16,12 @@ public class AcknowledgeAlertsAction implements OmnipodAction<StatusResponse> {
public AcknowledgeAlertsAction(PodSessionState podState, AlertSet alerts) { public AcknowledgeAlertsAction(PodSessionState podState, AlertSet alerts) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (alerts == 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) { } 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.podState = podState;
this.alerts = alerts; 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.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BolusDeliverySchedule; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class BolusAction implements OmnipodAction<StatusResponse> { public class BolusAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -22,10 +23,10 @@ public class BolusAction implements OmnipodAction<StatusResponse> {
public BolusAction(PodSessionState podState, double units, Duration timeBetweenPulses, public BolusAction(PodSessionState podState, double units, Duration timeBetweenPulses,
boolean acknowledgementBeep, boolean completionBeep) { boolean acknowledgementBeep, boolean completionBeep) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (timeBetweenPulses == 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.podState = podState;
this.units = units; 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.BeepType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class CancelDeliveryAction implements OmnipodAction<StatusResponse> { public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -17,10 +18,10 @@ public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
public CancelDeliveryAction(PodSessionState podState, EnumSet<DeliveryType> deliveryTypes, public CancelDeliveryAction(PodSessionState podState, EnumSet<DeliveryType> deliveryTypes,
boolean acknowledgementBeep) { boolean acknowledgementBeep) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (deliveryTypes == null) { if (deliveryTypes == null) {
throw new IllegalArgumentException("Delivery types cannot be null"); throw new ActionInitializationException("Delivery types cannot be null");
} }
this.podState = podState; this.podState = podState;
this.deliveryTypes = deliveryTypes; 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.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertConfiguration; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class ConfigureAlertsAction implements OmnipodAction<StatusResponse> { public class ConfigureAlertsAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -14,10 +15,10 @@ public class ConfigureAlertsAction implements OmnipodAction<StatusResponse> {
public ConfigureAlertsAction(PodSessionState podState, List<AlertConfiguration> alertConfigurations) { public ConfigureAlertsAction(PodSessionState podState, List<AlertConfiguration> alertConfigurations) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (alertConfigurations == null) { if (alertConfigurations == null) {
throw new IllegalArgumentException("Alert configurations cannot be null"); throw new ActionInitializationException("Alert configurations cannot be null");
} }
this.podState = podState; this.podState = podState;
this.alertConfigurations = alertConfigurations; 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.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class DeactivatePodAction implements OmnipodAction<StatusResponse> { public class DeactivatePodAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -14,7 +15,7 @@ public class DeactivatePodAction implements OmnipodAction<StatusResponse> {
public DeactivatePodAction(PodSessionState podState, boolean acknowledgementBeep) { public DeactivatePodAction(PodSessionState podState, boolean acknowledgementBeep) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
this.podState = podState; this.podState = podState;
this.acknowledgementBeep = acknowledgementBeep; 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.comm.message.response.podinfo.PodInfoResponse;
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.state.PodSessionState; 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> { public class GetPodInfoAction implements OmnipodAction<PodInfoResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -12,10 +13,10 @@ public class GetPodInfoAction implements OmnipodAction<PodInfoResponse> {
public GetPodInfoAction(PodSessionState podState, PodInfoType podInfoType) { public GetPodInfoAction(PodSessionState podState, PodInfoType podInfoType) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (podInfoType == 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.podState = podState;
this.podInfoType = podInfoType; 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.comm.message.response.StatusResponse;
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.state.PodSessionState; 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> { public class GetStatusAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
public GetStatusAction(PodSessionState podState) { public GetStatusAction(PodSessionState podState) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
this.podState = podState; 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.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; 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.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> { public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(InsertCannulaAction.class); 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) { public InsertCannulaAction(InsertCannulaService insertCannulaService, PodSessionState podState, BasalSchedule initialBasalSchedule) {
if (insertCannulaService == null) { if (insertCannulaService == null) {
throw new IllegalArgumentException("Insert cannula service cannot be null"); throw new ActionInitializationException("Insert cannula service cannot be null");
} }
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (initialBasalSchedule == 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.service = insertCannulaService;
this.podState = podState; this.podState = podState;
@ -45,7 +47,7 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
@Override @Override
public StatusResponse execute(OmnipodCommunicationService communicationService) { public StatusResponse execute(OmnipodCommunicationService communicationService) {
if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { 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)) { if (podState.getSetupProgress().isBefore(SetupProgress.INITIAL_BASAL_SCHEDULE_SET)) {
@ -67,7 +69,7 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
updateCannulaInsertionStatus(podState, statusResponse); updateCannulaInsertionStatus(podState, statusResponse);
return statusResponse; return statusResponse;
} else { } 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.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; 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.defs.state.PodSetupState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class PairAction implements OmnipodAction<PodSessionState> { public class PairAction implements OmnipodAction<PodSessionState> {
private final PairService service; private final PairService service;
@ -18,7 +19,7 @@ public class PairAction implements OmnipodAction<PodSessionState> {
public PairAction(PairService pairService, int address) { public PairAction(PairService pairService, int address) {
if (pairService == null) { if (pairService == null) {
throw new IllegalArgumentException("Pair service cannot be null"); throw new ActionInitializationException("Pair service cannot be null");
} }
this.service = pairService; this.service = pairService;
this.address = address; 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.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; 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.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> { public class PrimeAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(PrimeAction.class); 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) { public PrimeAction(PrimeService primeService, PodSessionState podState) {
if (primeService == null) { if (primeService == null) {
throw new IllegalArgumentException("Prime service cannot be null"); throw new ActionInitializationException("Prime service cannot be null");
} }
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
this.service = primeService; this.service = primeService;
this.podState = podState; this.podState = podState;
@ -39,7 +41,7 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
@Override @Override
public StatusResponse execute(OmnipodCommunicationService communicationService) { public StatusResponse execute(OmnipodCommunicationService communicationService) {
if (podState.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) { 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)) { if (podState.getSetupProgress().isBefore(SetupProgress.STARTING_PRIME)) {
service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podState); service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podState);
@ -57,7 +59,7 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
updatePrimingStatus(podState, statusResponse); updatePrimingStatus(podState, statusResponse);
return statusResponse; return statusResponse;
} else { } 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.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
public class SetBasalScheduleAction implements OmnipodAction<StatusResponse> { public class SetBasalScheduleAction implements OmnipodAction<StatusResponse> {
private final PodSessionState podState; private final PodSessionState podState;
@ -22,13 +23,13 @@ public class SetBasalScheduleAction implements OmnipodAction<StatusResponse> {
public SetBasalScheduleAction(PodSessionState podState, BasalSchedule basalSchedule, public SetBasalScheduleAction(PodSessionState podState, BasalSchedule basalSchedule,
boolean confidenceReminder, Duration scheduleOffset, boolean acknowledgementBeep) { boolean confidenceReminder, Duration scheduleOffset, boolean acknowledgementBeep) {
if (podState == null) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (basalSchedule == null) { if (basalSchedule == null) {
throw new IllegalArgumentException("Basal schedule cannot be null"); throw new ActionInitializationException("Basal schedule cannot be null");
} }
if (scheduleOffset == null) { if (scheduleOffset == null) {
throw new IllegalArgumentException("Schedule offset cannot be null"); throw new ActionInitializationException("Schedule offset cannot be null");
} }
this.podState = podState; this.podState = podState;
this.basalSchedule = basalSchedule; 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.comm.message.response.StatusResponse;
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.state.PodSessionState; 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> { public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
private final SetTempBasalService service; private final SetTempBasalService service;
@ -19,13 +21,13 @@ public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
public SetTempBasalAction(SetTempBasalService setTempBasalService, PodSessionState podState, public SetTempBasalAction(SetTempBasalService setTempBasalService, PodSessionState podState,
double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep) { double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep) {
if (setTempBasalService == null) { 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) { if (podState == null) {
throw new IllegalArgumentException("Pod state cannot be null"); throw new ActionInitializationException("Pod state cannot be null");
} }
if (duration == null) { if (duration == null) {
throw new IllegalArgumentException("Duration cannot be null"); throw new ActionInitializationException("Duration cannot be null");
} }
this.service = setTempBasalService; this.service = setTempBasalService;
this.podState = podState; this.podState = podState;
@ -40,8 +42,7 @@ public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
StatusResponse statusResponse = service.cancelTempBasal(communicationService, podState); StatusResponse statusResponse = service.cancelTempBasal(communicationService, podState);
if (statusResponse.getDeliveryStatus() != DeliveryStatus.NORMAL) { if (statusResponse.getDeliveryStatus() != DeliveryStatus.NORMAL) {
throw new IllegalStateException("Illegal delivery status: " + throw new IllegalDeliveryStatusException(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
statusResponse.getDeliveryStatus().name());
} }
return service.executeTempBasalCommand(communicationService, podState, rate, duration, 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.comm.message.response.VersionResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; 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.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; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class PairService { public class PairService {
@ -37,7 +37,7 @@ public class PairService {
message, OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress()); message, OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress());
if (configurePodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_SUCCESS) { 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; 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.comm.OmnipodCommunicationService;
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.exception.CrcMismatchException; 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.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
public class OmnipodMessage { public class OmnipodMessage {
@ -29,7 +29,7 @@ public class OmnipodMessage {
public static OmnipodMessage decodeMessage(byte[] data) { public static OmnipodMessage decodeMessage(byte[] data) {
if (data.length < 10) { 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], int address = ByteUtil.toInt((int) data[0], (int) data[1], (int) data[2],
@ -37,21 +37,20 @@ public class OmnipodMessage {
byte b9 = data[4]; byte b9 = data[4];
int bodyLength = ByteUtil.convertUnsignedByteToInt(data[5]); int bodyLength = ByteUtil.convertUnsignedByteToInt(data[5]);
if (data.length - 8 < bodyLength) { 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 sequenceNumber = (((int) b9 >> 2) & 0b11111);
int crc = ByteUtil.toInt(data[data.length - 2], data[data.length - 1]); int crc = ByteUtil.toInt(data[data.length - 2], data[data.length - 1]);
int calculatedCrc = OmniCRC.crc16(ByteUtil.substring(data, 0, data.length - 2)); int calculatedCrc = OmniCRC.crc16(ByteUtil.substring(data, 0, data.length - 2));
if (crc != calculatedCrc) { 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)); List<MessageBlock> blocks = decodeBlocks(ByteUtil.substring(data, 6, data.length - 6 - 2));
if (blocks == null || blocks.size() == 0) { 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 new OmnipodMessage(address, blocks, sequenceNumber);
return result;
} }
private static List<MessageBlock> decodeBlocks(byte[] data) { private static List<MessageBlock> decodeBlocks(byte[] data) {
@ -65,7 +64,7 @@ public class OmnipodMessage {
int blockLength = block.getRawData().length; int blockLength = block.getRawData().length;
index += blockLength; index += blockLength;
} catch (Exception ex) { } 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) (((sequenceNumber & 0x1F) << 2) + ((encodedData.length >> 8) & 0x03)));
header = ByteUtil.concat(header, (byte) (encodedData.length & 0xFF)); header = ByteUtil.concat(header, (byte) (encodedData.length & 0xFF));
encodedData = ByteUtil.concat(header, encodedData); encodedData = ByteUtil.concat(header, encodedData);
String myString = ByteUtil.shortHexString(encodedData);
int crc = OmniCRC.crc16(encodedData); int crc = OmniCRC.crc16(encodedData);
encodedData = ByteUtil.concat(encodedData, ByteUtil.substring(ByteUtil.getBytesFromInt(crc), 2, 2)); encodedData = ByteUtil.concat(encodedData, ByteUtil.substring(ByteUtil.getBytesFromInt(crc), 2, 2));
return encodedData; 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.common.utils.ByteUtil;
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.exception.CrcMismatchException; 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; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
/** /**
@ -26,15 +26,12 @@ public class OmnipodPacket implements RLMessage {
try { try {
this.packetType = PacketType.fromByte((byte) (((int) encoded[4] & 0xFF) >> 5)); this.packetType = PacketType.fromByte((byte) (((int) encoded[4] & 0xFF) >> 5));
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
throw new OmnipodException("Invalid packet type", ex); throw new IllegalPacketTypeException(null, null);
} }
this.sequenceNumber = (encoded[4] & 0b11111); this.sequenceNumber = (encoded[4] & 0b11111);
byte crc = OmniCRC.crc8(ByteUtil.substring(encoded, 0, encoded.length - 1)); byte crc = OmniCRC.crc8(ByteUtil.substring(encoded, 0, encoded.length - 1));
if (crc != encoded[encoded.length - 1]) { if (crc != encoded[encoded.length - 1]) {
throw new CrcMismatchException("CRC mismatch: " + throw new CrcMismatchException(crc, encoded[encoded.length - 1]);
ByteUtil.shortHexString(new byte[]{crc}) + " <> " +
ByteUtil.shortHexString(new byte[]{encoded[encoded.length - 1]}) +
" (packetType=" + packetType.name() + ",packetLength=" + encoded.length + ")");
} }
this.encodedMessage = ByteUtil.substring(encoded, 5, encoded.length - 1 - 5); this.encodedMessage = ByteUtil.substring(encoded, 5, encoded.length - 1 - 5);
valid = true; 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.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.MessageBlockType; 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; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class BolusExtraCommand extends MessageBlock { public class BolusExtraCommand extends MessageBlock {
@ -28,9 +29,9 @@ public class BolusExtraCommand extends MessageBlock {
boolean acknowledgementBeep, boolean completionBeep, boolean acknowledgementBeep, boolean completionBeep,
Duration programReminderInterval, Duration timeBetweenPulses) { Duration programReminderInterval, Duration timeBetweenPulses) {
if (units <= 0D) { if (units <= 0D) {
throw new IllegalArgumentException("Units should be > 0"); throw new CommandInitializationException("Units should be > 0");
} else if (units > OmnipodConst.MAX_BOLUS) { } else if (units > OmnipodConst.MAX_BOLUS) {
throw new IllegalArgumentException("Units exceeds max bolus"); throw new CommandInitializationException("Units exceeds max bolus");
} }
this.units = units; this.units = units;
this.squareWaveUnits = squareWaveUnits; 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.BolusDeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.DeliverySchedule; 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.defs.schedule.TempBasalDeliverySchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock { public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock {
@ -50,12 +51,12 @@ public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock {
// Temp basal // Temp basal
public SetInsulinScheduleCommand(int nonce, double tempBasalRate, Duration duration) { public SetInsulinScheduleCommand(int nonce, double tempBasalRate, Duration duration) {
if (tempBasalRate < 0D) { if (tempBasalRate < 0D) {
throw new IllegalArgumentException("Rate should be >= 0"); throw new CommandInitializationException("Rate should be >= 0");
} else if (tempBasalRate > OmnipodConst.MAX_BASAL_RATE) { } 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)) { 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 pulsesPerHour = (int) Math.round(tempBasalRate / OmnipodConst.POD_PULSE_SIZE);
int pulsesPerSegment = pulsesPerHour / 2; 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.comm.message.MessageBlock;
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.schedule.RateEntry; 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; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class TempBasalExtraCommand extends MessageBlock { public class TempBasalExtraCommand extends MessageBlock {
@ -23,12 +24,12 @@ public class TempBasalExtraCommand extends MessageBlock {
public TempBasalExtraCommand(double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep, public TempBasalExtraCommand(double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep,
Duration programReminderInterval) { Duration programReminderInterval) {
if (rate < 0D) { if (rate < 0D) {
throw new IllegalArgumentException("Rate should be >= 0"); throw new CommandInitializationException("Rate should be >= 0");
} else if (rate > OmnipodConst.MAX_BASAL_RATE) { } 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)) { 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; 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; package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
public class CrcMismatchException extends OmnipodException { public class CrcMismatchException extends OmnipodException {
public CrcMismatchException(String message) { private final int expected;
super(message); 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) { public int getExpected() {
super(message, cause); 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; package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
public class NotEnoughDataException extends OmnipodException { public class NotEnoughDataException extends OmnipodException {
public NotEnoughDataException(String message) { private final byte[] data;
super(message);
public NotEnoughDataException(byte[] data) {
super("Not enough data: " + ByteUtil.shortHexString(data));
this.data = data;
} }
public NotEnoughDataException(String message, Throwable cause) { public byte[] getData() {
super(message, cause); return data;
} }
} }

View file

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

View file

@ -8,27 +8,12 @@ public class PodFaultException extends OmnipodException {
private final PodInfoFaultEvent faultEvent; private final PodInfoFaultEvent faultEvent;
public PodFaultException(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; 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() { public PodInfoFaultEvent getFaultEvent() {
return faultEvent; 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; private final ErrorResponse errorResponse;
public PodReturnedErrorResponseException(ErrorResponse errorResponse) { public PodReturnedErrorResponseException(ErrorResponse errorResponse) {
super("Pod returned error response"); super("Pod returned error response: " + errorResponse.getErrorResponseType());
this.errorResponse = errorResponse;
}
public PodReturnedErrorResponseException(ErrorResponse errorResponse, Throwable cause) {
super("Pod returned error response", cause);
this.errorResponse = errorResponse; this.errorResponse = errorResponse;
} }
public ErrorResponse getErrorResponse() { public ErrorResponse getErrorResponse() {
return errorResponse; return errorResponse;
} }
@Override
public void printStackTrace() {
System.out.println(errorResponse.toString());
super.printStackTrace();
}
} }