Various small fixes/improvements

- Throw podFaultException in OmnipodManager.cancelBolus() and handle in AapsOmnipodManager
- Sound confirmation beep when deactivating pod
- Add logging in verifyCommand
This commit is contained in:
Bart Sopers 2019-12-24 12:08:39 -05:00
parent 3cb58133dd
commit 49a9ddf72d
2 changed files with 35 additions and 14 deletions

View file

@ -328,18 +328,21 @@ public class OmnipodManager {
try { try {
cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep); cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep);
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
if (isLoggingEnabled()) { discardActiveBolusData();
LOG.info("Ignoring PodFaultException in cancelBolus", ex); throw ex;
}
} finally { } finally {
logCommandExecutionFinished("cancelBolus"); logCommandExecutionFinished("cancelBolus");
} }
discardActiveBolusData();
}
}
private void discardActiveBolusData() {
activeBolusData.getDisposables().dispose(); activeBolusData.getDisposables().dispose();
activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered())); activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered()));
activeBolusData = null; activeBolusData = null;
} }
}
public synchronized void suspendDelivery(boolean acknowledgementBeep) { public synchronized void suspendDelivery(boolean acknowledgementBeep) {
cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep); cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep);
@ -399,8 +402,8 @@ public class OmnipodManager {
logStartingCommandExecution("deactivatePod"); logStartingCommandExecution("deactivatePod");
try { try {
// Never send acknowledgement beeps here. Matches the PDM's behavior // Always send acknowledgement beeps here. Matches the PDM's behavior
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, false))); executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, true)));
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
LOG.info("Ignoring PodFaultException in deactivatePod", ex); LOG.info("Ignoring PodFaultException in deactivatePod", ex);
@ -445,7 +448,12 @@ public class OmnipodManager {
if (isCertainFailure(ex)) { if (isCertainFailure(ex)) {
throw ex; throw ex;
} else { } else {
if (isLoggingEnabled()) {
LOG.debug("Caught exception in executeAndVerify: ", ex);
}
CommandDeliveryStatus verificationResult = verifyCommand(); CommandDeliveryStatus verificationResult = verifyCommand();
switch (verificationResult) { switch (verificationResult) {
case CERTAIN_FAILURE: case CERTAIN_FAILURE:
if (ex instanceof OmnipodException) { if (ex instanceof OmnipodException) {
@ -501,6 +509,7 @@ public class OmnipodManager {
LOG.warn("Verifying command by using cancel none command to verify nonce"); LOG.warn("Verifying command by using cancel none command to verify nonce");
} }
try { try {
logStartingCommandExecution("verifyCommand");
communicationService.sendCommand(StatusResponse.class, podState, communicationService.sendCommand(StatusResponse.class, podState,
new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false); new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false);
} catch (NonceOutOfSyncException ex) { } catch (NonceOutOfSyncException ex) {
@ -513,6 +522,8 @@ public class OmnipodManager {
LOG.error("Command unresolved (UNCERTAIN_FAILURE)", ex); LOG.error("Command unresolved (UNCERTAIN_FAILURE)", ex);
} }
return CommandDeliveryStatus.UNCERTAIN_FAILURE; return CommandDeliveryStatus.UNCERTAIN_FAILURE;
} finally {
logCommandExecutionFinished("verifyCommand");
} }
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
@ -627,8 +638,6 @@ public class OmnipodManager {
} }
public double estimateUnitsDelivered() { public double estimateUnitsDelivered() {
// TODO this needs improvement
// take (average) radio communication time into account
long elapsedMillis = new Duration(startDate, DateTime.now()).getMillis(); long elapsedMillis = new Duration(startDate, DateTime.now()).getMillis();
long totalDurationMillis = (long) (units / OmnipodConst.POD_BOLUS_DELIVERY_RATE * 1000); long totalDurationMillis = (long) (units / OmnipodConst.POD_BOLUS_DELIVERY_RATE * 1000);
double factor = (double) elapsedMillis / totalDurationMillis; double factor = (double) elapsedMillis / totalDurationMillis;

View file

@ -292,7 +292,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
// For safety reasons, we treat this as a bolus that has successfully been delivered, in order to prevent insulin overdose // For safety reasons, we treat this as a bolus that has successfully been delivered, in order to prevent insulin overdose
// FIXME We can't dismiss the alert while the bolus progress dialog is open, so don't use a sound // FIXME We can't dismiss the alert while the bolus progress dialog is open, so don't use a sound
showNotification(getStringResource(R.string.omnipod_bolus_failed_uncertain), Notification.URGENT, null); showNotificationWithDialog(getStringResource(R.string.omnipod_bolus_failed_uncertain), Notification.URGENT, null);
} }
// Wait for the bolus to finish // Wait for the bolus to finish
@ -315,6 +315,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
try { try {
delegate.cancelBolus(isBolusBeepsEnabled()); delegate.cancelBolus(isBolusBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
} catch(PodFaultException ex) {
showNotificationWithDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), Notification.URGENT, null);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment); addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
@ -550,10 +552,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} else if (ex instanceof NotEnoughDataException) { } else if (ex instanceof NotEnoughDataException) {
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data); comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
} else if (ex instanceof PodFaultException) { } else if (ex instanceof PodFaultException) {
// TODO handle pod fault with some kind of dialog that has a button to start pod deactivation
FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType(); FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType();
comment = getStringResource(R.string.omnipod_driver_error_pod_fault, comment = createPodFaultErrorMessage(faultEventType);
ByteUtil.convertUnsignedByteToInt(faultEventType.getValue()), faultEventType.name());
} else if (ex instanceof PodReturnedErrorResponseException) { } else if (ex instanceof PodReturnedErrorResponseException) {
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response); comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
} else { } else {
@ -573,10 +573,22 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
return comment; return comment;
} }
private String createPodFaultErrorMessage(FaultEventType faultEventType) {
String comment;
comment = getStringResource(R.string.omnipod_driver_error_pod_fault,
ByteUtil.convertUnsignedByteToInt(faultEventType.getValue()), faultEventType.name());
return comment;
}
private void sendEvent(Event event) { private void sendEvent(Event event) {
RxBus.INSTANCE.send(event); RxBus.INSTANCE.send(event);
} }
private void showNotificationWithDialog(String message, int urgency, Integer sound) {
// TODO
showNotification(message, urgency, sound);
}
private void showNotification(String message, int urgency, Integer sound) { private void showNotification(String message, int urgency, Integer sound) {
Notification notification = new Notification( // Notification notification = new Notification( //
Notification.OMNIPOD_PUMP_ALARM, // Notification.OMNIPOD_PUMP_ALARM, //