From bc822aa4ffc02bbd9bb488c86f11fa45767401b2 Mon Sep 17 00:00:00 2001 From: Volker Richert <v.richert@addmore.de> Date: Sat, 10 Dec 2016 18:30:09 +0100 Subject: [PATCH] refactoring --- .../nightscout/android/medtronic/MedtronicCnlReader.java | 8 -------- .../medtronic/message/ContourNextLinkBinaryMessage.java | 2 +- .../android/medtronic/message/ContourNextLinkMessage.java | 4 ++++ .../message/DeviceInfoRequestCommandMessage.java | 8 +++++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/android/medtronic/MedtronicCnlReader.java b/app/src/main/java/info/nightscout/android/medtronic/MedtronicCnlReader.java index 7acee74..1cb46a5 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/MedtronicCnlReader.java +++ b/app/src/main/java/info/nightscout/android/medtronic/MedtronicCnlReader.java @@ -164,14 +164,6 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler { } } - // TODO - get rid of this - it should be in a message decoder - private void checkControlMessage(byte[] msg, byte controlCharacter) throws IOException, TimeoutException, UnexpectedMessageException { - if (msg.length != 1 || msg[0] != controlCharacter) { - throw new UnexpectedMessageException(String.format(Locale.getDefault(), "Expected to get control character '%d' Got '%d'.", - (int) controlCharacter, (int) msg[0])); - } - } - public void requestDeviceInfo() throws IOException, TimeoutException, UnexpectedMessageException, ChecksumException, EncryptionException { DeviceInfoResponseCommandMessage response = new DeviceInfoRequestCommandMessage().send(mDevice); diff --git a/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkBinaryMessage.java b/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkBinaryMessage.java index 51ff599..b7dd2ff 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkBinaryMessage.java +++ b/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkBinaryMessage.java @@ -17,7 +17,7 @@ public class ContourNextLinkBinaryMessage extends ContourNextLinkMessage { //protected ByteBuffer mBayerPayload; protected CommandType mCommandType = CommandType.NO_TYPE; - static int ENVELOPE_SIZE = 33; + private final static int ENVELOPE_SIZE = 33; public enum CommandType { NO_TYPE(0x0), diff --git a/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkMessage.java b/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkMessage.java index 159ac17..6aab874 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkMessage.java +++ b/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkMessage.java @@ -115,5 +115,9 @@ public class ContourNextLinkMessage { ASCII(int code) { this.value = (byte) code; } + + public boolean equals(byte value) { + return this.value == value; + } } } diff --git a/app/src/main/java/info/nightscout/android/medtronic/message/DeviceInfoRequestCommandMessage.java b/app/src/main/java/info/nightscout/android/medtronic/message/DeviceInfoRequestCommandMessage.java index 0aab014..e92a185 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/message/DeviceInfoRequestCommandMessage.java +++ b/app/src/main/java/info/nightscout/android/medtronic/message/DeviceInfoRequestCommandMessage.java @@ -25,14 +25,16 @@ public class DeviceInfoRequestCommandMessage extends ContourNextLinkMessage { do { try { - if (response1[0] == ASCII.EOT.value) { + if (ASCII.EOT.equals(response1[0])) { // response 1 is the ASTM message response = new DeviceInfoResponseCommandMessage(mPumpSession, response1); - response.checkControlMessage(response2, ASCII.ENQ.value); + // ugly.... + response.checkControlMessage(response2, ASCII.ENQ); } else { // response 2 is the ASTM message response = new DeviceInfoResponseCommandMessage(mPumpSession, response1); - response.checkControlMessage(response1, ASCII.ENQ.value); + // ugly, too.... + response.checkControlMessage(response1, ASCII.ENQ); } } catch (TimeoutException e) { doRetry = true; -- GitLab