diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 021f80325..dc633a4d3 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -274,7 +274,7 @@ class MeshService : Service(), Logging { /** * Send a mesh packet to the radio, if the radio is not currently connected this function will throw NotConnectedException */ - private fun sendMeshPacket(packet: MeshPacket) { + private fun sendToRadio(packet: MeshPacket) { sendToRadio(ToRadio.newBuilder().apply { this.packet = packet }) @@ -769,7 +769,7 @@ class MeshService : Service(), Logging { earlyReceivedPackets.forEach { processReceivedMeshPacket(it) } earlyReceivedPackets.clear() - offlineSentPackets.forEach { sendMeshPacket(it) } + offlineSentPackets.forEach { sendToRadio(it) } offlineSentPackets.clear() } @@ -1188,7 +1188,9 @@ class MeshService : Service(), Logging { newNodes.clear() newMyNodeInfo = null - TODO("send cmd") + sendToRadio(ToRadio.newBuilder().apply { + this.wantConfigId = configNonce + }) } /// Send a position (typically from our built in GPS) into the mesh @@ -1220,7 +1222,7 @@ class MeshService : Service(), Logging { handleReceivedPosition(myNodeInfo!!.myNodeNum, position) // send the packet into the mesh - sendMeshPacket(packet.build()) + sendToRadio(packet.build()) } private val binder = object : IMeshService.Stub() { @@ -1285,7 +1287,7 @@ class MeshService : Service(), Logging { ConnectionState.DEVICE_SLEEP -> offlineSentPackets.add(packet) else -> - sendMeshPacket(packet) + sendToRadio(packet) } GeeksvilleApplication.analytics.track( diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index ac95b6788..c0b77ee78 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -237,17 +237,30 @@ class RadioInterfaceService : Service(), Logging { sendBroadcast(intent) } + /** + * With the new rev2 api, our first send is to start the configure readbacks. In that case, + * rather than waiting for FromNum notifies - we try to just aggressively read all of the responses. + */ + private var isFirstSend = true + /// Send a packet/command out the radio link private fun handleSendToRadio(p: ByteArray) { + // Do this in the IO thread because it might take a while + serviceScope.handledLaunch { + debug("sending to radio") + doWrite( + BTM_TORADIO_CHARACTER, + p + ) // Do a synchronous write, so that we can then do our reads if needed + if (logSends) { + sentPacketsLog.write(p) + sentPacketsLog.flush() + } - // For debugging/logging purposes ONLY we convert back into a protobuf for readability - // al proto = MeshProtos.ToRadio.parseFrom(p) - - debug("sending to radio") - doAsyncWrite(BTM_TORADIO_CHARACTER, p) - if (logSends) { - sentPacketsLog.write(p) - sentPacketsLog.flush() + if (isFirstSend) { + isFirstSend = false + doReadFromRadio(false) + } } } @@ -391,6 +404,9 @@ class RadioInterfaceService : Service(), Logging { // We must set this to true before broadcasting connectionChanged isConnected = true + // We treat the first send by a client as special + isFirstSend = true + // Now tell clients they can (finally use the api) broadcastConnectionChanged(true, isPermanent = false)