kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
channel setting is healthier
rodzic
1eaabfc216
commit
850358e103
|
@ -419,6 +419,8 @@ class MeshService : Service(), Logging {
|
|||
|
||||
private var radioConfig: RadioConfigProtos.RadioConfig? = null
|
||||
|
||||
private var channels = listOf<ChannelProtos.Channel>()
|
||||
|
||||
/// True after we've done our initial node db init
|
||||
@Volatile
|
||||
private var haveNodeDB = false
|
||||
|
@ -510,6 +512,33 @@ class MeshService : Service(), Logging {
|
|||
/// My node ID string
|
||||
private val myNodeID get() = toNodeID(myNodeNum)
|
||||
|
||||
/// Convert the channels array into a ChannelSet
|
||||
private var channelSet: AppOnlyProtos.ChannelSet
|
||||
get() {
|
||||
val cs = channels.filter {
|
||||
it.role != ChannelProtos.Channel.Role.DISABLED
|
||||
}.map {
|
||||
it.settings
|
||||
}
|
||||
|
||||
return AppOnlyProtos.ChannelSet.newBuilder().apply {
|
||||
addAllSettings(cs)
|
||||
}.build()
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
// FIXME, send channels to device!
|
||||
|
||||
channels = asChannels
|
||||
}
|
||||
|
||||
/// 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)
|
||||
|
@ -1604,12 +1633,13 @@ class MeshService : Service(), Logging {
|
|||
this@MeshService.setRadioConfig(payload)
|
||||
}
|
||||
|
||||
override fun getChannels(): ByteArray {
|
||||
TODO("Not yet implemented")
|
||||
override fun getChannels(): ByteArray = toRemoteExceptions {
|
||||
channelSet.toByteArray()
|
||||
}
|
||||
|
||||
override fun setChannels(payload: ByteArray?) {
|
||||
TODO("Not yet implemented")
|
||||
val parsed = AppOnlyProtos.ChannelSet.parseFrom(payload)
|
||||
channelSet = parsed
|
||||
}
|
||||
|
||||
override fun getNodes(): MutableList<NodeInfo> = toRemoteExceptions {
|
||||
|
|
|
@ -16,12 +16,14 @@ import com.geeksville.analytics.DataPair
|
|||
import com.geeksville.android.GeeksvilleApplication
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.android.hideKeyboard
|
||||
import com.geeksville.mesh.AppOnlyProtos
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.databinding.ChannelFragmentBinding
|
||||
import com.geeksville.mesh.model.Channel
|
||||
import com.geeksville.mesh.model.ChannelOption
|
||||
import com.geeksville.mesh.model.ChannelSet
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.service.MeshService
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -197,9 +199,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
|
||||
if (modemConfig != ChannelProtos.ChannelSettings.ModemConfig.UNRECOGNIZED)
|
||||
newSettings.modemConfig = modemConfig
|
||||
|
||||
val newChannel = newSettings.build()
|
||||
val newSet = ChannelSet(AppOnlyProtos.ChannelSet.newBuilder().addSettings(newChannel).build())
|
||||
// Try to change the radio, if it fails, tell the user why and throw away their redits
|
||||
try {
|
||||
model.setChannel(newSettings.build())
|
||||
model.setChannels(newSet)
|
||||
// Since we are writing to radioconfig, that will trigger the rest of the GUI update (QR code etc)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("ignoring channel problem", ex)
|
||||
|
|
Ładowanie…
Reference in New Issue