Increase MTU _before_ discovering services, because it will speed up the link

This commit is contained in:
geeksville 2020-04-22 08:10:23 -07:00
parent b63ebadf72
commit 8ec8b038b6
2 changed files with 11 additions and 11 deletions

View file

@ -372,17 +372,17 @@ class RadioInterfaceService : Service(), Logging {
// hasForcedRefresh = true
forceServiceRefresh()
}
// we begin by setting our MTU size as high as it can go
safe!!.asyncRequestMtu(512) { mtuRes ->
mtuRes.getOrThrow() // FIXME - why sometimes is the result Unit!?!
debug("requested MTU result=$mtuRes")
// FIXME - no need to discover services more than once - instead use lazy() to use them in future attempts
safe!!.asyncDiscoverServices { discRes ->
discRes.getOrThrow() // FIXME, instead just try to reconnect?
debug("Discovered services!")
// we begin by setting our MTU size as high as it can go
safe!!.asyncRequestMtu(512) { mtuRes ->
// FIXME - no need to discover services more than once - instead use lazy() to use them in future attempts
safe!!.asyncDiscoverServices { discRes ->
discRes.getOrThrow() // FIXME, instead just try to reconnect?
debug("Discovered services!")
serviceScope.handledLaunch {
debug("requested MTU result=$mtuRes")
mtuRes.getOrThrow() // FIXME - why sometimes is the result Unit!?!
delay(500) // android BLE is buggy and needs a 500ms sleep before calling getChracteristic, or you might get back null
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)!!

View file

@ -46,11 +46,11 @@ class SoftwareUpdateService : JobIntentService(), Logging {
sync.connect()
sync.use { _ ->
sync.discoverServices() // Get our services
// we begin by setting our MTU size as high as it can go
sync.requestMtu(512)
sync.discoverServices() // Get our services
val service = sync.gatt!!.services.find { it.uuid == SW_UPDATE_UUID }!!
fun doFirmwareUpdate(assetName: String) {