From 321f5eec3c7a40f7e4bc998e6578961070aca0ae Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sat, 7 Dec 2019 15:21:16 +0100 Subject: [PATCH] Mark exceptions in packet transports as certain failures when it is not the last packet for the message --- .../comm/OmnipodCommunicationService.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 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 61eab14b78..d00a0f177b 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 @@ -155,17 +155,33 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager { PacketType packetType = firstPacket ? PacketType.PDM : PacketType.CON; OmnipodPacket packet = new OmnipodPacket(packetAddress, packetType, podState.getPacketNumber(), encodedMessage); byte[] encodedMessageInPacket = packet.getEncodedMessage(); - //getting the data remaining to be sent + + // getting the data remaining to be sent encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length); firstPacket = false; + + // If this is not the last packet, the message wasn't fully sent, + // so it's impossible for the pod to have received the message + boolean isCertainFailure = encodedMessage.length > 0; + try { + // We actually ignore previous (ack) responses if it was not last packet to send response = exchangePackets(podState, packet); - } catch (OmnipodException ex) { - throw ex; } catch (Exception ex) { - throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex); + OmnipodException newException; + if (ex instanceof OmnipodException) { + newException = (OmnipodException) ex; + } else { + newException = new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex); + } + + if (isLoggingEnabled()) { + LOG.debug("Caught exception in transportMessages. Setting certainFailure to {} because encodedMessage.length={}", isCertainFailure, encodedMessage.length); + } + newException.setCertainFailure(isCertainFailure); + + throw newException; } - //We actually ignore (ack) responses if it is not last packet to send } if (response.getPacketType() == PacketType.ACK) {