update for proto changes

This commit is contained in:
andrekir
2022-09-18 18:35:13 -03:00
parent 5c586526da
commit 5382fdae49
10 changed files with 78 additions and 60 deletions

View File

@@ -1,6 +1,7 @@
package com.geeksville.mesh.model
import com.geeksville.mesh.ChannelProtos
import com.geeksville.mesh.ConfigProtos.Config.LoRaConfig.ModemPreset
import com.geeksville.mesh.ConfigKt.loRaConfig
import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.channelSettings
@@ -28,7 +29,7 @@ data class Channel(
// The default channel that devices ship with
val default = Channel(
channelSettings { psk = ByteString.copyFrom(defaultPSK) },
loRaConfig { modemPreset = ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast }
loRaConfig { usePreset = true; modemPreset = ModemPreset.LONG_FAST }
)
}
@@ -39,13 +40,13 @@ data class Channel(
if (loraConfig.bandwidth != 0)
"Unset"
else when (loraConfig.modemPreset) {
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortFast -> "ShortFast"
ConfigProtos.Config.LoRaConfig.ModemPreset.ShortSlow -> "ShortSlow"
ConfigProtos.Config.LoRaConfig.ModemPreset.MedFast -> "MidFast"
ConfigProtos.Config.LoRaConfig.ModemPreset.MedSlow -> "MidSlow"
ConfigProtos.Config.LoRaConfig.ModemPreset.LongFast -> "LongFast"
ConfigProtos.Config.LoRaConfig.ModemPreset.LongSlow -> "LongSlow"
ConfigProtos.Config.LoRaConfig.ModemPreset.VLongSlow -> "VLongSlow"
ModemPreset.SHORT_FAST -> "ShortFast"
ModemPreset.SHORT_SLOW -> "ShortSlow"
ModemPreset.MEDIUM_FAST -> "MidFast"
ModemPreset.MEDIUM_SLOW -> "MidSlow"
ModemPreset.LONG_FAST -> "LongFast"
ModemPreset.LONG_SLOW -> "LongSlow"
ModemPreset.VERY_LONG_SLOW -> "VLongSlow"
else -> "Invalid"
}
}

View File

@@ -1,23 +1,23 @@
package com.geeksville.mesh.model
import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.ConfigProtos.Config.LoRaConfig.ModemPreset
import com.geeksville.mesh.R
enum class ChannelOption(
val modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset,
val modemPreset: ModemPreset,
val configRes: Int,
val minBroadcastPeriodSecs: Int
) {
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.MedFast, R.string.modem_config_medium, 60),
MED_SLOW(ConfigProtos.Config.LoRaConfig.ModemPreset.MedSlow, 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);
SHORT_FAST(ModemPreset.SHORT_FAST, R.string.modem_config_short, 30),
SHORT_SLOW(ModemPreset.SHORT_SLOW, R.string.modem_config_slow_short, 30),
MEDIUM_FAST(ModemPreset.MEDIUM_FAST, R.string.modem_config_medium, 60),
MEDIUM_SLOW(ModemPreset.MEDIUM_SLOW, R.string.modem_config_slow_medium, 60),
LONG_FAST(ModemPreset.LONG_FAST, R.string.modem_config_long, 60),
LONG_SLOW(ModemPreset.LONG_SLOW, R.string.modem_config_slow_long, 240),
VERY_LONG_SLOW(ModemPreset.VERY_LONG_SLOW, R.string.modem_config_very_long, 375);
companion object {
fun fromConfig(modemPreset: ConfigProtos.Config.LoRaConfig.ModemPreset?): ChannelOption? {
fun fromConfig(modemPreset: ModemPreset?): ChannelOption? {
for (option in values()) {
if (option.modemPreset == modemPreset)
return option
@@ -25,6 +25,6 @@ enum class ChannelOption(
return null
}
val defaultMinBroadcastPeriod = VERY_LONG.minBroadcastPeriodSecs
val defaultMinBroadcastPeriod = VERY_LONG_SLOW.minBroadcastPeriodSecs
}
}

View File

@@ -206,24 +206,30 @@ class UIViewModel @Inject constructor(
_requestChannelUrl.value = null
}
var txEnabled: Boolean
get() = config.lora.txEnabled
set(value) {
updateLoraConfig { it.copy { txEnabled = value } }
}
var region: Config.LoRaConfig.RegionCode
get() = config.lora?.region ?: Config.LoRaConfig.RegionCode.Unset
get() = config.lora.region
set(value) {
updateLoraConfig { it.copy { region = value } }
}
fun gpsString(pos: Position): String {
return when (_localConfig.value?.display?.gpsFormat) {
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatDec -> GPSFormat.dec(pos)
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatDMS -> GPSFormat.toDMS(pos)
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatUTM -> GPSFormat.toUTM(pos)
ConfigProtos.Config.DisplayConfig.GpsCoordinateFormat.GpsFormatMGRS -> GPSFormat.toMGRS(pos)
else -> GPSFormat.dec(pos)
fun gpsString(p: Position): String {
return when (config.display.gpsFormat) {
Config.DisplayConfig.GpsCoordinateFormat.DEC -> GPSFormat.DEC(p)
Config.DisplayConfig.GpsCoordinateFormat.DMS -> GPSFormat.DMS(p)
Config.DisplayConfig.GpsCoordinateFormat.UTM -> GPSFormat.UTM(p)
Config.DisplayConfig.GpsCoordinateFormat.MGRS -> GPSFormat.MGRS(p)
else -> GPSFormat.DEC(p)
}
}
@Suppress("MemberVisibilityCanBePrivate")
val isRouter: Boolean = config.device?.role == Config.DeviceConfig.Role.Router
val isRouter: Boolean = config.device.role == Config.DeviceConfig.Role.ROUTER
// We consider hasWifi = ESP32
fun isESP32() = myNodeInfo.value?.hasWifi == true
@@ -279,9 +285,9 @@ class UIViewModel @Inject constructor(
setDeviceConfig(config { power = data })
}
inline fun updateNetworkConfig(crossinline body: (Config.WiFiConfig) -> Config.WiFiConfig) {
val data = body(config.wifi)
setDeviceConfig(config { wifi = data })
inline fun updateNetworkConfig(crossinline body: (Config.NetworkConfig) -> Config.NetworkConfig) {
val data = body(config.network)
setDeviceConfig(config { network = data })
}
inline fun updateDisplayConfig(crossinline body: (Config.DisplayConfig) -> Config.DisplayConfig) {
@@ -360,14 +366,7 @@ class UIViewModel @Inject constructor(
}
fun requestFactoryReset() {
val config = _localConfig.value
if (config != null) {
val builder = config.device.toBuilder()
builder.factoryReset = true
val newConfig = ConfigProtos.Config.newBuilder()
newConfig.device = builder.build()
setDeviceConfig(newConfig.build())
}
meshService?.requestFactoryReset(DataPacket.ID_LOCAL)
}
/**

View File

@@ -59,7 +59,7 @@ class LocalConfigRepository @Inject constructor(
if (config.hasDevice()) setDeviceConfig(config.device)
if (config.hasPosition()) setPositionConfig(config.position)
if (config.hasPower()) setPowerConfig(config.power)
if (config.hasWifi()) setWifiConfig(config.wifi)
if (config.hasNetwork()) setWifiConfig(config.network)
if (config.hasDisplay()) setDisplayConfig(config.display)
if (config.hasLora()) setLoraConfig(config.lora)
if (config.hasBluetooth()) setBluetoothConfig(config.bluetooth)
@@ -83,9 +83,9 @@ class LocalConfigRepository @Inject constructor(
}
}
private suspend fun setWifiConfig(config: ConfigProtos.Config.WiFiConfig) {
private suspend fun setWifiConfig(config: ConfigProtos.Config.NetworkConfig) {
localConfigStore.updateData { preference ->
preference.toBuilder().setWifi(config).build()
preference.toBuilder().setNetwork(config).build()
}
}

View File

@@ -729,14 +729,14 @@ class MeshService : Service(), Logging {
private fun handleReceivedAdmin(fromNodeNum: Int, a: AdminProtos.AdminMessage) {
// For the time being we only care about admin messages from our local node
if (fromNodeNum == myNodeNum) {
when (a.variantCase) {
AdminProtos.AdminMessage.VariantCase.GET_CONFIG_RESPONSE -> {
when (a.payloadVariantCase) {
AdminProtos.AdminMessage.PayloadVariantCase.GET_CONFIG_RESPONSE -> {
val response = a.getConfigResponse
debug("Admin: received config ${response.payloadVariantCase}")
setLocalConfig(response)
}
AdminProtos.AdminMessage.VariantCase.GET_CHANNEL_RESPONSE -> {
AdminProtos.AdminMessage.PayloadVariantCase.GET_CHANNEL_RESPONSE -> {
val mi = myNodeInfo
if (mi != null) {
val ch = a.getChannelResponse
@@ -768,7 +768,7 @@ class MeshService : Service(), Logging {
}
}
else ->
warn("No special processing needed for ${a.variantCase}")
warn("No special processing needed for ${a.payloadVariantCase}")
}
}
@@ -1277,7 +1277,7 @@ class MeshService : Service(), Logging {
DataPair("dev_error_count", myInfo.errorCount)
)
if (myInfo.errorCode != MeshProtos.CriticalErrorCode.Unspecified && myInfo.errorCode != MeshProtos.CriticalErrorCode.None) {
if (myInfo.errorCode != MeshProtos.CriticalErrorCode.UNSPECIFIED && myInfo.errorCode != MeshProtos.CriticalErrorCode.NONE) {
GeeksvilleApplication.analytics.track(
"dev_error",
DataPair("code", myInfo.errorCode.number),
@@ -1395,6 +1395,12 @@ class MeshService : Service(), Logging {
})
}
private fun requestFactoryReset(nodeId: String) {
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
factoryReset = 1
})
}
/**
* Start the modern (REV2) API configuration flow
*/
@@ -1722,6 +1728,10 @@ class MeshService : Service(), Logging {
override fun requestReboot(nodeId: String) = toRemoteExceptions {
this@MeshService.requestReboot(nodeId)
}
override fun requestFactoryReset(nodeId: String) = toRemoteExceptions {
this@MeshService.requestFactoryReset(nodeId)
}
}
}

View File

@@ -43,15 +43,15 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
model.localConfig.asLiveData().observe(viewLifecycleOwner) {
binding.positionBroadcastPeriodEditText.setText(model.config.position.positionBroadcastSecs.toString())
binding.lsSleepEditText.setText(model.config.power.lsSecs.toString())
binding.positionBroadcastPeriodView.isEnabled = !model.config.position.gpsDisabled
binding.positionBroadcastSwitch.isChecked = !model.config.position.gpsDisabled
binding.positionBroadcastPeriodView.isEnabled = model.config.position.gpsEnabled
binding.positionBroadcastSwitch.isChecked = model.config.position.gpsEnabled
binding.lsSleepView.isEnabled = model.config.power.isPowerSaving && model.isESP32()
binding.lsSleepSwitch.isChecked = model.config.power.isPowerSaving && model.isESP32()
}
model.connectionState.observe(viewLifecycleOwner) { connectionState ->
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.positionBroadcastPeriodView.isEnabled = connected && !model.config.position.gpsDisabled
binding.positionBroadcastPeriodView.isEnabled = connected && model.config.position.gpsEnabled
binding.lsSleepView.isEnabled = connected && model.config.power.isPowerSaving
binding.positionBroadcastSwitch.isEnabled = connected
binding.lsSleepSwitch.isEnabled = connected && model.isESP32()
@@ -87,7 +87,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.positionBroadcastSwitch.setOnCheckedChangeListener { btn, isChecked ->
if (btn.isPressed) {
model.updatePositionConfig { it.copy { gpsDisabled = !isChecked } }
model.updatePositionConfig { it.copy { gpsEnabled = isChecked } }
debug("User changed locationShare to $isChecked")
}
}

View File

@@ -251,7 +251,10 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
debug("Switching back to default channel")
installSettings(
Channel.default.settings,
Channel.default.loraConfig.copy { region = model.region }
Channel.default.loraConfig.copy {
region = model.region
txEnabled = model.txEnabled
}
)
}
.show()
@@ -312,6 +315,8 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
// No matter what apply the speed selection from the user
val newLoRaConfig = loRaConfig {
region = model.region
txEnabled = model.txEnabled
usePreset = true
modemPreset = newModemPreset
}

View File

@@ -161,17 +161,17 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (connected == MeshService.ConnectionState.DISCONNECTED)
model.setOwner("")
if (model.config.position.gpsDisabled) {
if (model.config.position.gpsEnabled) {
binding.provideLocationCheckbox.isEnabled = true
} else {
binding.provideLocationCheckbox.isChecked = false
binding.provideLocationCheckbox.isEnabled = false
} else {
binding.provideLocationCheckbox.isEnabled = true
}
// update the region selection from the device
val region = model.region
val spinner = binding.regionSpinner
val unsetIndex = regions.indexOf(ConfigProtos.Config.LoRaConfig.RegionCode.Unset.name)
val unsetIndex = regions.indexOf(ConfigProtos.Config.LoRaConfig.RegionCode.UNSET.name)
spinner.onItemSelectedListener = null
debug("current region is $region")

View File

@@ -20,18 +20,18 @@ import kotlin.math.sin
******************************************************************************/
object GPSFormat {
fun dec(p: Position): String {
fun DEC(p: Position): String {
return String.format("%.5f %.5f", p.latitude, p.longitude).replace(",", ".")
}
fun toDMS(p: Position): String {
fun DMS(p: Position): String {
val lat = degreesToDMS(p.latitude, true)
val lon = degreesToDMS(p.longitude, false)
fun string(a: Array<String>) = String.format("%s°%s'%.5s\"%s", a[0], a[1], a[2], a[3])
return string(lat) + " " + string(lon)
}
fun toUTM(p: Position): String {
fun UTM(p: Position): String {
val UTM = UTM.from(Point.point(p.longitude, p.latitude))
return String.format(
"%s%s %.6s %.7s",
@@ -42,7 +42,7 @@ object GPSFormat {
)
}
fun toMGRS(p: Position): String {
fun MGRS(p: Position): String {
val MGRS = MGRS.from(Point.point(p.longitude, p.latitude))
return String.format(
"%s%s %s%s %05d %05d",