1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-09 22:57:54 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vivomovehr/messages/MessageReader.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

85 lines
2.5 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages;
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils;
import java.nio.charset.StandardCharsets;
public class MessageReader {
private final byte[] data;
private int position;
public MessageReader(byte[] data) {
this.data = data;
}
public MessageReader(byte[] data, int skipOffset) {
this.data = data;
this.position = skipOffset;
}
public boolean isEof() {
return position >= data.length;
}
public int getPosition() {
return position;
}
public void skip(int offset) {
if (position + offset > data.length) throw new IllegalStateException();
position += offset;
}
public int readByte() {
if (position + 1 > data.length) throw new IllegalStateException();
final int result = BinaryUtils.readByte(data, position);
++position;
return result;
}
public int readShort() {
if (position + 2 > data.length) throw new IllegalStateException();
final int result = BinaryUtils.readShort(data, position);
position += 2;
return result;
}
public int readInt() {
if (position + 4 > data.length) throw new IllegalStateException();
final int result = BinaryUtils.readInt(data, position);
position += 4;
return result;
}
public long readLong() {
if (position + 8 > data.length) throw new IllegalStateException();
final long result = BinaryUtils.readLong(data, position);
position += 8;
return result;
}
public String readString() {
final int size = readByte();
if (position + size > data.length) throw new IllegalStateException();
final String result = new String(data, position, size, StandardCharsets.UTF_8);
position += size;
return result;
}
public byte[] readBytes(int size) {
if (position + size > data.length) throw new IllegalStateException();
final byte[] result = new byte[size];
System.arraycopy(data, position, result, 0, size);
position += size;
return result;
}
public byte[] readBytesTo(int size, byte[] buffer, int offset) {
if (offset + size > buffer.length) throw new IllegalArgumentException();
if (position + size > data.length) throw new IllegalStateException();
System.arraycopy(data, position, buffer, offset, size);
position += size;
return buffer;
}
}