From 33cb10a108ff7ad525e8e0a2679aed200fbd27cd Mon Sep 17 00:00:00 2001 From: JinGen Lim <1116555+jglim@users.noreply.github.com> Date: Mon, 6 Sep 2021 13:56:33 +0800 Subject: [PATCH] Fixed interpretation of raw DTC values to ID (UDS) https://github.com/jglim/CaesarSuite/issues/36 --- Caesar/Diogenes/DiagnosticProtocol/UDS.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Caesar/Diogenes/DiagnosticProtocol/UDS.cs b/Caesar/Diogenes/DiagnosticProtocol/UDS.cs index aedb830..2131c1d 100644 --- a/Caesar/Diogenes/DiagnosticProtocol/UDS.cs +++ b/Caesar/Diogenes/DiagnosticProtocol/UDS.cs @@ -222,13 +222,20 @@ public override List ReportDtcsByStatusMask(ECUConnection connection Array.ConstrainedCopy(response, i, dtcRow, 0, 4); byte statusMask = dtcRow[3]; long dtcIdRaw = ((dtcRow[0] << 16) | (dtcRow[1] << 8) | dtcRow[2]); - // issue raised in https://github.com/jglim/CaesarSuite/discussions/21#discussioncomment-587029 - // no idea which part of the spec requires ANDing 3FFFFF; what do the upper 2+8 bits do? - dtcIdRaw &= 0x3FFFFF; + // fixup DTC prefix in https://github.com/jglim/CaesarSuite/issues/36 + int dtcId = (int)dtcIdRaw & 0x3FFFFF; // id is the lowest 22 bits + int dtcPrefix = (int)(dtcIdRaw >> 22) & 3; // prefix is the next 2 bits - string dtcIdentifier = $"{dtcIdRaw:X6}"; + string[] prefixTable = new string[] { + "P", // powertrain + "C", // chassis + "B", // body + "U" // network + }; - DTC foundDtc = DTC.FindDTCById(dtcIdentifier, variant); + string dtcIdentifier = $"{prefixTable[dtcPrefix]}{dtcId:X6}"; + + DTC foundDtc = FindDTCById(dtcIdentifier, variant); if (foundDtc is null) { Console.WriteLine($"DTC: No matching DTC available for {dtcIdentifier}");