1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-27 01:57:32 +01:00

added mtu transactions

This commit is contained in:
Daniel Dakhno 2019-11-14 04:53:19 +01:00
parent 98ea9be5cd
commit 64b407da92
7 changed files with 71 additions and 0 deletions

View File

@ -351,6 +351,11 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
}
}
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
}
@Override
public void onSetFmFrequency(float frequency) {

View File

@ -209,4 +209,9 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
mSupport.onReadRemoteRssi(gatt, rssi, status);
}
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
mSupport.onMtuChanged(gatt, mtu, status);
}
}

View File

@ -60,4 +60,8 @@ public abstract class AbstractGattCallback implements GattCallback {
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
}
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
}
}

View File

@ -533,6 +533,19 @@ public final class BtLEQueue {
checkWaitingCharacteristic(characteristic, status);
}
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
if(getCallbackToUse() != null){
getCallbackToUse().onMtuChanged(gatt, mtu, status);
}
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,

View File

@ -104,6 +104,8 @@ public interface GattCallback {
*/
void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status);
void onMtuChanged(BluetoothGatt gatt, int mtu, int status);
// /**
// * @see BluetoothGattCallback#onMtuChanged(BluetoothGatt, int, int)
// * @param gatt

View File

@ -18,13 +18,17 @@
package nodomain.freeyourgadget.gadgetbridge.service.btle;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.Build;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.NotifyAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ReadAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.RequestMtuAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
@ -56,6 +60,13 @@ public class TransactionBuilder {
return add(action);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public TransactionBuilder requestMtu(int mtu){
return add(
new RequestMtuAction(mtu)
);
}
public TransactionBuilder notify(BluetoothGattCharacteristic characteristic, boolean enable) {
if (characteristic == null) {
LOG.warn("Unable to notify characteristic: null");

View File

@ -0,0 +1,31 @@
package nodomain.freeyourgadget.gadgetbridge.service.btle.actions;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.Build;
import androidx.annotation.RequiresApi;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
public class RequestMtuAction extends BtLEAction {
private int mtu;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public RequestMtuAction(int mtu) {
super(null);
this.mtu = mtu;
}
@Override
public boolean expectsResult() {
return false;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean run(BluetoothGatt gatt) {
return gatt.requestMtu(this.mtu);
}
}