mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: Fix checksum of concatenated fit files
This commit is contained in:
+8
@@ -31,6 +31,14 @@ public class GarminByteBufferReader {
|
||||
return byteBuffer.position();
|
||||
}
|
||||
|
||||
public void setPosition(final int position) {
|
||||
byteBuffer.position(position);
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return byteBuffer.limit();
|
||||
}
|
||||
|
||||
public int readShort() {
|
||||
return Short.toUnsignedInt(byteBuffer.getShort());
|
||||
}
|
||||
|
||||
+5
-1
@@ -106,10 +106,14 @@ public class FitFile {
|
||||
}
|
||||
garminByteBufferReader.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
final int fileCrc = garminByteBufferReader.readShort();
|
||||
final int actualCrc = ChecksumCalculator.computeCrc(fileContents, 0, fileContents.length - 2);
|
||||
final int actualCrc = ChecksumCalculator.computeCrc(fileContents, 0, garminByteBufferReader.getPosition() - 2);
|
||||
if (fileCrc != actualCrc) {
|
||||
throw new FitParseException("Wrong CRC for FIT file: got " + actualCrc + " expected " + fileCrc);
|
||||
}
|
||||
if (garminByteBufferReader.getPosition() < garminByteBufferReader.getLimit()) {
|
||||
LOG.warn("There are {} bytes after the fit file", garminByteBufferReader.getLimit() - garminByteBufferReader.getPosition());
|
||||
// TODO a fit file should actually be multiple fit files
|
||||
}
|
||||
return new FitFile(header, dataRecords);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user