From 36a1a138464e08d9fa9a844dc89e5900ec27eb41 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Tue, 24 Dec 2019 15:39:49 -0500 Subject: [PATCH] Don't pad messages that contain a DeactivatePodCommand message block and don't use verification for deactivatePod --- .../comm/OmnipodCommunicationService.java | 5 ++++- .../pump/omnipod/comm/OmnipodManager.java | 2 +- .../omnipod/comm/message/OmnipodMessage.java | 16 ++++++++++------ .../omnipod/driver/comm/AapsOmnipodManager.java | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java index 6a7c135565..21c5459a91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.OmnipodAction import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodPacket; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.DeactivatePodCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.ErrorResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; @@ -149,7 +150,9 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager { boolean firstPacket = true; byte[] encodedMessage; - if (message.isNonceResyncable()) { + // this does not work well with the deactivate pod command, we somehow either + // receive an ACK instead of a normal response, or a partial response and a communication timeout + if (message.isNonceResyncable() && !message.containsBlock(DeactivatePodCommand.class)) { OmnipodMessage paddedMessage = new OmnipodMessage(message); // If messages are nonce resyncable, we want do distinguish between certain and uncertain failures for verification purposes // However, some commands (e.g. cancel delivery) are single packet command by nature. When we get a timeout with a single packet, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java index 1e115d1156..f82528aa9b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java @@ -403,7 +403,7 @@ public class OmnipodManager { try { // Always send acknowledgement beeps here. Matches the PDM's behavior - executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, true))); + communicationService.executeAction(new DeactivatePodAction(podState, true)); } catch (PodFaultException ex) { if (isLoggingEnabled()) { LOG.info("Ignoring PodFaultException in deactivatePod", ex); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java index d5329ac312..68b43d96d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java @@ -115,12 +115,7 @@ public class OmnipodMessage { } public boolean isNonceResyncable() { - for (MessageBlock messageBlock : messageBlocks) { - if (messageBlock instanceof NonceResyncableMessageBlock) { - return true; - } - } - return false; + return containsBlock(NonceResyncableMessageBlock.class); } public int getSentNonce() { @@ -139,4 +134,13 @@ public class OmnipodMessage { } } } + + public boolean containsBlock(Class blockType) { + for (MessageBlock messageBlock : messageBlocks) { + if (blockType.isInstance(messageBlock)) { + return true; + } + } + return false; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index c95f3b1c77..ba5b2bd842 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -316,7 +316,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface try { delegate.cancelBolus(isBolusBeepsEnabled()); addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); - } catch(PodFaultException ex) { + } catch (PodFaultException ex) { showNotificationWithDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), Notification.URGENT, null); } catch (Exception ex) { String comment = handleAndTranslateException(ex);