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());
        }
Exemple #2
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);
        }
 // 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);
        }
Exemple #5
0
        private void tvMain_DoubleClick(object sender, EventArgs e)
        {
            TreeNode node = tvMain.SelectedNode;

            if (node is null)
            {
                return;
            }

            if (node.Tag.ToString() == nameof(VCDomain))
            {
                // variant coding
                treeViewSelectVariantCoding(node);
            }
            else if (node.Tag.ToString() == "VCBackup")
            {
                // variant coding backup
                VCReport.treeViewSelectVariantCodingBackup(node, Connection, Containers);
            }
            else if (node.Tag.ToString().StartsWith(nameof(ECUInterfaceSubtype)))
            {
                // initiate contact
                string connectionProfileName = node.Tag.ToString().Substring(nameof(ECUInterfaceSubtype).Length + 1);
                string ecuName = node.Parent.Parent.Text;

                foreach (CaesarContainer container in Containers)
                {
                    ECU ecu = container.CaesarECUs.Find(x => x.Qualifier == ecuName);
                    if (ecu != null)
                    {
                        ECUInterfaceSubtype subtype = ecu.ECUInterfaceSubtypes.Find(x => x.Qualifier == connectionProfileName);
                        if (subtype != null)
                        {
                            Console.WriteLine($"Attempting to open a connection to ({ecuName}) with profile '{connectionProfileName}'");
                            ECUConnection.ConnectResponse response = Connection.Connect(subtype, ecu);
                            if (response == ECUConnection.ConnectResponse.OK)
                            {
                                ProtocolPostConnect();
                            }
                            else if (response == ECUConnection.ConnectResponse.NoValidInterface)
                            {
                                BlinkConnectionMenu();
                                connectionToolStripMenuItem.ShowDropDown();
                                j2534InterfacesToolStripMenuItem.ShowDropDown();
                            }
                            else
                            {
                                // uhoh
                                Console.WriteLine($"ECU connection was unsuccessful : {response}");
                            }
                            break;
                        }
                    }
                }
            }
            else if (node.Tag.ToString().StartsWith(nameof(DiagService)))
            {
                // execute diag service (modal)
                string diagOrigin  = node.Tag.ToString().Substring(nameof(DiagService).Length + 1);
                string variantName = "";
                string ecuName     = "";

                if (diagOrigin.StartsWith($"{nameof(ECUVariant)}:"))
                {
                    variantName = node.Parent.Text;
                    ecuName     = node.Parent.Parent.Text;
                }
                else
                {
                    ecuName = node.Parent.Text;
                }

                foreach (CaesarContainer container in Containers)
                {
                    ECU ecu = container.CaesarECUs.Find(x => x.Qualifier == ecuName);
                    if (ecu != null)
                    {
                        PickDiagForm picker;
                        ECUVariant   variant = ecu.ECUVariants.Find(x => x.Qualifier == variantName);
                        if (variant != null)
                        {
                            //Console.WriteLine($"Starting Diagnostic Service picker modal for variant {variantName}");
                            picker = new PickDiagForm(variant.DiagServices);
                        }
                        else
                        {
                            //Console.WriteLine($"Starting Diagnostic Service picker modal for root {ecuName}");
                            picker = new PickDiagForm(ecu.GlobalDiagServices.ToArray());
                        }
                        if (picker.ShowDialog() == DialogResult.OK)
                        {
                            PresentRunDiagDialog(picker.SelectedDiagService);
                        }
                        break;
                    }
                }
            }
            TreeViewDoubleClickCheckIfSession(node);
            TreeViewDoubleClickCheckIfVariantDiag(node);
        }