Пример #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);
 }
Пример #2
0
 private static bool GetVariantID(ECUConnection connection, out int variantId)
 {
     if (GetVariantID_1A86(connection, out int idFor1A86))
     {
         variantId = idFor1A86;
         return(true);
     }
     if (GetVariantID_1A87(connection, out int idFor1A87))
     {
         variantId = idFor1A87;
         return(true);
     }
     variantId = 0;
     return(false);
 }
Пример #3
0
        public static void ReceiveSecurityResponse(byte[] response, ECU parentEcu, ECUConnection connection)
        {
            if (response.Length == 2)
            {
                // level change ack
                Console.WriteLine($"Security level has been successfully changed to 0x{(response[1] - 1):X}");
            }
            else
            {
                // seed received
                byte[] seedValue         = response.Skip(2).ToArray();
                string seedValueAsString = BitUtility.BytesToHex(seedValue, true);
                int    receiveLevel      = response[1];

                bool manualUnlockRequired = true;
                if (QueryUnlockEcu(seedValue, parentEcu.Qualifier, receiveLevel, out byte[] key))
Пример #4
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);
            }
        }
Пример #5
0
 public override void ConnectionEstablishedHandler(ECUConnection connection)
 {
     if (!EnterDiagnosticSession(connection))
     {
         return;
     }
     if (GetVariantID(connection, out int variantId))
     {
         connection.VariantIsAvailable = true;
         connection.ECUVariantID       = variantId;
         Console.WriteLine($"Variant has been successfully configured as {(variantId & 0xFFFF):X4}");
     }
     else
     {
         return;
     }
 }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
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);
        }
Пример #9
0
 public virtual List <DTCContext> ReportDtcsByStatusMask(ECUConnection connection, ECUVariant variant, byte inMask = 0)
 {
     return(new List <DTCContext>());
 }
Пример #10
0
 public virtual ECUMetadata QueryECUMetadata(ECUConnection connection)
 {
     return(new ECUMetadata()
     {
     });
 }
Пример #11
0
 public override void ConnectionClosingHandler(ECUConnection connection)
 {
     ExitDiagnosticSession(connection);
 }
Пример #12
0
 public override void SendTesterPresent(ECUConnection connection)
 {
     connection.SendMessage(new byte[] { 0x3E, 0x00 }, true);
 }
Пример #13
0
 public override bool GetDtcSnapshot(DTC dtc, ECUConnection connection, out byte[] snapshotBytes)
 {
     // FIXME
     return(base.GetDtcSnapshot(dtc, connection, out snapshotBytes));
 }
Пример #14
0
 public virtual void ConnectionClosingHandler(ECUConnection connection)
 {
 }
Пример #15
0
 public virtual bool GetDtcSnapshot(DTC dtc, ECUConnection connection, out byte[] snapshotBytes)
 {
     snapshotBytes = new byte[] { };
     return(false);
 }
Пример #16
0
 public override void SendTesterPresent(ECUConnection connection)
 {
     // looks like 3E 01 for KW2C3PE
     connection.SendMessage(new byte[] { 0x3E, 0x01 }, true);
 }
Пример #17
0
        public override ECUMetadata QueryECUMetadata(ECUConnection connection)
        {
            ECUMetadata metadata = new ECUMetadata();

            if (ReadDataByIdentifier(connection, 0xF100, out byte[] diagInfoRaw))
Пример #18
0
 public virtual void ConnectionEstablishedHandler(ECUConnection connection)
 {
 }
Пример #19
0
 public override void ConnectionEstablishedHandler(ECUConnection connection)
 {
     //Console.WriteLine("The current protocol is unsupported. Most functions will not be available.");
 }
Пример #20
0
 public virtual void SendTesterPresent(ECUConnection connection)
 {
 }
Пример #21
0
 public override List <DTCContext> ReportDtcsByStatusMask(ECUConnection connection, ECUVariant variant, byte inMask = 0)
 {
     // FIXME : KW2C3PE probably uses a different set of commands at 0x18
     return(base.ReportDtcsByStatusMask(connection, variant, inMask));
 }