mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-02 19:36:14 +02:00
57db0c7c33
- refactor the logic of Global and Local messages - add some Global messages with naming taken from [1] - Global messages are not enum because there are too many - introduce the concept of FieldDefinitionPrimitive - add new Field Definitions - add support for developer fields and array fields - add test case for FIT files taken from [0] [0] https://github.com/polyvertex/fitdecode/ [1] https://www.fitfileviewer.com/
49 lines
1.4 KiB
Java
49 lines
1.4 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.fieldDefinitions;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FieldDefinition;
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.baseTypes.BaseType;
|
|
|
|
public class FieldDefinitionGoalSource extends FieldDefinition {
|
|
|
|
public FieldDefinitionGoalSource(int localNumber, int size, BaseType baseType, String name) {
|
|
super(localNumber, size, baseType, name, 1, 0);
|
|
}
|
|
|
|
@Override
|
|
public Object decode(ByteBuffer byteBuffer) {
|
|
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
|
return Source.fromId(raw);
|
|
}
|
|
|
|
@Override
|
|
public void encode(ByteBuffer byteBuffer, Object o) {
|
|
if (o instanceof Source) {
|
|
baseType.encode(byteBuffer, (((Source) o).ordinal()), scale, offset);
|
|
return;
|
|
}
|
|
baseType.encode(byteBuffer, o, scale, offset);
|
|
}
|
|
|
|
public enum Source {
|
|
auto,
|
|
community,
|
|
manual,
|
|
;
|
|
|
|
@Nullable
|
|
public static Source fromId(int id) {
|
|
for (Source source :
|
|
Source.values()) {
|
|
if (id == source.ordinal()) {
|
|
return source;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|