private void TreeViewDoubleClickCheckIfVariantDiag(TreeNode node) { string validNodePrefix = $"Exec{nameof(DiagService)}:"; if (node.Parent is null) { return; } if (node.Parent.Tag.ToString().StartsWith(validNodePrefix)) { string variantName = node.Parent.Tag.ToString().Substring(validNodePrefix.Length); ECUVariant foundVariant = null; foreach (CaesarContainer container in Containers) { foreach (ECU ecu in container.CaesarECUs) { foreach (ECUVariant variant in ecu.ECUVariants) { if (variant.Qualifier == variantName) { foundVariant = variant; } } } } // variant found, exec the diag service if (foundVariant != null) { DiagService ds = foundVariant.DiagServices[int.Parse(node.Tag.ToString())]; bool connectionSupportsUnlocking = Connection?.ConnectionProtocol?.SupportsUnlocking() ?? false; // can we help to skip the modal if the ds doesn't require additional user input? common for data, stored data if ((ds.DataClass_ServiceType == (int)DiagService.ServiceType.StoredData) || (ds.DataClass_ServiceType == (int)DiagService.ServiceType.Data)) { Connection?.ExecUserDiagJob(ds.RequestBytes, ds); } else if (connectionSupportsUnlocking && (ds.RequestBytes.Length == 2) && (ds.RequestBytes[0] == 0x27)) { // request seed, no need to prompt Connection?.ExecUserDiagJob(ds.RequestBytes, ds); } else { PresentRunDiagDialog(ds); } } } }
private void PresentRunDiagDialog(DiagService ds) { RunDiagForm runDiagForm = new RunDiagForm(ds); if (runDiagForm.ShowDialog() == DialogResult.OK) { Connection.ExecUserDiagJob(runDiagForm.Result, ds); } }
private static void ExecVCWrite(byte[] request, DiagService service, ECUConnection connection, bool writesEnabled) { bool allowVcWrite = writesEnabled; // allowWriteVariantCodingToolStripMenuItem.Checked; if (allowVcWrite) { connection.ExecUserDiagJob(request, service); Console.WriteLine("VC Write completed"); } else { MessageBox.Show("This VC write action has to be manually enabled under \r\nFile > Allow Write Variant Coding\r\nPlease make sure that you understand the risks before doing so.", "Accidental Brick Protection"); } }