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

Is there a trick to set the MTU size? #581

Open
mikedorin opened this issue Oct 7, 2023 · 1 comment
Open

Is there a trick to set the MTU size? #581

mikedorin opened this issue Oct 7, 2023 · 1 comment

Comments

@mikedorin
Copy link

Sometimes it works, and sometimes I get a timeout/error.
Is there a trick to setting it?
Is there a maximum value?
Thank you,
Mike

@hcyAndroid
Copy link

private suspend fun initBleMTU(bleDevice: BleDevice): Boolean {
    val MAX_MTU = 180
    return withContext(Dispatchers.IO) {
        suspendCoroutine { continuation ->
            BleManager.getInstance()
                .setMtu(bleDevice, MAX_MTU, object : BleMtuChangedCallback() {
                    override fun onSetMTUFailure(exception: BleException) {
                        // 设置 MTU 失败
                        Logger.e("$TAG 设置MTU失败==${exception.description}")
                        if (isActive) {
                            continuation.resume(false) // 返回 false 表示初始化失败
                        }

                    }

                    override fun onMtuChanged(mtu: Int) {
                        // 设置 MTU 成功
                        Logger.d("$TAG 设置MTU成功==${mtu}")
                        if (isActive) {
                            continuation.resume(true) // 返回 true 表示初始化成功
                        }
                    }
                })
        }
    }

},

mtu between 23 and 512

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

No branches or pull requests

2 participants