1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 14:31:23 +02:00

Rename Converters.toUnsignedInt* to Convertors.toInt*.

These functions work equally well with signed values.
This commit is contained in:
Maks Verver
2018-10-13 14:40:54 +02:00
parent 303aedb4e7
commit 94d138b9af
5 changed files with 13 additions and 13 deletions

View File

@@ -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),

View File

@@ -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]};

View File

@@ -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],

View File

@@ -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);

View File

@@ -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));
}
}