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:
parent
3cb58133dd
commit
49a9ddf72d
|
@ -328,19 +328,22 @@ public class OmnipodManager {
|
|||
try {
|
||||
cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep);
|
||||
} catch (PodFaultException ex) {
|
||||
if (isLoggingEnabled()) {
|
||||
LOG.info("Ignoring PodFaultException in cancelBolus", ex);
|
||||
}
|
||||
discardActiveBolusData();
|
||||
throw ex;
|
||||
} finally {
|
||||
logCommandExecutionFinished("cancelBolus");
|
||||
}
|
||||
|
||||
activeBolusData.getDisposables().dispose();
|
||||
activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered()));
|
||||
activeBolusData = null;
|
||||
discardActiveBolusData();
|
||||
}
|
||||
}
|
||||
|
||||
private void discardActiveBolusData() {
|
||||
activeBolusData.getDisposables().dispose();
|
||||
activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered()));
|
||||
activeBolusData = null;
|
||||
}
|
||||
|
||||
public synchronized void suspendDelivery(boolean acknowledgementBeep) {
|
||||
cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep);
|
||||
}
|
||||
|
@ -399,8 +402,8 @@ public class OmnipodManager {
|
|||
logStartingCommandExecution("deactivatePod");
|
||||
|
||||
try {
|
||||
// Never send acknowledgement beeps here. Matches the PDM's behavior
|
||||
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, false)));
|
||||
// Always send acknowledgement beeps here. Matches the PDM's behavior
|
||||
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, true)));
|
||||
} catch (PodFaultException ex) {
|
||||
if (isLoggingEnabled()) {
|
||||
LOG.info("Ignoring PodFaultException in deactivatePod", ex);
|
||||
|
@ -445,7 +448,12 @@ public class OmnipodManager {
|
|||
if (isCertainFailure(ex)) {
|
||||
throw ex;
|
||||
} else {
|
||||
if (isLoggingEnabled()) {
|
||||
LOG.debug("Caught exception in executeAndVerify: ", ex);
|
||||
}
|
||||
|
||||
CommandDeliveryStatus verificationResult = verifyCommand();
|
||||
|
||||
switch (verificationResult) {
|
||||
case CERTAIN_FAILURE:
|
||||
if (ex instanceof OmnipodException) {
|
||||
|
@ -501,6 +509,7 @@ public class OmnipodManager {
|
|||
LOG.warn("Verifying command by using cancel none command to verify nonce");
|
||||
}
|
||||
try {
|
||||
logStartingCommandExecution("verifyCommand");
|
||||
communicationService.sendCommand(StatusResponse.class, podState,
|
||||
new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false);
|
||||
} catch (NonceOutOfSyncException ex) {
|
||||
|
@ -513,6 +522,8 @@ public class OmnipodManager {
|
|||
LOG.error("Command unresolved (UNCERTAIN_FAILURE)", ex);
|
||||
}
|
||||
return CommandDeliveryStatus.UNCERTAIN_FAILURE;
|
||||
} finally {
|
||||
logCommandExecutionFinished("verifyCommand");
|
||||
}
|
||||
|
||||
if (isLoggingEnabled()) {
|
||||
|
@ -627,8 +638,6 @@ public class OmnipodManager {
|
|||
}
|
||||
|
||||
public double estimateUnitsDelivered() {
|
||||
// TODO this needs improvement
|
||||
// take (average) radio communication time into account
|
||||
long elapsedMillis = new Duration(startDate, DateTime.now()).getMillis();
|
||||
long totalDurationMillis = (long) (units / OmnipodConst.POD_BOLUS_DELIVERY_RATE * 1000);
|
||||
double factor = (double) elapsedMillis / totalDurationMillis;
|
||||
|
|
|
@ -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
|
||||
|
||||
// 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
|
||||
|
@ -315,6 +315,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
try {
|
||||
delegate.cancelBolus(isBolusBeepsEnabled());
|
||||
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
|
||||
} catch(PodFaultException ex) {
|
||||
showNotificationWithDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), Notification.URGENT, null);
|
||||
} catch (Exception ex) {
|
||||
String comment = handleAndTranslateException(ex);
|
||||
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
|
||||
|
@ -550,10 +552,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
} else if (ex instanceof NotEnoughDataException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
|
||||
} else if (ex instanceof PodFaultException) {
|
||||
// TODO handle pod fault with some kind of dialog that has a button to start pod deactivation
|
||||
FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType();
|
||||
comment = getStringResource(R.string.omnipod_driver_error_pod_fault,
|
||||
ByteUtil.convertUnsignedByteToInt(faultEventType.getValue()), faultEventType.name());
|
||||
comment = createPodFaultErrorMessage(faultEventType);
|
||||
} else if (ex instanceof PodReturnedErrorResponseException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
|
||||
} else {
|
||||
|
@ -573,10 +573,22 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
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) {
|
||||
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) {
|
||||
Notification notification = new Notification( //
|
||||
Notification.OMNIPOD_PUMP_ALARM, //
|
||||
|
|
Loading…
Reference in a new issue