1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

CMF Watch Pro 2: Fix workout summary parsing

This commit is contained in:
José Rebelo 2024-07-19 20:22:34 +01:00
parent b13c1b52be
commit 2e491d91a4

View File

@ -382,19 +382,25 @@ public class CmfActivitySync {
} }
private void handleWorkoutSummary(final byte[] payload) { private void handleWorkoutSummary(final byte[] payload) {
if (payload.length % 32 != 0) { final int bytesPerWorkout;
LOG.error("Workout summary payload size {} not divisible by 32", payload.length);
if (payload.length % 32 == 0) {
bytesPerWorkout = 32;
} else if (payload.length % 54 == 0) {
bytesPerWorkout = 54;
} else {
LOG.error("Workout summary payload size {} not divisible by 32 or 54", payload.length);
return; return;
} }
LOG.debug("Got {} workout summary samples", payload.length / 32); LOG.debug("Got {} workout summary samples", payload.length / bytesPerWorkout);
final ByteBuffer buf = ByteBuffer.wrap(payload).order(ByteOrder.LITTLE_ENDIAN); final ByteBuffer buf = ByteBuffer.wrap(payload).order(ByteOrder.LITTLE_ENDIAN);
final CmfWorkoutSummaryParser summaryParser = new CmfWorkoutSummaryParser(getDevice()); final CmfWorkoutSummaryParser summaryParser = new CmfWorkoutSummaryParser(getDevice());
while (buf.remaining() > 0) { while (buf.remaining() > 0) {
final byte[] summaryBytes = new byte[32]; final byte[] summaryBytes = new byte[bytesPerWorkout];
buf.get(summaryBytes); buf.get(summaryBytes);
BaseActivitySummary summary = new BaseActivitySummary(); BaseActivitySummary summary = new BaseActivitySummary();