Garmin: Remove timeout logic from CobsCoDec

The decoder should not be responsible from keeping track of timeouts,
and this is doing more harm than good - some devices stop sending data
for ~3 seconds sometimes, which then gets out of sync and never
recovers, especially without MLR.
This commit is contained in:
José Rebelo
2026-06-24 21:53:58 +01:00
parent c2f7f8f883
commit a561809ec9
6 changed files with 6 additions and 16 deletions
+1
View File
@@ -50,6 +50,7 @@
* Fix connection attempts while bluetooth is off for some devices
* Fix drawer being drawn behind status bar
* Fix file type when sharing
* Garmin: Fix activity sync getting stuck on some devices
* Garmin: Fix empty caller when unknown
* Garmin: Fix http request without headers
* Garmin: Fix unknown transfer notification
@@ -276,6 +276,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
return new GarminPrefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()), gbDevice);
}
@NonNull
@Override
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
builder.setDeviceState(GBDevice.State.INITIALIZING);
@@ -20,6 +20,7 @@ import android.content.Intent;
import android.widget.Toast;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
@@ -65,6 +66,7 @@ public class GarminSupportHrm extends GarminSupport {
addSupportedProfile(heartRateProfile);
}
@NonNull
@Override
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
super.initializeDevice(builder);
@@ -3,33 +3,18 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.communicator
import java.nio.ByteBuffer;
public class CobsCoDec {
private static final long BUFFER_TIMEOUT = 1500L; // turn this value up while debugging
private final ByteBuffer byteBuffer = ByteBuffer.allocate(10_000);
private long lastUpdate;
private byte[] cobsDecodedMessage;
/**
* Accumulates received bytes in a local buffer, clearing it after a timeout, and attempts to
* parse it.
*
* @param bytes
*/
public void receivedBytes(byte[] bytes) {
final long now = System.currentTimeMillis();
if ((now - lastUpdate) > BUFFER_TIMEOUT) {
reset();
}
lastUpdate = now;
byteBuffer.put(bytes);
decode();
}
private void reset() {
cobsDecodedMessage = null;
byteBuffer.clear();
}
public byte[] retrieveMessage() {
final byte[] resultPacket = cobsDecodedMessage;
cobsDecodedMessage = null;
@@ -84,7 +84,7 @@ public class CommunicatorV1 implements ICommunicator {
if (null == message)
return;
final byte[] payload = cobsCoDec.encode(message);
final byte[] payload = CobsCoDec.encode(message);
final TransactionBuilder builder = mSupport.createTransactionBuilder(taskName);
int remainingBytes = payload.length;
@@ -49,6 +49,7 @@
<change>Fix connection attempts while bluetooth is off for some devices</change>
<change>Fix drawer being drawn behind status bar</change>
<change>Fix file type when sharing</change>
<change>Garmin: Fix activity sync getting stuck on some devices</change>
<change>Garmin: Fix empty caller when unknown</change>
<change>Garmin: Fix http request without headers</change>
<change>Garmin: Fix unknown transfer notification</change>