mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-12 21:19:25 +01:00
Add customize buffer size on BTBRQueue
This commit is contained in:
parent
247a954920
commit
916fb6b768
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user