1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Amazfit GTS: Fix broken activity data on Firmware 0.0.9.xx

Fixes #1924
This commit is contained in:
Andreas Shimokawa 2020-07-22 11:03:30 +02:00
parent f460f6abd1
commit ef09e24482
3 changed files with 25 additions and 6 deletions

View File

@ -193,6 +193,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
protected MusicStateSpec bufferMusicStateSpec = null;
private boolean heartRateNotifyEnabled;
private int mMTU = 23;
protected int mActivitySampleSize = 4;
public HuamiSupport() {
this(LOG);
@ -1665,7 +1666,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
// TODO: react on 0x10, 0x02, 0x01 on notification (success)
}
private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
protected void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
// if (getDeviceInfo().supportsHeartrate()) {
// getDevice().addDeviceInfo(new GenericItem(
// getContext().getString(R.string.DEVINFO_HR_VER),
@ -2526,4 +2527,8 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
public int getMTU() {
return mMTU;
}
public int getActivitySampleSize() {
return mActivitySampleSize;
}
}

View File

@ -37,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperationNew;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
public class AmazfitGTSSupport extends AmazfitBipSupport {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTSSupport.class);
@ -124,4 +125,15 @@ public class AmazfitGTSSupport extends AmazfitBipSupport {
return this;
}
@Override
protected void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
super.handleDeviceInfo(info);
if (gbDevice.getFirmwareVersion() != null) {
Version version = new Version(gbDevice.getFirmwareVersion());
if (version.compareTo(new Version("0.0.9.00")) > 0) {
mActivitySampleSize = 8;
}
}
}
}

View File

@ -52,11 +52,13 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class FetchActivityOperation extends AbstractFetchOperation {
private static final Logger LOG = LoggerFactory.getLogger(FetchActivityOperation.class);
private final int sampleSize;
private List<MiBandActivitySample> samples = new ArrayList<>(60 * 24); // 1day per default
public FetchActivityOperation(HuamiSupport support) {
super(support);
setName("fetching activity data");
sampleSize = getSupport().getActivitySampleSize();
}
@Override
@ -160,7 +162,7 @@ public class FetchActivityOperation extends AbstractFetchOperation {
return;
}
if ((value.length % 4) == 1) {
if ((value.length % sampleSize) == 1) {
if ((byte) (lastPacketCounter + 1) == value[0]) {
lastPacketCounter++;
bufferActivityData(value);
@ -182,11 +184,11 @@ public class FetchActivityOperation extends AbstractFetchOperation {
protected void bufferActivityData(byte[] value) {
int len = value.length;
if (len % 4 != 1) {
if (len % sampleSize != 1) {
throw new AssertionError("Unexpected activity array size: " + len);
}
for (int i = 1; i < len; i+=4) {
for (int i = 1; i < len; i += sampleSize) {
MiBandActivitySample sample = createSample(value[i], value[i + 1], value[i + 2], value[i + 3]); // lgtm [java/index-out-of-bounds]
samples.add(sample);
}