expose channel settings via an URL

This commit is contained in:
geeksville 2020-02-16 18:14:40 -08:00
parent 7cfcda2a30
commit 227450528d
4 changed files with 42 additions and 8 deletions

View file

@ -20,6 +20,7 @@ import com.geeksville.mesh.service.*
import com.geeksville.mesh.ui.MeshApp
import com.geeksville.mesh.ui.TextMessage
import com.geeksville.mesh.ui.UIState
import com.geeksville.mesh.ui.getInitials
import com.geeksville.util.exceptionReporter
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
@ -152,7 +153,8 @@ class MainActivity : AppCompatActivity(), Logging,
private fun setOwner() {
// Note: we are careful to not set a new unique ID
meshService!!.setOwner(null, "Kevin Xter", "kx")
val name = UIState.ownerName.value
meshService!!.setOwner(null, name, getInitials(name))
}
private fun sendTestPackets() {
@ -263,12 +265,25 @@ class MainActivity : AppCompatActivity(), Logging,
}
}
/// Read the config bytes from the radio so we can show them in our GUI, the radio's copy is ground truth
private fun readRadioConfig() {
val bytes = meshService!!.radioConfig
val config = MeshProtos.RadioConfig.parseFrom(bytes)
UIState.radioConfig.value = config
debug("Read config from radio, channel URL ${UIState.channelUrl}")
}
/// Called when we gain/lose a connection to our mesh radio
private fun onMeshConnectionChanged(connected: Boolean) {
UIState.isConnected.value = connected
debug("connchange ${UIState.isConnected.value}")
if (connected) {
// everytime the radio reconnects, we slam in our current owner data
// always get the current radio config when we connect
readRadioConfig()
// everytime the radio reconnects, we slam in our current owner data, the radio is smart enough to only broadcast if needed
setOwner()
}
}

View file

@ -1,7 +1,9 @@
package com.geeksville.mesh.ui
import android.util.Base64
import androidx.compose.Model
import androidx.compose.mutableStateOf
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
@ -72,8 +74,23 @@ object UIState {
val messages = mutableStateOf(testTexts)
/// Are we connected to our radio device
var isConnected = mutableStateOf(false)
val isConnected = mutableStateOf(false)
/// various radio settings (including the channel)
val radioConfig = mutableStateOf(MeshProtos.RadioConfig.getDefaultInstance())
/// our name in hte radio
/// Note, we generate owner initials automatically for now
val ownerName = mutableStateOf("fixme readfromprefs")
/// Return an URL that represents the current channel values
val channelUrl
get(): String {
val channelBytes = radioConfig.value.channelSettings.toByteArray()
val enc = Base64.encodeToString(channelBytes, Base64.URL_SAFE + Base64.NO_WRAP)
return "https://www.meshtastic.org/c/$enc"
}
}
/**