mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
commit
f02bd519a9
4 changed files with 79 additions and 13 deletions
|
|
@ -30,8 +30,8 @@ android {
|
|||
applicationId "com.geeksville.mesh"
|
||||
minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works)
|
||||
targetSdkVersion 29
|
||||
versionCode 20106 // format is Mmmss (where M is 1+the numeric major number
|
||||
versionName "1.1.6"
|
||||
versionCode 20107 // format is Mmmss (where M is 1+the numeric major number
|
||||
versionName "1.1.7"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
|||
|
|
@ -337,7 +337,8 @@ class MeshService : Service(), Logging {
|
|||
val settings = MeshServiceSettingsData(
|
||||
myInfo = myInfo,
|
||||
nodeDB = nodeDBbyNodeNum.values.toTypedArray(),
|
||||
messages = recentDataPackets.toTypedArray()
|
||||
messages = recentDataPackets.toTypedArray(),
|
||||
regionCode = curRegionValue
|
||||
)
|
||||
val json = Json { isLenient = true }
|
||||
val asString = json.encodeToString(MeshServiceSettingsData.serializer(), settings)
|
||||
|
|
@ -373,6 +374,7 @@ class MeshService : Service(), Logging {
|
|||
val json = Json { isLenient = true }
|
||||
val settings = json.decodeFromString(MeshServiceSettingsData.serializer(), asString)
|
||||
installNewNodeDB(settings.myInfo, settings.nodeDB)
|
||||
curRegionValue = settings.regionCode
|
||||
|
||||
// Note: we do not haveNodeDB = true because that means we've got a valid db from a real device (rather than this possibly stale hint)
|
||||
|
||||
|
|
@ -1093,6 +1095,58 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
// If we've ever read a valid region code from our device it will be here
|
||||
var curRegionValue = MeshProtos.RegionCode.Unset_VALUE
|
||||
|
||||
/**
|
||||
* If we are updating nodes we might need to use old (fixed by firmware build)
|
||||
* region info to populate our new universal ROMs.
|
||||
*
|
||||
* This function updates our saved preferences region info and if the device has an unset new
|
||||
* region info, we set it.
|
||||
*/
|
||||
private fun updateRegion() {
|
||||
ignoreException {
|
||||
// Try to pull our region code from the new preferences field
|
||||
// FIXME - do not check net - figuring out why board is rebooting
|
||||
val curConfigRegion = radioConfig?.preferences?.region ?: MeshProtos.RegionCode.Unset
|
||||
if (curConfigRegion != MeshProtos.RegionCode.Unset) {
|
||||
info("Using device region $curConfigRegion (code ${curConfigRegion.number})")
|
||||
curRegionValue = curConfigRegion.number
|
||||
}
|
||||
|
||||
if (curRegionValue == MeshProtos.RegionCode.Unset_VALUE) {
|
||||
// look for a legacy region
|
||||
val legacyRegex = Regex(".+-(.+)")
|
||||
myNodeInfo?.region?.let { legacyRegion ->
|
||||
val matches = legacyRegex.find(legacyRegion)
|
||||
if (matches != null) {
|
||||
val (region) = matches.destructured
|
||||
val newRegion = MeshProtos.RegionCode.valueOf(region)
|
||||
info("Upgrading legacy region $newRegion (code ${newRegion.number})")
|
||||
curRegionValue = newRegion.number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing was set in our (new style radio preferences, but we now have a valid setting - slam it in)
|
||||
if (curConfigRegion == MeshProtos.RegionCode.Unset && curRegionValue != MeshProtos.RegionCode.Unset_VALUE) {
|
||||
info("Telling device to upgrade region")
|
||||
|
||||
// Tell the device to set the new region field (old devices will simply ignore this)
|
||||
radioConfig?.let { currentConfig ->
|
||||
val newConfig = currentConfig.toBuilder()
|
||||
|
||||
val newPrefs = currentConfig.preferences.toBuilder()
|
||||
newPrefs.regionValue = curRegionValue
|
||||
newConfig.preferences = newPrefs.build()
|
||||
|
||||
sendRadioConfig(newConfig.build())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleConfigComplete(configCompleteId: Int) {
|
||||
if (configCompleteId == configNonce) {
|
||||
|
||||
|
|
@ -1122,6 +1176,8 @@ class MeshService : Service(), Logging {
|
|||
serviceBroadcasts.broadcastConnection()
|
||||
onNodeDBChanged()
|
||||
reportConnection()
|
||||
|
||||
updateRegion()
|
||||
}
|
||||
} else
|
||||
warn("Ignoring stale config complete")
|
||||
|
|
@ -1187,18 +1243,24 @@ class MeshService : Service(), Logging {
|
|||
sendPosition(lat, lon, alt, destNum, wantResponse)
|
||||
}
|
||||
|
||||
/** Set our radio config either with the new or old API
|
||||
/** Send our current radio config to the device
|
||||
*/
|
||||
private fun sendRadioConfig(c: MeshProtos.RadioConfig) {
|
||||
// Update our device
|
||||
sendToRadio(ToRadio.newBuilder().apply {
|
||||
this.setRadio = c
|
||||
})
|
||||
|
||||
// Update our cached copy
|
||||
this@MeshService.radioConfig = c
|
||||
}
|
||||
|
||||
/** Set our radio config
|
||||
*/
|
||||
private fun setRadioConfig(payload: ByteArray) {
|
||||
val parsed = MeshProtos.RadioConfig.parseFrom(payload)
|
||||
|
||||
// Update our device
|
||||
sendToRadio(ToRadio.newBuilder().apply {
|
||||
this.setRadio = parsed
|
||||
})
|
||||
|
||||
// Update our cached copy
|
||||
this@MeshService.radioConfig = parsed
|
||||
sendRadioConfig(parsed)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.geeksville.mesh.service
|
||||
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import kotlinx.serialization.Serializable
|
||||
|
|
@ -10,7 +11,8 @@ import kotlinx.serialization.Serializable
|
|||
data class MeshServiceSettingsData(
|
||||
val nodeDB: Array<NodeInfo>,
|
||||
val myInfo: MyNodeInfo,
|
||||
val messages: Array<DataPacket>
|
||||
val messages: Array<DataPacket>,
|
||||
val regionCode: Int = MeshProtos.RegionCode.Unset_VALUE
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
|
@ -21,6 +23,7 @@ data class MeshServiceSettingsData(
|
|||
if (!nodeDB.contentEquals(other.nodeDB)) return false
|
||||
if (myInfo != other.myInfo) return false
|
||||
if (!messages.contentEquals(other.messages)) return false
|
||||
if (regionCode != other.regionCode) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
@ -29,6 +32,7 @@ data class MeshServiceSettingsData(
|
|||
var result = nodeDB.contentHashCode()
|
||||
result = 31 * result + myInfo.hashCode()
|
||||
result = 31 * result + messages.contentHashCode()
|
||||
result = 31 * result + regionCode
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit
|
|||
/**
|
||||
* Helper that calls MeshService.startService()
|
||||
*/
|
||||
private class ServiceStarter(
|
||||
public class ServiceStarter(
|
||||
appContext: Context,
|
||||
workerParams: WorkerParameters
|
||||
) : Worker(appContext, workerParams) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue