1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-11 07:38:29 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/fit/FieldDefinition.java
Daniele Gobbetti 7ee82e6afa Garmin protocol: add initial support for FIT messages
note: only weather message definition and data tested so far
also enable weather support for Instinct 2S and vivomove style
also cleanup some unused constants that have been migrated to new enums in GFDIMessage
additionally switch to new local implementation of GarminTimeUtils with needed methods
2024-05-01 23:35:15 +01:00

74 lines
2.0 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.baseTypes.BaseType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MessageReader;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MessageWriter;
public class FieldDefinition {
private final int localNumber;
private final int size;
private final BaseType baseType;
private final String name;
private final int scale;
private final int offset;
public FieldDefinition(int localNumber, int size, BaseType baseType, String name, int scale, int offset) {
this.localNumber = localNumber;
this.size = size;
this.baseType = baseType;
this.name = name;
this.scale = scale;
this.offset = offset;
}
public FieldDefinition(int localNumber, int size, BaseType baseType, String name) {
this(localNumber, size, baseType, name, 1, 0);
}
public static FieldDefinition parseIncoming(MessageReader reader) {
int localNumber = reader.readByte();
int size = reader.readByte();
int baseTypeIdentifier = reader.readByte();
BaseType baseType = BaseType.fromIdentifier(baseTypeIdentifier);
if (size % baseType.getSize() != 0) {
baseType = BaseType.BASE_TYPE_BYTE;
}
return new FieldDefinition(localNumber, size, baseType, "");
}
public int getScale() {
return scale;
}
public int getOffset() {
return offset;
}
public int getLocalNumber() {
return localNumber;
}
public int getSize() {
return size;
}
public BaseType getBaseType() {
return baseType;
}
public String getName() {
return name;
}
public void generateOutgoingPayload(MessageWriter writer) {
writer.writeByte(localNumber);
writer.writeByte(size);
writer.writeByte(baseType.getIdentifier());
}
}