Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DashKitDataSource(

override fun disconnect() {
manager.removeGattListener(this)
decoder.destroy()
}

override fun onServicesReady(gatt: BluetoothGatt) {
Expand Down Expand Up @@ -66,7 +67,7 @@ class DashKitDataSource(
private fun parseAndEmit(payload: ByteArray) {
if (payload.isEmpty()) return
for (frame in parseCanPacket(payload)) {
currentState = decoder.decodeFrame(frame.bus, frame.address, frame.data)
currentState = decoder.decodeFrame(frame.bus, frame.address, frame.data) ?: return
}
_incoming.tryEmit(currentState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ class CanFrameDecoder(
private val bridge: VehicleBridge,
profile: VehicleProfile
) {
val decoderHandle: Long = bridge.nativeCreateVehicleDecoder(
var decoderHandle: Long = bridge.nativeCreateVehicleDecoder(
profile.dbcContents, profile.busIndices, profile.type
)

fun decodeFrame(bus: Int, address: Int, data: ByteArray): CarState {
@Synchronized fun decodeFrame(bus: Int, address: Int, data: ByteArray): CarState? {
if (decoderHandle == 0L) return null
val values = bridge.nativeDecodeCanFrame(decoderHandle, bus, address, data)
return arrayToCarState(values)
}

fun destroy() {
@Synchronized fun destroy() {
bridge.nativeDestroyVehicleDecoder(decoderHandle)
decoderHandle = 0
}

companion object {
Expand Down
Loading