diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt index 177f8ed552..e56d717041 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt @@ -127,7 +127,7 @@ class Connection( @Synchronized fun disconnect(closeGatt: Boolean) { aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt") - if (closeGatt == false && gattConnection != null) { + if (!closeGatt && gattConnection != null) { // Disconnect first, then close gatt gattConnection?.disconnect() } else { diff --git a/pump/pump-core/src/main/java/info/nightscout/pump/core/utils/ByteUtil.java b/pump/pump-core/src/main/java/info/nightscout/pump/core/utils/ByteUtil.java index fef889df2e..1e7442e3a6 100644 --- a/pump/pump-core/src/main/java/info/nightscout/pump/core/utils/ByteUtil.java +++ b/pump/pump-core/src/main/java/info/nightscout/pump/core/utils/ByteUtil.java @@ -15,24 +15,11 @@ public class ByteUtil { private final static String HEX_DIGITS_STR = "0123456789ABCDEF"; - public static byte highByte(short s) { - return (byte) (s / 256); - } - - - public static byte lowByte(short s) { - return (byte) (s % 256); - } - - + /** @noinspection SpellCheckingInspection*/ public static int asUINT8(byte b) { return (b < 0) ? b + 256 : b; } - public static int asUINT8(Integer b) { - return (b < 0) ? b + 256 : b; - } - public static byte[] getBytesFromInt16(int value) { byte[] array = getBytesFromInt(value); return new byte[]{array[2], array[3]}; @@ -79,67 +66,64 @@ public class ByteUtil { public static byte[] substring(byte[] a, int start, int len) { - byte[] rval = new byte[len]; - System.arraycopy(a, start, rval, 0, len); - return rval; + byte[] rVal = new byte[len]; + System.arraycopy(a, start, rVal, 0, len); + return rVal; } public static byte[] substring(List a, int start, int len) { - byte[] rval = new byte[len]; + byte[] rVal = new byte[len]; for (int i = start, j = 0; i < start + len; i++, j++) { - rval[j] = a.get(i); + rVal[j] = a.get(i); } - return rval; + return rVal; } public static byte[] substring(byte[] a, int start) { int len = a.length - start; - byte[] rval = new byte[len]; - System.arraycopy(a, start, rval, 0, len); - return rval; + byte[] rVal = new byte[len]; + System.arraycopy(a, start, rVal, 0, len); + return rVal; } public static String shortHexString(byte[] ra) { - String rval = ""; + StringBuilder rVal = new StringBuilder(); if (ra == null) { - return rval; + return rVal.toString(); } if (ra.length == 0) { - return rval; + return rVal.toString(); } for (int i = 0; i < ra.length; i++) { - rval = rval + HEX_DIGITS[(ra[i] & 0xF0) >> 4]; - rval = rval + HEX_DIGITS[(ra[i] & 0x0F)]; + rVal.append(HEX_DIGITS[(ra[i] & 0xF0) >> 4]); + rVal.append(HEX_DIGITS[(ra[i] & 0x0F)]); if (i < ra.length - 1) { - rval = rval + " "; + rVal.append(" "); } } - return rval; + return rVal.toString(); } public static String shortHexStringWithoutSpaces(byte[] byteArray) { - String hexString = ""; + StringBuilder hexString = new StringBuilder(); if (byteArray == null) { - return hexString; - } - if (byteArray.length == 0) { - return hexString; + return hexString.toString(); } for (byte b : byteArray) { - hexString = hexString + HEX_DIGITS[(b & 0xF0) >> 4]; - hexString = hexString + HEX_DIGITS[(b & 0x0F)]; + hexString.append(HEX_DIGITS[(b & 0xF0) >> 4]); + hexString.append(HEX_DIGITS[(b & 0x0F)]); } - return hexString; + return hexString.toString(); } public static String shortHexString(List list) { - byte[] abyte0 = getByteArrayFromList(list); + byte[] aByte0 = getByteArrayFromList(list); - return shortHexString(abyte0); + return shortHexString(aByte0); } @@ -148,23 +132,9 @@ public class ByteUtil { } - public static String showPrintable(byte[] ra) { - String s = ""; - for (int i = 0; i < ra.length; i++) { - char c = (char) ra[i]; - if (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) { - s = s + c; - } else { - s = s + '.'; - } - } - return s; - } - - public static byte[] fromHexString(String src) { String s = src.toUpperCase(); - byte[] rval = new byte[]{}; + byte[] rVal = new byte[]{}; if ((s.length() % 2) != 0) { // invalid hex string! return null; @@ -180,14 +150,14 @@ public class ByteUtil { // Not a hex digit return null; } - rval = concat(rval, (byte) (highNibbleOrd * 16 + lowNibbleOrd)); + rVal = concat(rVal, (byte) (highNibbleOrd * 16 + lowNibbleOrd)); } - return rval; + return rVal; } public static List getListFromByteArray(byte[] array) { - List listOut = new ArrayList(); + List listOut = new ArrayList<>(); for (byte val : array) { listOut.add(val); @@ -334,42 +304,14 @@ public class ByteUtil { public static int makeUnsignedShort(int i, int j) { - int k = (i & 0xff) << 8 | j & 0xff; - return k; - } - - - /** - * Gets the correct hex value. - * - * @param inp the inp - * @return the correct hex value - */ - public static String getCorrectHexValue(int inp) { - String hx = Integer.toHexString((char) inp); - - if (hx.length() == 0) - return "00"; - else if (hx.length() == 1) - return "0" + hx; - else if (hx.length() == 2) - return hx; - else if (hx.length() == 4) - return hx.substring(2); - else { - System.out.println("Hex Error: " + inp); - } - - return null; + return (i & 0xff) << 8 | j & 0xff; } public static String getCorrectHexValue(byte inp) { String hx = Integer.toHexString((char) inp); - if (hx.length() == 0) - return "00"; - else if (hx.length() == 1) + if (hx.length() == 1) return "0" + hx; else if (hx.length() == 2) return hx; @@ -383,15 +325,15 @@ public class ByteUtil { } - public static String getHex(byte[] abyte0) { - return abyte0 != null ? getHex(abyte0, abyte0.length) : null; + public static String getHex(byte[] aByte0) { + return aByte0 != null ? getHex(aByte0, aByte0.length) : null; } - public static String getString(short[] abyte0) { + public static String getString(short[] aByte0) { StringBuilder sb = new StringBuilder(); - for (short i : abyte0) { + for (short i : aByte0) { sb.append(i); sb.append(" "); } @@ -402,25 +344,25 @@ public class ByteUtil { public static String getHex(List list) { - byte[] abyte0 = getByteArrayFromList(list); + byte[] aByte0 = getByteArrayFromList(list); - return abyte0 != null ? getHex(abyte0, abyte0.length) : null; + return getHex(aByte0, aByte0.length); } - public static String getHex(byte[] abyte0, int i) { - StringBuffer stringbuffer = new StringBuffer(); - if (abyte0 != null) { - i = Math.min(i, abyte0.length); + public static String getHex(byte[] aByte0, int i) { + StringBuilder sb = new StringBuilder(); + if (aByte0 != null) { + i = Math.min(i, aByte0.length); for (int j = 0; j < i; j++) { - stringbuffer.append(shortHexString(abyte0[j])); + sb.append(shortHexString(aByte0[j])); if (j < i - 1) { - stringbuffer.append(" "); + sb.append(" "); } } } - return new String(stringbuffer); + return new String(sb); } @@ -441,11 +383,6 @@ public class ByteUtil { } - // public String getHexCompact(int i) { - // long l = i != -1 ? convertUnsignedIntToLong(i) : i; - // return getHexCompact(l); - // } - public static String getHexCompact(int l) { String s = Long.toHexString(l).toUpperCase(); String s1 = isOdd(s.length()) ? "0" : ""; @@ -468,17 +405,6 @@ public class ByteUtil { } - public static String getCompactString(byte[] data) { - if (data == null) - return "null"; - - String vval2 = ByteUtil.getHex(data); - vval2 = vval2.replace(" 0x", ""); - vval2 = vval2.replace("0x", ""); - return vval2; - } - - // 000300050100C800A0 public static byte[] createByteArrayFromCompactString(String dataFull) { return createByteArrayFromCompactString(dataFull, 0, dataFull.length()); @@ -503,11 +429,6 @@ public class ByteUtil { } - public static byte[] createByteArrayFromCompactString(String dataFull, int startIndex) { - return createByteArrayFromCompactString(dataFull, startIndex, dataFull.length()); - } - - public static byte[] createByteArrayFromCompactString(String dataFull, int startIndex, int length) { String data = dataFull.substring(startIndex);