reformat per coding conventions

This commit is contained in:
Kevin Hester 2021-03-29 20:33:06 +08:00
parent 2c75d0dee7
commit 5b653d29f8
29 changed files with 207 additions and 149 deletions

View file

@ -18,7 +18,8 @@ data class Channel(
)
private val cleartextPSK = ByteString.EMPTY
private val defaultPSK = byteArrayOfInts(1) // a shortstring code to indicate we need our default PSK
private val defaultPSK =
byteArrayOfInts(1) // a shortstring code to indicate we need our default PSK
// TH=he unsecured channel that devices ship with
val defaultChannel = Channel(
@ -55,7 +56,7 @@ data class Channel(
val pskIndex = settings.psk.byteAt(0).toInt()
if (pskIndex == 0)
cleartextPSK
cleartextPSK
else {
// Treat an index of 1 as the old channelDefaultKey and work up from there
val bytes = channelDefaultKey.clone()

View file

@ -1,14 +1,29 @@
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) {
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);
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? {
@ -18,6 +33,7 @@ enum class ChannelOption(val modemConfig: ChannelProtos.ChannelSettings.ModemCon
}
return null
}
val defaultMinBroadcastPeriod = VERY_LONG.minBroadcastPeriodSecs
}
}

View file

@ -4,8 +4,6 @@ import android.graphics.Bitmap
import android.net.Uri
import android.util.Base64
import com.geeksville.mesh.AppOnlyProtos
import com.geeksville.mesh.MeshProtos
import com.google.protobuf.ByteString
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter
import com.journeyapps.barcodescanner.BarcodeEncoder
@ -42,11 +40,12 @@ data class ChannelSet(
/**
* Return the primary channel info
*/
val primaryChannel: Channel? get() =
if(protobuf.settingsCount > 0)
Channel(protobuf.getSettings(0))
else
null
val primaryChannel: Channel?
get() =
if (protobuf.settingsCount > 0)
Channel(protobuf.getSettings(0))
else
null
/// 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
@ -56,7 +55,7 @@ data class ChannelSet(
val channelBytes = protobuf.toByteArray() ?: ByteArray(0) // if unset just use empty
val enc = Base64.encodeToString(channelBytes, base64Flags)
val p = if(upperCasePrefix)
val p = if (upperCasePrefix)
prefix.toUpperCase()
else
prefix
@ -68,7 +67,12 @@ data class ChannelSet(
// We encode as UPPER case for the QR code URL because QR codes are more efficient for that special case
val bitMatrix =
multiFormatWriter.encode(getChannelUrl(true).toString(), BarcodeFormat.QR_CODE, 192, 192);
multiFormatWriter.encode(
getChannelUrl(true).toString(),
BarcodeFormat.QR_CODE,
192,
192
)
val barcodeEncoder = BarcodeEncoder()
return barcodeEncoder.createBitmap(bitMatrix)
}

View file

@ -5,14 +5,15 @@ import com.geeksville.android.Logging
/**
* Provide structured access to parse and compare device version strings
*/
data class DeviceVersion(val asString: String): Comparable<DeviceVersion>, Logging {
data class DeviceVersion(val asString: String) : Comparable<DeviceVersion>, Logging {
val asInt get() = try {
verStringToInt(asString)
} catch(e: Exception) {
warn("Exception while parsing version '$asString', assuming version 0")
0
}
val asInt
get() = try {
verStringToInt(asString)
} catch (e: Exception) {
warn("Exception while parsing version '$asString', assuming version 0")
0
}
/**
* Convert a version string of the form 1.23.57 to a comparable integer of

View file

@ -12,7 +12,9 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.geeksville.android.Logging
import com.geeksville.mesh.*
import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.MyNodeInfo
import com.geeksville.mesh.RadioConfigProtos
import com.geeksville.mesh.database.MeshtasticDatabase
import com.geeksville.mesh.database.PacketRepository
import com.geeksville.mesh.database.entity.Packet
@ -135,7 +137,8 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
}
var region: RadioConfigProtos.RegionCode
get() = meshService?.region?.let { RadioConfigProtos.RegionCode.forNumber(it) } ?: RadioConfigProtos.RegionCode.Unset
get() = meshService?.region?.let { RadioConfigProtos.RegionCode.forNumber(it) }
?: RadioConfigProtos.RegionCode.Unset
set(value) {
meshService?.region = value.number
}