From f0ccf57e69482026cd1c3b423c324b6c2552bd1f Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Wed, 28 Aug 2019 14:10:28 +0100 Subject: [PATCH 1/3] - fixing reading profile --- .../comm/MedtronicCommunicationManager.java | 21 +++++++------------ .../medtronic/comm/message/PumpMessage.java | 5 +++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java index 27bd436364..2562ac9376 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java @@ -703,7 +703,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager // create message PumpMessage msg; - // if (bodyData == null) msg = makePumpMessage(commandType); // send and wait for response @@ -718,8 +717,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager byte[] data = null; - int runs = 1; - if (check == null) { data = response.getRawContentOfFrame(); @@ -728,24 +725,21 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager while (checkIfWeHaveMoreData(commandType, response, data)) { - runs++; - - PumpMessage response2 = sendAndListen(ackMsg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries)); + response = sendAndListen(ackMsg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries)); // LOG.debug("{} Response: {}", runs, HexDump.toHexStringDisplayable(response2.getRawContent())); // LOG.debug("{} Response: {}", runs, // HexDump.toHexStringDisplayable(response2.getMessageBody().getTxData())); - String check2 = checkResponseContent(response2, commandType.commandDescription, 1); + String check2 = checkResponseContent(response, commandType.commandDescription, 1); if (check2 == null) { - data = ByteUtil.concat(data, response2.getRawContentOfFrame()); + data = ByteUtil.concat(data, response.getRawContentOfFrame()); } else { this.errorMessage = check2; - if (isLogEnabled()) - LOG.debug("Error message: " + check2); + LOG.error("Error with response got GetProfile: " + check2); } } @@ -784,12 +778,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager if (commandType == MedtronicCommandType.GetBasalProfileSTD || // commandType == MedtronicCommandType.GetBasalProfileA || // commandType == MedtronicCommandType.GetBasalProfileB) { - byte[] responseRaw = response.getRawContent(); + byte[] responseRaw = response.getRawContentOfFrame(); int last = responseRaw.length - 1; - if (isLogEnabled()) - LOG.debug("Length: " + data.length); + LOG.debug("Length: " + data.length); if (data.length >= BasalProfile.MAX_RAW_DATA_SIZE) { return false; @@ -954,7 +947,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1); } - if (responseMessage!=null) + if (responseMessage != null) LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent())); else LOG.warn("Set Basal Profile: Null response."); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java index ab61c2f67e..81a8e553ef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java @@ -129,9 +129,10 @@ public class PumpMessage implements RLMessage { return arrayOut; } + public byte[] getRawContentOfFrame() { - byte[] raw = getRawContent(); - return ByteUtil.substring(raw, 0, raw.length - 1); + byte[] raw = messageBody.getTxData(); + return ByteUtil.substring(raw, 1); } From d50d6087ea20c997c9e09b59468471b2242aae62 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 31 Aug 2019 17:32:09 +0100 Subject: [PATCH 2/3] - changed PumpMessage to be get correct frame from 523 and 554 --- .../pump/medtronic/comm/message/PumpMessage.java | 7 ++++++- .../pump/medtronic/defs/MedtronicDeviceType.java | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java index 81a8e553ef..44d34c6e84 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; +import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; /** * Created by geoff on 5/29/16. @@ -132,7 +133,11 @@ public class PumpMessage implements RLMessage { public byte[] getRawContentOfFrame() { byte[] raw = messageBody.getTxData(); - return ByteUtil.substring(raw, 1); + + if (MedtronicUtil.getMedtronicPumpModel().isMedtronic_523orHigher()) + return ByteUtil.substring(raw, 1, raw.length - 2); + else + return ByteUtil.substring(raw, 1); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.java index 174405dc7b..f13974999b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.java @@ -105,9 +105,9 @@ public enum MedtronicDeviceType { } - public static boolean isLargerFormat(MedtronicDeviceType model) { - return isSameDevice(model, Medtronic_523andHigher); - } +// public static boolean isLargerFormat(MedtronicDeviceType model) { +// return isSameDevice(model, Medtronic_523andHigher); +// } public boolean isFamily() { @@ -120,13 +120,17 @@ public enum MedtronicDeviceType { } - public boolean isLargerFormat() { +// public boolean isLargerFormat() { +// return isSameDevice(this, Medtronic_523andHigher); +// } + + public boolean isMedtronic_523orHigher() { return isSameDevice(this, Medtronic_523andHigher); } public int getBolusStrokes() { - return (isLargerFormat(this)) ? 40 : 10; + return (isMedtronic_523orHigher()) ? 40 : 10; } From bdf65ab077697b82b53a463d9e91231768321068 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 12 Sep 2019 12:36:13 +0100 Subject: [PATCH 3/3] - fix for getting basal profile (getRawContentOfFrame needed to be rewritten to cut 1 character and then create fixed length of frame at 64 bytes (it seems that in some cases frame can contain crc at end) --- .../plugins/pump/medtronic/comm/message/PumpMessage.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java index 44d34c6e84..4d81d81bfe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java @@ -7,7 +7,6 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; -import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; /** * Created by geoff on 5/29/16. @@ -23,6 +22,8 @@ public class PumpMessage implements RLMessage { public MessageBody messageBody = new MessageBody(); public String error = null; + public static final int FRAME_DATA_LENGTH = 64; + public PumpMessage(String error) { this.error = error; @@ -133,11 +134,7 @@ public class PumpMessage implements RLMessage { public byte[] getRawContentOfFrame() { byte[] raw = messageBody.getTxData(); - - if (MedtronicUtil.getMedtronicPumpModel().isMedtronic_523orHigher()) - return ByteUtil.substring(raw, 1, raw.length - 2); - else - return ByteUtil.substring(raw, 1); + return ByteUtil.substring(raw, 1, Math.min(FRAME_DATA_LENGTH, raw.length - 1)); }