mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-21 16:02:04 +02:00
Rename byte[] to int converters
This commit is contained in:
@@ -435,7 +435,7 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
|
|
||||||
if ((data[0] & 0xFF) == startByte && (data[1] & 0xFF) == 0x58) {
|
if ((data[0] & 0xFF) == startByte && (data[1] & 0xFF) == 0x58) {
|
||||||
Log.d(TAG, "Active measurement");
|
Log.d(TAG, "Active measurement");
|
||||||
float weight = parseKiloGram(data, 3);
|
float weight = getKiloGram(data, 3);
|
||||||
if ((data[2] & 0xFF) != 0x00) {
|
if ((data[2] & 0xFF) != 0x00) {
|
||||||
// temporary value;
|
// temporary value;
|
||||||
sendMessage(R.string.info_measuring, weight);
|
sendMessage(R.string.info_measuring, weight);
|
||||||
@@ -508,14 +508,14 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private float parseKiloGram(byte[] data, int offset) {
|
private float getKiloGram(byte[] data, int offset) {
|
||||||
// Unit is 50 g
|
// Unit is 50 g
|
||||||
return Converters.parseUnsignedInt16Be(data, offset) * 50.0f / 1000.0f;
|
return Converters.fromUnsignedInt16Be(data, offset) * 50.0f / 1000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float parsePercent(byte[] data, int offset) {
|
private float getPercent(byte[] data, int offset) {
|
||||||
// Unit is 0.1 %
|
// Unit is 0.1 %
|
||||||
return Converters.parseUnsignedInt16Be(data, offset) / 10.0f;
|
return Converters.fromUnsignedInt16Be(data, offset) / 10.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScaleMeasurement parseScaleData(byte[] data) throws ParseException {
|
private ScaleMeasurement parseScaleData(byte[] data) throws ParseException {
|
||||||
@@ -524,15 +524,15 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long timestamp = ByteBuffer.wrap(data, 0, 4).getInt() * 1000L;
|
long timestamp = ByteBuffer.wrap(data, 0, 4).getInt() * 1000L;
|
||||||
float weight = parseKiloGram(data, 4);
|
float weight = getKiloGram(data, 4);
|
||||||
int impedance = Converters.parseUnsignedInt16Be(data, 6);
|
int impedance = Converters.fromUnsignedInt16Be(data, 6);
|
||||||
float fat = parsePercent(data, 8);
|
float fat = getPercent(data, 8);
|
||||||
float water = parsePercent(data, 10);
|
float water = getPercent(data, 10);
|
||||||
float muscle = parsePercent(data, 12);
|
float muscle = getPercent(data, 12);
|
||||||
float bone = parseKiloGram(data, 14);
|
float bone = getKiloGram(data, 14);
|
||||||
int bmr = Converters.parseUnsignedInt16Be(data, 16);
|
int bmr = Converters.fromUnsignedInt16Be(data, 16);
|
||||||
int amr = Converters.parseUnsignedInt16Be(data, 18);
|
int amr = Converters.fromUnsignedInt16Be(data, 18);
|
||||||
float bmi = Converters.parseUnsignedInt16Be(data, 20) / 10.0f;
|
float bmi = Converters.fromUnsignedInt16Be(data, 20) / 10.0f;
|
||||||
|
|
||||||
ScaleMeasurement receivedMeasurement = new ScaleMeasurement();
|
ScaleMeasurement receivedMeasurement = new ScaleMeasurement();
|
||||||
receivedMeasurement.setDateTime(new Date(timestamp));
|
receivedMeasurement.setDateTime(new Date(timestamp));
|
||||||
|
@@ -124,7 +124,7 @@ public class Converters {
|
|||||||
return kg;
|
return kg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseUnsignedInt16Be(byte[] data, int offset) {
|
public static int fromUnsignedInt16Be(byte[] data, int offset) {
|
||||||
int value = (data[offset] & 0xFF) << 8;
|
int value = (data[offset] & 0xFF) << 8;
|
||||||
value += data[offset + 1] & 0xFF;
|
value += data[offset + 1] & 0xFF;
|
||||||
return value;
|
return value;
|
||||||
|
@@ -81,11 +81,11 @@ public class ConvertersTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unsignedIntConverters() throws Exception {
|
public void unsignedInt16Converters() throws Exception {
|
||||||
byte[] data = new byte[]{(byte) 0xfd, (byte) 0xfe, (byte) 0xfc, (byte) 0x10, (byte) 0x7f};
|
byte[] data = new byte[]{(byte) 0xfd, (byte) 0xfe, (byte) 0xfc, (byte) 0x10, (byte) 0x7f};
|
||||||
assertEquals(0xfdfe, Converters.parseUnsignedInt16Be(data, 0));
|
assertEquals(0xfdfe, Converters.fromUnsignedInt16Be(data, 0));
|
||||||
assertEquals(0xfefc, Converters.parseUnsignedInt16Be(data, 1));
|
assertEquals(0xfefc, Converters.fromUnsignedInt16Be(data, 1));
|
||||||
assertEquals(0xfc10, Converters.parseUnsignedInt16Be(data, 2));
|
assertEquals(0xfc10, Converters.fromUnsignedInt16Be(data, 2));
|
||||||
assertEquals(0x107f, Converters.parseUnsignedInt16Be(data, 3));
|
assertEquals(0x107f, Converters.fromUnsignedInt16Be(data, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user