Open mikedorin opened 11 months ago
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
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