From 8a384af1d2234c0c55188f55aabb1d174683c29a Mon Sep 17 00:00:00 2001 From: Andre K Date: Tue, 11 Oct 2022 16:25:46 -0300 Subject: [PATCH 1/3] Change UUID for FromRadio characteristic --- .../com/geeksville/mesh/repository/radio/BluetoothInterface.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/BluetoothInterface.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/BluetoothInterface.kt index 00ca34e6..d77dab87 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/BluetoothInterface.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/radio/BluetoothInterface.kt @@ -100,7 +100,7 @@ class BluetoothInterface( val BTM_SERVICE_UUID: UUID = UUID.fromString("6ba1b218-15a8-461f-9fa8-5dcae273eafd") val BTM_FROMRADIO_CHARACTER: UUID = - UUID.fromString("8ba2bcc2-ee02-4a55-a531-c525c5e454d5") + UUID.fromString("2c55e69e-4993-11ed-b878-0242ac120002") val BTM_TORADIO_CHARACTER: UUID = UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7") val BTM_FROMNUM_CHARACTER: UUID = From 07ac4f8392cf57db8b71aa26f1f704c8717a3d02 Mon Sep 17 00:00:00 2001 From: andrekir Date: Tue, 11 Oct 2022 19:21:03 -0300 Subject: [PATCH 2/3] bump minDeviceVersion to 1.3.43 --- app/src/main/java/com/geeksville/mesh/service/MeshService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d9146614..560c65a2 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -117,7 +117,7 @@ class MeshService : Service(), Logging { /** The minimmum firmware version we know how to talk to. We'll still be able to talk to 1.0 firmwares but only well enough to ask them to firmware update */ - val minDeviceVersion = DeviceVersion("1.3.41") + val minDeviceVersion = DeviceVersion("1.3.43") } enum class ConnectionState { From 88b94bd018c4eeea89ce3d0d67365a305392e635 Mon Sep 17 00:00:00 2001 From: andrekir Date: Tue, 11 Oct 2022 16:27:36 -0300 Subject: [PATCH 3/3] move ChannelSet out of service --- .../com/geeksville/mesh/IMeshService.aidl | 16 ++--- .../java/com/geeksville/mesh/model/UIState.kt | 51 ++++++++++++---- .../geeksville/mesh/service/MeshService.kt | 60 +++---------------- .../com/geeksville/mesh/ui/ChannelFragment.kt | 5 +- 4 files changed, 54 insertions(+), 78 deletions(-) diff --git a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl index 329f3715..55206fcc 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl @@ -72,20 +72,12 @@ interface IMeshService { List getNodes(); /// This method is only intended for use in our GUI, so the user can set radio options - /// It returns a DeviceConfig protobuf. - byte []getDeviceConfig(); + /// It sets a Config protobuf via admin packet + void setConfig(in byte []payload); /// This method is only intended for use in our GUI, so the user can set radio options - /// It sets a DeviceConfig protobuf - void setDeviceConfig(in byte []payload); - - /// This method is only intended for use in our GUI, so the user can set radio options - /// It returns a ChannelSet protobuf. - byte []getChannels(); - - /// This method is only intended for use in our GUI, so the user can set radio options - /// It sets a ChannelSet protobuf - void setChannels(in byte []payload); + /// It sets a Channel protobuf via admin packet + void setChannel(in byte []payload); /// Send Shutdown admin packet to nodeNum void requestShutdown(in int idNum); diff --git a/app/src/main/java/com/geeksville/mesh/model/UIState.kt b/app/src/main/java/com/geeksville/mesh/model/UIState.kt index 2404ff11..9886ecf2 100644 --- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt +++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt @@ -94,7 +94,6 @@ class UIViewModel @Inject constructor( private val _channels = MutableStateFlow(ChannelSet()) val channels: StateFlow = _channels - val channelSet get() = channels.value.protobuf private val _quickChatActions = MutableStateFlow>(emptyList()) val quickChatActions: StateFlow> = _quickChatActions @@ -271,48 +270,76 @@ class UIViewModel @Inject constructor( inline fun updateDeviceConfig(crossinline body: (Config.DeviceConfig) -> Config.DeviceConfig) { val data = body(config.device) - setDeviceConfig(config { device = data }) + setConfig(config { device = data }) } inline fun updatePositionConfig(crossinline body: (Config.PositionConfig) -> Config.PositionConfig) { val data = body(config.position) - setDeviceConfig(config { position = data }) + setConfig(config { position = data }) } inline fun updatePowerConfig(crossinline body: (Config.PowerConfig) -> Config.PowerConfig) { val data = body(config.power) - setDeviceConfig(config { power = data }) + setConfig(config { power = data }) } inline fun updateNetworkConfig(crossinline body: (Config.NetworkConfig) -> Config.NetworkConfig) { val data = body(config.network) - setDeviceConfig(config { network = data }) + setConfig(config { network = data }) } inline fun updateDisplayConfig(crossinline body: (Config.DisplayConfig) -> Config.DisplayConfig) { val data = body(config.display) - setDeviceConfig(config { display = data }) + setConfig(config { display = data }) } inline fun updateLoraConfig(crossinline body: (Config.LoRaConfig) -> Config.LoRaConfig) { val data = body(config.lora) - setDeviceConfig(config { lora = data }) + setConfig(config { lora = data }) } inline fun updateBluetoothConfig(crossinline body: (Config.BluetoothConfig) -> Config.BluetoothConfig) { val data = body(config.bluetooth) - setDeviceConfig(config { bluetooth = data }) + setConfig(config { bluetooth = data }) } // Set the radio config (also updates our saved copy in preferences) - fun setDeviceConfig(config: Config) { - meshService?.deviceConfig = config.toByteArray() + fun setConfig(config: Config) { + meshService?.setConfig(config.toByteArray()) } + /// Convert the channels array to and from [AppOnlyProtos.ChannelSet] + private var _channelSet: AppOnlyProtos.ChannelSet + get() = channels.value.protobuf + set(value) { + val asChannels = value.settingsList.mapIndexed { i, c -> + channel { + role = if (i == 0) ChannelProtos.Channel.Role.PRIMARY + else ChannelProtos.Channel.Role.SECONDARY + index = i + settings = c + } + } + + debug("Sending channels to device") + asChannels.forEach { + meshService?.setChannel(it.toByteArray()) + } + + viewModelScope.launch { + channelSetRepository.clearSettings() + channelSetRepository.addAllSettings(value) + } + + val newConfig = config { lora = value.loraConfig } + if (config.lora != newConfig.lora) setConfig(newConfig) + } + val channelSet get() = _channelSet + /// Set the radio config (also updates our saved copy in preferences) - fun setChannels(c: ChannelSet) { + fun setChannels(channelSet: ChannelSet) { debug("Setting new channels!") - meshService?.channels = c.protobuf.toByteArray() + this._channelSet = channelSet.protobuf } /// our name in hte radio 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 d9146614..1f2bcd21 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -94,9 +94,6 @@ class MeshService : Service(), Logging { class NodeNumNotFoundException(id: Int) : NodeNotFoundException("NodeNum not found $id") class IdNotFoundException(id: String) : NodeNotFoundException("ID not found $id") - class NoDeviceConfigException(message: String = "No radio settings received (is our app too old?)") : - RadioNotConnectedException(message) - /** We treat software update as similar to loss of comms to the regular bluetooth service (so things like sendPosition for background GPS ignores the problem */ class IsUpdatingException : RadioNotConnectedException("Operation prohibited during firmware update") @@ -466,36 +463,6 @@ class MeshService : Service(), Logging { /// Admin channel index private var adminChannelIndex: Int = 0 - /// Convert the channels array into a ChannelSet - private var channelSet: AppOnlyProtos.ChannelSet - get() { - // this is never called - return AppOnlyProtos.ChannelSet.getDefaultInstance() - } - set(value) { - val asChannels = value.settingsList.mapIndexed { i, c -> - ChannelProtos.Channel.newBuilder().apply { - role = - if (i == 0) ChannelProtos.Channel.Role.PRIMARY else ChannelProtos.Channel.Role.SECONDARY - index = i - settings = c - }.build() - } - - debug("Sending channels to device") - asChannels.forEach { - setChannel(it) - } - - serviceScope.handledLaunch { - channelSetRepository.clearSettings() - channelSetRepository.addAllSettings(value) - } - - val newConfig = config { lora = value.loraConfig } - if (localConfig.lora != newConfig.lora) sendDeviceConfig(newConfig) - } - /// Generate a new mesh packet builder with our node as the sender, and the specified node num private fun newMeshPacketTo(idNum: Int) = MeshPacket.newBuilder().apply { if (myNodeInfo == null) @@ -1475,15 +1442,13 @@ class MeshService : Service(), Logging { /** Send our current radio config to the device */ - private fun sendDeviceConfig(c: ConfigProtos.Config) { + private fun setConfig(config: ConfigProtos.Config) { if (deviceVersion < minDeviceVersion) return debug("Setting new radio config!") sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket { - setConfig = c + setConfig = config }) - - // Update our cached copy - setLocalConfig(c) + setLocalConfig(config) // Update our cached copy } /** @@ -1698,23 +1663,14 @@ class MeshService : Service(), Logging { } } - override fun getDeviceConfig(): ByteArray = toRemoteExceptions { - this@MeshService.localConfig.toByteArray() - ?: throw NoDeviceConfigException() - } - - override fun setDeviceConfig(payload: ByteArray) = toRemoteExceptions { + override fun setConfig(payload: ByteArray) = toRemoteExceptions { val parsed = ConfigProtos.Config.parseFrom(payload) - sendDeviceConfig(parsed) + setConfig(parsed) } - override fun getChannels(): ByteArray = toRemoteExceptions { - channelSet.toByteArray() - } - - override fun setChannels(payload: ByteArray?) = toRemoteExceptions { - val parsed = AppOnlyProtos.ChannelSet.parseFrom(payload) - channelSet = parsed + override fun setChannel(payload: ByteArray?) = toRemoteExceptions { + val parsed = ChannelProtos.Channel.parseFrom(payload) + setChannel(parsed) } override fun getNodes(): MutableList = toRemoteExceptions { diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index 25ad2d77..a04cbc06 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -314,10 +314,11 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { // No matter what apply the speed selection from the user val newLoRaConfig = loRaConfig { - region = model.region - txEnabled = model.txEnabled usePreset = true modemPreset = newModemPreset + region = model.region + txEnabled = model.txEnabled + txPower = model.config.lora.txPower } val humanName = Channel(newSettings, newLoRaConfig).humanName