mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
update protobufs
This commit is contained in:
parent
60f6e0a96f
commit
48fd657d8a
15 changed files with 140 additions and 150 deletions
|
|
@ -22,7 +22,7 @@ data class Channel(val settings: ChannelProtos.ChannelSettings) {
|
|||
// TH=he unsecured channel that devices ship with
|
||||
val default = Channel(
|
||||
ChannelProtos.ChannelSettings.newBuilder()
|
||||
.setModemConfig(ChannelProtos.ChannelSettings.ModemConfig.LongFast)
|
||||
// .setModemConfig(ChannelProtos.ChannelSettings.ModemConfig.LongFast)
|
||||
.setPsk(ByteString.copyFrom(defaultPSK))
|
||||
.build()
|
||||
)
|
||||
|
|
@ -30,26 +30,20 @@ data class Channel(val settings: ChannelProtos.ChannelSettings) {
|
|||
|
||||
/// Return the name of our channel as a human readable string. If empty string, assume "Default" per mesh.proto spec
|
||||
val name: String
|
||||
get() = if (settings.name.isEmpty()) {
|
||||
// We have a new style 'empty' channel name. Use the same logic from the device to convert that to a human readable name
|
||||
if (settings.bandwidth != 0)
|
||||
"Unset"
|
||||
else when (settings.modemConfig) {
|
||||
ChannelProtos.ChannelSettings.ModemConfig.ShortFast -> "ShortFast"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.ShortSlow -> "ShortSlow"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.MidFast -> "MidFast"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.MidSlow -> "MidSlow"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.LongFast -> "LongFast"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.LongSlow -> "LongSlow"
|
||||
ChannelProtos.ChannelSettings.ModemConfig.VLongSlow -> "VLongSlow"
|
||||
get() = settings.name.ifEmpty { "Placeholder" /*
|
||||
when (settings.modemConfig) {
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortFast -> "ShortFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortSlow -> "ShortSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.MidFast -> "MidFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.MidSlow -> "MidSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast -> "LongFast"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.LongSlow -> "LongSlow"
|
||||
ConfigProtos.Config.LoRaConfig.ModemPreset.VLongSlow -> "VLongSlow"
|
||||
else -> "Invalid"
|
||||
}
|
||||
} else
|
||||
settings.name
|
||||
}*/
|
||||
}
|
||||
|
||||
val modemConfig: ChannelProtos.ChannelSettings.ModemConfig get() = settings.modemConfig
|
||||
|
||||
val psk
|
||||
val psk: ByteString
|
||||
get() = if (settings.psk.size() != 1)
|
||||
settings.psk // A standard PSK
|
||||
else {
|
||||
|
|
@ -86,4 +80,4 @@ data class Channel(val settings: ChannelProtos.ChannelSettings) {
|
|||
&& name == o.name
|
||||
}
|
||||
|
||||
fun xorHash(b: ByteArray) = b.fold(0, { acc, x -> acc xor (x.toInt() and 0xff) })
|
||||
fun xorHash(b: ByteArray) = b.fold(0) { acc, x -> acc xor (x.toInt() and 0xff) }
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.R
|
||||
|
||||
enum class ChannelOption(
|
||||
val modemConfig: ChannelProtos.ChannelSettings.ModemConfig,
|
||||
val modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset,
|
||||
val configRes: Int,
|
||||
val minBroadcastPeriodSecs: Int
|
||||
) {
|
||||
SHORT_FAST(ChannelProtos.ChannelSettings.ModemConfig.ShortFast,R.string.modem_config_short, 30),
|
||||
SHORT_SLOW(ChannelProtos.ChannelSettings.ModemConfig.ShortSlow, R.string.modem_config_slow_short, 30),
|
||||
MED_FAST(ChannelProtos.ChannelSettings.ModemConfig.MidFast,R.string.modem_config_medium, 60),
|
||||
MED_SLOW(ChannelProtos.ChannelSettings.ModemConfig.MidSlow,R.string.modem_config_slow_medium, 60),
|
||||
LONG_FAST(ChannelProtos.ChannelSettings.ModemConfig.LongFast, R.string.modem_config_long, 240),
|
||||
LONG_SLOW(ChannelProtos.ChannelSettings.ModemConfig.LongSlow, R.string.modem_config_slow_long, 375),
|
||||
VERY_LONG(ChannelProtos.ChannelSettings.ModemConfig.VLongSlow, R.string.modem_config_very_long, 375);
|
||||
SHORT_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.ShortFast, R.string.modem_config_short, 30),
|
||||
SHORT_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.ShortSlow, R.string.modem_config_slow_short, 30),
|
||||
MED_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.MidFast, R.string.modem_config_medium, 60),
|
||||
MED_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.MidSlow, R.string.modem_config_slow_medium, 60),
|
||||
LONG_FAST(ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast, R.string.modem_config_long, 240),
|
||||
LONG_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.LongSlow, R.string.modem_config_slow_long, 375),
|
||||
VERY_LONG(ConfigProtos.Config.LoRaConfig.ModemPreset.VLongSlow, R.string.modem_config_very_long, 375);
|
||||
|
||||
companion object {
|
||||
fun fromConfig(modemConfig: ChannelProtos.ChannelSettings.ModemConfig?): ChannelOption? {
|
||||
fun fromConfig(modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset?): ChannelOption? {
|
||||
for (option in values()) {
|
||||
if (option.modemConfig == modemConfig)
|
||||
if (option.modemPreset == modemPreset)
|
||||
return option
|
||||
}
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ data class ChannelSet(
|
|||
private fun urlToChannels(url: Uri): AppOnlyProtos.ChannelSet {
|
||||
val urlStr = url.toString()
|
||||
|
||||
// We no longer support the super old (about 0.8ish? verison of the URLs that don't use the # separator - I doubt
|
||||
// anyone is still using that old format
|
||||
val pathRegex = Regex("$prefix(.*)", RegexOption.IGNORE_CASE)
|
||||
val (base64) = pathRegex.find(urlStr)?.destructured
|
||||
?: throw MalformedURLException("Not a meshtastic URL: ${urlStr.take(40)}")
|
||||
|
|
@ -51,13 +49,13 @@ data class ChannelSet(
|
|||
/// 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 {
|
||||
// If we have a valid radio config use it, othterwise use whatever we have saved in the prefs
|
||||
// If we have a valid radio config use it, otherwise use whatever we have saved in the prefs
|
||||
|
||||
val channelBytes = protobuf.toByteArray() ?: ByteArray(0) // if unset just use empty
|
||||
val enc = Base64.encodeToString(channelBytes, base64Flags)
|
||||
|
||||
val p = if (upperCasePrefix)
|
||||
prefix.toUpperCase()
|
||||
prefix.uppercase()
|
||||
else
|
||||
prefix
|
||||
return Uri.parse("$p$enc")
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ fun getInitials(nameIn: String): String {
|
|||
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||
|
||||
val initials = when (words.size) {
|
||||
in 0..minchars - 1 -> {
|
||||
val nm = if (name.length >= 1)
|
||||
in 0 until minchars -> {
|
||||
val nm = if (name.isNotEmpty())
|
||||
name.first() + name.drop(1).filterNot { c -> c.lowercase() in "aeiou" }
|
||||
else
|
||||
""
|
||||
|
|
@ -101,8 +101,8 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
/// various radio settings (including the channel)
|
||||
private val _radioConfig = MutableLiveData<RadioConfigProtos.RadioConfig?>()
|
||||
val radioConfig: LiveData<RadioConfigProtos.RadioConfig?> get() = _radioConfig
|
||||
private val _deviceConfig = MutableLiveData<ConfigProtos.Config?>()
|
||||
val deviceConfig: LiveData<ConfigProtos.Config?> get() = _deviceConfig
|
||||
|
||||
private val _channels = MutableLiveData<ChannelSet?>()
|
||||
val channels: LiveData<ChannelSet?> get() = _channels
|
||||
|
|
@ -123,7 +123,7 @@ class UIViewModel @Inject constructor(
|
|||
|
||||
var positionBroadcastSecs: Int?
|
||||
get() {
|
||||
_radioConfig.value?.preferences?.let {
|
||||
_deviceConfig.value?.position?.let {
|
||||
if (it.positionBroadcastSecs > 0) return it.positionBroadcastSecs
|
||||
// These default values are borrowed from the device code.
|
||||
return 15 * 60
|
||||
|
|
@ -131,50 +131,50 @@ class UIViewModel @Inject constructor(
|
|||
return null
|
||||
}
|
||||
set(value) {
|
||||
val config = _radioConfig.value
|
||||
val config = _deviceConfig.value
|
||||
if (value != null && config != null) {
|
||||
val builder = config.toBuilder()
|
||||
builder.preferencesBuilder.positionBroadcastSecs = value
|
||||
setRadioConfig(builder.build())
|
||||
builder.positionBuilder.positionBroadcastSecs = value
|
||||
setDeviceConfig(builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
var lsSleepSecs: Int?
|
||||
get() = _radioConfig.value?.preferences?.lsSecs
|
||||
get() = _deviceConfig.value?.power?.lsSecs
|
||||
set(value) {
|
||||
val config = _radioConfig.value
|
||||
val config = _deviceConfig.value
|
||||
if (value != null && config != null) {
|
||||
val builder = config.toBuilder()
|
||||
builder.preferencesBuilder.lsSecs = value
|
||||
setRadioConfig(builder.build())
|
||||
builder.powerBuilder.lsSecs = value
|
||||
setDeviceConfig(builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
var locationShareDisabled: Boolean
|
||||
get() = _radioConfig.value?.preferences?.locationShareDisabled ?: false
|
||||
var gpsDisabled: Boolean
|
||||
get() = _deviceConfig.value?.position?.gpsDisabled ?: false
|
||||
set(value) {
|
||||
val config = _radioConfig.value
|
||||
val config = _deviceConfig.value
|
||||
if (config != null) {
|
||||
val builder = config.toBuilder()
|
||||
builder.preferencesBuilder.locationShareDisabled = value
|
||||
setRadioConfig(builder.build())
|
||||
builder.positionBuilder.gpsDisabled = value
|
||||
setDeviceConfig(builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
var isPowerSaving: Boolean?
|
||||
get() = _radioConfig.value?.preferences?.isPowerSaving
|
||||
get() = _deviceConfig.value?.power?.isPowerSaving
|
||||
set(value) {
|
||||
val config = _radioConfig.value
|
||||
val config = _deviceConfig.value
|
||||
if (value != null && config != null) {
|
||||
val builder = config.toBuilder()
|
||||
builder.preferencesBuilder.isPowerSaving = value
|
||||
setRadioConfig(builder.build())
|
||||
builder.powerBuilder.isPowerSaving = value
|
||||
setDeviceConfig(builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
var region: RadioConfigProtos.RegionCode
|
||||
get() = meshService?.region?.let { RadioConfigProtos.RegionCode.forNumber(it) }
|
||||
?: RadioConfigProtos.RegionCode.Unset
|
||||
var region: ConfigProtos.Config.LoRaConfig.RegionCode
|
||||
get() = meshService?.region?.let { ConfigProtos.Config.LoRaConfig.RegionCode.forNumber(it) }
|
||||
?: ConfigProtos.Config.LoRaConfig.RegionCode.Unset
|
||||
set(value) {
|
||||
meshService?.region = value.number
|
||||
}
|
||||
|
|
@ -216,10 +216,10 @@ class UIViewModel @Inject constructor(
|
|||
val primaryChannel: Channel? get() = _channels.value?.primaryChannel
|
||||
|
||||
// Set the radio config (also updates our saved copy in preferences)
|
||||
fun setRadioConfig(c: RadioConfigProtos.RadioConfig) {
|
||||
fun setDeviceConfig(c: ConfigProtos.Config) {
|
||||
debug("Setting new radio config!")
|
||||
meshService?.radioConfig = c.toByteArray()
|
||||
_radioConfig.value =
|
||||
meshService?.deviceConfig = c.toByteArray()
|
||||
_deviceConfig.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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue