1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Add customize buffer size on BTBRQueue

This commit is contained in:
Damien 'Psolyca' Gaignon 2023-07-18 18:25:59 +02:00 committed by José Rebelo
parent 247a954920
commit 916fb6b768
2 changed files with 14 additions and 3 deletions

View File

@ -42,6 +42,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.CheckInitialize
public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport implements SocketCallback {
private BtBRQueue mQueue;
private UUID mSupportedService = null;
private int mBufferSize = 1024;
private Logger logger;
public AbstractBTBRDeviceSupport(Logger logger) {
@ -54,7 +55,7 @@ public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport im
@Override
public boolean connect() {
if (mQueue == null) {
mQueue = new BtBRQueue(getBluetoothAdapter(), getDevice(), getContext(), this, getSupportedService());
mQueue = new BtBRQueue(getBluetoothAdapter(), getDevice(), getContext(), this, getSupportedService(), getBufferSize());
}
return mQueue.connect();
}
@ -117,6 +118,14 @@ public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport im
return mSupportedService;
}
protected void setBufferSize(int bufferSize) {
mBufferSize = bufferSize;
}
protected int getBufferSize() {
return mBufferSize;
}
/**
* Utility method that may be used to log incoming messages when we don't know how to deal with them yet.
*

View File

@ -56,6 +56,7 @@ public final class BtBRQueue {
private Context mContext;
private CountDownLatch mConnectionLatch;
private CountDownLatch mAvailableData;
private int mBufferSize;
private Thread writeThread = new Thread("Gadgetbridge IO writeThread") {
@Override
@ -124,7 +125,7 @@ public final class BtBRQueue {
mAvailableData.countDown();
}
}
byte[] data = new byte[1024];
byte[] data = new byte[mBufferSize];
int len = mBtSocket.getInputStream().read(data);
LOG.debug("Received data: " + StringUtils.bytesToHex(data));
mCallback.onSocketRead(Arrays.copyOf(data, len));
@ -140,12 +141,13 @@ public final class BtBRQueue {
}
};
public BtBRQueue(BluetoothAdapter btAdapter, GBDevice gbDevice, Context context, SocketCallback socketCallback, UUID supportedService) {
public BtBRQueue(BluetoothAdapter btAdapter, GBDevice gbDevice, Context context, SocketCallback socketCallback, UUID supportedService, int bufferSize) {
mBtAdapter = btAdapter;
mGbDevice = gbDevice;
mContext = context;
mCallback = socketCallback;
mService = supportedService;
mBufferSize = bufferSize;
writeThread.start();
readThread.start();