1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-09 14:48:24 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/SyncRequestMessage.java
Mormegil 3a58314db6 Garmin Vivomove HR support
- communication protocols
- device support implementation
- download FIT file storage

Features:
- basic connectivity: time sync, battery status, HW/FW version info
- real-time activity tracking
- fitness data sync
- find the device, find the phone
- factory reset

Features implemented but not working:
- notifications: fully implemented, seem to communicate correctly, but not shown on watch

Features implemented partially (not expected to work now):
- weather information (and in future possibly weather alerts)
- music info
- firmware update: only the initial file upload implemented, not used

Things to improve/change:
- Device name hardcoded in `VivomoveHrCoordinator.getSupportedType`, service UUIDs not available
- Download FIT file storage: Should be store (and offer the user to export?) the FIT data forever?
- Obviously, various code improvements, cleanup, etc.
2023-07-20 20:30:14 +00:00

46 lines
1.7 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages;
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils;
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminMessageType;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import java.util.HashSet;
import java.util.Set;
public class SyncRequestMessage {
public static final int OPTION_MANUAL = 0;
public static final int OPTION_INVISIBLE = 1;
public static final int OPTION_VISIBLE_AS_NEEDED = 2;
public final int option;
public final Set<GarminMessageType> fileTypes;
public SyncRequestMessage(int option, Set<GarminMessageType> fileTypes) {
this.option = option;
this.fileTypes = fileTypes;
}
public static SyncRequestMessage parsePacket(byte[] packet) {
final MessageReader reader = new MessageReader(packet, 4);
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);
final Set<GarminMessageType> fileTypes = new HashSet<>(GarminMessageType.values().length);
for (GarminMessageType messageType : GarminMessageType.values()) {
int num = messageType.ordinal();
long mask = 1L << num;
if ((bitMask & mask) != 0) {
fileTypes.add(messageType);
bitMask &= ~mask;
}
}
if (bitMask != 0) {
throw new IllegalArgumentException("Unknown bit mask " + GB.hexdump(longBits, 0, longBits.length));
}
return new SyncRequestMessage(option, fileTypes);
}
}