kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
commit
73b8eef25b
|
@ -17,8 +17,8 @@ android {
|
||||||
applicationId "com.geeksville.mesh"
|
applicationId "com.geeksville.mesh"
|
||||||
minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works)
|
minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works)
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10788 // format is Mmmss (where M is 1+the numeric major number
|
versionCode 10789 // format is Mmmss (where M is 1+the numeric major number
|
||||||
versionName "0.7.88"
|
versionName "0.7.89"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
@ -354,42 +354,46 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
||||||
private var isFirstTime = true
|
private var isFirstTime = true
|
||||||
|
|
||||||
private fun doDiscoverServicesAndInit() {
|
private fun doDiscoverServicesAndInit() {
|
||||||
safe!!.asyncDiscoverServices { discRes ->
|
val s = safe
|
||||||
try {
|
if (s == null)
|
||||||
discRes.getOrThrow()
|
warn("Interface is shutting down, so skipping discover")
|
||||||
|
else
|
||||||
|
s.asyncDiscoverServices { discRes ->
|
||||||
|
try {
|
||||||
|
discRes.getOrThrow()
|
||||||
|
|
||||||
service.serviceScope.handledLaunch {
|
service.serviceScope.handledLaunch {
|
||||||
try {
|
try {
|
||||||
debug("Discovered services!")
|
debug("Discovered services!")
|
||||||
delay(1000) // android BLE is buggy and needs a 500ms sleep before calling getChracteristic, or you might get back null
|
delay(1000) // android BLE is buggy and needs a 500ms sleep before calling getChracteristic, or you might get back null
|
||||||
|
|
||||||
/* if (isFirstTime) {
|
/* if (isFirstTime) {
|
||||||
isFirstTime = false
|
isFirstTime = false
|
||||||
throw BLEException("Faking a BLE failure")
|
throw BLEException("Faking a BLE failure")
|
||||||
} */
|
} */
|
||||||
|
|
||||||
fromNum = getCharacteristic(BTM_FROMNUM_CHARACTER)
|
fromNum = getCharacteristic(BTM_FROMNUM_CHARACTER)
|
||||||
|
|
||||||
// We treat the first send by a client as special
|
// We treat the first send by a client as special
|
||||||
isFirstSend = true
|
isFirstSend = true
|
||||||
|
|
||||||
// Now tell clients they can (finally use the api)
|
// Now tell clients they can (finally use the api)
|
||||||
service.onConnect()
|
service.onConnect()
|
||||||
|
|
||||||
// Immediately broadcast any queued packets sitting on the device
|
// Immediately broadcast any queued packets sitting on the device
|
||||||
doReadFromRadio(true)
|
doReadFromRadio(true)
|
||||||
} catch (ex: BLEException) {
|
} catch (ex: BLEException) {
|
||||||
scheduleReconnect(
|
scheduleReconnect(
|
||||||
"Unexpected error in initial device enumeration, forcing disconnect $ex"
|
"Unexpected error in initial device enumeration, forcing disconnect $ex"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ex: BLEException) {
|
||||||
|
scheduleReconnect(
|
||||||
|
"Unexpected error discovering services, forcing disconnect $ex"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (ex: BLEException) {
|
|
||||||
scheduleReconnect(
|
|
||||||
"Unexpected error discovering services, forcing disconnect $ex"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var needForceRefresh = true
|
private var needForceRefresh = true
|
||||||
|
|
|
@ -392,25 +392,30 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
// startup next job in queue before calling the completion handler
|
// startup next job in queue before calling the completion handler
|
||||||
val work =
|
val work =
|
||||||
synchronized(workQueue) {
|
synchronized(workQueue) {
|
||||||
val w =
|
val w = currentWork
|
||||||
currentWork
|
|
||||||
?: throw Exception("currentWork was null") // will throw if null, which is helpful (FIXME - throws in the field - because of a bogus mtu completion gatt call)
|
|
||||||
stopCurrentWork() // We are now no longer working on anything
|
|
||||||
|
|
||||||
startNewWork()
|
if (w != null) {
|
||||||
|
stopCurrentWork() // We are now no longer working on anything
|
||||||
|
|
||||||
|
startNewWork()
|
||||||
|
}
|
||||||
w
|
w
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("work ${work.tag} is completed, resuming status=$status, res=$res")
|
if (work == null)
|
||||||
if (status != 0)
|
warn("wor completed, but we already killed it via failsafetimer? status=$status, res=$res")
|
||||||
work.completion.resumeWithException(
|
else {
|
||||||
BLEStatusException(
|
debug("work ${work.tag} is completed, resuming status=$status, res=$res")
|
||||||
status,
|
if (status != 0)
|
||||||
"Bluetooth status=$status while doing ${work.tag}"
|
work.completion.resumeWithException(
|
||||||
|
BLEStatusException(
|
||||||
|
status,
|
||||||
|
"Bluetooth status=$status while doing ${work.tag}"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
else
|
||||||
else
|
work.completion.resume(Result.success(res) as Result<Nothing>)
|
||||||
work.completion.resume(Result.success(res) as Result<Nothing>)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +426,14 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
synchronized(workQueue) {
|
synchronized(workQueue) {
|
||||||
warn("Failing ${workQueue.size} works, because ${ex.message}")
|
warn("Failing ${workQueue.size} works, because ${ex.message}")
|
||||||
workQueue.forEach {
|
workQueue.forEach {
|
||||||
it.completion.resumeWithException(ex)
|
try {
|
||||||
|
it.completion.resumeWithException(ex)
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
errormsg(
|
||||||
|
"Mystery exception, why were we informed about our own exceptions?",
|
||||||
|
ex
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
workQueue.clear()
|
workQueue.clear()
|
||||||
stopCurrentWork()
|
stopCurrentWork()
|
||||||
|
@ -607,7 +619,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
private fun queueRequestMtu(
|
private fun queueRequestMtu(
|
||||||
len: Int,
|
len: Int,
|
||||||
cont: Continuation<Unit>
|
cont: Continuation<Unit>
|
||||||
) = queueWork("reqMtu", cont, 5 * 1000) {
|
) = queueWork("reqMtu", cont, 10 * 1000) {
|
||||||
isSettingMtu = true
|
isSettingMtu = true
|
||||||
gatt?.requestMtu(len) ?: false
|
gatt?.requestMtu(len) ?: false
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,7 +268,8 @@ class SoftwareUpdateService : JobIntentService(), Logging {
|
||||||
fun doUpdate(context: Context, sync: SafeBluetooth, assetName: String) {
|
fun doUpdate(context: Context, sync: SafeBluetooth, assetName: String) {
|
||||||
try {
|
try {
|
||||||
val g = sync.gatt!!
|
val g = sync.gatt!!
|
||||||
val service = g.services.find { it.uuid == SW_UPDATE_UUID }!!
|
val service = g.services.find { it.uuid == SW_UPDATE_UUID }
|
||||||
|
?: throw BLEException("Couldn't find update service")
|
||||||
|
|
||||||
info("Starting firmware update for $assetName")
|
info("Starting firmware update for $assetName")
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 95c5a9aa950f917857a3cc0c7cd84a4a56993032
|
Subproject commit 99dbf61fad087db910be7f74867a8f14aba877a4
|
Ładowanie…
Reference in New Issue