Skip to content

Commit

Permalink
fix crashed getting dtc's
Browse files Browse the repository at this point in the history
  • Loading branch information
kkonteh97 committed Apr 18, 2024
1 parent e9d0076 commit 2ea4d4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SwiftOBD2/decoders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftOBD2/elm327.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down

0 comments on commit 2ea4d4c

Please sign in to comment.