diff --git a/Sources/SwiftOBD2/commands.swift b/Sources/SwiftOBD2/commands.swift index 7376a16..cbc9016 100644 --- a/Sources/SwiftOBD2/commands.swift +++ b/Sources/SwiftOBD2/commands.swift @@ -35,6 +35,11 @@ public extension DecodeResult { if case let .troubleCode(res) = self { return res as [TroubleCode] } return nil } + + var measurementMonitor: Monitor? { + if case let .measurementMonitor(res) = self { return res as Monitor } + return nil + } } public struct CommandProperties { diff --git a/Sources/SwiftOBD2/decoders.swift b/Sources/SwiftOBD2/decoders.swift index 768c7fd..371f8bd 100644 --- a/Sources/SwiftOBD2/decoders.swift +++ b/Sources/SwiftOBD2/decoders.swift @@ -261,7 +261,7 @@ public enum Decoders: Equatable { case .status: return decodeStatus(data) case .temp: - return decodeTemp(data, unit: unit) + return tempDecoder(data, unit: unit) case .percent: return percentDecoder(data) case .currentCentered: @@ -556,7 +556,7 @@ func percentCenteredDecoder(_ data: Data) -> Result { // -128 to 128 mA func currentCenteredDecoder(_ data: Data) -> Result { - var value = Double(bytesToInt(data[2 ... 3])) + var value = Double(bytesToInt(data.dropFirst(2))) value = (value / 256.0) - 128.0 return .success(.measurementResult(MeasurementResult(value: value, unit: UnitElectricCurrent.milliamperes))) } @@ -597,7 +597,7 @@ func airStatusDecoder(_ data: Data) -> Result { return .failure(.invalidData) } -func decodeTemp(_ data: Data, unit: MeasurementUnit) -> Result { +func tempDecoder(_ data: Data, unit: MeasurementUnit) -> Result { let value = Double(bytesToInt(data)) - 40.0 return .success(.measurementResult(MeasurementResult(value: value, unit: UnitTemperature.celsius))) } @@ -623,7 +623,7 @@ func decodeStatus(_ data: Data) -> Result { // [# DTC] X [supprt] [~ready] // convert to binaryarray - let bits = BitArray(data: data.dropFirst()) + let bits = BitArray(data: data) var output = Status() output.MIL = bits.binaryArray[0] == 1 diff --git a/Tests/SwiftOBD2Tests/decodersTests.swift b/Tests/SwiftOBD2Tests/decodersTests.swift index 2936a5c..a65e055 100644 --- a/Tests/SwiftOBD2Tests/decodersTests.swift +++ b/Tests/SwiftOBD2Tests/decodersTests.swift @@ -10,127 +10,281 @@ import XCTest final class decodersTests: XCTestCase { func testPercent() { - XCTAssertEqual(percent(Data([0x00])), MeasurementResult(value: 0, unit: Unit.percent)) - XCTAssertEqual(percent(Data([0xFF])), MeasurementResult(value: 100, unit: Unit.percent)) + let tests = [Data([0x00]): MeasurementResult(value: 0, unit: Unit.percent), + Data([0xFF]): MeasurementResult(value: 100, unit: Unit.percent)] + for (data, expected) in tests { + switch percentDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 1) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testPercentCentered() { - XCTAssertEqual(percentCentered(Data([0x00])), MeasurementResult(value: -100, unit: Unit.percent)) - XCTAssertEqual(percentCentered(Data([0x80])), MeasurementResult(value: 0, unit: Unit.percent)) - XCTAssertEqual(percentCentered(Data([0xFF]))!.value, MeasurementResult(value: 100, unit: Unit.percent).value, accuracy: 1) + let tests = [Data([0x00]): MeasurementResult(value: -100, unit: Unit.percent), + Data([0x80]): MeasurementResult(value: 0, unit: Unit.percent), + Data([0xFF]): MeasurementResult(value: 100, unit: Unit.percent)] + for (data, expected) in tests { + switch percentCenteredDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 1) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testTemp() { - XCTAssertEqual(decodeTemp(Data([0x00])), MeasurementResult(value: -40, unit: UnitTemperature.celsius)) - XCTAssertEqual(decodeTemp(Data([0xFF])), MeasurementResult(value: 215, unit: UnitTemperature.celsius)) - XCTAssertEqual(decodeTemp(Data([0x03, 0xE8])), MeasurementResult(value: 960, unit: UnitTemperature.celsius)) + let tests = [Data([0x00]): MeasurementResult(value: -40, unit: UnitTemperature.celsius), + Data([0xFF]): MeasurementResult(value: 215, unit: UnitTemperature.celsius), + Data([0x03, 0xE8]): MeasurementResult(value: 960, unit: UnitTemperature.celsius)] + for (data, expected) in tests { + switch tempDecoder(data, unit: .metric) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testCurrentCentered() { - XCTAssertEqual(currentCentered(Data([0x00, 0x00, 0x00, 0x00])), MeasurementResult(value: -128, unit: UnitElectricCurrent.milliamperes)) - XCTAssertEqual(currentCentered(Data([0x00, 0x00, 0x80, 0x00])), MeasurementResult(value: 0, unit: UnitElectricCurrent.milliamperes)) - XCTAssertEqual(currentCentered(Data([0x00, 0x00, 0xFF, 0xFF]))!.value, 128.0, accuracy: 0.01) + let tests = [Data([0x00, 0x00, 0x00, 0x00]): MeasurementResult(value: -128, unit: UnitElectricCurrent.milliamperes), + Data([0x00, 0x00, 0x80, 0x00]): MeasurementResult(value: 0, unit: UnitElectricCurrent.milliamperes), + Data([0xFF, 0x00, 0xFF, 0xFF]): MeasurementResult(value: 128, unit: UnitElectricCurrent.milliamperes)] + for (data, expected) in tests { + switch currentCenteredDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testSensorVoltage() { - XCTAssertEqual(sensorVoltage(Data([0x00, 0x00])), MeasurementResult(value: 0, unit: UnitElectricPotentialDifference.volts)) - XCTAssertEqual(sensorVoltage(Data([0xFF, 0xFF])), MeasurementResult(value: 1.275, unit: UnitElectricPotentialDifference.volts)) + let tests = [Data([0x00, 0x00]): MeasurementResult(value: 0, unit: UnitElectricPotentialDifference.volts), + Data([0xFF, 0xFF]): MeasurementResult(value: 1.275, unit: UnitElectricPotentialDifference.volts)] + for (data, expected) in tests { + switch sensorVoltageDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testSensorVoltageBig() { - XCTAssertEqual(sensorVoltageBig(Data([0x00, 0x00, 0x00, 0x00])), MeasurementResult(value: 0, unit: UnitElectricPotentialDifference.volts)) - XCTAssertEqual(sensorVoltageBig(Data([0x00, 0x00, 0x80, 0x00]))!.value, 4, accuracy: 0.01) - XCTAssertEqual(sensorVoltageBig(Data([0x00, 0x00, 0xFF, 0xFF])), MeasurementResult(value: 8, unit: UnitElectricPotentialDifference.volts)) + let tests = [Data([0x00, 0x00, 0x00, 0x00]): MeasurementResult(value: 0, unit: UnitElectricPotentialDifference.volts), + Data([0x00, 0x00, 0x80, 0x00]): MeasurementResult(value: 4, unit: UnitElectricPotentialDifference.volts), + Data([0x00, 0x00, 0xFF, 0xFF]): MeasurementResult(value: 8, unit: UnitElectricPotentialDifference.volts)] + for (data, expected) in tests { + switch sensorVoltageBigDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testFuelPressure() { - XCTAssertEqual(fuelPressure(Data([0x00])), MeasurementResult(value: 0, unit: UnitPressure.kilopascals)) - XCTAssertEqual(fuelPressure(Data([0x80])), MeasurementResult(value: 384, unit: UnitPressure.kilopascals)) - XCTAssertEqual(fuelPressure(Data([0xFF])), MeasurementResult(value: 765, unit: UnitPressure.kilopascals)) + let tests = [Data([0x00]): MeasurementResult(value: 0, unit: UnitPressure.kilopascals), + Data([0x80]): MeasurementResult(value: 384, unit: UnitPressure.kilopascals), + Data([0xFF]): MeasurementResult(value: 765, unit: UnitPressure.kilopascals)] + for (data, expected) in tests { + switch fuelPressureDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testPressure() { - XCTAssertEqual(pressure(Data([0x00])), MeasurementResult(value: 0, unit: UnitPressure.kilopascals)) + let tests = [Data([0x00]): MeasurementResult(value: 0, unit: UnitPressure.kilopascals) +// Data([0x80]): MeasurementResult(value: 0.5, unit: UnitPressure.kilopascals), +// Data([0xFF]): MeasurementResult(value: 1, unit: UnitPressure.kilopascals) + ] + for (data, expected) in tests { + switch pressureDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testAbsEvapPressure() { - XCTAssertEqual(absEvapPressure(Data([0x00, 0x00])), MeasurementResult(value: 0, unit: UnitPressure.kilopascals)) - XCTAssertEqual(absEvapPressure(Data([0xFF, 0xFF])), MeasurementResult(value: 327.675, unit: UnitPressure.kilopascals)) + let tests = [Data([0x00, 0x00]): MeasurementResult(value: 0, unit: UnitPressure.kilopascals), + Data([0xFF, 0xFF]): MeasurementResult(value: 327.675, unit: UnitPressure.kilopascals)] + for (data, expected) in tests { + switch absEvapPressureDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 0.01) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testEvapPressureAlt() { - XCTAssertEqual(evapPressureAlt(Data([0x00, 0x00])), MeasurementResult(value: -32767, unit: Unit.Pascal)) - XCTAssertEqual(evapPressureAlt(Data([0x7F, 0xFF])), MeasurementResult(value: 0, unit: Unit.Pascal)) - XCTAssertEqual(evapPressureAlt(Data([0xFF, 0xFF])), MeasurementResult(value: 32768, unit: Unit.Pascal)) + let tests = [Data([0x00, 0x00]): MeasurementResult(value: -32767, unit: Unit.Pascal), + Data([0x7F, 0xFF]): MeasurementResult(value: 0, unit: Unit.Pascal), + Data([0xFF, 0xFF]): MeasurementResult(value: 32768, unit: Unit.Pascal)] + for (data, expected) in tests { + switch evapPressureAltDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 1) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testTimingAdvance() { - XCTAssertEqual(timingAdvance(Data([0x00])), MeasurementResult(value: -64, unit: UnitAngle.degrees)) - XCTAssertEqual(timingAdvance(Data([0xFF])), MeasurementResult(value: 63.5, unit: UnitAngle.degrees)) + let tests = [Data([0x00]): MeasurementResult(value: -64, unit: UnitAngle.degrees), + Data([0xFF]): MeasurementResult(value: 63.5, unit: UnitAngle.degrees)] + for (data, expected) in tests { + switch timingAdvanceDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 1) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testInjectTiming() { - XCTAssertEqual(injectTiming(Data([0x00, 0x00])), MeasurementResult(value: -210, unit: UnitPressure.degrees)) - XCTAssertEqual(injectTiming(Data([0xFF, 0xFF]))!.value, 301, accuracy: 1) + let tests = [Data([0x00, 0x00]): MeasurementResult(value: -210, unit: UnitPressure.degrees), + Data([0xFF, 0xFF]): MeasurementResult(value: 301, unit: UnitPressure.degrees)] + for (data, expected) in tests { + switch injectTimingDecoder(data) { + case .success(let result): + XCTAssertEqual(result.measurementResult!.value, expected.value, accuracy: 1) + XCTAssertEqual(result.measurementResult!.unit, expected.unit) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testStatus() { - let status = decodeStatus(Data([0x00, 0x83, 0x07, 0xFF, 0x00])) - XCTAssertEqual(status.MIL, true) - XCTAssertEqual(status.dtcCount, 3) - XCTAssertEqual(status.ignitionType, "Spark") + let statusResult = decodeStatus(Data([0x00, 0x83, 0x07, 0xFF, 0x00])) + switch statusResult { + case .success(let status): + XCTAssertEqual(status.statusResult?.MIL, true) + XCTAssertEqual(status.statusResult?.dtcCount, 3) + XCTAssertEqual(status.statusResult?.ignitionType, "Spark") + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } } func testSingleDtc() { - XCTAssertEqual(singleDtc(Data([0x01, 0x04])), TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent")) - XCTAssertEqual(singleDtc(Data([0x41, 0x23])), TroubleCode(code: "C0123", description: "No description available.")) - XCTAssertEqual(singleDtc(Data([0x01])), nil) - XCTAssertEqual(singleDtc(Data([0x01, 0x04, 0x00])), nil) + let tests = [Data([0x01, 0x04]): TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent"), + Data([0x41, 0x23]): TroubleCode(code: "C0123", description: "No description available."), + Data([0x01]): nil, + Data([0x01, 0x04, 0x00]): nil + ] + + for (data, expected) in tests { + let result = singleDtcDecoder(data) + switch result { + case .success(let dtc): + XCTAssertEqual(dtc.troubleCode?.first, expected) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + } } func testDtc() { - XCTAssertEqual(dtc(Data([0x01, 0x04])), [TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent")]) - XCTAssertEqual(dtc(Data([0x01, 0x04, 0x80, 0x03, 0x41, 0x23]))!, [ - TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent"), - TroubleCode(code: "B0003", description: "No description available."), - TroubleCode(code: "C0123", description: "No description available.") - ]) + let tests = [ + Data([0x01, 0x04]): + [ + TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent") + ], + Data([0x01, 0x04, 0x80, 0x03, 0x41, 0x23]) : + [ + TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent"), + TroubleCode(code: "B0003", description: "No description available."), + TroubleCode(code: "C0123", description: "No description available.") + ], + Data([0x01, 0x04, 0x80, 0x03, 0x41]) : + [ + TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent"), + TroubleCode(code: "B0003", description: "No description available.") + ], + Data([0x00, 0x00, 0x01, 0x04, 0x00, 0x00]) : + [ + TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent") + ] + ] - XCTAssertEqual(dtc(Data([0x01, 0x04, 0x80, 0x03, 0x41])), [ - TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent"), - TroubleCode(code: "B0003", description: "No description available.") - ]) + for test in tests { + let result = dtcDecoder(test.key) + switch result { + case .success(let troubleCodes): + XCTAssertEqual(troubleCodes.troubleCode, test.value) + case .failure: + XCTFail() + } + } - XCTAssertEqual(dtc(Data([0x00, 0x00, 0x01, 0x04, 0x00, 0x00])), [ - TroubleCode(code: "P0104", description: "Mass or Volume Air Flow Circuit Intermittent") - ]) } func testMonitor() { - let monitor = decodeMonitor(Data([0x01, 0x01, 0x0A, 0x0B, 0xB0, 0x0B, 0xB0, 0x0B, 0xB0])) - guard let tests = monitor?.tests else { - XCTFail() - return - } - XCTAssertEqual(tests.count, 1) - XCTAssertEqual(tests[0x01]?.name, "RTLThresholdVoltage") - XCTAssertEqual(tests[0x01]!.value!.value, 365.0, accuracy: 0.1) - XCTAssertEqual(tests[0x01]!.value!.unit, UnitElectricPotentialDifference.millivolts) -// 01 01 0A 0B B0 0B B0 0B B0 0105100048 00 00 00 640185240096004BFFFF - let monitor2 = decodeMonitor(Data([0x01, 0x01, 0x0A, 0x0B, 0xB0, 0x0B, 0xB0, 0x0B, 0xB0, 0x01, 0x05, 0x10, 0x00, 0x48, 0x00, 0x00, 0x00, 0x64, 0x01, 0x85, 0x24, 0x00, 0x96, 0x00, 0x4B, 0xFF, 0xFF])) - guard let tests2 = monitor2?.tests else { - XCTFail() - return + let monitorResult = decodeMonitor(Data([0x01, 0x01, 0x0A, 0x0B, 0xB0, 0x0B, 0xB0, 0x0B, 0xB0])) + switch monitorResult { + case .success(let monitor): + guard let tests = monitor.measurementMonitor?.tests else { + XCTFail() + return + } + XCTAssertEqual(tests.count, 1) + XCTAssertEqual(tests[0x01]?.name, "RTLThresholdVoltage") + XCTAssertEqual(tests[0x01]!.value!.value, 365.0, accuracy: 0.1) + XCTAssertEqual(tests[0x01]!.value!.unit, UnitElectricPotentialDifference.millivolts) + default: + XCTFail("Monitor decoding failed") } - XCTAssertEqual(tests2.count, 3) - XCTAssertEqual(tests2[0x01]?.name, "RTLThresholdVoltage") - XCTAssertEqual(tests2[0x01]!.value!.value, 365.0, accuracy: 0.1) - XCTAssertEqual(tests2[0x01]!.value!.unit, UnitElectricPotentialDifference.millivolts) - XCTAssertEqual(tests2[0x01]!.value!.value, 365.0, accuracy: 0.1) +// 01 01 0A 0B B0 0B B0 0B B0 0105100048 00 00 00 640185240096004BFFFF + let monitorResult2 = decodeMonitor(Data([0x01, 0x01, 0x0A, 0x0B, 0xB0, 0x0B, 0xB0, 0x0B, 0xB0, 0x01, 0x05, 0x10, 0x00, 0x48, 0x00, 0x00, 0x00, 0x64, 0x01, 0x85, 0x24, 0x00, 0x96, 0x00, 0x4B, 0xFF, 0xFF])) - XCTAssertEqual(tests2[0x05]?.name, "RTLSwitchTime") - XCTAssertEqual(tests2[0x05]!.value!.value, 72, accuracy: 0.1) - XCTAssertEqual(tests2[0x05]!.value!.unit, UnitDuration.milliseconds) + switch monitorResult2 { + case .success(let monitor): + guard let tests = monitor.measurementMonitor?.tests else { + XCTFail() + return + } + XCTAssertEqual(tests.count, 3) + XCTAssertEqual(tests[0x01]?.name, "RTLThresholdVoltage") + XCTAssertEqual(tests[0x01]!.value!.value, 365.0, accuracy: 0.1) + XCTAssertEqual(tests[0x01]!.value!.unit, UnitElectricPotentialDifference.millivolts) + XCTAssertEqual(tests[0x01]!.value!.value, 365.0, accuracy: 0.1) + XCTAssertEqual(tests[0x05]?.name, "RTLSwitchTime") + XCTAssertEqual(tests[0x05]!.value!.value, 72, accuracy: 0.1) + XCTAssertEqual(tests[0x05]!.value!.unit, UnitDuration.milliseconds) + default: + XCTFail("Monitor decoding failed") + } } } diff --git a/Tests/SwiftOBD2Tests/elm327Test.swift b/Tests/SwiftOBD2Tests/elm327Test.swift index 7df322b..e7fb571 100644 --- a/Tests/SwiftOBD2Tests/elm327Test.swift +++ b/Tests/SwiftOBD2Tests/elm327Test.swift @@ -51,7 +51,7 @@ final class ELM327Test: XCTestCase { func testPIDExtractor() { let response = ["86 F1 10 41 00 BF 9F E8 91 9F ", "86 F1 1A 41 00 88 18 80 10 02 "] - guard let data = ISO_14230_4_KWP_Fast().parcer(response).first?.data else { + guard let data = ISO_14230_4_KWP_Fast().parce(response).first?.data else { XCTFail("Expected data to be not nil") return } diff --git a/Tests/SwiftOBD2Tests/test_protocol_can.swift b/Tests/SwiftOBD2Tests/test_protocol_can.swift index 99fd26e..c499ddb 100644 --- a/Tests/SwiftOBD2Tests/test_protocol_can.swift +++ b/Tests/SwiftOBD2Tests/test_protocol_can.swift @@ -24,16 +24,16 @@ final class test_protocol_can: XCTestCase { func test_single_frame() { for canprotocol in CAN_11_PROTOCOLS { - var data = canprotocol.parcer(["7E8 06 41 00 00 01 02 03"]).first?.data + var data = canprotocol.parce(["7E8 06 41 00 00 01 02 03"]).first?.data XCTAssertNotNil(data) XCTAssertEqual(data, Data([0x00, 0x00,0x01, 0x02, 0x03])) // minimum valid length - data = canprotocol.parcer(["7E8 01 41"]).first?.data + data = canprotocol.parce(["7E8 01 41"]).first?.data XCTAssertNotNil(data) // to short - data = canprotocol.parcer(["7E8 01"]).first?.data + data = canprotocol.parce(["7E8 01"]).first?.data XCTAssertNil(data) diff --git a/Tests/SwiftOBD2Tests/test_protocol_legacy.swift b/Tests/SwiftOBD2Tests/test_protocol_legacy.swift index 4f36873..ea76915 100644 --- a/Tests/SwiftOBD2Tests/test_protocol_legacy.swift +++ b/Tests/SwiftOBD2Tests/test_protocol_legacy.swift @@ -20,16 +20,16 @@ final class test_protocol_legacy: XCTestCase { func test_single_frame() { for canprotocol in LEGACY_PROTOCOLS { // minimum valid length - var data = canprotocol.parcer(["48 6B 10 41 00 FF"]).first?.data + var data = canprotocol.parce(["48 6B 10 41 00 FF"]).first?.data XCTAssertEqual(data, Data([0x00])) // maximum valid length - data = canprotocol.parcer(["48 6B 10 41 00 00 01 02 03 04 FF"]).first?.data + data = canprotocol.parce(["48 6B 10 41 00 00 01 02 03 04 FF"]).first?.data XCTAssertEqual(data, Data([0x00, 0x00, 0x01, 0x02, 0x03, 0x04])) // to short - data = canprotocol.parcer(["48 6B 10 41"]).first?.data + data = canprotocol.parce(["48 6B 10 41"]).first?.data XCTAssertNil(data) } }