mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-24 09:13:04 +02:00
Rename Converters.toUnsignedInt*
to Convertors.toInt*
.
These functions work equally well with signed values.
This commit is contained in:
@@ -588,7 +588,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication {
|
|||||||
private void updateDateTime() {
|
private void updateDateTime() {
|
||||||
// Update date/time of the scale
|
// Update date/time of the scale
|
||||||
long unixTime = System.currentTimeMillis() / 1000L;
|
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));
|
Timber.d("Write new Date/Time: %d (%s)", unixTime, byteInHex(unixTimeBytes));
|
||||||
|
|
||||||
writeBytes(new byte[]{(byte) getAlternativeStartByte(9),
|
writeBytes(new byte[]{(byte) getAlternativeStartByte(9),
|
||||||
|
@@ -73,7 +73,7 @@ public class BluetoothMedisanaBS44x extends BluetoothCommunication {
|
|||||||
// send magic number to receive weight data
|
// send magic number to receive weight data
|
||||||
long timestamp = new Date().getTime() / 1000;
|
long timestamp = new Date().getTime() / 1000;
|
||||||
timestamp -= SCALE_UNIX_TIMESTAMP_OFFSET;
|
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]};
|
byte[] magicBytes = new byte[] {(byte)0x02, date[0], date[1], date[2], date[3]};
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
|
|||||||
protected boolean nextInitCmd(int stateNr) {
|
protected boolean nextInitCmd(int stateNr) {
|
||||||
switch (stateNr) {
|
switch (stateNr) {
|
||||||
case 0:
|
case 0:
|
||||||
byte[] userId = Converters.toUnsignedInt16Be(getUniqueNumber());
|
byte[] userId = Converters.toInt16Be(getUniqueNumber());
|
||||||
|
|
||||||
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||||
byte sex = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0x02;
|
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);
|
writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
|
||||||
break;
|
break;
|
||||||
case 1:
|
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,
|
byte[] set_time = new byte[]{(byte)0x0d, (byte) 0x0d, (byte) 0x11,
|
||||||
unixTime[0], unixTime[1], unixTime[2], unixTime[3],
|
unixTime[0], unixTime[1], unixTime[2], unixTime[3],
|
||||||
|
@@ -247,7 +247,7 @@ public class Converters {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] toUnsignedInt16Be(int value) {
|
public static byte[] toInt16Be(int value) {
|
||||||
byte[] data = new byte[2];
|
byte[] data = new byte[2];
|
||||||
data[0] = (byte) ((value >> 8) & 0xFF);
|
data[0] = (byte) ((value >> 8) & 0xFF);
|
||||||
data[1] = (byte) (value & 0xFF);
|
data[1] = (byte) (value & 0xFF);
|
||||||
@@ -277,7 +277,7 @@ public class Converters {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] toUnsignedInt32Le(long value) {
|
public static byte[] toInt32Le(long value) {
|
||||||
byte[] data = new byte[4];
|
byte[] data = new byte[4];
|
||||||
data[3] = (byte) ((value >> 24) & 0xFF);
|
data[3] = (byte) ((value >> 24) & 0xFF);
|
||||||
data[2] = (byte) ((value >> 16) & 0xFF);
|
data[2] = (byte) ((value >> 16) & 0xFF);
|
||||||
@@ -286,7 +286,7 @@ public class Converters {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] toUnsignedInt32Be(long value) {
|
public static byte[] toInt32Be(long value) {
|
||||||
byte[] data = new byte[4];
|
byte[] data = new byte[4];
|
||||||
data[0] = (byte) ((value >> 24) & 0xFF);
|
data[0] = (byte) ((value >> 24) & 0xFF);
|
||||||
data[1] = (byte) ((value >> 16) & 0xFF);
|
data[1] = (byte) ((value >> 16) & 0xFF);
|
||||||
|
@@ -96,10 +96,10 @@ public class ConvertersTest {
|
|||||||
assertEquals(0x107f, Converters.fromUnsignedInt16Be(data, 3));
|
assertEquals(0x107f, Converters.fromUnsignedInt16Be(data, 3));
|
||||||
|
|
||||||
data = new byte[]{(byte) 0xff, (byte) 0xfe};
|
data = new byte[]{(byte) 0xff, (byte) 0xfe};
|
||||||
assertArrayEquals(data, Converters.toUnsignedInt16Be(0xfffe));
|
assertArrayEquals(data, Converters.toInt16Be(0xfffe));
|
||||||
assertEquals(0xffff,
|
assertEquals(0xffff,
|
||||||
Converters.fromUnsignedInt16Be(
|
Converters.fromUnsignedInt16Be(
|
||||||
Converters.toUnsignedInt16Be(0xffff), 0));
|
Converters.toInt16Be(0xffff), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -130,13 +130,13 @@ public class ConvertersTest {
|
|||||||
assertEquals(0x1ff00L, Converters.fromUnsignedInt32Be(data, 1));
|
assertEquals(0x1ff00L, Converters.fromUnsignedInt32Be(data, 1));
|
||||||
|
|
||||||
data = new byte[]{(byte) 0xff, (byte) 0xfe, (byte) 0xfd, (byte) 0xfc};
|
data = new byte[]{(byte) 0xff, (byte) 0xfe, (byte) 0xfd, (byte) 0xfc};
|
||||||
assertArrayEquals(data, Converters.toUnsignedInt32Le(0xfcfdfeffL));
|
assertArrayEquals(data, Converters.toInt32Le(0xfcfdfeffL));
|
||||||
assertArrayEquals(data, Converters.toUnsignedInt32Be(0xfffefdfcL));
|
assertArrayEquals(data, Converters.toInt32Be(0xfffefdfcL));
|
||||||
assertEquals(0xffffffffL,
|
assertEquals(0xffffffffL,
|
||||||
Converters.fromUnsignedInt32Le(
|
Converters.fromUnsignedInt32Le(
|
||||||
Converters.toUnsignedInt32Le(0xffffffffL), 0));
|
Converters.toInt32Le(0xffffffffL), 0));
|
||||||
assertEquals(0xffffffffL,
|
assertEquals(0xffffffffL,
|
||||||
Converters.fromUnsignedInt32Be(
|
Converters.fromUnsignedInt32Be(
|
||||||
Converters.toUnsignedInt32Be(0xffffffffL), 0));
|
Converters.toInt32Be(0xffffffffL), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user