mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor: Create core:api module and set up publishing (#4362)
This commit is contained in:
parent
4e7de3b73c
commit
15760da074
23 changed files with 381 additions and 55 deletions
|
|
@ -17,8 +17,8 @@
|
|||
package org.meshtastic.core.model
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import org.meshtastic.core.common.byteArrayOfInts
|
||||
import org.meshtastic.core.common.xorHash
|
||||
import org.meshtastic.core.model.util.byteArrayOfInts
|
||||
import org.meshtastic.core.model.util.xorHash
|
||||
import org.meshtastic.proto.ChannelProtos
|
||||
import org.meshtastic.proto.ConfigKt.loRaConfig
|
||||
import org.meshtastic.proto.ConfigProtos
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
* Copyright (c) 2025-2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -14,23 +14,10 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@file:Suppress("MagicNumber")
|
||||
|
||||
package org.meshtastic.core.model
|
||||
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.label_long_fast
|
||||
import org.meshtastic.core.strings.label_long_moderate
|
||||
import org.meshtastic.core.strings.label_long_slow
|
||||
import org.meshtastic.core.strings.label_long_turbo
|
||||
import org.meshtastic.core.strings.label_medium_fast
|
||||
import org.meshtastic.core.strings.label_medium_slow
|
||||
import org.meshtastic.core.strings.label_short_fast
|
||||
import org.meshtastic.core.strings.label_short_slow
|
||||
import org.meshtastic.core.strings.label_short_turbo
|
||||
import org.meshtastic.core.strings.label_very_long_slow
|
||||
import org.meshtastic.proto.ConfigProtos.Config.LoRaConfig
|
||||
import org.meshtastic.proto.ConfigProtos.Config.LoRaConfig.ModemPreset
|
||||
import org.meshtastic.proto.ConfigProtos.Config.LoRaConfig.RegionCode
|
||||
|
|
@ -308,18 +295,18 @@ enum class RegionInfo(
|
|||
}
|
||||
}
|
||||
|
||||
enum class ChannelOption(val modemPreset: ModemPreset, val labelRes: StringResource, val bandwidth: Float) {
|
||||
enum class ChannelOption(val modemPreset: ModemPreset, val bandwidth: Float) {
|
||||
// Grouped by range and speed for better readability
|
||||
VERY_LONG_SLOW(ModemPreset.VERY_LONG_SLOW, Res.string.label_very_long_slow, 0.0625f),
|
||||
LONG_TURBO(ModemPreset.LONG_TURBO, Res.string.label_long_turbo, 0.500f),
|
||||
LONG_FAST(ModemPreset.LONG_FAST, Res.string.label_long_fast, 0.250f),
|
||||
LONG_MODERATE(ModemPreset.LONG_MODERATE, Res.string.label_long_moderate, 0.125f),
|
||||
LONG_SLOW(ModemPreset.LONG_SLOW, Res.string.label_long_slow, 0.125f),
|
||||
MEDIUM_FAST(ModemPreset.MEDIUM_FAST, Res.string.label_medium_fast, 0.250f),
|
||||
MEDIUM_SLOW(ModemPreset.MEDIUM_SLOW, Res.string.label_medium_slow, 0.250f),
|
||||
SHORT_FAST(ModemPreset.SHORT_FAST, Res.string.label_short_fast, 0.250f),
|
||||
SHORT_SLOW(ModemPreset.SHORT_SLOW, Res.string.label_short_slow, 0.250f),
|
||||
SHORT_TURBO(ModemPreset.SHORT_TURBO, Res.string.label_short_turbo, 0.500f),
|
||||
VERY_LONG_SLOW(ModemPreset.VERY_LONG_SLOW, 0.0625f),
|
||||
LONG_TURBO(ModemPreset.LONG_TURBO, 0.500f),
|
||||
LONG_FAST(ModemPreset.LONG_FAST, 0.250f),
|
||||
LONG_MODERATE(ModemPreset.LONG_MODERATE, 0.125f),
|
||||
LONG_SLOW(ModemPreset.LONG_SLOW, 0.125f),
|
||||
MEDIUM_FAST(ModemPreset.MEDIUM_FAST, 0.250f),
|
||||
MEDIUM_SLOW(ModemPreset.MEDIUM_SLOW, 0.250f),
|
||||
SHORT_FAST(ModemPreset.SHORT_FAST, 0.250f),
|
||||
SHORT_SLOW(ModemPreset.SHORT_SLOW, 0.250f),
|
||||
SHORT_TURBO(ModemPreset.SHORT_TURBO, 0.500f),
|
||||
;
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,6 @@
|
|||
*/
|
||||
package org.meshtastic.core.model
|
||||
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.traceroute_endpoint_missing
|
||||
import org.meshtastic.core.strings.traceroute_map_no_data
|
||||
import org.meshtastic.proto.MeshProtos
|
||||
import org.meshtastic.proto.MeshProtos.RouteDiscovery
|
||||
import org.meshtastic.proto.Portnums
|
||||
|
|
@ -129,9 +125,3 @@ fun evaluateTracerouteMapAvailability(
|
|||
val hasAnyMappable = relatedNodeNums.any { positionedNodeNums.contains(it) }
|
||||
return if (hasAnyMappable) TracerouteMapAvailability.Ok else TracerouteMapAvailability.NoMappableNodes
|
||||
}
|
||||
|
||||
fun TracerouteMapAvailability.toMessageRes(): StringResource? = when (this) {
|
||||
TracerouteMapAvailability.Ok -> null
|
||||
TracerouteMapAvailability.MissingEndpoints -> Res.string.traceroute_endpoint_missing
|
||||
TracerouteMapAvailability.NoMappableNodes -> Res.string.traceroute_map_no_data
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2025-2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.model.util
|
||||
|
||||
/** Utility function to make it easy to declare byte arrays */
|
||||
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
|
||||
|
||||
fun xorHash(b: ByteArray) = b.fold(0) { acc, x -> acc xor (x.toInt() and BYTE_MASK) }
|
||||
|
||||
private const val BYTE_MASK = 0xff
|
||||
Loading…
Add table
Add a link
Reference in a new issue