mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-07 13:47:49 +02:00
09c44f05f8
* Remove the dependency on PredefinedLocalMessage from generic fit parsing code * Standardize toString methods, omit types for known fields * Return null on unknown field number or names, instead of crashing * Map more Global FIT messages (device info, monitoring, sleep stages, sleep stats, stress level) * Prioritize "timestamp" over "253_timestamp" if specified explicitly in the global message definition * Introduce RecordData wrappers for each global message, allowing us to have proper types when getting data. If missing or unknown, the getter returns null. All classes are auto-generated by the FitCodeGen. * Persist a list of RecordData, instead of a Map from RecordDefinition * Fix parsing of compressed timestamps - keep them in computedTimestamp on each data record * Use timestamp16 if available in Monitoring records
58 lines
1.6 KiB
Java
58 lines
1.6 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 FieldDefinitionSleepStage extends FieldDefinition {
|
|
public FieldDefinitionSleepStage(final int localNumber, final int size, final BaseType baseType, final String name) {
|
|
super(localNumber, size, baseType, name, 1, 0);
|
|
}
|
|
|
|
@Override
|
|
public Object decode(final ByteBuffer byteBuffer) {
|
|
final int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
|
return SleepStage.fromId(raw);
|
|
}
|
|
|
|
@Override
|
|
public void encode(final ByteBuffer byteBuffer, final Object o) {
|
|
if (o instanceof SleepStage) {
|
|
baseType.encode(byteBuffer, (((SleepStage) o).getId()), scale, offset);
|
|
return;
|
|
}
|
|
baseType.encode(byteBuffer, o, scale, offset);
|
|
}
|
|
|
|
public enum SleepStage {
|
|
AWAKE(1),
|
|
LIGHT(2),
|
|
DEEP(3),
|
|
REM(4),
|
|
;
|
|
|
|
private final int id;
|
|
|
|
SleepStage(final int i) {
|
|
id = i;
|
|
}
|
|
|
|
@Nullable
|
|
public static SleepStage fromId(final int id) {
|
|
for (SleepStage stage : SleepStage.values()) {
|
|
if (id == stage.getId()) {
|
|
return stage;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
}
|
|
}
|