1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 14:32:54 +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 { public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport implements SocketCallback {
private BtBRQueue mQueue; private BtBRQueue mQueue;
private UUID mSupportedService = null; private UUID mSupportedService = null;
private int mBufferSize = 1024;
private Logger logger; private Logger logger;
public AbstractBTBRDeviceSupport(Logger logger) { public AbstractBTBRDeviceSupport(Logger logger) {
@ -54,7 +55,7 @@ public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport im
@Override @Override
public boolean connect() { public boolean connect() {
if (mQueue == null) { if (mQueue == null) {
mQueue = new BtBRQueue(getBluetoothAdapter(), getDevice(), getContext(), this, getSupportedService()); mQueue = new BtBRQueue(getBluetoothAdapter(), getDevice(), getContext(), this, getSupportedService(), getBufferSize());
} }
return mQueue.connect(); return mQueue.connect();
} }
@ -117,6 +118,14 @@ public abstract class AbstractBTBRDeviceSupport extends AbstractDeviceSupport im
return mSupportedService; 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. * 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 Context mContext;
private CountDownLatch mConnectionLatch; private CountDownLatch mConnectionLatch;
private CountDownLatch mAvailableData; private CountDownLatch mAvailableData;
private int mBufferSize;
private Thread writeThread = new Thread("Gadgetbridge IO writeThread") { private Thread writeThread = new Thread("Gadgetbridge IO writeThread") {
@Override @Override
@ -124,7 +125,7 @@ public final class BtBRQueue {
mAvailableData.countDown(); mAvailableData.countDown();
} }
} }
byte[] data = new byte[1024]; byte[] data = new byte[mBufferSize];
int len = mBtSocket.getInputStream().read(data); int len = mBtSocket.getInputStream().read(data);
LOG.debug("Received data: " + StringUtils.bytesToHex(data)); LOG.debug("Received data: " + StringUtils.bytesToHex(data));
mCallback.onSocketRead(Arrays.copyOf(data, len)); 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; mBtAdapter = btAdapter;
mGbDevice = gbDevice; mGbDevice = gbDevice;
mContext = context; mContext = context;
mCallback = socketCallback; mCallback = socketCallback;
mService = supportedService; mService = supportedService;
mBufferSize = bufferSize;
writeThread.start(); writeThread.start();
readThread.start(); readThread.start();