mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
Xiaomi: Fix gps track parsing
The crc at the end was not being taken into account to check the file size.
This commit is contained in:
parent
e3e5c20a5a
commit
edd1a660da
@ -63,6 +63,7 @@ public class DailyDetailsParser extends XiaomiActivityParser {
|
||||
}
|
||||
|
||||
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.limit(buf.limit() - 4); // discard crc at the end
|
||||
buf.get(new byte[7]); // skip fileId bytes
|
||||
final byte fileIdPadding = buf.get();
|
||||
if (fileIdPadding != 0) {
|
||||
@ -80,7 +81,7 @@ public class DailyDetailsParser extends XiaomiActivityParser {
|
||||
timestamp.setTime(fileId.getTimestamp());
|
||||
|
||||
final List<XiaomiActivitySample> samples = new ArrayList<>();
|
||||
while (buf.position() < buf.limit() - 4 /* crc at the end */) {
|
||||
while (buf.position() < buf.limit()) {
|
||||
complexParser.reset();
|
||||
|
||||
final XiaomiActivitySample sample = new XiaomiActivitySample();
|
||||
|
@ -51,6 +51,7 @@ public class ManualSamplesParser extends XiaomiActivityParser {
|
||||
}
|
||||
|
||||
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.limit(buf.limit() - 4); // discard crc at the end
|
||||
buf.get(new byte[7]); // skip fileId bytes
|
||||
final byte fileIdPadding = buf.get();
|
||||
if (fileIdPadding != 0) {
|
||||
@ -67,7 +68,7 @@ public class ManualSamplesParser extends XiaomiActivityParser {
|
||||
|
||||
final List<XiaomiManualSample> samples = new ArrayList<>();
|
||||
|
||||
while (buf.position() < buf.limit() - 4 /* crc at the end */) {
|
||||
while (buf.position() < buf.limit()) {
|
||||
final int timestamp = buf.getInt();
|
||||
final int type = buf.get() & 0xff;
|
||||
|
||||
|
@ -68,12 +68,12 @@ public class WorkoutGpsParser extends XiaomiActivityParser {
|
||||
}
|
||||
|
||||
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.limit(buf.limit() - 4); // discard crc at the end
|
||||
buf.get(new byte[7]); // skip fileId bytes
|
||||
final byte fileIdPadding = buf.get();
|
||||
if (fileIdPadding != 0) {
|
||||
LOG.warn("Expected 0 padding after fileId, got {} - parsing might fail", fileIdPadding);
|
||||
}
|
||||
|
||||
final byte[] header = new byte[headerSize];
|
||||
buf.get(header);
|
||||
|
||||
@ -81,12 +81,11 @@ public class WorkoutGpsParser extends XiaomiActivityParser {
|
||||
|
||||
if ((buf.limit() - buf.position()) % sampleSize != 0) {
|
||||
LOG.warn("Remaining data in the buffer is not a multiple of {}", sampleSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
final ActivityTrack activityTrack = new ActivityTrack();
|
||||
|
||||
while (buf.position() < buf.limit() - 4 /* crc at the end */) {
|
||||
while (buf.position() < buf.limit()) {
|
||||
final int ts = buf.getInt();
|
||||
final float longitude = buf.getFloat();
|
||||
final float latitude = buf.getFloat();
|
||||
|
Loading…
Reference in New Issue
Block a user