fix: Proces threading fix

This commit is contained in:
Piotr Dec 2024-07-31 18:38:42 +02:00
parent 116b13adcb
commit 75e10c1579
Signed by: stawros
GPG key ID: F89F27AD8F881A91
3 changed files with 20 additions and 16 deletions

View file

@ -23,7 +23,7 @@ class Garmin(
) {
private lateinit var connection: ConnectThread
private lateinit var processing: ProcessingThread
private val observer = ProcessingThreadObserver()
private val cache = DataCache()
fun start() {
@ -36,15 +36,11 @@ class Garmin(
}
fun process(maneuver: Maneuver) {
processing = ManeuverProcessingThread(maneuver)
processing.start()
processing.join()
ManeuverProcessingThread(maneuver).start()
}
fun process(location: LocationMatcherResult) {
processing = LocationProcessingThread(location)
processing.start()
processing.join()
LocationProcessingThread(location).start()
}
fun process(navigationSessionState: NavigationSessionState) {
@ -83,6 +79,15 @@ class Garmin(
connection.enqueue(GarminMapper.setDirection(incoming))
}
cache.update(incoming)
observer.join(this)
}
}
private inner class ProcessingThreadObserver {
fun join(thread: ProcessingThread) {
thread.join()
}
}
@ -165,6 +170,8 @@ class Garmin(
companion object {
lateinit var instance: Garmin
fun prepareData(input: IntArray): IntArray {
val n = input.size
var crc = (0xeb + n + n).toUInt()