From 227450528dc76275894410efc199e8453b9a9a7c Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 16 Feb 2020 18:14:40 -0800 Subject: [PATCH] expose channel settings via an URL --- TODO.md | 10 ++++++---- app/src/main/AndroidManifest.xml | 2 +- .../java/com/geeksville/mesh/MainActivity.kt | 19 +++++++++++++++++-- .../java/com/geeksville/mesh/ui/Status.kt | 19 ++++++++++++++++++- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 329915820..fcc02ebd4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,14 @@ # High priority MVP features required for first public alpha +* make chat pretty and functional * let user set name and shortname +* take video + * stop scan when we start the service * set the radio by using the service * startforegroundservice only if we have a valid radio * if no radio is selected, launch app on the radio select screen -* provide gps location for devices that don't have it * let user send texts * when we select a new radio, restart the service * show bt scan progress centered and towards the bottom of the screen @@ -17,14 +19,12 @@ MVP features required for first public alpha * on onStop somehow stop the BT scan (to prevent burning battery) * add alphatest screen at boot * have the foreground service's notification show a summary of network status, add (individually maskable) notifications for received texts or new positions -* prompt user to turnon bluetooth and bind * test bt boot behavior * fix BT device scanning - make a setup screen * when a text arrives, move that node info card to the bottom on the window - put the text to the left of the card. with a small arrow/distance/shortname * let the user type texts somewhere * include a background behind our cloud graphics, so redraws work properly * show direction and distance on the nodeinfo cards -* show radio config screen, it shows past channels (and the current one) * use this for preferences? https://developer.android.com/guide/topics/ui/settings/ * do setOwner every time we connect to the radio, use our settings, radio should ignore if unchanged * send location data for devices that don't have a GPS - https://developer.android.com/training/location/change-location-settings @@ -122,4 +122,6 @@ Don't leave device discoverable. Don't let unpaired users do things with device * all chat in the app defaults to group chat * start bt receive on boot * warn user to bt pair -* suppress logging output if running a release build (required for play store) \ No newline at end of file +* suppress logging output if running a release build (required for play store) +* provide gps location for devices that don't have it +* prompt user to turnon bluetooth and bind \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1531466cf..6f5c3e9a5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -102,7 +102,7 @@ + android:pathPrefix="/c/" /> diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 181a62da5..1f7b176ba 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -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() } } diff --git a/app/src/main/java/com/geeksville/mesh/ui/Status.kt b/app/src/main/java/com/geeksville/mesh/ui/Status.kt index 2f0fc37f9..f16b5b268 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/Status.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/Status.kt @@ -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" + } } /**