Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HID equipment negotiation MTU optimization suggestion #691

Open
ZacharyTech opened this issue May 25, 2020 · 0 comments
Open

HID equipment negotiation MTU optimization suggestion #691

ZacharyTech opened this issue May 25, 2020 · 0 comments

Comments

@ZacharyTech
Copy link

ZacharyTech commented May 25, 2020

Describe the bug

  1. The HID device is connected through the system settings, and the APP will receive BleGattException for the first time the device is connected, status = 4
rxBleDevice
    .establishConnection(false)
    .flatMapSingle (rxConn-> rxConn.requestMtu (517))

To Reproduce

  1. HID devices are connected through system settings
  2. Open the APP to connect the device and negotiate MTU
  3. Disconnect the device in the APP
  4. Connect the device again
  5. Received BleGattException

Expected behavior
Get the correct MTU after executing RxBleConnection#getMtu()

Reason
Android's native API BluetoothGattCallback#onMtuChanged() will be notified twice: first status = 0, then status = 4, RxAndroidBle received 4 issued a BleGattException, but RxAndroidBle has retained the correct MTU, through RxBleConnection#getMtu() can be obtained

There are two situations when the APP connects to the device connected in the Android system settings:
No MTU negotiated: need to call BluetoothGatt#requestMtu to negotiate MTU
MTU has been negotiated: BluetoothGattCallback#onMtuChanged will directly return to MTU when connected.

My solution

 rxBleDevice
    .establishConnection(false)
    .flatMapSingle (rxConn-> rxConn.requestMtu (517))
    .onErrorResumeNext(t-> 
    (t instanceof BleGattException) && (((BleGattException) t).getStatus() == 4) 
        ? Single.just(rxBleConnection.getMtu()) 
        : Single.error(t))

Suggest
Please consider adding similar processing in RxAndroidBle to ensure that RxBleConnection#requestMtu() can return the correct MTU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant