Per-channel minimum broadcast period enforcement

pull/244/head
Vadim Furman 2021-02-12 19:07:14 -08:00
rodzic a8d095d1d7
commit 8a065c5b88
3 zmienionych plików z 21 dodań i 11 usunięć

Wyświetl plik

@ -3,11 +3,11 @@ 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) {
SHORT(MeshProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128, R.string.modem_config_short),
MEDIUM(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128, R.string.modem_config_medium),
LONG(MeshProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512, R.string.modem_config_long),
VERY_LONG(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096, R.string.modem_config_very_long);
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? {

Wyświetl plik

@ -30,11 +30,11 @@ import com.geeksville.android.Logging
import com.geeksville.android.hideKeyboard
import com.geeksville.android.isGooglePlayAvailable
import com.geeksville.mesh.MainActivity
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.R
import com.geeksville.mesh.android.bluetoothManager
import com.geeksville.mesh.android.usbManager
import com.geeksville.mesh.databinding.SettingsFragmentBinding
import com.geeksville.mesh.model.ChannelOption
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.BluetoothInterface
import com.geeksville.mesh.service.MeshService
@ -620,13 +620,22 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
}
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
val str = binding.positionBroadcastPeriodEditText.text.toString()
val n = str.toIntOrNull()
if (n != null && n <= MAX_INT_DEVICE && n >= 0) {
model.positionBroadcastSecs = n
val textEdit = binding.positionBroadcastPeriodEditText
val n = textEdit.text.toString().toIntOrNull()
val minBroadcastPeriodSecs =
ChannelOption.fromConfig(model.radioConfig.value?.channelSettings?.modemConfig)?.minBroadcastPeriodSecs
?: 9000
info("edit broadcast $n min $minBroadcastPeriodSecs")
if (n != null && n >= 0 && n >= minBroadcastPeriodSecs) {
model.positionBroadcastSecs = n
} else {
binding.scanStatusText.text = "Bad value: $str"
// restore the value in the edit field
textEdit.setText(model.positionBroadcastSecs.toString())
val errorText = if (n == null || n <= 0) "Bad value: ${textEdit.text.toString()}" else
getString(R.string.broadcast_period_too_small).format(minBroadcastPeriodSecs)
Toast.makeText(context, errorText, Toast.LENGTH_LONG).show()
}
requireActivity().hideKeyboard()
}

Wyświetl plik

@ -86,4 +86,5 @@
<string name="broadcast_position_secs">Broadcast position period (in seconds), 0 - disable</string>
<string name="ls_sleep_secs">Device sleep period (in seconds)</string>
<string name="meshtastic_messages_notifications">Notifications about messages</string>
<string name="broadcast_period_too_small">Minimum broadcast period for this channel is %d</string>
</resources>