From 303aedb4e7de7a40c5987ab573373b3d03931a22 Mon Sep 17 00:00:00 2001 From: Maks Verver Date: Sat, 13 Oct 2018 14:13:02 +0200 Subject: [PATCH] Reuse Converters.fromUnsignedInt24Le() to implement getBase10Float(). From the observed data, it's not clear whether the mantissa should be interpreted as signed or not. Since two metrics encoded as base-10 floats (weight and resistance) cannot be negative, and the Trisa Health Vital app interprets the mantissa as unsigned, we will treat it as unsigned here, too. --- .../openscale/core/bluetooth/lib/TrisaBodyAnalyzeLib.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/TrisaBodyAnalyzeLib.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/TrisaBodyAnalyzeLib.java index c25d2f99..3e918464 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/TrisaBodyAnalyzeLib.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/TrisaBodyAnalyzeLib.java @@ -51,8 +51,7 @@ public class TrisaBodyAnalyzeLib { * @throws IndexOutOfBoundsException if {@code offset < 0} or {@code offset + 4> data.length} */ public static double getBase10Float(byte[] data, int offset) { - int mantissa = (data[offset] & 0xff) | ((data[offset + 1] & 0xff) << 8) | - ((data[offset + 2] & 0xff) << 16); + int mantissa = Converters.fromUnsignedInt24Le(data, offset); int exponent = data[offset + 3]; // note: byte is signed. return mantissa * Math.pow(10, exponent); }