mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix java paths for protos
This commit is contained in:
parent
bd796524b9
commit
1eaabfc216
11 changed files with 113 additions and 118 deletions
|
|
@ -3,6 +3,7 @@ package com.geeksville.mesh.model
|
|||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.google.protobuf.ByteString
|
||||
import com.google.zxing.BarcodeFormat
|
||||
|
|
@ -15,7 +16,7 @@ fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].
|
|||
|
||||
|
||||
data class Channel(
|
||||
val settings: MeshProtos.ChannelSettings = MeshProtos.ChannelSettings.getDefaultInstance()
|
||||
val settings: ChannelProtos.ChannelSettings = ChannelProtos.ChannelSettings.getDefaultInstance()
|
||||
) {
|
||||
companion object {
|
||||
// Note: this string _SHOULD NOT BE LOCALIZED_ because it directly hashes to values used on the device for the default channel name.
|
||||
|
|
@ -30,8 +31,8 @@ data class Channel(
|
|||
|
||||
// Placeholder when emulating
|
||||
val emulated = Channel(
|
||||
MeshProtos.ChannelSettings.newBuilder().setName(defaultChannelName)
|
||||
.setModemConfig(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build()
|
||||
ChannelProtos.ChannelSettings.newBuilder().setName(defaultChannelName)
|
||||
.setModemConfig(ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -42,16 +43,16 @@ data class Channel(
|
|||
if (settings.bandwidth != 0)
|
||||
"Unset"
|
||||
else when (settings.modemConfig) {
|
||||
MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128 -> "Medium"
|
||||
MeshProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128 -> "ShortFast"
|
||||
MeshProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512 -> "LongAlt"
|
||||
MeshProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096 -> "LongSlow"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128 -> "Medium"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128 -> "ShortFast"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512 -> "LongAlt"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096 -> "LongSlow"
|
||||
else -> "Invalid"
|
||||
}
|
||||
} else
|
||||
settings.name
|
||||
|
||||
val modemConfig: MeshProtos.ChannelSettings.ModemConfig get() = settings.modemConfig
|
||||
val modemConfig: ChannelProtos.ChannelSettings.ModemConfig get() = settings.modemConfig
|
||||
|
||||
val psk
|
||||
get() = if (settings.psk.size() != 1)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.R
|
||||
|
||||
enum class ChannelOption(val modemConfig: MeshProtos.ChannelSettings.ModemConfig, val configRes: Int, val minBroadcastPeriodSecs: Int) {
|
||||
SHORT(MeshProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128, R.string.modem_config_short, 3),
|
||||
MEDIUM(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128, R.string.modem_config_medium, 12),
|
||||
LONG(MeshProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512, R.string.modem_config_long, 240),
|
||||
VERY_LONG(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096, R.string.modem_config_very_long, 375);
|
||||
|
||||
companion object {
|
||||
fun fromConfig(modemConfig: MeshProtos.ChannelSettings.ModemConfig?): ChannelOption? {
|
||||
for (option in values()) {
|
||||
if (option.modemConfig == modemConfig)
|
||||
return option
|
||||
}
|
||||
return null
|
||||
}
|
||||
val defaultMinBroadcastPeriod = VERY_LONG.minBroadcastPeriodSecs
|
||||
}
|
||||
package com.geeksville.mesh.model
|
||||
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.R
|
||||
|
||||
enum class ChannelOption(val modemConfig: ChannelProtos.ChannelSettings.ModemConfig, val configRes: Int, val minBroadcastPeriodSecs: Int) {
|
||||
SHORT(ChannelProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128, R.string.modem_config_short, 3),
|
||||
MEDIUM(ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128, R.string.modem_config_medium, 12),
|
||||
LONG(ChannelProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512, R.string.modem_config_long, 240),
|
||||
VERY_LONG(ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096, R.string.modem_config_very_long, 375);
|
||||
|
||||
companion object {
|
||||
fun fromConfig(modemConfig: ChannelProtos.ChannelSettings.ModemConfig?): ChannelOption? {
|
||||
for (option in values()) {
|
||||
if (option.modemConfig == modemConfig)
|
||||
return option
|
||||
}
|
||||
return null
|
||||
}
|
||||
val defaultMinBroadcastPeriod = VERY_LONG.minBroadcastPeriodSecs
|
||||
}
|
||||
}
|
||||
|
|
@ -11,10 +11,6 @@ import com.google.zxing.MultiFormatWriter
|
|||
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||
import java.net.MalformedURLException
|
||||
|
||||
/** Utility function to make it easy to declare byte arrays - FIXME move someplace better */
|
||||
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
|
||||
|
||||
|
||||
data class ChannelSet(
|
||||
val protobuf: AppOnlyProtos.ChannelSet = AppOnlyProtos.ChannelSet.getDefaultInstance()
|
||||
) {
|
||||
|
|
@ -48,6 +44,13 @@ data class ChannelSet(
|
|||
/// Can this channel be changed right now?
|
||||
var editable = false
|
||||
|
||||
/**
|
||||
* Return the primary channel info
|
||||
*/
|
||||
val primaryChannel: Channel get() {
|
||||
return Channel(protobuf.getSettings(0))
|
||||
}
|
||||
|
||||
/// Return an URL that represents the current channel values
|
||||
/// @param upperCasePrefix - portions of the URL can be upper case to make for more efficient QR codes
|
||||
fun getChannelUrl(upperCasePrefix: Boolean = false): Uri {
|
||||
|
|
|
|||
|
|
@ -12,10 +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
|
||||
import com.geeksville.mesh.*
|
||||
import com.geeksville.mesh.database.MeshtasticDatabase
|
||||
import com.geeksville.mesh.database.PacketRepository
|
||||
import com.geeksville.mesh.database.entity.Packet
|
||||
|
|
@ -90,16 +87,16 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
}
|
||||
|
||||
/// various radio settings (including the channel)
|
||||
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
|
||||
val radioConfig = object : MutableLiveData<RadioConfigProtos.RadioConfig?>(null) {
|
||||
}
|
||||
|
||||
val channels = object : MutableLiveData<AppOnlyProtos.ChannelSet?>(null) {
|
||||
val channels = object : MutableLiveData<ChannelSet?>(null) {
|
||||
}
|
||||
|
||||
var positionBroadcastSecs: Int?
|
||||
get() {
|
||||
radioConfig.value?.preferences?.let {
|
||||
if (it.locationShare == MeshProtos.LocationSharing.LocDisabled) return 0
|
||||
if (it.locationShare == RadioConfigProtos.LocationSharing.LocDisabled) return 0
|
||||
if (it.positionBroadcastSecs > 0) return it.positionBroadcastSecs
|
||||
// These default values are borrowed from the device code.
|
||||
if (it.isRouter) return 60 * 60
|
||||
|
|
@ -116,11 +113,11 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
builder.preferencesBuilder.gpsUpdateInterval = value
|
||||
builder.preferencesBuilder.sendOwnerInterval = max(1, 3600 / value).toInt()
|
||||
builder.preferencesBuilder.locationShare =
|
||||
MeshProtos.LocationSharing.LocEnabled
|
||||
RadioConfigProtos.LocationSharing.LocEnabled
|
||||
} else {
|
||||
builder.preferencesBuilder.positionBroadcastSecs = Int.MAX_VALUE
|
||||
builder.preferencesBuilder.locationShare =
|
||||
MeshProtos.LocationSharing.LocDisabled
|
||||
RadioConfigProtos.LocationSharing.LocDisabled
|
||||
}
|
||||
setRadioConfig(builder.build())
|
||||
}
|
||||
|
|
@ -153,13 +150,11 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
/**
|
||||
* 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)
|
||||
private fun setRadioConfig(c: MeshProtos.RadioConfig) {
|
||||
val primaryChannel: Channel? get() = channels.value?.primaryChannel
|
||||
|
||||
///
|
||||
// Set the radio config (also updates our saved copy in preferences)
|
||||
private fun setRadioConfig(c: RadioConfigProtos.RadioConfig) {
|
||||
debug("Setting new radio config!")
|
||||
meshService?.radioConfig = c.toByteArray()
|
||||
radioConfig.value =
|
||||
|
|
@ -167,23 +162,14 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
}
|
||||
|
||||
/// Set the radio config (also updates our saved copy in preferences)
|
||||
private fun setChannels(c: AppOnlyProtos.ChannelSet) {
|
||||
fun setChannels(c: ChannelSet) {
|
||||
debug("Setting new channels!")
|
||||
meshService?.channels = c.toByteArray()
|
||||
meshService?.channels = c.protobuf.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", primaryChannel!!.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
|
||||
/** Update just the channel settings portion of our config (both in the device and in saved preferences) */
|
||||
fun setChannel(c: MeshProtos.ChannelSettings) {
|
||||
// When running on the emulator, radio config might not really be available, in that case, just ignore attempts to change the config
|
||||
radioConfig.value?.toBuilder()?.let { config ->
|
||||
config.channelSettings = c
|
||||
setRadioConfig(config.build())
|
||||
this.putString("channel-url", c.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue