From 0743feadc496e8963b47a45c1122d98589eb564a Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 27 Feb 2021 11:44:05 +0800 Subject: [PATCH] wip adding channelset --- .../com/geeksville/mesh/IMeshService.aidl | 16 ++++++--- .../java/com/geeksville/mesh/model/UIState.kt | 33 ++++++++++++------- .../geeksville/mesh/service/MeshService.kt | 4 +++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl index fcb44874a..03580804d 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl @@ -71,18 +71,26 @@ interface IMeshService { */ List getNodes(); - /// This method is only intended for use in our GUI, so the user can set radio options - /// It returns a RadioConfig protobuf. - byte []getRadioConfig(); - /// Return an list of MeshPacket protobuf (byte arrays) which were received while your client app was offline (recent messages only). /// Also includes any messages we have sent recently (useful for finding current message status) List getOldMessages(); + /// This method is only intended for use in our GUI, so the user can set radio options + /// It returns a RadioConfig protobuf. + byte []getRadioConfig(); + /// This method is only intended for use in our GUI, so the user can set radio options /// It sets a RadioConfig protobuf void setRadioConfig(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); + /** Is the packet radio currently connected to the phone? Returns a ConnectionState string. */ 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 34ff5992b..bc4f3a0b5 100644 --- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt +++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt @@ -12,6 +12,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.geeksville.android.Logging +import com.geeksville.mesh.AppOnlyProtos import com.geeksville.mesh.IMeshService import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.MyNodeInfo @@ -69,15 +70,6 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging } companion object { - /** - * Return the current channel info - */ - fun getChannel(c: MeshProtos.RadioConfig?): Channel? { - val channel = c?.channelSettings?.let { Channel(it) } - - return channel - } - fun getPreferences(context: Context): SharedPreferences = context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE) } @@ -101,6 +93,9 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging val radioConfig = object : MutableLiveData(null) { } + val channels = object : MutableLiveData(null) { + } + var positionBroadcastSecs: Int? get() { radioConfig.value?.preferences?.let { @@ -155,15 +150,31 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging debug("ViewModel cleared") } + /** + * Return the primary channel info + */ + val primaryChannel: ChannelSet? get() { + return channels.value?.let { it -> + Channel(it.getSettings(0)) + } + } /// Set the radio config (also updates our saved copy in preferences) - fun setRadioConfig(c: MeshProtos.RadioConfig) { + private fun setRadioConfig(c: MeshProtos.RadioConfig) { debug("Setting new radio config!") meshService?.radioConfig = c.toByteArray() radioConfig.value = c // Must be done after calling the service, so we will will properly throw if the service failed (and therefore not cache invalid new settings) + } + + /// Set the radio config (also updates our saved copy in preferences) + private fun setChannels(c: AppOnlyProtos.ChannelSet) { + debug("Setting new channels!") + meshService?.channels = c.toByteArray() + channels.value = + c // Must be done after calling the service, so we will will properly throw if the service failed (and therefore not cache invalid new settings) getPreferences(context).edit(commit = true) { - this.putString("channel-url", getChannel(c)!!.getChannelUrl().toString()) + this.putString("channel-url", primaryChannel!!.getChannelUrl().toString()) } } 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 501f6cc77..861a2f295 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -1604,6 +1604,10 @@ class MeshService : Service(), Logging { this@MeshService.setRadioConfig(payload) } + override fun getChannels(): ByteArray { + TODO("Not yet implemented") + } + override fun getNodes(): MutableList = toRemoteExceptions { val r = nodeDBbyID.values.toMutableList() info("in getOnline, count=${r.size}")