mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-11 18:35:49 +01:00
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)
This commit is contained in:
parent
3a58314db6
commit
dccb8ed1c4
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@ -62,4 +62,4 @@
|
||||
}
|
||||
|
||||
# Keep generated protobuf classes
|
||||
-keep class nodomain.freeyourgadget.gadgetbridge.proto.* { *; }
|
||||
-keep class nodomain.freeyourgadget.gadgetbridge.proto.** { *; }
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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<AncsAppAttribute> 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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<GarminMessageType> fileTypes = new HashSet<>(GarminMessageType.values().length);
|
||||
for (GarminMessageType messageType : GarminMessageType.values()) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user