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:
José Rebelo
2025-03-23 14:17:21 +00:00
parent 59dd321069
commit 1f8fdf7eef
@@ -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);