From 2ea4d4c05840df5889cd567c832c05864f1a6bcc Mon Sep 17 00:00:00 2001 From: kkonteh97 <55326260+kkonteh97@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:50:36 -0700 Subject: [PATCH] fix crashed getting dtc's --- Sources/SwiftOBD2/decoders.swift | 2 +- Sources/SwiftOBD2/elm327.swift | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftOBD2/decoders.swift b/Sources/SwiftOBD2/decoders.swift index 83a459f..ad56ee8 100644 --- a/Sources/SwiftOBD2/decoders.swift +++ b/Sources/SwiftOBD2/decoders.swift @@ -532,7 +532,7 @@ func decodeStatus(_ data: Data, isMetric _: MeasurementUnits = .metric) -> Statu // [# DTC] X [supprt] [~ready] // convert to binaryarray - let bits = BitArray(data: data[1...]) + let bits = BitArray(data: data.dropFirst()) var output = Status() output.MIL = bits.binaryArray[0] == 1 diff --git a/Sources/SwiftOBD2/elm327.swift b/Sources/SwiftOBD2/elm327.swift index 65ce63c..3b15b43 100644 --- a/Sources/SwiftOBD2/elm327.swift +++ b/Sources/SwiftOBD2/elm327.swift @@ -245,8 +245,10 @@ class ELM327 { } func getStatus() async throws -> Status? { + logger.info("Getting status") let statusCommand = OBDCommand.Mode1.status let statusResponse = try await sendCommand(statusCommand.properties.command) + logger.debug("Status response: \(statusResponse)") let statueMessages = OBDParcer(statusResponse, idBits: obdProtocol.idBits)?.messages guard let statusData = statueMessages?.first?.data, @@ -258,6 +260,7 @@ class ELM327 { } func scanForTroubleCodes() async throws -> [TroubleCode] { + logger.info("Scanning for trouble codes") let dtcCommand = OBDCommand.Mode3.GET_DTC let dtcResponse = try await sendCommand(dtcCommand.properties.command)