From e20e66b7f7bbe1805c50af4da0a32d03f0e89378 Mon Sep 17 00:00:00 2001 From: andrekir Date: Mon, 11 Sep 2023 19:39:49 -0300 Subject: [PATCH] refactor: handle range test messages when module enabled --- .../geeksville/mesh/service/MeshService.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 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 8298e72c7..34c609d58 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -13,6 +13,7 @@ import com.geeksville.mesh.android.Logging import com.geeksville.mesh.concurrent.handledLaunch import com.geeksville.mesh.* import com.geeksville.mesh.LocalOnlyProtos.LocalConfig +import com.geeksville.mesh.LocalOnlyProtos.LocalModuleConfig import com.geeksville.mesh.MeshProtos.MeshPacket import com.geeksville.mesh.MeshProtos.ToRadio import com.geeksville.mesh.android.hasBackgroundPermission @@ -248,6 +249,8 @@ class MeshService : Service(), Logging { .launchIn(serviceScope) radioConfigRepository.localConfigFlow.onEach { localConfig = it } .launchIn(serviceScope) + radioConfigRepository.moduleConfigFlow.onEach { moduleConfig = it } + .launchIn(serviceScope) radioConfigRepository.channelSetFlow.onEach { channelSet = it } .launchIn(serviceScope) @@ -351,6 +354,7 @@ class MeshService : Service(), Logging { var myNodeInfo: MyNodeInfo? = null private var localConfig: LocalConfig = LocalConfig.getDefaultInstance() + private var moduleConfig: LocalModuleConfig = LocalModuleConfig.getDefaultInstance() private var channelSet: AppOnlyProtos.ChannelSet = AppOnlyProtos.ChannelSet.getDefaultInstance() /// True after we've done our initial node db init @@ -540,7 +544,7 @@ class MeshService : Service(), Logging { to = toId, time = rxTime * 1000L, id = packet.id, - dataType = if (data.portnumValue == Portnums.PortNum.DETECTION_SENSOR_APP_VALUE) Portnums.PortNum.TEXT_MESSAGE_APP_VALUE else data.portnumValue, + dataType = data.portnumValue, bytes = bytes, hopLimit = hopLimit, channel = packet.channel, @@ -659,8 +663,20 @@ class MeshService : Service(), Logging { shouldBroadcast = false } - else -> - debug("No custom processing needed for ${data.portnumValue}") + Portnums.PortNum.RANGE_TEST_APP_VALUE -> { + if (!moduleConfig.rangeTest.enabled) return + val u = dataPacket.copy(dataType = Portnums.PortNum.TEXT_MESSAGE_APP_VALUE) + rememberDataPacket(u) + updateMessageNotification(u) + } + + Portnums.PortNum.DETECTION_SENSOR_APP_VALUE -> { + val u = dataPacket.copy(dataType = Portnums.PortNum.TEXT_MESSAGE_APP_VALUE) + rememberDataPacket(u) + updateMessageNotification(u) + } + + else -> debug("No custom processing needed for ${data.portnumValue}") } // We always tell other apps when new data packets arrive