wip adding channelset

pull/257/head
Kevin Hester 2021-02-27 11:44:05 +08:00
rodzic 31a106039b
commit 0743feadc4
3 zmienionych plików z 38 dodań i 15 usunięć

Wyświetl plik

@ -71,18 +71,26 @@ interface IMeshService {
*/ */
List<NodeInfo> getNodes(); List<NodeInfo> 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). /// 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) /// Also includes any messages we have sent recently (useful for finding current message status)
List<DataPacket> getOldMessages(); List<DataPacket> 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 /// This method is only intended for use in our GUI, so the user can set radio options
/// It sets a RadioConfig protobuf /// It sets a RadioConfig protobuf
void setRadioConfig(in byte []payload); 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. Is the packet radio currently connected to the phone? Returns a ConnectionState string.
*/ */

Wyświetl plik

@ -12,6 +12,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.geeksville.android.Logging import com.geeksville.android.Logging
import com.geeksville.mesh.AppOnlyProtos
import com.geeksville.mesh.IMeshService import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MyNodeInfo import com.geeksville.mesh.MyNodeInfo
@ -69,15 +70,6 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
} }
companion object { 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 = fun getPreferences(context: Context): SharedPreferences =
context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE) context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
} }
@ -101,6 +93,9 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) { val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
} }
val channels = object : MutableLiveData<AppOnlyProtos.ChannelSet?>(null) {
}
var positionBroadcastSecs: Int? var positionBroadcastSecs: Int?
get() { get() {
radioConfig.value?.preferences?.let { radioConfig.value?.preferences?.let {
@ -155,15 +150,31 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
debug("ViewModel cleared") 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) /// 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!") debug("Setting new radio config!")
meshService?.radioConfig = c.toByteArray() meshService?.radioConfig = c.toByteArray()
radioConfig.value = 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) 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) { getPreferences(context).edit(commit = true) {
this.putString("channel-url", getChannel(c)!!.getChannelUrl().toString()) this.putString("channel-url", primaryChannel!!.getChannelUrl().toString())
} }
} }

Wyświetl plik

@ -1604,6 +1604,10 @@ class MeshService : Service(), Logging {
this@MeshService.setRadioConfig(payload) this@MeshService.setRadioConfig(payload)
} }
override fun getChannels(): ByteArray {
TODO("Not yet implemented")
}
override fun getNodes(): MutableList<NodeInfo> = toRemoteExceptions { override fun getNodes(): MutableList<NodeInfo> = toRemoteExceptions {
val r = nodeDBbyID.values.toMutableList() val r = nodeDBbyID.values.toMutableList()
info("in getOnline, count=${r.size}") info("in getOnline, count=${r.size}")