Beispiel #1
0
        public void J2534SetFilters(ECUInterfaceSubtype profile)
        {
            // setup ecu filter (mimicking vediamo's behavior)

            // convert the CBF's identifier integers to byte arrays
            CanIdentifier   = BitConverter.GetBytes(profile.GetComParameterValue(ECUInterfaceSubtype.ParamName.CP_REQUEST_CANIDENTIFIER));
            RxCanIdentifier = BitConverter.GetBytes(profile.GetComParameterValue(ECUInterfaceSubtype.ParamName.CP_RESPONSE_CANIDENTIFIER));
            // input byte data is in big-endian
            Array.Reverse(CanIdentifier);
            Array.Reverse(RxCanIdentifier);

            MessageFilter filter = new MessageFilter();

            // Apparently in the EIS series, the RX identifier is !! NOT !! CanIdentifier+8 per ISO15765, so the automatic config in J2534-Sharp will fail

            // manually configure a ISO15765 filter
            filter.FilterType  = Filter.FLOW_CONTROL_FILTER;
            filter.Mask        = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
            filter.Pattern     = RxCanIdentifier; // RX address, typically CanIdentifier+8, EXCEPT EIS
            filter.FlowControl = CanIdentifier;   // TX address
            filter.TxFlags     = TxFlag.ISO15765_FRAME_PAD;

            ConnectionChannel.StartMsgFilter(filter);
        }
        public void J2534SetConfig(ECUInterfaceSubtype profile)
        {
            List <SConfig> sconfigList = new List <SConfig>();

            List <Tuple <Parameter, ECUInterfaceSubtype.ParamName> > comPairs = new List <Tuple <Parameter, ECUInterfaceSubtype.ParamName> >();

            comPairs.Add(new Tuple <Parameter, ECUInterfaceSubtype.ParamName>(Parameter.STMIN_TX, ECUInterfaceSubtype.ParamName.CP_STMIN_SUG));
            comPairs.Add(new Tuple <Parameter, ECUInterfaceSubtype.ParamName>(Parameter.ISO15765_STMIN, ECUInterfaceSubtype.ParamName.CP_STMIN_SUG));
            comPairs.Add(new Tuple <Parameter, ECUInterfaceSubtype.ParamName>(Parameter.ISO15765_BS, ECUInterfaceSubtype.ParamName.CP_BLOCKSIZE_SUG));

            foreach (Tuple <Parameter, ECUInterfaceSubtype.ParamName> comPair in comPairs)
            {
                // apparently some are optional so we have to check for the presence of known comparams to configure the target j2534 device
                if (profile.GetComParameterValue(comPair.Item2, out int comValue))
                {
                    sconfigList.Add(new SConfig(comPair.Item1, comValue));
                }
            }
            ConnectionChannel.SetConfig(sconfigList.ToArray());
        }
 // this (and the overloaded variant) will be an issue when operating in gateway mode;
 // gateway mode will likely require the two separate can ids to be defined
 public void SetCANIdentifiers(ECUInterfaceSubtype profile)
 {
     SetCANIdentifiers(profile.GetComParameterValue(ECUInterfaceSubtype.ParamName.CP_REQUEST_CANIDENTIFIER), profile.GetComParameterValue(ECUInterfaceSubtype.ParamName.CP_RESPONSE_CANIDENTIFIER));
 }
        public ConnectResponse Connect(ECUInterfaceSubtype profile, ECU ecuContext)
        {
            State      = ConnectionState.PendingDeviceSelection;
            EcuContext = ecuContext;

            if (!IsSimulation())
            {
                if (ConnectionDevice is null)
                {
                    Console.WriteLine("No interfaces available : please select a J2534 interface from the Connection menu");
                    return(ConnectResponse.NoValidInterface);
                }
            }

            if (!profile.Qualifier.StartsWith("HSCAN"))
            {
                Console.WriteLine("Profile not supported: only HSCAN interfaces are supported.");
                return(ConnectResponse.UnsupportedProtocol);
            }

            ConnectionProtocol = BaseProtocol.GetProtocol(profile.Qualifier);

            // actually start fixing up the connection
            if (ConnectionChannel != null)
            {
                ConnectionChannel.Dispose();
                ConnectionChannel = null;
            }
            FriendlyProfileName = profile.Qualifier;

            if (IsSimulation())
            {
                SimulationChannel = new Simulation.Simulated_CRD3();
                Console.WriteLine("Connected (Simulation)");
            }
            else
            {
                try
                {
                    // only ISO15765 is supported
                    // CAN_ID_BOTH : accepts 11-bit and 29-bit CAN messages
                    // baudrate is specified by the ECU
                    ConnectionChannel = ConnectionDevice.GetChannel(Protocol.ISO15765, (Baud)profile.GetComParameterValue(ECUInterfaceSubtype.ParamName.CP_BAUDRATE), ConnectFlag.CAN_ID_BOTH);
                    Console.WriteLine($"Target voltage : {ConnectionChannel.MeasureBatteryVoltage()} mV");
                    ConnectionChannel.DefaultTxFlag = TxFlag.ISO15765_FRAME_PAD;

                    SetCANIdentifiers(profile);
                    J2534SetFilters();
                    J2534SetConfig(profile);
                    J2534FlushBuffers();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Connection failed with exception : {e.Message}");
                    return(ConnectResponse.FailedWithException);
                }

                // this chunk is repeated for AVDI devices; OpenPort2 does not care, Scanmatik refuses to continue if reconfigured without clearing prior filters
                // wrap the second attempt in a separate try block, so that we can suppress any potential filter errors
                if (DriverIsAVDI())
                {
                    try
                    {
                        ConnectionChannel.ClearMsgFilters();
                        SetCANIdentifiers(profile);
                        J2534SetFilters();
                        J2534SetConfig(profile);
                        J2534FlushBuffers();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"AVDI Second config exception suppressed: {ex.Message}");
                    }
                }
            }


            State = ConnectionState.ChannelConnectedPendingEcuContact;
            ConnectionUpdateState();
            return(ConnectResponse.OK);
        }