get ready for the new short channelsettings

This commit is contained in:
Kevin Hester 2020-12-14 21:30:00 +08:00
parent f754a19c95
commit 0f63835a7f
3 changed files with 21 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import android.graphics.Bitmap
import android.net.Uri
import android.util.Base64
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
@ -52,9 +53,26 @@ data class Channel(
constructor(url: Uri) : this(urlToSettings(url))
val name: String get() = settings.name
/// 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()) defaultChannelName else settings.name
val modemConfig: MeshProtos.ChannelSettings.ModemConfig get() = settings.modemConfig
val psk get() = if(settings.psk.size() != 1)
settings.psk // A standard PSK
else {
// One of our special 1 byte PSKs, see mesh.proto for docs.
val pskIndex = settings.psk.byteAt(0).toInt()
if(pskIndex == 0)
ByteString.EMPTY // Treat as an empty PSK (no encryption)
else {
// Treat an index of 1 as the old channelDefaultKey and work up from there
val bytes = channelDefaultKey.clone()
bytes[bytes.size - 1] = (0xff and (bytes[bytes.size - 1] + pskIndex - 1)).toByte()
ByteString.copyFrom(bytes)
}
}
/**
* Return a name that is formatted as #channename-suffix
*

@ -1 +1 @@
Subproject commit aac0044b2dcca5daa86c6532c1d8c43475956d31
Subproject commit 8729bad7f6cfa461be02e3ea65fbde29435b3fe3

View file

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.20'
ext.kotlin_version = '1.4.21'
ext.coroutines_version = "1.3.9"
repositories {