mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Zepp OS: Fix parsing of PAI values after factory reset
It looks like they come with type 0 after a factory reset..? Probably some undefined behavior, but the sample size still matches. It seems to disappear for subsequent samples.
This commit is contained in:
+12
-1
@@ -61,10 +61,15 @@ public class FetchPaiOperation extends AbstractRepeatingFetchOperation {
|
||||
|
||||
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
if (bytes.length % 102 != 0) {
|
||||
LOG.error("Unexpected length for PAI data {}, not divisible by 102", bytes.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (buf.position() < bytes.length) {
|
||||
final int type = buf.get() & 0xff;
|
||||
|
||||
if (type != 5) {
|
||||
if (type != 5 && type != 0) {
|
||||
LOG.error("Unsupported PAI type {}", type);
|
||||
return false;
|
||||
}
|
||||
@@ -98,6 +103,12 @@ public class FetchPaiOperation extends AbstractRepeatingFetchOperation {
|
||||
GB.hexdump(unknown2)
|
||||
);
|
||||
|
||||
if (type == 0) {
|
||||
// Values from before the factory reset?
|
||||
LOG.warn("Ignoring PAI type 0");
|
||||
continue;
|
||||
}
|
||||
|
||||
final HuamiPaiSample sample = new HuamiPaiSample();
|
||||
sample.setTimestamp(timestamp.getTimeInMillis());
|
||||
sample.setUtcOffset(utcOffsetInQuarterHours * 900000);
|
||||
|
||||
Reference in New Issue
Block a user