make sending packets to the BT radio async, for better throughput

This commit is contained in:
geeksville 2020-02-16 13:33:29 -08:00
parent 27d437e6ab
commit 9756c5c5e3

View file

@ -197,7 +197,7 @@ class RadioInterfaceService : Service(), Logging {
// al proto = MeshProtos.ToRadio.parseFrom(p)
debug("sending to radio")
doWrite(BTM_TORADIO_CHARACTER, p)
doAsyncWrite(BTM_TORADIO_CHARACTER, p)
if (logSends) {
sentPacketsLog.write(p)
sentPacketsLog.flush()
@ -337,6 +337,27 @@ class RadioInterfaceService : Service(), Logging {
}
}
/**
* do an asynchronous write operation
* Any error responses will be ignored (other than log messages)
*/
private fun doAsyncWrite(uuid: UUID, a: ByteArray) = toRemoteExceptions {
if (!isConnected)
throw RadioNotConnectedException()
else {
debug("queuing ${a.size} bytes to $uuid")
// Note: we generate a new characteristic each time, because we are about to
// change the data and we want the data stored in the closure
val toRadio = service.getCharacteristic(uuid)
toRadio.value = a
safe!!.asyncWriteCharacteristic(toRadio) {
debug("asyncwrite of ${a.size} bytes completed")
}
}
}
/**
* do a synchronous read operation
*/