From 32cef96e165c5da57934caa5a2990f43d232cfda Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 27 Mar 2021 18:15:57 +0800 Subject: [PATCH] some operations should be allowed before isConnected (autobug) --- .../geeksville/mesh/service/MeshService.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) 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 f68cbc82c..21fc0b8b9 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -273,24 +273,31 @@ class MeshService : Service(), Logging { get() = (if (connectionState == ConnectionState.CONNECTED) radio.serviceP else null) ?: throw RadioNotConnectedException() - /// Send a command/packet to our radio. But cope with the possiblity that we might start up - /// before we are fully bound to the RadioInterfaceService - private fun sendToRadio(p: ToRadio.Builder) { + /** Send a command/packet to our radio. But cope with the possiblity that we might start up + before we are fully bound to the RadioInterfaceService + @param requireConnected set to false if you are okay with using a partially connected device (i.e. during startup) + */ + private fun sendToRadio(p: ToRadio.Builder, requireConnected: Boolean = true) { val b = p.build().toByteArray() if (SoftwareUpdateService.isUpdating) throw IsUpdatingException() - connectedRadio.sendToRadio(b) + if (requireConnected) + connectedRadio.sendToRadio(b) + else { + val s = radio.serviceP ?: throw RadioNotConnectedException() + s.sendToRadio(b) + } } /** * Send a mesh packet to the radio, if the radio is not currently connected this function will throw NotConnectedException */ - private fun sendToRadio(packet: MeshPacket) { + private fun sendToRadio(packet: MeshPacket, requireConnected: Boolean = true) { sendToRadio(ToRadio.newBuilder().apply { this.packet = packet - }) + }, requireConnected) } private fun updateMessageNotification(message: DataPacket) = @@ -1510,13 +1517,13 @@ class MeshService : Service(), Logging { private fun requestRadioConfig() { sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket(wantResponse = true) { getRadioRequest = true - }) + }, requireConnected = false) } private fun requestChannel(channelIndex: Int) { sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket(wantResponse = true) { getChannelRequest = channelIndex + 1 - }) + }, requireConnected = false) } private fun setChannel(channel: ChannelProtos.Channel) {