Exemple #1
0
 private static bool ExitDiagnosticSession(ECUConnection connection)
 {
     Console.WriteLine("UDS: Switching session states");
     byte[] sessionSwitchResponse   = connection.SendMessage(new byte[] { 0x10, 0x01 });
     byte[] sessionExpectedResponse = new byte[] { 0x50, 0x01 };
     if (!sessionSwitchResponse.Take(2).SequenceEqual(sessionExpectedResponse))
     {
         Console.WriteLine($"Failed to switch session : target responded with [{BitUtility.BytesToHex(sessionSwitchResponse, true)}]");
         return(false);
     }
     return(true);
 }
Exemple #2
0
        private static bool GetVariantID_1A87(ECUConnection connection, out int variantId)
        {
            byte[] variantQueryResponse    = connection.SendMessage(new byte[] { 0x1A, 0x87 });
            byte[] variantExpectedResponse = new byte[] { 0x5A, 0x87 };

            if (!variantQueryResponse.Take(2).SequenceEqual(variantExpectedResponse))
            {
                variantId = 0;
                return(false);
            }
            else
            {
                variantId = (variantQueryResponse[4] << 8) | variantQueryResponse[5];
                return(true);
            }
        }
Exemple #3
0
        private static bool GetVariantID(ECUConnection connection, out int variantId)
        {
            byte[] variantQueryResponse    = connection.SendMessage(new byte[] { 0x22, 0xF1, 0x00 });
            byte[] variantExpectedResponse = new byte[] { 0x62, 0xF1 };

            if (!variantQueryResponse.Take(2).SequenceEqual(variantExpectedResponse))
            {
                Console.WriteLine($"Failed to identify variant (unexpected response) : target responded with [{BitUtility.BytesToHex(variantQueryResponse, true)}]");
                variantId = 0;
                return(false);
            }
            else
            {
                // found a variant id, check loaded ecus if any of them have a match
                variantId = (variantQueryResponse[3] << 16) | (variantQueryResponse[4] << 8) | variantQueryResponse[5];
                return(true);
            }
        }
Exemple #4
0
        public override bool GetDtcSnapshot(DTC dtc, ECUConnection connection, out byte[] snapshotBytes)
        {
            byte[] identifier = BitUtility.BytesFromHex(dtc.Qualifier.Substring(1));

            // apparently the existing dtc's mask should be ignored, use FF instead
            byte[] request          = new byte[] { 0x19, 0x06, identifier[0], identifier[1], identifier[2], 0xFF };
            byte[] expectedResponse = new byte[] { 0x59, 0x06 };

            byte[] response = connection.SendMessage(request);
            if (response.Take(expectedResponse.Length).SequenceEqual(expectedResponse))
            {
                snapshotBytes = response;
                return(true);
            }
            else
            {
                snapshotBytes = new byte[] { };
                return(false);
            }
        }
Exemple #5
0
        public override List <DTCContext> ReportDtcsByStatusMask(ECUConnection connection, ECUVariant variant, byte inMask = 0)
        {
            List <DTCContext> dtcCtx = new List <DTCContext>();

            byte mask = (byte)(DTCStatusByte.TestFailedAtRequestTime |
                               DTCStatusByte.TestFailedAtCurrentCycle |
                               DTCStatusByte.PendingDTC |
                               DTCStatusByte.ConfirmedDTC |
                               DTCStatusByte.TestFailedSinceLastClear);

            byte[] request          = new byte[] { 0x19, 0x02, inMask == 0 ? mask : inMask };
            byte[] expectedResponse = new byte[] { 0x59, 0x02 };

            byte[] response = connection.SendMessage(request);
            if (!response.Take(expectedResponse.Length).SequenceEqual(expectedResponse))
            {
                return(new List <DTCContext>());
            }

            for (int i = 3; i < response.Length; i += 4)
            {
                byte[] dtcRow = new byte[4];
                Array.ConstrainedCopy(response, i, dtcRow, 0, 4);
                string dtcIdentifier = BitUtility.BytesToHex(dtcRow.Take(3).ToArray(), false);

                DTC foundDtc = DTC.FindDTCById(dtcIdentifier, variant);
                if (foundDtc is null)
                {
                    Console.WriteLine($"DTC: No matching DTC available for {dtcIdentifier}");
                }
                dtcCtx.Add(new DTCContext()
                {
                    DTC = foundDtc, StatusByte = dtcRow[3], EnvironmentContext = new List <string[]>()
                });
            }
            return(dtcCtx);
        }
Exemple #6
0
 public override void SendTesterPresent(ECUConnection connection)
 {
     connection.SendMessage(new byte[] { 0x3E, 0x00 }, true);
 }
Exemple #7
0
 public override void SendTesterPresent(ECUConnection connection)
 {
     // looks like 3E 01 for KW2C3PE
     connection.SendMessage(new byte[] { 0x3E, 0x01 }, true);
 }