From dccb8ed1c49477de91b2a06378022b1e51b9ae3e Mon Sep 17 00:00:00 2001 From: mormegil Date: Sat, 17 Jun 2023 15:08:11 +0200 Subject: [PATCH] Changes suggested in PR - use `BLETypeConversions`, added the missing functions there (+ unit tests for all) - change Java package of Protobuf definitions so that they are not discarded by Proguard -- +add subpackages to the Proguard rules so we can subdivide the classes + disable device-specific settings for Vivomove (no settings yet) --- app/proguard-rules.pro | 2 +- .../vivomovehr/VivomoveHrCoordinator.java | 6 + .../service/btle/BLETypeConversions.java | 41 ++++ .../devices/vivomovehr/BinaryUtils.java | 50 ----- .../vivomovehr/RealTimeActivityHandler.java | 33 ++- .../devices/vivomovehr/VivomoveHrSupport.java | 18 +- .../vivomovehr/ancs/AncsControlCommand.java | 10 +- .../devices/vivomovehr/fit/FitParser.java | 6 +- .../devices/vivomovehr/fit/FitSerializer.java | 10 +- .../messages/AuthNegotiationMessage.java | 6 +- .../messages/BatteryStatusMessage.java | 6 +- .../messages/ConfigurationMessage.java | 6 +- .../messages/CreateFileRequestMessage.java | 6 +- .../CurrentTimeRequestResponseMessage.java | 6 +- .../DeviceInformationResponseMessage.java | 6 +- .../DirectoryFileFilterRequestMessage.java | 6 +- .../messages/DownloadRequestMessage.java | 6 +- .../messages/FileTransferDataMessage.java | 6 +- .../FileTransferDataResponseMessage.java | 6 +- .../vivomovehr/messages/FitDataMessage.java | 6 +- .../messages/FitDefinitionMessage.java | 6 +- .../messages/GenericResponseMessage.java | 6 +- .../GncsControlPointResponseMessage.java | 6 +- .../messages/GncsDataSourceMessage.java | 6 +- .../GncsNotificationSourceMessage.java | 6 +- .../vivomovehr/messages/MessageReader.java | 10 +- .../vivomovehr/messages/MessageWriter.java | 10 +- ...sicControlCapabilitiesResponseMessage.java | 6 +- .../MusicControlEntityUpdateMessage.java | 6 +- ...ionServiceSubscriptionResponseMessage.java | 6 +- .../messages/ProtobufRequestMessage.java | 6 +- .../vivomovehr/messages/RequestMessage.java | 9 +- .../messages/SetDeviceSettingsMessage.java | 6 +- .../SupportedFileTypesRequestMessage.java | 6 +- .../messages/SyncRequestMessage.java | 4 +- .../messages/SystemEventMessage.java | 6 +- .../messages/UploadRequestMessage.java | 6 +- .../WeatherRequestResponseMessage.java | 6 +- .../proto/garmin_vivomovehr/gdi_core.proto | 2 +- .../garmin_vivomovehr/gdi_device_status.proto | 2 +- .../garmin_vivomovehr/gdi_find_my_watch.proto | 2 +- .../garmin_vivomovehr/gdi_smart_proto.proto | 2 +- .../gdi_sms_notification.proto | 2 +- .../test/BLETypeConversionsTest.java | 201 +++++++++++++++++- 44 files changed, 369 insertions(+), 201 deletions(-) delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/BinaryUtils.java diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 535de5252..9e987a2b0 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -62,4 +62,4 @@ } # Keep generated protobuf classes --keep class nodomain.freeyourgadget.gadgetbridge.proto.* { *; } +-keep class nodomain.freeyourgadget.gadgetbridge.proto.** { *; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java index 211d67c35..ae7034775 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/vivomovehr/VivomoveHrCoordinator.java @@ -107,6 +107,12 @@ public class VivomoveHrCoordinator extends AbstractDeviceCoordinator { return true; } + @Override + public int[] getSupportedDeviceSpecificSettings(GBDevice device) { + // no device-specific settings yet + return null; + } + @Override public boolean supportsFindDevice() { return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java index 7814442e6..e83c87624 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java @@ -164,6 +164,10 @@ public class BLETypeConversions { return value & 0xff; } + public static int toUnsigned(byte[] bytes, int offset) { + return bytes[offset + 0] & 0xff; + } + public static int toUint16(byte value) { return toUnsigned(value); } @@ -188,6 +192,16 @@ public class BLETypeConversions { return (bytes[offset + 0] & 0xff) | ((bytes[offset + 1] & 0xff) << 8) | ((bytes[offset + 2] & 0xff) << 16) | ((bytes[offset + 3] & 0xff) << 24); } + public static long toUint64(byte... bytes) { + return (bytes[0] & 0xFFL) | ((bytes[1] & 0xFFL) << 8) | ((bytes[2] & 0xFFL) << 16) | ((bytes[3] & 0xFFL) << 24) | + ((bytes[4] & 0xFFL) << 32) | ((bytes[5] & 0xFFL) << 40) | ((bytes[6] & 0xFFL) << 48) | ((bytes[7] & 0xFFL) << 56); + } + + public static long toUint64(byte[] bytes, int offset) { + return (bytes[offset + 0] & 0xFFL) | ((bytes[offset + 1] & 0xFFL) << 8) | ((bytes[offset + 2] & 0xFFL) << 16) | ((bytes[offset + 3] & 0xFFL) << 24) | + ((bytes[offset + 4] & 0xFFL) << 32) | ((bytes[offset + 5] & 0xFFL) << 40) | ((bytes[offset + 6] & 0xFFL) << 48) | ((bytes[offset + 7] & 0xFFL) << 56); + } + public static byte[] fromUint16(int value) { return new byte[] { (byte) (value & 0xff), @@ -229,6 +243,33 @@ public class BLETypeConversions { return (byte) (value & 0xff); } + public static void writeUint8(byte[] array, int offset, int value) { + array[offset] = (byte) value; + } + + public static void writeUint16(byte[] array, int offset, int value) { + array[offset] = (byte) value; + array[offset + 1] = (byte) (value >> 8); + } + + public static void writeUint32(byte[] array, int offset, int value) { + array[offset] = (byte) value; + array[offset + 1] = (byte) (value >> 8); + array[offset + 2] = (byte) (value >> 16); + array[offset + 3] = (byte) (value >> 24); + } + + public static void writeUint64(byte[] array, int offset, long value) { + array[offset] = (byte) value; + array[offset + 1] = (byte) (value >> 8); + array[offset + 2] = (byte) (value >> 16); + array[offset + 3] = (byte) (value >> 24); + array[offset + 4] = (byte) (value >> 32); + array[offset + 5] = (byte) (value >> 40); + array[offset + 6] = (byte) (value >> 48); + array[offset + 7] = (byte) (value >> 56); + } + /** * Creates a calendar object representing the current date and time. */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/BinaryUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/BinaryUtils.java deleted file mode 100644 index 040b2d1ed..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/BinaryUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr; - -public final class BinaryUtils { - private BinaryUtils() { - } - - public static int readByte(byte[] array, int offset) { - return array[offset] & 0xFF; - } - - public static int readShort(byte[] array, int offset) { - return (array[offset] & 0xFF) | ((array[offset + 1] & 0xFF) << 8); - } - - public static int readInt(byte[] array, int offset) { - return (array[offset] & 0xFF) | ((array[offset + 1] & 0xFF) << 8) | ((array[offset + 2] & 0xFF) << 16) | ((array[offset + 3] & 0xFF) << 24); - } - - public static long readLong(byte[] array, int offset) { - return (array[offset] & 0xFFL) | ((array[offset + 1] & 0xFFL) << 8) | ((array[offset + 2] & 0xFFL) << 16) | ((array[offset + 3] & 0xFFL) << 24) | - ((array[offset + 4] & 0xFFL) << 32) | ((array[offset + 5] & 0xFFL) << 40) | ((array[offset + 6] & 0xFFL) << 48) | ((array[offset + 7] & 0xFFL) << 56); - } - - public static void writeByte(byte[] array, int offset, int value) { - array[offset] = (byte) value; - } - - public static void writeShort(byte[] array, int offset, int value) { - array[offset] = (byte) value; - array[offset + 1] = (byte) (value >> 8); - } - - public static void writeInt(byte[] array, int offset, int value) { - array[offset] = (byte) value; - array[offset + 1] = (byte) (value >> 8); - array[offset + 2] = (byte) (value >> 16); - array[offset + 3] = (byte) (value >> 24); - } - - public static void writeLong(byte[] array, int offset, long value) { - array[offset] = (byte) value; - array[offset + 1] = (byte) (value >> 8); - array[offset + 2] = (byte) (value >> 16); - array[offset + 3] = (byte) (value >> 24); - array[offset + 4] = (byte) (value >> 32); - array[offset + 5] = (byte) (value >> 40); - array[offset + 6] = (byte) (value >> 48); - array[offset + 7] = (byte) (value >> 56); - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/RealTimeActivityHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/RealTimeActivityHandler.java index 39a41f51b..1898ce43b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/RealTimeActivityHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/RealTimeActivityHandler.java @@ -15,15 +15,12 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.UUID; -import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils.readByte; -import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils.readInt; -import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils.readShort; - /* default */ class RealTimeActivityHandler { private static final Logger LOG = LoggerFactory.getLogger(RealTimeActivityHandler.class); @@ -64,10 +61,10 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.Bi } private void processRealtimeHeartRate(byte[] data) { - int unknown1 = readByte(data, 0); - int heartRate = readByte(data, 1); - int unknown2 = readByte(data, 2); - int unknown3 = readShort(data, 3); + int unknown1 = BLETypeConversions.toUnsigned(data, 0); + int heartRate = BLETypeConversions.toUnsigned(data, 1); + int unknown2 = BLETypeConversions.toUnsigned(data, 2); + int unknown3 = BLETypeConversions.toUint16(data, 3); lastSample.setHeartRate(heartRate); processSample(); @@ -76,8 +73,8 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.Bi } private void processRealtimeSteps(byte[] data) { - int steps = readInt(data, 0); - int goal = readInt(data, 4); + int steps = BLETypeConversions.toUint32(data, 0); + int goal = BLETypeConversions.toUint32(data, 4); lastSample.setSteps(steps); processSample(); @@ -86,8 +83,8 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.Bi } private void processRealtimeCalories(byte[] data) { - int calories = readInt(data, 0); - int unknown = readInt(data, 4); + int calories = BLETypeConversions.toUint32(data, 0); + int unknown = BLETypeConversions.toUint32(data, 4); lastSample.setCaloriesBurnt(calories); processSample(); @@ -96,9 +93,9 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.Bi } private void processRealtimeStairs(byte[] data) { - int floorsClimbed = readShort(data, 0); - int unknown = readShort(data, 2); - int floorGoal = readShort(data, 4); + int floorsClimbed = BLETypeConversions.toUint16(data, 0); + int unknown = BLETypeConversions.toUint16(data, 2); + int floorGoal = BLETypeConversions.toUint16(data, 4); lastSample.setFloorsClimbed(floorsClimbed); processSample(); @@ -107,14 +104,14 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.Bi } private void processRealtimeIntensityMinutes(byte[] data) { - int weeklyLimit = readInt(data, 10); + int weeklyLimit = BLETypeConversions.toUint32(data, 10); LOG.debug("Realtime intensity recorded; weekly limit: {}", weeklyLimit); } private void handleRealtimeHeartbeat(byte[] data) { - int interval = readShort(data, 0); - int timer = readInt(data, 2); + int interval = BLETypeConversions.toUint16(data, 0); + int timer = BLETypeConversions.toUint32(data, 2); float heartRate = (60.0f * 1024.0f) / interval; LOG.debug("Realtime heartbeat frequency {} at {}", heartRate, timer); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/VivomoveHrSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/VivomoveHrSupport.java index d8b22b4f7..f96f3a16f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/VivomoveHrSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/VivomoveHrSupport.java @@ -21,11 +21,15 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DownloadedFitFile; import nodomain.freeyourgadget.gadgetbridge.entities.DownloadedFitFileDao; import nodomain.freeyourgadget.gadgetbridge.entities.User; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; +import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiCore; +import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiDeviceStatus; +import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiFindMyWatch; +import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiSmartProto; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ams.AmsEntity; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ams.AmsEntityAttribute; @@ -89,10 +93,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages. import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages.WeatherRequestResponseMessage; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.notifications.NotificationData; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.notifications.NotificationStorage; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf.GdiCore; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf.GdiDeviceStatus; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf.GdiFindMyWatch; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf.GdiSmartProto; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.uploads.FileUploadQueue; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -110,8 +110,6 @@ import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import static nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils.readShort; - public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements FileDownloadListener { private static final Logger LOG = LoggerFactory.getLogger(VivomoveHrSupport.class); @@ -219,19 +217,19 @@ public class VivomoveHrSupport extends AbstractBTLEDeviceSupport implements File } private void processGfdiPacket(byte[] packet) { - final int size = readShort(packet, 0); + final int size = BLETypeConversions.toUint16(packet, 0); if (size != packet.length) { LOG.error("Received GFDI packet with invalid length: {} vs {}", size, packet.length); return; } - final int crc = readShort(packet, packet.length - 2); + final int crc = BLETypeConversions.toUint16(packet, packet.length - 2); final int correctCrc = ChecksumCalculator.computeCrc(packet, 0, packet.length - 2); if (crc != correctCrc) { LOG.error("Received GFDI packet with invalid CRC: {} vs {}", crc, correctCrc); return; } - final int messageType = readShort(packet, 2); + final int messageType = BLETypeConversions.toUint16(packet, 2); switch (messageType) { case VivomoveConstants.MESSAGE_RESPONSE: processResponseMessage(ResponseMessage.parsePacket(packet), packet); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/ancs/AncsControlCommand.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/ancs/AncsControlCommand.java index d657fe82b..3d2c538bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/ancs/AncsControlCommand.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/ancs/AncsControlCommand.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ancs; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages.MessageReader; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; import org.slf4j.Logger; @@ -23,7 +23,7 @@ public abstract class AncsControlCommand { } public static AncsControlCommand parseCommand(byte[] buffer, int offset, int size) { - final int commandID = BinaryUtils.readByte(buffer, offset); + final int commandID = BLETypeConversions.toUnsigned(buffer, offset); final AncsCommand command = AncsCommand.getByCode(commandID); if (command == null) { LOG.error("Unknown ANCS command {}", commandID); @@ -45,8 +45,8 @@ public abstract class AncsControlCommand { } private static AncsPerformAndroidAction createPerformAndroidAction(byte[] buffer, int offset, int size) { - final int notificationUID = BinaryUtils.readInt(buffer, offset); - final int actionID = BinaryUtils.readByte(buffer, offset + 4); + final int notificationUID = BLETypeConversions.toUint32(buffer, offset); + final int actionID = BLETypeConversions.toUnsigned(buffer, offset + 4); final AncsAndroidAction action = AncsAndroidAction.getByCode(actionID); if (action == null) { LOG.error("Unknown ANCS Android action {}", actionID); @@ -77,7 +77,7 @@ public abstract class AncsControlCommand { final int attributeCount = size - (zero - offset); final List requestedAttributes = new ArrayList<>(attributeCount); for (int i = 0; i < attributeCount; ++i) { - final int attributeID = BinaryUtils.readByte(buffer, zero + 1 + i); + final int attributeID = BLETypeConversions.toUnsigned(buffer, zero + 1 + i); if (attributeID < 0 || attributeID >= APP_ATTRIBUTE_VALUES.length) { LOG.error("Unknown ANCS app attribute {}", attributeID); return null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitParser.java index 3dd5528bc..a4302ad83 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitParser.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.fit; import android.util.SparseArray; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages.MessageReader; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; import org.slf4j.Logger; @@ -184,7 +184,7 @@ public class FitParser { // this is strange? byte[] bytes = new byte[4]; reader.readBytesTo(3, bytes, 0); - return BinaryUtils.readInt(bytes, 0); + return BLETypeConversions.toUint32(bytes, 0); } case 4: return reader.readInt(); @@ -192,7 +192,7 @@ public class FitParser { // this is strange? byte[] bytes = new byte[8]; reader.readBytesTo(7, bytes, 0); - return BinaryUtils.readLong(bytes, 0); + return BLETypeConversions.toUint64(bytes, 0); } case 8: return reader.readLong(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitSerializer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitSerializer.java index f382eb58f..69c24fb08 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitSerializer.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/fit/FitSerializer.java @@ -3,7 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.fit; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.SparseIntArray; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages.MessageWriter; import org.slf4j.Logger; @@ -96,9 +96,9 @@ public class FitSerializer { final byte[] bytes = writer.getBytes(); // rewrite size - BinaryUtils.writeInt(bytes, 4, bytes.length - 14 - 2); + BLETypeConversions.writeUint32(bytes, 4, bytes.length - 14 - 2); // rewrite header CRC - BinaryUtils.writeShort(bytes, 12, ChecksumCalculator.computeCrc(bytes, 0, 12)); + BLETypeConversions.writeUint16(bytes, 12, ChecksumCalculator.computeCrc(bytes, 0, 12)); return bytes; } @@ -216,7 +216,7 @@ public class FitSerializer { case 3: { // this is strange? byte[] bytes = new byte[4]; - BinaryUtils.writeInt(bytes, 0, (int) value); + BLETypeConversions.writeUint32(bytes, 0, (int) value); writer.writeBytes(bytes, 0, 3); break; } @@ -226,7 +226,7 @@ public class FitSerializer { case 7: { // this is strange? byte[] bytes = new byte[8]; - BinaryUtils.writeLong(bytes, 0, (long) value); + BLETypeConversions.writeUint64(bytes, 0, (long) value); writer.writeBytes(bytes, 0, 7); break; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/AuthNegotiationMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/AuthNegotiationMessage.java index d53a1c2f7..23092c776 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/AuthNegotiationMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/AuthNegotiationMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class AuthNegotiationMessage { @@ -22,8 +22,8 @@ public class AuthNegotiationMessage { writer.writeInt(supportedEncryptionAlgorithms); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/BatteryStatusMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/BatteryStatusMessage.java index 4cadc056d..ea2b90752 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/BatteryStatusMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/BatteryStatusMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class BatteryStatusMessage { @@ -16,8 +16,8 @@ public class BatteryStatusMessage { writer.writeByte(255); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ConfigurationMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ConfigurationMessage.java index f1f085ba4..d2c3be2bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ConfigurationMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ConfigurationMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import java.util.Arrays; @@ -21,8 +21,8 @@ public class ConfigurationMessage { writer.writeBytes(configurationPayload); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CreateFileRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CreateFileRequestMessage.java index b112edfa6..9b7edb88f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CreateFileRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CreateFileRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class CreateFileRequestMessage { @@ -21,8 +21,8 @@ public class CreateFileRequestMessage { writer.writeString(path); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CurrentTimeRequestResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CurrentTimeRequestResponseMessage.java index 1e38ce4b9..70dadcdbf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CurrentTimeRequestResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/CurrentTimeRequestResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class CurrentTimeRequestResponseMessage { @@ -21,8 +21,8 @@ public class CurrentTimeRequestResponseMessage { writer.writeInt(0); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DeviceInformationResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DeviceInformationResponseMessage.java index dff8bfd24..321e47506 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DeviceInformationResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DeviceInformationResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class DeviceInformationResponseMessage { @@ -24,8 +24,8 @@ public class DeviceInformationResponseMessage { writer.writeByte(protocolFlags); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DirectoryFileFilterRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DirectoryFileFilterRequestMessage.java index 208595dcf..d9cc7008b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DirectoryFileFilterRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DirectoryFileFilterRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class DirectoryFileFilterRequestMessage { @@ -19,8 +19,8 @@ public class DirectoryFileFilterRequestMessage { writer.writeByte(filterType); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DownloadRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DownloadRequestMessage.java index fe20eed7a..4e9c18ec1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DownloadRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/DownloadRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class DownloadRequestMessage { @@ -21,8 +21,8 @@ public class DownloadRequestMessage { writer.writeInt(dataSize); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataMessage.java index d68ab1286..dcf9f15f0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class FileTransferDataMessage { @@ -27,8 +27,8 @@ public class FileTransferDataMessage { writer.writeBytes(data); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataResponseMessage.java index 484e3a989..753de8df1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FileTransferDataResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class FileTransferDataResponseMessage { @@ -32,8 +32,8 @@ public class FileTransferDataResponseMessage { writer.writeInt(nextDataOffset); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDataMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDataMessage.java index 9c529d73b..549febc4a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDataMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDataMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.fit.FitMessage; @@ -17,8 +17,8 @@ public class FitDataMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDefinitionMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDefinitionMessage.java index c0e780d42..23c0d7f92 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDefinitionMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/FitDefinitionMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.fit.FitMessageDefinition; @@ -17,8 +17,8 @@ public class FitDefinitionMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GenericResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GenericResponseMessage.java index 8dd1c1af9..ebed2f370 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GenericResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GenericResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class GenericResponseMessage { @@ -15,8 +15,8 @@ public class GenericResponseMessage { writer.writeByte(status); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsControlPointResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsControlPointResponseMessage.java index f3cd4264f..8f35e79c1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsControlPointResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsControlPointResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class GncsControlPointResponseMessage { @@ -27,8 +27,8 @@ public class GncsControlPointResponseMessage { writer.writeByte(ancsError); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsDataSourceMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsDataSourceMessage.java index acb4c7e65..677f31ac0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsDataSourceMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsDataSourceMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class GncsDataSourceMessage { @@ -18,8 +18,8 @@ public class GncsDataSourceMessage { writer.writeBytes(ancsMessage, dataOffset, size); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsNotificationSourceMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsNotificationSourceMessage.java index d0a76ffc1..978128f0a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsNotificationSourceMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/GncsNotificationSourceMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ancs.AncsCategory; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ancs.AncsEvent; @@ -28,8 +28,8 @@ public class GncsNotificationSourceMessage { writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageReader.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageReader.java index 06c51ce1b..cf7b3d512 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageReader.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageReader.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import java.nio.charset.StandardCharsets; @@ -32,28 +32,28 @@ public class MessageReader { public int readByte() { if (position + 1 > data.length) throw new IllegalStateException(); - final int result = BinaryUtils.readByte(data, position); + final int result = BLETypeConversions.toUnsigned(data, position); ++position; return result; } public int readShort() { if (position + 2 > data.length) throw new IllegalStateException(); - final int result = BinaryUtils.readShort(data, position); + final int result = BLETypeConversions.toUint16(data, position); position += 2; return result; } public int readInt() { if (position + 4 > data.length) throw new IllegalStateException(); - final int result = BinaryUtils.readInt(data, position); + final int result = BLETypeConversions.toUint32(data, position); position += 4; return result; } public long readLong() { if (position + 8 > data.length) throw new IllegalStateException(); - final long result = BinaryUtils.readLong(data, position); + final long result = BLETypeConversions.toUint64(data, position); position += 8; return result; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageWriter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageWriter.java index 070414459..db89fbafb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageWriter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageWriter.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -21,25 +21,25 @@ public class MessageWriter { public void writeByte(int value) { if (position + 1 > buffer.length) throw new IllegalStateException(); - BinaryUtils.writeByte(buffer, position, value); + BLETypeConversions.writeUint8(buffer, position, value); ++position; } public void writeShort(int value) { if (position + 2 > buffer.length) throw new IllegalStateException(); - BinaryUtils.writeShort(buffer, position, value); + BLETypeConversions.writeUint16(buffer, position, value); position += 2; } public void writeInt(int value) { if (position + 4 > buffer.length) throw new IllegalStateException(); - BinaryUtils.writeInt(buffer, position, value); + BLETypeConversions.writeUint32(buffer, position, value); position += 4; } public void writeLong(long value) { if (position + 8 > buffer.length) throw new IllegalStateException(); - BinaryUtils.writeLong(buffer, position, value); + BLETypeConversions.writeUint64(buffer, position, value); position += 8; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlCapabilitiesResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlCapabilitiesResponseMessage.java index e536f1d67..ddc0dbf80 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlCapabilitiesResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlCapabilitiesResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminMusicControlCommand; @@ -21,8 +21,8 @@ public class MusicControlCapabilitiesResponseMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlEntityUpdateMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlEntityUpdateMessage.java index c88f440d4..522571b76 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlEntityUpdateMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MusicControlEntityUpdateMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ams.AmsEntityAttribute; @@ -17,8 +17,8 @@ public class MusicControlEntityUpdateMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/NotificationServiceSubscriptionResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/NotificationServiceSubscriptionResponseMessage.java index a186fed3d..02f9b93ce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/NotificationServiceSubscriptionResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/NotificationServiceSubscriptionResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class NotificationServiceSubscriptionResponseMessage { @@ -18,8 +18,8 @@ public class NotificationServiceSubscriptionResponseMessage { writer.writeByte(featureFlags); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ProtobufRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ProtobufRequestMessage.java index eeef471bb..e9e17c733 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ProtobufRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/ProtobufRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class ProtobufRequestMessage { @@ -29,8 +29,8 @@ public class ProtobufRequestMessage { writer.writeBytes(messageBytes); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/RequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/RequestMessage.java index da4d42ee0..68a0796b3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/RequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/RequestMessage.java @@ -1,11 +1,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminDeviceSetting; - -import java.util.Map; public class RequestMessage { public final byte[] packet; @@ -17,8 +14,8 @@ public class RequestMessage { writer.writeShort(requestMessageID); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SetDeviceSettingsMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SetDeviceSettingsMessage.java index c69e17ad3..a50b916bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SetDeviceSettingsMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SetDeviceSettingsMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminDeviceSetting; @@ -37,8 +37,8 @@ public class SetDeviceSettingsMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SupportedFileTypesRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SupportedFileTypesRequestMessage.java index 40c4045de..2f6560f02 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SupportedFileTypesRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SupportedFileTypesRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class SupportedFileTypesRequestMessage { @@ -13,8 +13,8 @@ public class SupportedFileTypesRequestMessage { writer.writeShort(VivomoveConstants.MESSAGE_SUPPORTED_FILE_TYPES_REQUEST); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SyncRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SyncRequestMessage.java index 94bbd3931..fcaf153bc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SyncRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SyncRequestMessage.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminMessageType; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -25,7 +25,7 @@ public class SyncRequestMessage { final int option = reader.readByte(); final int bitMaskSize = reader.readByte(); final byte[] longBits = reader.readBytesTo(bitMaskSize, new byte[8], 0); - long bitMask = BinaryUtils.readLong(longBits, 0); + long bitMask = BLETypeConversions.toUint64(longBits, 0); final Set fileTypes = new HashSet<>(GarminMessageType.values().length); for (GarminMessageType messageType : GarminMessageType.values()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SystemEventMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SystemEventMessage.java index f1ec7ea98..622acf713 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SystemEventMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SystemEventMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminSystemEventType; @@ -22,8 +22,8 @@ public class SystemEventMessage { } writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/UploadRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/UploadRequestMessage.java index 730398029..5932a9b95 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/UploadRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/UploadRequestMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class UploadRequestMessage { @@ -17,8 +17,8 @@ public class UploadRequestMessage { writer.writeShort(crcSeed); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/WeatherRequestResponseMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/WeatherRequestResponseMessage.java index 848ab81bd..9dfbf5569 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/WeatherRequestResponseMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/WeatherRequestResponseMessage.java @@ -1,7 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages; import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants; -import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator; public class WeatherRequestResponseMessage { @@ -18,8 +18,8 @@ public class WeatherRequestResponseMessage { writer.writeShort(timeout); writer.writeShort(0); // CRC will be filled below final byte[] packet = writer.getBytes(); - BinaryUtils.writeShort(packet, 0, packet.length); - BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); + BLETypeConversions.writeUint16(packet, 0, packet.length); + BLETypeConversions.writeUint16(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2)); this.packet = packet; } } diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_core.proto b/app/src/main/proto/garmin_vivomovehr/gdi_core.proto index a4c049b99..411be5238 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_core.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_core.proto @@ -2,7 +2,7 @@ syntax = "proto2"; package garmin_vivomovehr; -option java_package = "nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf"; +option java_package = "nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr"; message CoreService { optional SyncRequest sync_request = 1; diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_device_status.proto b/app/src/main/proto/garmin_vivomovehr/gdi_device_status.proto index 85ce73197..99ee75c64 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_device_status.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_device_status.proto @@ -2,7 +2,7 @@ syntax = "proto2"; package garmin_vivomovehr; -option java_package = "nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf"; +option java_package = "nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr"; message DeviceStatusService { optional RemoteDeviceBatteryStatusChangedNotification remote_device_battery_status_changed_notification = 1; diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_find_my_watch.proto b/app/src/main/proto/garmin_vivomovehr/gdi_find_my_watch.proto index 32979e153..23e75c588 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_find_my_watch.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_find_my_watch.proto @@ -2,7 +2,7 @@ syntax = "proto2"; package garmin_vivomovehr; -option java_package = "nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf"; +option java_package = "nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr"; message FindMyWatchService { optional FindMyWatchRequest find_request = 1; diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_smart_proto.proto b/app/src/main/proto/garmin_vivomovehr/gdi_smart_proto.proto index 9aeb887e9..64098539e 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_smart_proto.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_smart_proto.proto @@ -2,7 +2,7 @@ syntax = "proto2"; package garmin_vivomovehr; -option java_package = "nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf"; +option java_package = "nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr"; import "garmin_vivomovehr/gdi_device_status.proto"; import "garmin_vivomovehr/gdi_find_my_watch.proto"; diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_sms_notification.proto b/app/src/main/proto/garmin_vivomovehr/gdi_sms_notification.proto index a86489c66..1a61ff911 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_sms_notification.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_sms_notification.proto @@ -2,7 +2,7 @@ syntax = "proto2"; package garmin_vivomovehr; -option java_package = "nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.protobuf"; +option java_package = "nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr"; message SmsNotificationService { optional SmsSendMessageRequest sms_send_message_request = 1; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/BLETypeConversionsTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/BLETypeConversionsTest.java index d6e92b700..a8da60a63 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/BLETypeConversionsTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/BLETypeConversionsTest.java @@ -1,39 +1,218 @@ package nodomain.freeyourgadget.gadgetbridge.test; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import org.junit.Test; +import java.util.Arrays; import java.util.GregorianCalendar; -import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; - +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class BLETypeConversionsTest extends TestBase { @Test public void testTimeParsing1() { - byte[] requested = new byte[] { - (byte) 0xe1, 0x07, 0x0a, 0x1d, 0x00, 0x1c, 0x00,0x08 + byte[] requested = new byte[]{ + (byte) 0xe1, 0x07, 0x0a, 0x1d, 0x00, 0x1c, 0x00, 0x08 }; - byte[] received = new byte[] { + byte[] received = new byte[]{ (byte) 0xe1, 0x07, 0x0a, 0x1c, 0x17, 0x1c, 0x00, 0x04 }; GregorianCalendar calRequested = BLETypeConversions.rawBytesToCalendar(requested); GregorianCalendar calReceived = BLETypeConversions.rawBytesToCalendar(received); - assertTrue(calRequested.getTime().equals(calReceived.getTime())); + assertEquals(calRequested.getTime(), calReceived.getTime()); } @Test public void testTimeParsingWithDST() { - byte[] requested = new byte[] { - (byte) 0xe1,0x07,0x0a,0x09,0x11,0x23,0x00,0x08 + byte[] requested = new byte[]{ + (byte) 0xe1, 0x07, 0x0a, 0x09, 0x11, 0x23, 0x00, 0x08 }; - byte[] received = new byte[] { - (byte) 0xe1,0x07,0x0a,0x09,0x10,0x23,0x00,0x04 + byte[] received = new byte[]{ + (byte) 0xe1, 0x07, 0x0a, 0x09, 0x10, 0x23, 0x00, 0x04 }; GregorianCalendar calRequested = BLETypeConversions.rawBytesToCalendar(requested); GregorianCalendar calReceived = BLETypeConversions.rawBytesToCalendar(received); - assertTrue(calRequested.getTime().equals(calReceived.getTime())); + assertEquals(calRequested.getTime(), calReceived.getTime()); + } + + @Test + public void testToUnsignedInt() { + assertEquals(0L, BLETypeConversions.toUnsigned(0)); + assertEquals(12345L, BLETypeConversions.toUnsigned(12345)); + assertEquals(0x7FFFFFFFL, BLETypeConversions.toUnsigned(0x7FFFFFFF)); + assertEquals(0x80000000L, BLETypeConversions.toUnsigned(0x80000000)); + assertEquals(0xFFFFFFFFL, BLETypeConversions.toUnsigned(0xFFFFFFFF)); + } + + @Test + public void testToUnsignedShort() { + assertEquals(0, BLETypeConversions.toUnsigned((short) 0)); + assertEquals(12345, BLETypeConversions.toUnsigned((short) 12345)); + assertEquals(0x7FFF, BLETypeConversions.toUnsigned((short) 0x7FFF)); + assertEquals(0x8000, BLETypeConversions.toUnsigned((short) 0x8000)); + assertEquals(0xFFFF, BLETypeConversions.toUnsigned((short) 0xFFFF)); + } + + @Test + public void testToUnsignedByte() { + assertEquals(0, BLETypeConversions.toUnsigned((byte) 0)); + assertEquals(123, BLETypeConversions.toUnsigned((byte) 123)); + assertEquals(0x7F, BLETypeConversions.toUnsigned((byte) 0x7F)); + assertEquals(0x80, BLETypeConversions.toUnsigned((byte) 0x80)); + assertEquals(0xFF, BLETypeConversions.toUnsigned((byte) 0xFF)); + } + + @Test + public void testToUnsignedByteArray() { + final byte[] array = new byte[]{(byte) 0x12, (byte) 0x00, (byte) 123, (byte) 0x7F, (byte) 0x80, (byte) 0xFF}; + assertEquals(0, BLETypeConversions.toUnsigned(array, 1)); + assertEquals(123, BLETypeConversions.toUnsigned(array, 2)); + assertEquals(0x7F, BLETypeConversions.toUnsigned(array, 3)); + assertEquals(0x80, BLETypeConversions.toUnsigned(array, 4)); + assertEquals(0xFF, BLETypeConversions.toUnsigned(array, 5)); + } + + @Test + public void testToUint16Single() { + assertEquals(0, BLETypeConversions.toUint16((byte) 0)); + assertEquals(123, BLETypeConversions.toUint16((byte) 123)); + assertEquals(0x7F, BLETypeConversions.toUint16((byte) 0x7F)); + assertEquals(0x80, BLETypeConversions.toUint16((byte) 0x80)); + assertEquals(0xFF, BLETypeConversions.toUint16((byte) 0xFF)); + } + + @Test + public void testToUint16Bytes() { + assertEquals(0, BLETypeConversions.toUint16((byte) 0, (byte) 0)); + assertEquals(0x1234, BLETypeConversions.toUint16((byte) 0x34, (byte) 0x12)); + assertEquals(0x369C, BLETypeConversions.toUint16((byte) 0x9C, (byte) 0x36)); + assertEquals(0x7FFF, BLETypeConversions.toUint16((byte) 0xFF, (byte) 0x7F)); + assertEquals(0x8000, BLETypeConversions.toUint16((byte) 0x00, (byte) 0x80)); + assertEquals(0xFFFF, BLETypeConversions.toUint16((byte) 0xFF, (byte) 0xFF)); + } + + @Test + public void testToUint16Array() { + final byte[] array = new byte[]{ + (byte) 0x12, + (byte) 0x00, (byte) 0x00, + (byte) 0x34, (byte) 0x12, + (byte) 0x9C, (byte) 0x36, + (byte) 0xFF, (byte) 0x7F, + (byte) 0x00, (byte) 0x80, + (byte) 0xFF, (byte) 0xFF, + }; + assertEquals(0, BLETypeConversions.toUint16(array, 1)); + assertEquals(0x1234, BLETypeConversions.toUint16(array, 3)); + assertEquals(0x369C, BLETypeConversions.toUint16(array, 5)); + assertEquals(0x7FFF, BLETypeConversions.toUint16(array, 7)); + assertEquals(0x8000, BLETypeConversions.toUint16(array, 9)); + assertEquals(0xFFFF, BLETypeConversions.toUint16(array, 11)); + } + + @Test + public void testToUint32Bytes() { + assertEquals(0, BLETypeConversions.toUint32((byte) 0, (byte) 0, (byte) 0, (byte) 0)); + assertEquals(0x12345678, BLETypeConversions.toUint32((byte) 0x78, (byte) 0x56, (byte) 0x34, (byte) 0x12)); + assertEquals(0x2468ACE0, BLETypeConversions.toUint32((byte) 0xE0, (byte) 0xAC, (byte) 0x68, (byte) 0x24)); + assertEquals(0x7FFFFFFF, BLETypeConversions.toUint32((byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F)); + assertEquals(0x80000000, BLETypeConversions.toUint32((byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80)); + assertEquals(0xFFFFFFFF, BLETypeConversions.toUint32((byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF)); + } + + @Test + public void testToUint32Array() { + final byte[] array = new byte[]{ + (byte) 0x12, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x78, (byte) 0x56, (byte) 0x34, (byte) 0x12, + (byte) 0xE0, (byte) 0xAC, (byte) 0x68, (byte) 0x24, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + }; + assertEquals(0, BLETypeConversions.toUint32(array, 1)); + assertEquals(0x12345678, BLETypeConversions.toUint32(array, 5)); + assertEquals(0x2468ACE0, BLETypeConversions.toUint32(array, 9)); + assertEquals(0x7FFFFFFF, BLETypeConversions.toUint32(array, 13)); + assertEquals(0x80000000, BLETypeConversions.toUint32(array, 17)); + assertEquals(0xFFFFFFFF, BLETypeConversions.toUint32(array, 21)); + } + + @Test + public void testToUint64Bytes() { + assertEquals(0, BLETypeConversions.toUint64((byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0)); + assertEquals(0x123456789ABCDEF0L, BLETypeConversions.toUint64((byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, (byte) 0x78, (byte) 0x56, (byte) 0x34, (byte) 0x12)); + assertEquals(0x7FFFFFFFFFFFFFFFL, BLETypeConversions.toUint64((byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F)); + assertEquals(0x8000000000000000L, BLETypeConversions.toUint64((byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80)); + assertEquals(0xFFFFFFFFFFFFFFFFL, BLETypeConversions.toUint64((byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF)); + } + + @Test + public void testToUint64Array() { + final byte[] array = new byte[]{ + (byte) 0x12, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, (byte) 0x78, (byte) 0x56, (byte) 0x34, (byte) 0x12, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + }; + assertEquals(0, BLETypeConversions.toUint64(array, 1)); + assertEquals(0x123456789ABCDEF0L, BLETypeConversions.toUint64(array, 9)); + assertEquals(0x7FFFFFFFFFFFFFFFL, BLETypeConversions.toUint64(array, 17)); + assertEquals(0x8000000000000000L, BLETypeConversions.toUint64(array, 25)); + assertEquals(0xFFFFFFFFFFFFFFFFL, BLETypeConversions.toUint64(array, 33)); + } + + @Test + public void testWriteUint8() { + for (final int testedValue : new int[]{ + 0x00, 123, 0x7F, 0x80, 0xFF + }) { + final byte[] buffer = new byte[2]; + Arrays.fill(buffer, (byte) 0xFF); + BLETypeConversions.writeUint8(buffer, 1, testedValue); + assertEquals(testedValue, BLETypeConversions.toUnsigned(buffer, 1)); + } + } + + @Test + public void testWriteUint16() { + for (final int testedValue : new int[]{ + 0x0000, 12345, 0x7FFF, 0x8000, 0xFFFF + }) { + final byte[] buffer = new byte[3]; + Arrays.fill(buffer, (byte) 0xFF); + BLETypeConversions.writeUint16(buffer, 1, testedValue); + assertEquals(testedValue, BLETypeConversions.toUint16(buffer, 1)); + } + } + + @Test + public void testWriteUint32() { + for (final int testedValue : new int[]{ + 0, 0x12345678, 0x7FFFFFFF, 0x80000000, 0xFFFFFFFF + }) { + final byte[] buffer = new byte[5]; + Arrays.fill(buffer, (byte) 0xFF); + BLETypeConversions.writeUint32(buffer, 1, testedValue); + assertEquals(testedValue, BLETypeConversions.toUint32(buffer, 1)); + } + } + + @Test + public void testWriteUint64() { + for (final long testedValue : new long[]{ + 0L, 0x123456789ABCDEF0L, 0x7FFFFFFFFFFFFFFFL, 0x8000000000000000L, 0xFFFFFFFFFFFFFFFFL + }) { + final byte[] buffer = new byte[9]; + Arrays.fill(buffer, (byte) 0xFF); + BLETypeConversions.writeUint64(buffer, 1, testedValue); + assertEquals(testedValue, BLETypeConversions.toUint64(buffer, 1)); + } } }