From ce140383bb33f2a9cb2a445fd0d275121550e385 Mon Sep 17 00:00:00 2001 From: andrekir Date: Sun, 16 Oct 2022 19:19:03 -0300 Subject: [PATCH] install channels from wantConfig --- .../datastore/ChannelSetRepository.kt | 2 +- .../geeksville/mesh/service/MeshService.kt | 39 ++++++++----------- .../geeksville/mesh/ui/SettingsFragment.kt | 9 +++-- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt b/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt index 25438373..bcb1f7f1 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt @@ -42,7 +42,7 @@ class ChannelSetRepository @Inject constructor( suspend fun addSettings(channel: ChannelProtos.Channel) { channelSetStore.updateData { preference -> - preference.toBuilder().addSettings(channel.index, channel.settings).build() + preference.toBuilder().addSettings(channel.settings).build() } } 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 f2841949..ffcf1dba 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -712,28 +712,8 @@ class MeshService : Service(), Logging { val ch = a.getChannelResponse debug("Admin: Received channel ${ch.index}") - val packetToSave = MeshLog( - UUID.randomUUID().toString(), - "Channel", - System.currentTimeMillis(), - ch.toString() - ) - insertMeshLog(packetToSave) - if (ch.index + 1 < mi.maxChannels) { - - // Stop once we get to the first disabled entry - if (/* ch.hasSettings() || */ ch.role != ChannelProtos.Channel.Role.DISABLED) { - // Not done yet, add new entries and request next channel - addChannelSettings(ch) - requestChannel(ch.index + 1) - } else { - debug("We've received the last channel, allowing rest of app to start...") - onHasSettings() - } - } else { - debug("Received max channels, starting app") - onHasSettings() + handleChannel(ch) } } } @@ -1110,6 +1090,7 @@ class MeshService : Service(), Logging { MeshProtos.FromRadio.CONFIG_COMPLETE_ID_FIELD_NUMBER -> handleConfigComplete(proto.configCompleteId) MeshProtos.FromRadio.MY_INFO_FIELD_NUMBER -> handleMyInfo(proto.myInfo) MeshProtos.FromRadio.NODE_INFO_FIELD_NUMBER -> handleNodeInfo(proto.nodeInfo) + MeshProtos.FromRadio.CHANNEL_FIELD_NUMBER -> handleChannel(proto.channel) MeshProtos.FromRadio.CONFIG_FIELD_NUMBER -> handleDeviceConfig(proto.config) MeshProtos.FromRadio.MODULECONFIG_FIELD_NUMBER -> handleModuleConfig(proto.moduleConfig) else -> errormsg("Unexpected FromRadio variant") @@ -1152,6 +1133,18 @@ class MeshService : Service(), Logging { // setModuleConfig(config) } + private fun handleChannel(ch: ChannelProtos.Channel) { + debug("Received channel ${ch.index}") + val packetToSave = MeshLog( + UUID.randomUUID().toString(), + "Channel", + System.currentTimeMillis(), + ch.toString() + ) + insertMeshLog(packetToSave) + if (ch.role != ChannelProtos.Channel.Role.DISABLED) addChannelSettings(ch) + } + /** * Convert a protobuf NodeInfo into our model objects and update our node DB */ @@ -1328,8 +1321,8 @@ class MeshService : Service(), Logging { if (deviceVersion < minDeviceVersion || appVersion < minAppVersion) { info("Device firmware or app is too old, faking config so firmware update can occur") clearLocalConfig() - onHasSettings() - } else requestChannel(0) // Now start reading channels + } + onHasSettings() } } else warn("Ignoring stale config complete") diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 3c9bae20..4f37591d 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -299,14 +299,15 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { model.localConfig.asLiveData().observe(viewLifecycleOwner) { if (!model.isConnected()) { val configCount = it.allFields.size - binding.scanStatusText.text = "Device config ($configCount / 7)" + if (configCount > 0) + binding.scanStatusText.text = "Device config ($configCount / 7)" } else updateNodeInfo() } model.channels.asLiveData().observe(viewLifecycleOwner) { - if (!model.isConnected()) { - val channelCount = it.protobuf.settingsCount - if (channelCount > 0) binding.scanStatusText.text = "Channels ($channelCount / 8)" + if (!model.isConnected()) it.protobuf.let { ch -> + if (!ch.hasLoraConfig() && ch.settingsCount > 0) + binding.scanStatusText.text = "Channels (${ch.settingsCount} / 8)" } }