use of com.health.openscale.core.bluetooth.lib.TrisaBodyAnalyzeLib in project openScale by oliexdev.
the class BluetoothQNScale method parseCustom1Data.
private void parseCustom1Data(byte[] data) {
StringBuilder sb = new StringBuilder();
int len = data.length;
for (int i = 0; i < len; i++) {
sb.append(String.format("%02X ", new Object[] { Byte.valueOf(data[i]) }));
}
Timber.d(sb.toString());
float weightKg = 0;
switch(data[0]) {
case (byte) 16:
if (data[5] == (byte) 0) {
this.hasReceived = false;
// this.callback.onUnsteadyWeight(this.qnBleDevice, decodeWeight(data[3], data[4]));
} else if (data[5] == (byte) 1) {
// writeData(CmdBuilder.buildOverCmd(this.protocolType, 16));
if (!this.hasReceived) {
this.hasReceived = true;
weightKg = decodeWeight(data[3], data[4]);
int weightByteOne = data[3] & 0xFF;
int weightByteTwo = data[4] & 0xFF;
Timber.d("Weight byte 1 %d", weightByteOne);
Timber.d("Weight byte 2 %d", weightByteTwo);
Timber.d("Raw Weight: %f", weightKg);
if (weightKg > 0.0f) {
// QNData md = buildMeasuredData(this.qnUser, weight, decodeIntegerValue
// (data[6], data[7]), decodeIntegerValue(data[8], data[9]),
// new Date(), data);
int resistance1 = decodeIntegerValue(data[6], data[7]);
int resistance2 = decodeIntegerValue(data[8], data[9]);
Timber.d("resistance1: %d", resistance1);
Timber.d("resistance2: %d", resistance2);
final ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
Timber.d("scale user " + scaleUser);
ScaleMeasurement btScaleMeasurement = new ScaleMeasurement();
// TrisaBodyAnalyzeLib gives almost simillar values for QNScale body fat calcualtion
TrisaBodyAnalyzeLib qnscalelib = new TrisaBodyAnalyzeLib(scaleUser.getGender().isMale() ? 1 : 0, scaleUser.getAge(), (int) scaleUser.getBodyHeight());
// Now much difference between resistance1 and resistance2.
// Will use resistance 1 for now
float impedance = resistance1 < 410f ? 3.0f : 0.3f * (resistance1 - 400f);
btScaleMeasurement.setFat(qnscalelib.getFat(weightKg, impedance));
btScaleMeasurement.setWater(qnscalelib.getWater(weightKg, impedance));
btScaleMeasurement.setMuscle(qnscalelib.getMuscle(weightKg, impedance));
btScaleMeasurement.setBone(qnscalelib.getBone(weightKg, impedance));
btScaleMeasurement.setWeight(weightKg);
addScaleMeasurement(btScaleMeasurement);
}
}
}
break;
case (byte) 18:
byte protocolType = data[2];
this.weightScale = data[10] == (byte) 1 ? 100.0f : 10.0f;
int[] iArr = new int[5];
// writeData(CmdBuilder.buildCmd(19, this.protocolType, 1, 16, 0, 0, 0));
break;
case (byte) 33:
// writeBleData(CmdBuilder.buildCmd(34, this.protocolType, new int[0]));
break;
case (byte) 35:
weightKg = decodeWeight(data[9], data[10]);
if (weightKg > 0.0f) {
int resistance = decodeIntegerValue(data[11], data[12]);
int resistance500 = decodeIntegerValue(data[13], data[14]);
long differTime = 0;
for (int i = 0; i < 4; i++) {
differTime |= (((long) data[i + 5]) & 255) << (i * 8);
}
Date date = new Date(MILLIS_2000_YEAR + (1000 * differTime));
if (data[3] == data[4]) {
// TODO
}
}
break;
}
}
use of com.health.openscale.core.bluetooth.lib.TrisaBodyAnalyzeLib in project openScale by oliexdev.
the class BluetoothTrisaBodyAnalyze method parseScaleMeasurementData.
public ScaleMeasurement parseScaleMeasurementData(byte[] data, ScaleUser user) {
// ScaleMeasurement needs.
if (data.length < 9) {
// data is too short
return null;
}
byte infoByte = data[0];
boolean hasTimestamp = (infoByte & 1) == 1;
boolean hasResistance1 = (infoByte & 2) == 2;
boolean hasResistance2 = (infoByte & 4) == 4;
if (!hasTimestamp) {
return null;
}
float weightKg = getBase10Float(data, 1);
int deviceTimestamp = Converters.fromSignedInt32Le(data, 5);
ScaleMeasurement measurement = new ScaleMeasurement();
measurement.setDateTime(new Date(convertDeviceTimestampToJava(deviceTimestamp)));
measurement.setWeight((float) weightKg);
// Only resistance 2 is used; resistance 1 is 0, even if it is present.
int resistance2Offset = 9 + (hasResistance1 ? 4 : 0);
if (hasResistance2 && resistance2Offset + 4 <= data.length && isValidUser(user)) {
// Calculate body composition statistics from measured weight & resistance, combined
// with age, height and sex from the user profile. The accuracy of the resulting figures
// is questionable, but it's better than nothing. Even if the absolute numbers aren't
// very meaningful, it might still be useful to track changes over time.
float resistance2 = getBase10Float(data, resistance2Offset);
float impedance = resistance2 < 410f ? 3.0f : 0.3f * (resistance2 - 400f);
TrisaBodyAnalyzeLib trisaBodyAnalyzeLib = new TrisaBodyAnalyzeLib(user.getGender().isMale() ? 1 : 0, user.getAge(), user.getBodyHeight());
measurement.setFat(trisaBodyAnalyzeLib.getFat(weightKg, impedance));
measurement.setWater(trisaBodyAnalyzeLib.getWater(weightKg, impedance));
measurement.setMuscle(trisaBodyAnalyzeLib.getMuscle(weightKg, impedance));
measurement.setBone(trisaBodyAnalyzeLib.getBone(weightKg, impedance));
}
return measurement;
}
Aggregations