diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java index 2b646a6d..17313ef4 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java @@ -588,7 +588,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication { private void updateDateTime() { // Update date/time of the scale long unixTime = System.currentTimeMillis() / 1000L; - byte[] unixTimeBytes = Converters.toUnsignedInt32Be(unixTime); + byte[] unixTimeBytes = Converters.toInt32Be(unixTime); Timber.d("Write new Date/Time: %d (%s)", unixTime, byteInHex(unixTimeBytes)); writeBytes(new byte[]{(byte) getAlternativeStartByte(9), diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java index f80ae6bb..f496b8df 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java @@ -73,7 +73,7 @@ public class BluetoothMedisanaBS44x extends BluetoothCommunication { // send magic number to receive weight data long timestamp = new Date().getTime() / 1000; timestamp -= SCALE_UNIX_TIMESTAMP_OFFSET; - byte[] date = Converters.toUnsignedInt32Le(timestamp); + byte[] date = Converters.toInt32Le(timestamp); byte[] magicBytes = new byte[] {(byte)0x02, date[0], date[1], date[2], date[3]}; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java index fcd2993d..4fdc7b65 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java @@ -58,7 +58,7 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication { protected boolean nextInitCmd(int stateNr) { switch (stateNr) { case 0: - byte[] userId = Converters.toUnsignedInt16Be(getUniqueNumber()); + byte[] userId = Converters.toInt16Be(getUniqueNumber()); final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); byte sex = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0x02; @@ -74,7 +74,7 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication { writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query); break; case 1: - byte[] unixTime = Converters.toUnsignedInt32Be(new Date().getTime() / 1000); + byte[] unixTime = Converters.toInt32Be(new Date().getTime() / 1000); byte[] set_time = new byte[]{(byte)0x0d, (byte) 0x0d, (byte) 0x11, unixTime[0], unixTime[1], unixTime[2], unixTime[3], diff --git a/android_app/app/src/main/java/com/health/openscale/core/utils/Converters.java b/android_app/app/src/main/java/com/health/openscale/core/utils/Converters.java index 1f755885..fc3a5caf 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/utils/Converters.java +++ b/android_app/app/src/main/java/com/health/openscale/core/utils/Converters.java @@ -247,7 +247,7 @@ public class Converters { return value; } - public static byte[] toUnsignedInt16Be(int value) { + public static byte[] toInt16Be(int value) { byte[] data = new byte[2]; data[0] = (byte) ((value >> 8) & 0xFF); data[1] = (byte) (value & 0xFF); @@ -277,7 +277,7 @@ public class Converters { return value; } - public static byte[] toUnsignedInt32Le(long value) { + public static byte[] toInt32Le(long value) { byte[] data = new byte[4]; data[3] = (byte) ((value >> 24) & 0xFF); data[2] = (byte) ((value >> 16) & 0xFF); @@ -286,7 +286,7 @@ public class Converters { return data; } - public static byte[] toUnsignedInt32Be(long value) { + public static byte[] toInt32Be(long value) { byte[] data = new byte[4]; data[0] = (byte) ((value >> 24) & 0xFF); data[1] = (byte) ((value >> 16) & 0xFF); diff --git a/android_app/app/src/test/java/com/health/openscale/ConvertersTest.java b/android_app/app/src/test/java/com/health/openscale/ConvertersTest.java index 4b95155c..6deead16 100644 --- a/android_app/app/src/test/java/com/health/openscale/ConvertersTest.java +++ b/android_app/app/src/test/java/com/health/openscale/ConvertersTest.java @@ -96,10 +96,10 @@ public class ConvertersTest { assertEquals(0x107f, Converters.fromUnsignedInt16Be(data, 3)); data = new byte[]{(byte) 0xff, (byte) 0xfe}; - assertArrayEquals(data, Converters.toUnsignedInt16Be(0xfffe)); + assertArrayEquals(data, Converters.toInt16Be(0xfffe)); assertEquals(0xffff, Converters.fromUnsignedInt16Be( - Converters.toUnsignedInt16Be(0xffff), 0)); + Converters.toInt16Be(0xffff), 0)); } @Test @@ -130,13 +130,13 @@ public class ConvertersTest { assertEquals(0x1ff00L, Converters.fromUnsignedInt32Be(data, 1)); data = new byte[]{(byte) 0xff, (byte) 0xfe, (byte) 0xfd, (byte) 0xfc}; - assertArrayEquals(data, Converters.toUnsignedInt32Le(0xfcfdfeffL)); - assertArrayEquals(data, Converters.toUnsignedInt32Be(0xfffefdfcL)); + assertArrayEquals(data, Converters.toInt32Le(0xfcfdfeffL)); + assertArrayEquals(data, Converters.toInt32Be(0xfffefdfcL)); assertEquals(0xffffffffL, Converters.fromUnsignedInt32Le( - Converters.toUnsignedInt32Le(0xffffffffL), 0)); + Converters.toInt32Le(0xffffffffL), 0)); assertEquals(0xffffffffL, Converters.fromUnsignedInt32Be( - Converters.toUnsignedInt32Be(0xffffffffL), 0)); + Converters.toInt32Be(0xffffffffL), 0)); } }