internal void LoadDataFromFile(string filename, SymbolCollection m_symbols) { richTextBox1.LoadFile(filename, RichTextBoxStreamType.RichText); //richTextBox1.LoadFile(filename, RichTextBoxStreamType.PlainText); /*string totaltext = string.Empty; int linecount = 0; using (StreamReader sr = new StreamReader(filename)) { using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\temp.asm", false)) { sw.Write(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fswiss\fcharset0 Courier new;}}{\colortbl ;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;}{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\lang1033\f0\fs20 "); string line = string.Empty; while ((line = sr.ReadLine()) != null) { sw.WriteLine(HighlightText(line) + @"\par"); linecount++; //if (linecount == 1000) break; } sw.Write(@"\lang1043\par}"); } } richTextBox1.LoadFile(Application.StartupPath + "\\temp.asm");*/ //richTextBox1.Text = totaltext; }
public void SetSymbolList(SymbolCollection sc) { lookUpEdit1.Properties.DisplayMember = "Varname"; lookUpEdit1.Properties.ValueMember = "Varname"; lookUpEdit2.Properties.DisplayMember = "Varname"; lookUpEdit2.Properties.ValueMember = "Varname"; lookUpEdit3.Properties.DisplayMember = "Varname"; lookUpEdit3.Properties.ValueMember = "Varname"; lookUpEdit1.Properties.DataSource = sc; lookUpEdit2.Properties.DataSource = sc; lookUpEdit3.Properties.DataSource = sc; _symbols = sc; }
public ECUConnection() { _sramDumpFile = string.Empty; m_Engine.onEngineRunning += new Engine.NotifyEngineState(m_Engine_onEngineRunning); m_MonitorECUTimer.AutoReset = true; m_MonitorECUTimer.Interval = 10; m_MonitorECUTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_MonitorECUTimer_Elapsed); m_MonitorECUTimer.Start(); m_SymbolsToMonitor = new SymbolCollection(); /*if (_tcan == null) { _tcan = new T5CANLib.T5CAN(); _usbcandevice = new T5CANLib.CAN.CANUSBDevice(); _tcan.onWriteProgress += new T5CANLib.T5CAN.WriteProgress(OnWriteProgress); _tcan.onCanInfo +=new T5CANLib.T5CAN.CanInfo(_tcan_onCanInfo); _tcan.onReadProgress += new T5CANLib.T5CAN.ReadProgress(_tcan_onReadProgress); _tcan.setCANDevice(_usbcandevice); _opened = false; Thread.Sleep(500); }*/ }
public void ShowSymbolCollection(SymbolCollection sc) { DataTable dt = new DataTable(); dt.Columns.Add("SYMBOLNAME"); dt.Columns.Add("DESCRIPTION"); dt.Columns.Add("XAXIS"); dt.Columns.Add("XAXISDESCRIPTION"); dt.Columns.Add("YAXIS"); dt.Columns.Add("YAXISDESCRIPTION"); SymbolAxesTranslator sat = new SymbolAxesTranslator(); SymbolTranslator symtrans = new SymbolTranslator(); string helptext = string.Empty; XDFCategories cat = XDFCategories.Undocumented; XDFSubCategory subcat = XDFSubCategory.Undocumented; foreach (SymbolHelper sh in sc) { string xaxis = sat.GetXaxisSymbol(sh.Varname); string yaxis = sat.GetYaxisSymbol(sh.Varname); string symboldescr = symtrans.TranslateSymbolToHelpText(sh.Varname, out helptext, out cat, out subcat); string xaxisdescr = ""; string yaxisdescr = ""; if (xaxis != "") { xaxisdescr = symtrans.TranslateSymbolToHelpText(xaxis, out helptext, out cat, out subcat); } if (yaxis != "") { yaxisdescr = symtrans.TranslateSymbolToHelpText(yaxis, out helptext, out cat, out subcat); } if (xaxis != "" || yaxis != "") { dt.Rows.Add(sh.Varname, symboldescr, xaxis, xaxisdescr, yaxis, yaxisdescr); } } gridControl1.DataSource = dt; }
public SymbolCollectionPropertyDescriptor(SymbolCollection coll, int idx) : base("#" + idx.ToString(), null) { this.collection = coll; this.index = idx; }
private void btnCompareSRAMSnapshots_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { // ask user to point out 2 SRAM files. OpenFileDialog ofd1 = new OpenFileDialog(); ofd1.Title = "First SRAM dump..."; ofd1.Filter = "SRAM dumps|*.ram"; ofd1.Multiselect = false; if (ofd1.ShowDialog() == DialogResult.OK) { string filename_1 = ofd1.FileName; ofd1.Title = "Second SRAM dump..."; if (ofd1.ShowDialog() == DialogResult.OK) { string filename_2 = ofd1.FileName; // now compare // frmProgress progress = new frmProgress(); // progress.SetProgress("Analyzing SRAM dumps... stand by"); // progress.Show(); // System.Windows.Forms.Application.DoEvents(); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("SYMBOLNAME"); dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32")); dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32")); dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32")); dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32")); dt.Columns.Add("DESCRIPTION"); dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean")); dt.Columns.Add("CATEGORY", Type.GetType("System.Int32")); dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double")); dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32")); dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double")); dt.Columns.Add("CATEGORYNAME"); dt.Columns.Add("SUBCATEGORYNAME"); int cnt = 0; foreach (Trionic5Tools.SymbolHelper sh in m_trionicFileInformation.SymbolCollection) { int percentage = cnt * 100 / m_trionicFileInformation.SymbolCollection.Count; cnt++; SetTaskProgress(percentage, true); byte[] data_1 = m_trionicFile.ReadDataFromFile(filename_1, (uint)sh.Start_address, (uint)sh.Length); byte[] data_2 = m_trionicFile.ReadDataFromFile(filename_2, (uint)sh.Start_address, (uint)sh.Length); if (data_1.Length != data_2.Length) { frmInfoBox info = new frmInfoBox("Sram data structure invalid... " + sh.Varname); return; } else { double diffperc = 0; int diffabs = 0; double diffavg = 0; bool isdifferent = false; if (m_trionicFileInformation.isSixteenBitTable(sh.Varname)) { for (int i = 0; i < data_1.Length; i += 2) { try { int value1 = (int)(byte)data_1.GetValue(i) * 256; value1 += (int)(byte)data_1.GetValue(i + 1); int value2 = (int)(byte)data_2.GetValue(i) * 256; value2 += (int)(byte)data_2.GetValue(i + 1); if (value1 != value2) { isdifferent = true; diffabs++; } } catch (Exception E) { Console.WriteLine(E.Message); } } } else { for (int i = 0; i < data_1.Length; i++) { if ((byte)data_1.GetValue(i) != (byte)data_2.GetValue(i)) { isdifferent = true; diffabs++; } } } if (isdifferent) { int lengthvalues = sh.Length; if (m_trionicFileInformation.isSixteenBitTable(sh.Varname)) lengthvalues /= 2; diffperc = (diffabs * 100) / lengthvalues; dt.Rows.Add(sh.Varname, sh.Start_address, sh.Flash_start_address, sh.Length, lengthvalues, sh.Helptext, false, (int)sh.Category, diffperc, diffabs, diffavg, sh.Category.ToString().Replace("_", " "), sh.Subcategory.ToString().Replace("_", " ")); } } } Trionic5Tools.SymbolCollection compSymbols = new Trionic5Tools.SymbolCollection(); AddressLookupCollection compAddressLookup = new AddressLookupCollection(); dockManager1.BeginUpdate(); try { DevExpress.XtraBars.Docking.DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500)); SRAMCompareResults tabdet = new SRAMCompareResults(); tabdet.Dock = DockStyle.Fill; tabdet.Filename1 = filename_1; tabdet.Filename2 = filename_2; tabdet.onSRAMSymbolSelect += new SRAMCompareResults.NotifySRAMSelectSymbol(tabdet_onSRAMSymbolSelect); dockPanel.Controls.Add(tabdet); //dockPanel.DockAsTab(dockPanel1); dockPanel.Text = "SRAM compare results: " + Path.GetFileName(filename_1) + " " + Path.GetFileName(filename_2); bool isDocked = false; foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels) { if (pnl.Text.StartsWith("SRAM compare results: ") && pnl != dockPanel && (pnl.Visibility == DevExpress.XtraBars.Docking.DockVisibility.Visible)) { dockPanel.DockAsTab(pnl, 0); isDocked = true; break; } } if (!isDocked) { dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Left, 1); dockPanel.Width = 700; } //CompareSymbolTable(filename, compSymbols, compAddressLookup, tabdet.gridControl1); tabdet.gridControl1.DataSource = dt; //tabdet.CompareTrionic5Tools.SymbolCollection = compSymbols; //tabdet.CompareAddressLookupCollection = compAddressLookup; tabdet.OpenGridViewGroups(tabdet.gridControl1, 1); } catch (Exception E) { Console.WriteLine(E.Message); } dockManager1.EndUpdate(); SetStatusText("SRAM compare done"); SetTaskProgress(0, false); } } }
public void SetRealtimeSymbollist(SymbolCollection m_RealtimeUserSymbols) { m_watchListCollection = m_RealtimeUserSymbols; foreach (SymbolHelper sh in m_watchListCollection) { AddSymbolToDataTable(sh.Varname, sh.Length); } }
private void LoadUserDefinedRealtimeSymbols(string filename) { if (File.Exists(filename)) { m_watchListCollection = new Trionic5Tools.SymbolCollection(); // first empty char[] sep = new char[1]; sep.SetValue(';', 0); using (StreamReader sr = new StreamReader(filename)) { string line = string.Empty; while ((line = sr.ReadLine()) != null) { string[] values = line.Split(sep); foreach (Trionic5Tools.SymbolHelper sh in m_RealtimeSymbolCollection) { if (sh.Varname == values.GetValue(0).ToString()) { Trionic5Tools.SymbolHelper shnew = new Trionic5Tools.SymbolHelper(); shnew.Varname = sh.Varname; shnew.Flash_start_address = sh.Flash_start_address; shnew.Length = sh.Length; shnew.Start_address = sh.Start_address; shnew.Color = sh.Color; shnew.UserCorrectionFactor = ConvertToDouble(values.GetValue(1).ToString()); shnew.UserCorrectionOffset = ConvertToDouble(values.GetValue(2).ToString()); shnew.UseUserCorrection = true; m_watchListCollection.Add(shnew); } } } } SetRealtimeSymbollist(m_watchListCollection); } }
private void CompareToFile(string filename) { Trionic5Tools.SymbolCollection compSymbols = new Trionic5Tools.SymbolCollection(); AddressLookupCollection compAddressLookup = new AddressLookupCollection(); dockManager1.BeginUpdate(); try { DevExpress.XtraBars.Docking.DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500)); CompareResults tabdet = new CompareResults(); tabdet.Dock = DockStyle.Fill; tabdet.Filename = filename; tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelect); dockPanel.Controls.Add(tabdet); //dockPanel.DockAsTab(dockPanel1); dockPanel.Text = "Compare results: " + Path.GetFileName(filename); bool isDocked = false; foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels) { if (pnl.Text.StartsWith("Compare results: ") && pnl != dockPanel && (pnl.Visibility == DevExpress.XtraBars.Docking.DockVisibility.Visible)) { dockPanel.DockAsTab(pnl, 0); isDocked = true; break; } } if (!isDocked) { dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Left, 1); dockPanel.Width = 400; } Trionic5FileInformation m_FileInformation = new Trionic5FileInformation(); Trionic5File m_CompareToFile = CompareSymbolTable(filename, compSymbols, compAddressLookup, tabdet.gridControl1, out m_FileInformation); m_CompareToFile.SetAutoUpdateChecksum(m_appSettings.AutoChecksum); tabdet.ComparedTrionic5File = m_CompareToFile; tabdet.ComparedTrionic5FileInformation = m_FileInformation; tabdet.CompareSymbolCollection = compSymbols; tabdet.CompareAddressLookupCollection = compAddressLookup; tabdet.OpenGridViewGroups(tabdet.gridControl1, 1); } catch (Exception E) { Console.WriteLine(E.Message); } dockManager1.EndUpdate(); }
public void SetSymbols(SymbolCollection sc) { repositoryItemLookUpEdit1.DataSource = sc; }
private bool TryToAddSymbolToCollection(string hexstring, SymbolCollection curSymbolCollection) { //1A 0C 00 05 41 4D 4F 53 5F 73 74 61 74 75 73 00 //19 3A 00 04 49 6E 74 5F 61 64 72 65 73 73 //19 74 00 04 44 61 5F 35 //40 B6 00 01 42 75 69 6C 64 5F 75 70 5F 74 69 6D 65 5F 73 77 69 74 63 68 21 00 bool retval = false; int address = 0x00000; int length = 0x00; bool symbol_invalid = false; int invalid_char_count = 0; string name = string.Empty; try { address = Convert.ToInt32(hexstring.Substring(0, 5).Replace(" ", ""), 16); length = Convert.ToInt32(hexstring.Substring(6, 5).Replace(" ", ""), 16); for (int i = 12; i < hexstring.Length; i += 3) { int val = Convert.ToInt16(hexstring.Substring(i, 3).Replace(" ", ""), 16); if (val < 10) invalid_char_count++; if (invalid_char_count > 2) symbol_invalid = true; name += Convert.ToChar(val); } if (symbol_invalid) { //AddLogItem("Found invalid symbol: " + name + " at " + address.ToString("X4") + " len " + length.ToString("X4")); } else { name = name.Replace("\0", ""); if (name.Length > 0) { SymbolHelper sh = new SymbolHelper(); sh.Varname = name; sh.Start_address = address; sh.Length = length; curSymbolCollection.Add(sh); /*if (name == "Tryck_mat!") { SymbolHelper sh2 = new SymbolHelper(); sh2.Varname = "Pressure map scaled for 3 bar mapsensor"; sh2.Start_address = address; sh2.Length = length; curSymbolCollection.Add(sh2); } if (name == "Tryck_mat_a!") { SymbolHelper sh2 = new SymbolHelper(); sh2.Varname = "Pressure map (AUT) scaled for 3 bar mapsensor"; sh2.Start_address = address; sh2.Length = length; curSymbolCollection.Add(sh2); }*/ retval = true; } else { retval = false; } } } catch (Exception E) { // AddLogItem("Failed to convert symbol: " + E.Message); Console.WriteLine(E.Message); } return retval; }
private bool OpenWorkingFile(string filename) { bool retval = false; if (File.Exists(filename)) { m_trionicFile = new Trionic5File(); m_trionicFile.LibraryPath = Application.StartupPath + "\\Binaries"; m_trionicFile.SetAutoUpdateChecksum(m_appSettings.AutoChecksum); FileInfo fi = new FileInfo(filename); //<GS-07102010> remove read only flag if possible try { fi.IsReadOnly = false; btnReadOnly.Caption = "File access OK"; } catch (Exception E) { Console.WriteLine("Failed to remove read only flag: " + E.Message); btnReadOnly.Caption = "File is READ ONLY"; } m_trionicFile.onDecodeProgress += new IECUFile.DecodeProgress(m_trionicFile_onDecodeProgress); m_trionicFile.onTransactionLogChanged += new IECUFile.TransactionLogChanged(m_trionicFile_onTransactionLogChanged); m_trionicFile.SelectFile(filename); //m_trionicFileInformation = m_trionicFile.ParseTrionicFile(ofd.FileName); m_trionicFileInformation = m_trionicFile.ParseFile(); props = m_trionicFile.GetTrionicProperties(); // set indicators and menu items accoring to the file that has been opened if (props.IsTrionic55) { barECUType.Caption = "T5.5"; // enable T5.5 maps EnableT55Maps(true); } else { barECUType.Caption = "T5.2"; EnableT55Maps(false); // disable T5.5 maps } barECUSpeed.Caption = props.CPUspeed; if (props.RAMlocked) { barECULocked.Caption = "RAM locked"; } else { barECULocked.Caption = "RAM unlocked"; } if (CheckFileInLibrary(props.Partnumber)) { btnCompareToOriginalFile.Enabled = true; } else { btnCompareToOriginalFile.Enabled = false; } _ecuConnection.MapSensorType = m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType); gridSymbols.DataSource = m_trionicFileInformation.SymbolCollection; barStaticItem2.Caption = "File: " + Path.GetFileName(m_trionicFileInformation.Filename); this.Text = "T5Suite Professional 2.0 [" + Path.GetFileName(m_trionicFileInformation.Filename) + "]"; OpenGridViewGroups(gridSymbols, 0); // enable buttons barButtonItem4.Enabled = true; btnConnectECU.Enabled = true; btnSwitchMode.Enabled = true; //btnSynchronizeMaps.Enabled = true; btnTuneForE85Fuel.Enabled = true; //<GS-06042010> todo btnTuneToLargerInjectors.Enabled = true; //<GS-06042010> todo btnTuneToStage1.Enabled = true; btnTuneToStage2.Enabled = true; btnTuneToStage3.Enabled = true; btnTuneToStageX.Enabled = true; // btnTuneToThreeBarSensor.Enabled = true; barConvertMapSensor.Enabled = true; btnBoostAdaptionWizard.Enabled = true; btnHardcodedRPMLimit.Enabled = true; if (m_trionicFileInformation.Has2DRegKonMat()) { btnChangeRegkonMatRange.Enabled = true; } else { btnChangeRegkonMatRange.Enabled = false; } m_appSettings.Lastfilename = filename; ctrlRealtime1.Currentfile = filename; if (m_AFRMaps != null) { m_AFRMaps.SaveMaps(); // first save changes that might have been done } m_AFRMaps = null; if (m_AFRMaps == null && m_appSettings.AlwaysCreateAFRMaps) { m_AFRMaps = new AFRMaps(); m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged); m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged); m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked); m_AFRMaps.TrionicFile = m_trionicFile; m_AFRMaps.InitializeMaps(); } // add realtime symbollist to ctrlRealtime1 Trionic5Tools.SymbolCollection _rtSymbols = new Trionic5Tools.SymbolCollection(); foreach (Trionic5Tools.SymbolHelper symh in m_trionicFileInformation.SymbolCollection) { if (symh.Start_address > 0 && (symh.Length >= 1 && symh.Length <= 4)) // <GS-29072010> was 1 & 2 only { _rtSymbols.Add(symh); } } ctrlRealtime1.RealtimeSymbolCollection = _rtSymbols; try { LoadUserDefinedRealtimeSymbols(); // try to load it } catch (Exception E) { Console.WriteLine(E.Message); } LoadKnockMaps(); SetTaskProgress(0, false); retval = true; } return retval; }
private void SetupLogFilters() { // setup the export filters LogFilters filterhelper = new LogFilters(); frmLogFilters frmfilters = new frmLogFilters(); LogFilterCollection filters = filterhelper.GetFiltersFromRegistry(); frmfilters.SetFilters(filters); Trionic5Tools.SymbolCollection sc = new Trionic5Tools.SymbolCollection(); foreach (Trionic5Tools.SymbolHelper sh in m_trionicFileInformation.SymbolCollection) { if (!sh.Varname.Contains("!")) sc.Add(sh); } frmfilters.SetSymbols(sc); if (frmfilters.ShowDialog() == DialogResult.OK) { filterhelper.SaveFiltersToRegistry(frmfilters.GetFilters()); } }
private void LoadUserDefinedRealtimeSymbols() { string savePath = Path.Combine(Application.LocalUserAppDataPath, "rtsymbols.txt"); if (File.Exists(savePath)) { m_RealtimeUserSymbols = new Trionic5Tools.SymbolCollection(); // first empty char[] sep = new char[1]; sep.SetValue(';', 0); using (StreamReader sr = new StreamReader(savePath)) { string line = string.Empty; while ((line = sr.ReadLine()) != null) { string[] values = line.Split(sep); foreach (Trionic5Tools.SymbolHelper sh in m_trionicFileInformation.SymbolCollection) { if (sh.Varname == values.GetValue(0).ToString()) { Trionic5Tools.SymbolHelper shnew = new Trionic5Tools.SymbolHelper(); shnew.Varname = sh.Varname; shnew.Flash_start_address = sh.Flash_start_address; shnew.Length = sh.Length; shnew.Start_address = sh.Start_address; shnew.Color = sh.Color; shnew.UserCorrectionFactor = ConvertToDouble(values.GetValue(1).ToString()); shnew.UserCorrectionOffset = ConvertToDouble(values.GetValue(2).ToString()); shnew.UseUserCorrection = true; m_RealtimeUserSymbols.Add(shnew); } } } } ctrlRealtime1.SetRealtimeSymbollist(m_RealtimeUserSymbols); } }
//string skinMask = "Skin: "; /// <summary> /// InitSkins: Initialiseer de skin engine om het voor de gebruiker mogelijk te maken /// om een skin te kiezen voor de user interface /// </summary> void InitSkins() { ribbonControl1.ForceInitialize(); BarButtonItem item; int skinCount = 0; DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.BonusSkins).Assembly); DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.OfficeSkins).Assembly); Trionic5Tools.SymbolCollection symcol = new Trionic5Tools.SymbolCollection(); foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins) { Trionic5Tools.SymbolHelper sh = new Trionic5Tools.SymbolHelper(); sh.Varname = cnt.SkinName; symcol.Add(sh); } symcol.SortColumn = "Varname"; symcol.SortingOrder = Trionic5Tools.GenericComparer.SortOrder.Ascending; symcol.Sort(); foreach(Trionic5Tools.SymbolHelper sh in symcol) { item = new BarButtonItem(); item.Caption = sh.Varname; BarItemLink il = rbnPageSkins.ItemLinks.Add(item); if ((skinCount++ % 3) == 0) il.BeginGroup = true; item.ItemClick += new ItemClickEventHandler(OnSkinClick); } try { if (m_appSettings.Skinname != string.Empty) { if (IsChristmasTime()) { // set chrismas skin DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Xmas 2008 Blue"); // don't save } else if (IsHalloweenTime()) { // set Halloween skin DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Pumpkin"); // don't save } else if (IsValetineTime()) { DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Valentine"); // don't save } else { DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(m_appSettings.Skinname); } } } catch (Exception E) { Console.WriteLine(E.Message); } SetToolstripTheme(); }
private void ConvertFileToDif(string filename, bool AutoExport) { System.Windows.Forms.Application.DoEvents(); DateTime startDate = DateTime.MaxValue; DateTime endDate = DateTime.MinValue; try { Trionic5Tools.SymbolCollection sc = new Trionic5Tools.SymbolCollection(); string[] alllines = File.ReadAllLines(filename); //using (StreamReader sr = new StreamReader(filename)) { //string line = string.Empty; char[] sep = new char[1]; char[] sep2 = new char[1]; //int linecount = 0; sep.SetValue('|', 0); sep2.SetValue('=', 0); //while ((line = sr.ReadLine()) != null) foreach(string line in alllines) { string[] values = line.Split(sep); if (values.Length > 0) { try { //dd/MM/yyyy HH:mm:ss //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|"; string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dt > endDate) endDate = dt; if (dt < startDate) startDate = dt; for (int t = 1; t < values.Length; t++) { string subvalue = (string)values.GetValue(t); string[] subvals = subvalue.Split(sep2); if (subvals.Length == 2) { string varname = (string)subvals.GetValue(0); bool sfound = false; foreach (Trionic5Tools.SymbolHelper sh in sc) { if (sh.Varname == varname) { sfound = true; } } Trionic5Tools.SymbolHelper nsh = new Trionic5Tools.SymbolHelper(); nsh.Varname = varname; if (!sfound) sc.Add(nsh); } } } catch (Exception pE) { Console.WriteLine(pE.Message); } } } } if (AutoExport) { foreach (Trionic5Tools.SymbolHelper sh in sc) { sh.Color = GetColorFromRegistry(sh.Varname); } DifGenerator difgen = new DifGenerator(); difgen.LowAFR = m_appSettings.WidebandLowAFR / 1000; difgen.HighAFR = m_appSettings.WidebandHighAFR / 1000; difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage / 1000; difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage / 1000; difgen.WidebandSymbol = m_appSettings.WidebandLambdaSymbol; difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol; difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress); System.Windows.Forms.Application.DoEvents(); try { difgen.ConvertFileToDif(filename, sc, startDate, endDate, true, true); } catch (Exception expE1) { Console.WriteLine(expE1.Message); } } else { // show selection screen frmPlotSelection plotsel = new frmPlotSelection(); foreach (Trionic5Tools.SymbolHelper sh in sc) { if (sh.Varname != "Pgm_status") { plotsel.AddItemToList(sh.Varname); } } plotsel.Startdate = startDate; plotsel.Enddate = endDate; plotsel.SelectAllSymbols(); if (plotsel.ShowDialog() == DialogResult.OK) { sc = plotsel.Sc; endDate = plotsel.Enddate; startDate = plotsel.Startdate; DifGenerator difgen = new DifGenerator(); LogFilters filterhelper = new LogFilters(); difgen.SetFilters(filterhelper.GetFiltersFromRegistry()); difgen.LowAFR = m_appSettings.WidebandLowAFR / 1000; difgen.HighAFR = m_appSettings.WidebandHighAFR / 1000; difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage / 1000; difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage / 1000; difgen.WidebandSymbol = m_appSettings.WidebandLambdaSymbol; difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol; difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress); try { if (difgen.ConvertFileToDif(filename, sc, startDate, endDate, m_appSettings.InterpolateLogWorksTimescale, true)) { //difgen.ConvertFileToDif(filename, sc, startDate, endDate, false, false); StartLogWorksWithCurrentFile(Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".dif"); } else { frmInfoBox info = new frmInfoBox("No data was found to export!"); } } catch (Exception expE2) { Console.WriteLine(expE2.Message); } } TimeSpan ts = new TimeSpan(endDate.Ticks - startDate.Ticks); } } catch (Exception E) { Console.WriteLine(E.Message); } }
private void FixMaskedSymbols(SymbolCollection thisSymbolCollection) { int idx = 0; string previoussymbol = string.Empty; foreach (SymbolHelper sh in thisSymbolCollection) { if (sh.Varname.Trim() == "") { Console.WriteLine("Fetching symbolname for symbol after: " + previoussymbol); sh.Varname = FetchSymbolNameFromSequenceList(idx, previoussymbol); } previoussymbol = sh.Varname; idx++; } }
public SelectSymbolEventArgs(int address, int length, string mapname, string filename, bool showdiffmap, SymbolCollection symColl, AddressLookupCollection adrColl, Trionic5File _file, Trionic5FileInformation _fileinfo) { this._address = address; this._length = length; this._mapname = mapname; this._filename = filename; this._showdiffmap = showdiffmap; this._symbols = symColl; this._addresses = adrColl; this.m_CompTrionic5File = _file; this.m_CompTrionic5FileInformation = _fileinfo; }
private void ParseFile(string filename, SymbolCollection curSymbolCollection, AddressLookupCollection curAddressLookupCollection) { // lezen tot END$ (einde symbol table) int m_symboltablestartaddress = 0; int state = 0; int charcount = 0; string dbgstring = string.Empty; string asciistring = string.Empty; // for test state = -10; // for test SignalDecodeProgress(5); //listBox1.Items.Clear(); try { FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); using (BinaryReader br = new BinaryReader(fs)) { byte[] filebytes = br.ReadBytes((int)fs.Length); for (int t = 0; t < filebytes.Length; t++) { byte b = filebytes[t]; /*for (int t = 0; t < fs.Length; t++) { byte b = br.ReadByte();*/ // first find string 00 0A 28 79 00 switch (state) { case -10: if (b == 0) { state++; } break; case -9: if (b == 0x0a) { state++; } else { state = -10; } break; case -8: if (b == 0x28) { state++; } else { state = -10; } break; case -7: if (b == 0x79) { state++; } else { state = -10; } break; case -6: if (b == 0x00) { state++; } else { state = -10; } break; case -5: if (b == 0x4E) { state++; } break; case -4: if (b == 0x75) { state = 2; } else { state = -5; } break; case 0: if (b == 0x0d) { // if (br.PeekChar() == 0x0a) // { state++; // } } break; case 1: if (b == 0x0a) { state++; charcount = 0; } else { state = 0; } break; case 2: if (charcount < 32) { if (b == 0x0d && /*br.PeekChar()*/ filebytes[t+1] == 0x0a) // start of next symbol { state = 1; int address = t - charcount; //AddLogItem(address.ToString("X6") + ": " + dbgstring + " - " + asciistring); TryToAddSymbolToCollection(dbgstring, curSymbolCollection); if (m_symboltablestartaddress == 0 && t > 0xA000) m_symboltablestartaddress = address; dbgstring = string.Empty; asciistring = string.Empty; } else { charcount++; dbgstring += b.ToString("X2") + " "; if (b >= 0x20 && b < 0x80) { asciistring += Convert.ToChar(b); } else { asciistring += "."; } } } else { int address = t - charcount; // AddLogItem(address.ToString("X6") + ": " + dbgstring + " - " + asciistring); TryToAddSymbolToCollection(dbgstring, curSymbolCollection); if (m_symboltablestartaddress == 0 && t > 0xA000) m_symboltablestartaddress = address; //TryToAddSymbolToCollection(dbgstring); if (asciistring.StartsWith("END$")) { br.Close(); fs.Close(); //button1.Enabled = true; //AddLogItem("Found end of symbol table, quit"); return; } else { dbgstring = string.Empty; asciistring = string.Empty; state = 0; } } break; } } br.Close(); } //fs.Flush(); fs.Close(); fs.Dispose(); SignalDecodeProgress(30); // now sort the symbols... } catch (Exception E) { //MessageBox.Show(E.Message); Console.WriteLine(E.Message); } finally { //button1.Enabled = true; try { // fix masked symbolnames... try { FixMaskedSymbols(curSymbolCollection); SignalDecodeProgress(40); } catch (Exception fmsE) { Console.WriteLine("Failed to fix masked symbols: " + fmsE.Message); } try { if (!File.Exists(System.Windows.Forms.Application.StartupPath + "\\symbolindex.xml")) { System.Data.DataTable dt = new System.Data.DataTable("DEFAULT"); dt.Columns.Add("SYMBOLNAME"); foreach (SymbolHelper sh in curSymbolCollection) { dt.Rows.Add(sh.Varname); } dt.WriteXml(System.Windows.Forms.Application.StartupPath + "\\symbolindex.xml"); } } catch (Exception wsiE) { Console.WriteLine("Failed to write symbolindex: " + wsiE.Message); } SignalDecodeProgress(50); ReadAddressLookupTableFromFile(m_symboltablestartaddress, curSymbolCollection.Count, curAddressLookupCollection, filename); //Console.WriteLine("Read address lookup table. Symbolcount = " + curSymbolCollection.Count.ToString() + " addresses = " + curAddressLookupCollection.Count.ToString()); SignalDecodeProgress(70); foreach (SymbolHelper sh in curSymbolCollection) { foreach (AddressLookupHelper alh in curAddressLookupCollection) { if (sh.Start_address == alh.Sram_adddress) { sh.Flash_start_address = alh.Flash_address; alh.UsedAddress = true; break; } } } SignalDecodeProgress(80); foreach (AddressLookupHelper alh in curAddressLookupCollection) { if (!alh.UsedAddress) { Console.WriteLine("Unused addresshelper: " + alh.Flash_address.ToString("X6") + " " + alh.Sram_adddress.ToString("X4")); } } SignalDecodeProgress(90); } catch (Exception finE) { Console.WriteLine(finE.Message); } } }
private void DisassembleFunction(long addr, SymbolCollection symbols, FileStream fs, BinaryReader br, long offset) { CastProgressEvent("Disassembling function: " + addr.ToString("X8"), func_count++, ProgressType.DisassemblingFunctions); //Console.WriteLine("DisassembleFunction: " + addr.ToString("X8")); MNemonicCollection functionList = new MNemonicCollection(); MNemonicHelper label = new MNemonicHelper(); //long realAddr = fs.Position + offset; //label.Mnemonic = "Function_" + realAddr.ToString("X8") + ":"; label.Mnemonic = "Function_" + addr.ToString("X8") +":"; label.Address = addr; if (AddressInMnemonicList(addr)) { //Console.WriteLine("Already disassembled: " + addr.ToString("X8")); return ; } functionList.Add(label); long offaddr = 0; if (addr == 0) return ; if (addr > offset) { fs.Position = addr - offset; } else { fs.Position = addr; } bool endsub = false; bool issub = false; bool isjump = false; string str; while (!endsub) { byte ch1 = br.ReadByte(); byte ch2 = br.ReadByte(); uint i = (uint)((ch1 << 8) + ch2); uint seg = (uint)(((addr + offaddr) & 0xffff0000) >> 16); uint adr = (uint)(((addr + offaddr) & 0xffff)); /*if (ch1 == 0x58 && ch2 == 0x8F) { Console.WriteLine("break!"); }*/ uint t = disasm(out str, addr, ch1, ch2, offaddr, br, out endsub, out issub, out isjump); //Console.WriteLine(str); if (str != "") { MNemonicHelper mnhelper = new MNemonicHelper(); mnhelper.Mnemonic = str; mnhelper.Address = addr; //realAddr = fs.Position + offset; //mnhelper.Address = realAddr; if (!AddressInMnemonicList(addr)) { if (isjump) { TranslateLabels(mnhelper); } mnemonics.Add(mnhelper); } functionList.Add(mnhelper); } if (t > 5) t = 5; //addr += t; switch (t) { case 0: case 1: addr += 2L; break; case 2: addr += 4L; break; case 3: addr += 6L; break; case 4: addr += 8L; break; case 5: addr += 10L; break; } if (issub) { /*if (trgdata == 0) { Console.WriteLine("break!"); }*/ // alleen als die nog niet geweest is if (trgdata != 0) { if (!AddressInMnemonicList(trgdata)) { if (trgdata < 0x00F00000) { long position = fs.Position; //Console.WriteLine("recursive: " + trgdata.ToString("X8") + " curr address: " + addr.ToString("X8")); DisassembleFunction(trgdata, symbols, fs, br, offset); //Console.WriteLine("After recursion: " + addr.ToString("X8")); fs.Position = position; // reset to previous position } } } } if (endsub) { } } // assign a meaningful name to the function if we can // we know what the rom->ram copy routine looks like bool _has_Rom_IgnitionMap = false; bool _has_Ram_IgnitionMap = false; bool _has_Rom_FuelMap = false; bool _has_Ram_FuelMap = false; bool _has_KontrollOrd = false; bool _has_Da_insp = false; bool _has_Tq = false; bool _has_EB = false; bool _has_IdleNeutral = false; string _functionName = string.Empty; foreach (MNemonicHelper functionHelper in functionList) { //Console.WriteLine(functionHelper.Address.ToString("X8") + " " + functionHelper.Mnemonic); if (functionHelper.Mnemonic.Contains("ROM_Ign_map_0!")) _has_Rom_IgnitionMap = true; if (functionHelper.Mnemonic.Contains("RAM_Ign_map_0!")) _has_Ram_IgnitionMap = true; if (functionHelper.Mnemonic.Contains("RAM_Insp_mat!")) _has_Ram_FuelMap = true; if (functionHelper.Mnemonic.Contains("ROM_Insp_mat!")) _has_Rom_FuelMap = true; if (functionHelper.Mnemonic.Contains("#ABCD")) _has_KontrollOrd = true; if (functionHelper.Mnemonic.Contains("Da_insp")) _has_Da_insp = true; if (functionHelper.Mnemonic.Contains("#EB")) _has_EB = true; if (functionHelper.Mnemonic.Contains("Tq")) _has_Tq = true; if (functionHelper.Mnemonic.Contains("Idle_rpm_offNeutral")) _has_IdleNeutral = true; //Idle_rpm_offNeutral } if (_has_Ram_IgnitionMap && _has_Rom_IgnitionMap) _functionName = "CopyIgnitionRomToRam:"; else if (_has_Ram_FuelMap && _has_Rom_FuelMap) _functionName = "CopyFuelRomToRam:"; else if (_has_Ram_IgnitionMap) _functionName = "CalculateIgnitionAngle:"; else if (_has_Ram_FuelMap && !_has_Rom_FuelMap) _functionName = "CalculateInjectionDuration:"; else if (_has_KontrollOrd) _functionName = "CheckSRAMIntegrity:"; else if (_has_Da_insp) _functionName = "CalcInjectionForCylinder:"; else if (_has_EB && _has_Tq) _functionName = "CalculateTorque:"; else if (_has_IdleNeutral) _functionName = "DetermineIdleStatus:"; if (_functionName != string.Empty) { label.Mnemonic = _functionName; } labels.Add(label); //Console.WriteLine("Done with function: " + mnemonics.Count.ToString()); }
private void btnCompareToBinary_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { // compare to other binary file(s)! OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Trionic 5 binary files|*.bin"; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { if (ofd.FileNames.Length > 1) { // bekijk het verschil voor alle geselecteerde bestanden en laat dit zien in een // symbolcompareselector DevExpress.XtraBars.Docking.DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500)); CompareResultSelector tabdet = new CompareResultSelector(); tabdet.onFileSelect += new CompareResultSelector.NotifySelectFile(tabdet_onFileSelect); tabdet.Dock = DockStyle.Fill; dockPanel.Controls.Add(tabdet); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("FILENAME"); dt.Columns.Add("PARTNUMBER"); dt.Columns.Add("SOFTWAREID"); dt.Columns.Add("NUMBEROFSYMBOLS", Type.GetType("System.Int32")); dt.Columns.Add("FULLFILENAME"); int numberofsymbols = 0; foreach (string filename in ofd.FileNames) { Trionic5Tools.SymbolCollection compSymbols = new Trionic5Tools.SymbolCollection(); AddressLookupCollection compAddressLookup = new AddressLookupCollection(); CompareSymbolTableToFile(filename, compSymbols, compAddressLookup, out numberofsymbols); dt.Rows.Add(Path.GetFileName(filename), "", "", numberofsymbols, filename); } tabdet.SetData(dt); dockPanel.Text = "Compare list: " + Path.GetFileName(m_trionicFileInformation.Filename); bool isDocked = false; foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels) { if (pnl.Text.StartsWith("Compare list: ") && pnl != dockPanel && (pnl.Visibility == DevExpress.XtraBars.Docking.DockVisibility.Visible)) { dockPanel.DockAsTab(pnl, 0); //pnl.Options.ShowCloseButton = false; isDocked = true; break; } } if (!isDocked) { dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Left, 1); dockPanel.Width = 700; } } else if (ofd.FileNames.Length == 1) { CompareToFile((string)ofd.FileNames.GetValue(0)); } } }
public bool DisassembleFile(IECUFile m_trionicFile, string inputfile, string outputfile/*, long startaddress*/, SymbolCollection symbols) { // recursive method when jsr was found mnemonics = new MNemonicCollection(); labels = new MNemonicCollection(); /*labels = */findLabels(m_trionicFile, inputfile); _passOne = false; uint i, t, seg, adr; long addr, endaddr, adrcntr, trgaddr, trgaddr1, trgaddr2, trgaddr3, offaddr; byte ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10; //byte n1, n2, n3, n4; //uint infile = 0, outfile = 0, uint addoff = 0; string inname, outname, offsetval; //byte inname[80], outname[80], offsetval[40]; //byte str[80],cmd[80]; string str, cmd; str = string.Empty; for (int temp = 0; temp < 8; temp++) { A_reg.SetValue(0, temp); D_reg.SetValue(0, temp); } m_symbols = symbols; swap = 0; addr = offaddr = 0; inname = inputfile; //infile = 1; // outname = outputfile; //outfile = 1; //addr = startaddress; /********************* DISASSEMBLY STARTS HERE *********************/ /* Read all the preceding words first */ adrcntr = 0L; //StreamWriter sw = new StreamWriter(outname, false); FileStream fsbr = new FileStream(inname, FileMode.Open, FileAccess.Read); if (fsbr == null) return false; BinaryReader br = new BinaryReader(fsbr); if (br == null) { fsbr.Close(); //sw.Close(); return false; } //fsbr.Position = addr; adrcntr = addr; // iterate through all functions // first get all the pointers to work from func_count = 0; FileInfo fi = new FileInfo(inputfile); CastProgressEvent("Starting disassembly", 0, ProgressType.DisassemblingVectors); for (int vec = 1; vec <= 127; vec++) { int percentage = (vec * 100) / 127; CastProgressEvent("Disassembling vectors", percentage, ProgressType.DisassemblingVectors); long vector = m_trionicFile.GetStartVectorAddress(inputfile, vec); long len = fi.Length; if (len == 0x20000) len = 0x60000; if (vector != 0 && vector < len * 2) { //Console.WriteLine("Vector: " + vec.ToString() + " addr: " + vector.ToString("X8")); try { DisassembleFunction(vector, symbols, fsbr, br, len); } catch (Exception E) { Console.WriteLine("Failed to handle vector: " + E.Message); } } } CastProgressEvent("Translating vector labels", 0, ProgressType.TranslatingVectors); //Console.WriteLine("Translating vector labels"); long[] vectors = m_trionicFile.GetVectorAddresses(m_trionicFile.GetFileInfo().Filename); int lblcount = 0; foreach (MNemonicHelper label in labels) { int percentage = (lblcount++ * 100) / labels.Count; CastProgressEvent("Translating vector labels", percentage, ProgressType.TranslatingVectors); for (i = 0; i < 128; i++) { if (label.Address == /*m_trionicFile.GetStartVectorAddress(m_trionicFileInformation.Filename, i)*/ Convert.ToInt64(vectors.GetValue(i))) { switch (i) { case 1: label.Mnemonic = "INIT_PROGRAM:"; break; case 2: label.Mnemonic = "BUS_ERROR:"; break; case 3: label.Mnemonic = "ADDRESS_ERROR:"; break; case 4: label.Mnemonic = "ILLEGAL_INSTRUCTION:"; break; case 5: label.Mnemonic = "DIVIDE_BY_ZERO:"; break; case 6: label.Mnemonic = "CHK12_INSTR:"; break; case 7: label.Mnemonic = "TRAPx_INSTR:"; break; case 8: label.Mnemonic = "PRIV_VIOLATION:"; break; case 9: label.Mnemonic = "TRACE:"; break; case 10: label.Mnemonic = "L1010_EMUL:"; break; case 11: label.Mnemonic = "L1111_EMUL:"; break; case 12: label.Mnemonic = "HW_BREAKPOINT:"; break; case 13: label.Mnemonic = "RESERVED:"; break; case 14: label.Mnemonic = "FMT_ERR1:"; break; case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: label.Mnemonic = "UNASSIGNED:"; break; case 23: label.Mnemonic = "FFFFFFFF:"; break; case 24: label.Mnemonic = "SPURIOUS_INTERRUPT:"; break; case 25: label.Mnemonic = "LEVEL1_INTERUPT_AUTOVECTOR:"; break; case 26: label.Mnemonic = "LEVEL2_INTERUPT_AUTOVECTOR:"; break; case 27: label.Mnemonic = "LEVEL3_INTERUPT_AUTOVECTOR:"; break; case 28: label.Mnemonic = "LEVEL4_INTERUPT_AUTOVECTOR:"; break; case 29: label.Mnemonic = "LEVEL5_INTERUPT_AUTOVECTOR:"; break; case 30: label.Mnemonic = "LEVEL6_INTERUPT_AUTOVECTOR:"; break; case 31: label.Mnemonic = "LEVEL7_INTERUPT_AUTOVECTOR:"; break; case 32: label.Mnemonic = "TAP0_INSTRUCTION_VECTOR:"; break; case 33: label.Mnemonic = "TAP1_INSTRUCTION_VECTOR:"; break; case 34: label.Mnemonic = "TAP2_INSTRUCTION_VECTOR:"; break; case 35: label.Mnemonic = "TAP3_INSTRUCTION_VECTOR:"; break; case 36: label.Mnemonic = "TAP4_INSTRUCTION_VECTOR:"; break; case 37: label.Mnemonic = "TAP5_INSTRUCTION_VECTOR:"; break; case 38: label.Mnemonic = "TAP6_INSTRUCTION_VECTOR:"; break; case 39: label.Mnemonic = "TAP7_INSTRUCTION_VECTOR:"; break; case 40: label.Mnemonic = "TAP8_INSTRUCTION_VECTOR:"; break; case 41: label.Mnemonic = "TAP9_INSTRUCTION_VECTOR:"; break; case 42: label.Mnemonic = "TAP10_INSTRUCTION_VECTOR:"; break; case 43: label.Mnemonic = "TAP11_INSTRUCTION_VECTOR:"; break; case 44: label.Mnemonic = "TAP12_INSTRUCTION_VECTOR:"; break; case 45: label.Mnemonic = "TAP13_INSTRUCTION_VECTOR:"; break; case 46: label.Mnemonic = "TAP14_INSTRUCTION_VECTOR:"; break; case 47: label.Mnemonic = "TAP15_INSTRUCTION_VECTOR:"; break; default: label.Mnemonic = "VECTOR_" + i.ToString() + ":"; break; } break; } } } /* Console.WriteLine("Translating known functions"); CastProgressEvent("Translating known functions", 0, ProgressType.TranslatingLabels); lblcount = 0; foreach (MNemonicHelper label in labels) { int percentage = (lblcount++ * 100) / labels.Count; CastProgressEvent("Translating known functions", percentage, ProgressType.TranslatingLabels); foreach (MNemonicHelper mnemonic in mnemonics) { if (mnemonic.Mnemonic.Contains("JSR") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); // break; } else if (mnemonic.Mnemonic.Contains("BEQ") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BRA") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BLS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BNE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BHI") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BCS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BCC") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BGE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BLT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BGT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } else if (mnemonic.Mnemonic.Contains("BLE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8"))) { mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", "")); } } }*/ CastProgressEvent("Adding labels", 0, ProgressType.AddingLabels); //Console.WriteLine("Adding labels"); lblcount = 0; foreach (MNemonicHelper label in labels) { int percentage = (lblcount++ * 100) / labels.Count; CastProgressEvent("Adding labels", percentage, ProgressType.AddingLabels); label.Address--; // for sequencing mnemonics.Add(label); } //Console.WriteLine("Sorting data"); CastProgressEvent("Sorting mnemonics", 0, ProgressType.SortingData); mnemonics.SortColumn = "Address"; mnemonics.SortingOrder = Trionic5Controls.GenericComparer.SortOrder.Ascending; mnemonics.Sort(); CastProgressEvent("Sorting mnemonics", 100, ProgressType.SortingData); return true; }
public bool ConvertFileToDif(string filename, SymbolCollection sc, DateTime startDate, DateTime endDate, bool RescaleTimeScaleToLogWorksInterval, bool DoInterpolationOfPoints) { bool retval = false; string newfilename = Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".dif"; bool _calculateregkonmat = false; bool pwmut10present = false; bool pfakpresent = false; bool ifakpresent = false; bool dfakpresent = false; foreach (SymbolHelper sh in sc) { if (sh.Varname == "Pgm_status") { //sc.Remove(sh); break; } } int colorindex = 1; foreach (SymbolHelper sh in sc) { if (System.Drawing.ColorTranslator.ToWin32(sh.Color) == 0) { sh.Color = System.Drawing.Color.FromArgb(0, colorindex, colorindex, colorindex); colorindex++; //sc.Remove(sh); //symbolremoved = true; //break; } } foreach (SymbolHelper sh in sc) { if (sh.Varname == "PWM_ut10") pwmut10present = true; if (sh.Varname == "P_fak") pfakpresent = true; if (sh.Varname == "I_fak") ifakpresent = true; if (sh.Varname == "D_fak") dfakpresent = true; } if (pwmut10present && pfakpresent && ifakpresent && dfakpresent) { // _calculateregkonmat = true; } //_calculateregkonmat = false; /// TEST CastExportProgressEvent(1); if (File.Exists(newfilename)) File.Delete(newfilename); using (StreamWriter sw = new StreamWriter(newfilename, false)) { // first write the dif header sw.WriteLine("TABLE"); sw.WriteLine("0,1"); sw.WriteLine("\"EXCEL\""); sw.WriteLine("VECTORS"); sw.WriteLine("0, 31280"); sw.WriteLine("\"LMTR\""); sw.WriteLine("TUPLES"); int count = sc.Count + 1; if (_calculateregkonmat) count++; sw.WriteLine("0," + count.ToString()); sw.WriteLine("\"1222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\""); sw.WriteLine("DATA"); sw.WriteLine("0,0"); sw.WriteLine("\"\""); sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Input Description\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); // 1 extra for regkonmat sw.WriteLine("\"\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"From device:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"LM-1 (LM-1:" + t.ToString() + ")\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"LM-1 (LM-1:" + sc.Count.ToString() + ")\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Name:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"" + sc[t].Varname + "\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"Regkonmat\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Unit:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"" + ConvertToUnits(sc[t].Varname) + "\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"%\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Range:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("0," + ConvertToRangeFrom(sc[t].Varname) /*+ "," + COnvertToRangeUpto(sc[t].Varname)*/); sw.WriteLine("V"); } if (_calculateregkonmat) { sw.WriteLine("0,0"); sw.WriteLine("V"); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"equiv(Sample):\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("0,0"); sw.WriteLine("V"); } if (_calculateregkonmat) { sw.WriteLine("0,0"); sw.WriteLine("V"); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"to:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("0," + COnvertToRangeUpto(sc[t].Varname) + ""); sw.WriteLine("V"); } if (_calculateregkonmat) { sw.WriteLine("0,100"); sw.WriteLine("V"); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"equiv(Sample):\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("0,4096"); sw.WriteLine("V"); } if (_calculateregkonmat) { sw.WriteLine("0,4096"); sw.WriteLine("V"); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Color:\""); for (int t = 0; t < sc.Count; t++) { Int32 color = sc[t].Color.R * 256 * 256; color += sc[t].Color.G * 256; color += sc[t].Color.B; sw.WriteLine("0," + /*System.Drawing.ColorTranslator.ToWin32(sc[t].Color).ToString()*/ color.ToString());//ConvertToColor(sc[t].Varname)); sw.WriteLine("V"); } if (_calculateregkonmat) { sw.WriteLine("0," + System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Pink).ToString()); sw.WriteLine("V"); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"-End-\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Session 1\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"\""); } sw.WriteLine("-1,0"); sw.WriteLine("BOT"); sw.WriteLine("1,0"); sw.WriteLine("\"Name:\""); for (int t = 0; t < sc.Count; t++) { sw.WriteLine("1,0"); sw.WriteLine("\"" + sc[t].Varname + "\""); } if (_calculateregkonmat) { sw.WriteLine("1,0"); sw.WriteLine("\"Regkonmat\""); } CastExportProgressEvent(10); FileInfo fi = new FileInfo(filename); string[] alllines = File.ReadAllLines(filename); //using (StreamReader sr = new StreamReader(filename)) { long rest_ticks = 0; //string line = string.Empty; string previousline = string.Empty; char[] sep = new char[1]; char[] sep2 = new char[1]; int linecount = 0; sep.SetValue('|', 0); sep2.SetValue('=', 0); DateTime dtpreviousline = DateTime.MaxValue; //while ((line = sr.ReadLine()) != null) foreach(string line in alllines) { linecount+= line.Length; int percentage = (linecount * 90) / (int)fi.Length; CastExportProgressEvent(10 + percentage); string[] values = line.Split(sep); if (values.Length > 0 && CheckValuesAgainstFilters(values)) { try { retval = true; string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dtstring.Length > 20) { dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)), Convert.ToInt32(dtstring.Substring(20, 3))); } if (dt >= startDate && dt <= endDate) { int numberofrepeats = 1; if (RescaleTimeScaleToLogWorksInterval) { dtpreviousline = dtpreviousline.AddTicks(-rest_ticks); if (dtpreviousline <= dt) { TimeSpan tsrepeats = new TimeSpan(dt.Ticks - dtpreviousline.Ticks); // tel vorige rest erbij //tsrepeats = tsrepeats.Add(new TimeSpan(rest_ticks)); numberofrepeats = (int)(tsrepeats.TotalMilliseconds / 83.33F/*82.0F*/); //if (numberofrepeats > 10) numberofrepeats = 10; if (numberofrepeats <= 0) numberofrepeats = 1; // rest_ticks opnieuw uitrekenen DateTime exported_to = dtpreviousline.AddMilliseconds((double)numberofrepeats * 83.33F); rest_ticks = Math.Abs(dt.Ticks - exported_to.Ticks); if (rest_ticks > TimeSpan.TicksPerMinute) rest_ticks = 0; long rest_ms = rest_ticks / TimeSpan.TicksPerMillisecond; // Console.WriteLine("From timespan: " + dtpreviousline.Minute.ToString("D2") + ":" + dtpreviousline.Second.ToString("D2") + "." + dtpreviousline.Millisecond.ToString("D3") + " upto " + dt.Minute.ToString("D2") + ":" + dt.Second.ToString("D2") + "." + dt.Millisecond.ToString("D3") + " export_to " + exported_to.Minute.ToString("D2") + ":" + exported_to.Second.ToString("D2") + "." + exported_to.Millisecond.ToString("D3") + " results in " + numberofrepeats.ToString() + " and rest = " + rest_ticks.ToString() + " is " + rest_ms.ToString() + " ms"); dtpreviousline = dt; } else { dtpreviousline = dt; // sync rest_ticks = 0; } } if (numberofrepeats > 500) numberofrepeats = 1; // prevent long pauses in the file <GS-19102010> for (int repeatcount = 1; repeatcount <= numberofrepeats; repeatcount++) { sw.WriteLine("-1,0"); sw.WriteLine("BOT"); TimeSpan ts = new TimeSpan(dt.Ticks - startDate.Ticks); float millisecs = (float)(ts.TotalMilliseconds) / 1000F; sw.WriteLine("0," + millisecs.ToString("F4").Replace(',', '.')); sw.WriteLine("V"); double ifak = -1000000; double pfak = -1000000; double dfak = -1000000; double pwmut = -1000000; bool symbolfound = false; foreach (SymbolHelper sh in sc) { symbolfound = false; for (int t = 1; t < values.Length; t++) { string subvalue = (string)values.GetValue(t); string[] subvals = subvalue.Split(sep2); if (subvals.Length == 2) { string varname = (string)subvals.GetValue(0); //foreach (SymbolHelper sh in sc) //{ if (sh.Varname == varname) { symbolfound = true; if ((varname != "Pgm_mod!") && (varname != "Pgm_status")) { double value = ConvertToDouble((string)subvals.GetValue(1)); if (varname == "AD_sond") { value = ConvertToLambda(value); } if (varname == _widebandSymbol) { if (value >= 25) { value = ConvertToWidebandLambda(value); } } if (varname == "P_fak" || varname == "P gain") { if (value > 32000) value = -(65535 - value); pfak = value; } if (varname == "I_fak" || varname == "I gain") { if (value > 32000) value = -(65535 - value); ifak = value; } if (varname == "D_fak" || varname == "D gain") { if (value > 32000) value = -(65535 - value); dfak = value; } if (varname == "PWM_ut10" || varname == "PWM APC") { //value /= 10; pwmut = value; } if (DoInterpolationOfPoints) { if (previousline != string.Empty) { if (numberofrepeats > 1) { double previousvalue = FetchPreviousValueFromLine(previousline, varname); if (previousvalue > -1000000) { // interpolate between current and float difference = (float)value - (float)previousvalue; float newvalue = (float)value - ((((float)(numberofrepeats)-(float)repeatcount) / (float)numberofrepeats) * difference); if (varname == "P_fak" || varname == "P gain") { if (newvalue > 32000) newvalue = -(65535 - newvalue); pfak = newvalue; } if (varname == "I_fak" || varname == "I gain") { if (newvalue > 32000) newvalue = -(65535 - newvalue); ifak = newvalue; } if (varname == "D_fak" || varname == "D gain") { if (newvalue > 32000) newvalue = -(65535 - newvalue); dfak = newvalue; } if (varname == "PWM_ut10" || varname == "PWM APC") { //value /= 10; pwmut = newvalue; } value = newvalue; } } } } if (varname == "Rpm" || varname == "Lufttemp" || varname == "Bil_hast" || varname == "EGT") { sw.WriteLine("0," + value.ToString().Replace(',', '.')); } else if (varname == "Ign_angle" || varname == "TQ" || varname == "InjectorDC" || varname == "Power" || varname == "Torque") { sw.WriteLine("0," + value.ToString("F1").Replace(',', '.')); } else { sw.WriteLine("0," + value.ToString("F2").Replace(',', '.')); } sw.WriteLine("V"); } /*else if (varname == "Pgm_status") { // indicate what fuelmap is used Int64 value = Convert.ToInt64((string)subvals.GetValue(1)); if ((value & 0x00000200) > 0) { Console.WriteLine("Knock map used on: " + dt.ToString()); } }*/ break; } //} } } if (!symbolfound) { // dan 0 schrijven sw.WriteLine("0,0"); sw.WriteLine("V"); } if (_calculateregkonmat) { if (pfak != -1000000 && ifak != -1000000 && dfak != -1000000 && pwmut != -1000000) { double regkonmat = (pwmut * 10) - pfak - ifak - dfak; regkonmat /= 10; sw.WriteLine("0," + regkonmat.ToString("F3").Replace(',', '.')); sw.WriteLine("V"); } else { sw.WriteLine("0,0"); sw.WriteLine("V"); } } } } } } catch (Exception E) { Console.WriteLine(E.Message); } } previousline = line; } sw.WriteLine("-1,0"); sw.WriteLine("EOD"); } CastExportProgressEvent(100); } return retval; }
private void btnViewMatrixFromLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { // let the user select x axis, y axis and z axis symbols from the logfile // OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Trionic 5 logfiles|*.t5l"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { string[] alllines = File.ReadAllLines(ofd.FileName); avgTable = null; System.Windows.Forms.Application.DoEvents(); DateTime startDate = DateTime.MaxValue; DateTime endDate = DateTime.MinValue; Trionic5Tools.SymbolCollection sc = new Trionic5Tools.SymbolCollection(); try { //using (StreamReader sr = new StreamReader(ofd.FileName)) { //string line = string.Empty; char[] sep = new char[1]; char[] sep2 = new char[1]; //int linecount = 0; sep.SetValue('|', 0); sep2.SetValue('=', 0); //while ((line = sr.ReadLine()) != null) foreach(string line in alllines) { string[] values = line.Split(sep); if (values.Length > 0) { try { //dd/MM/yyyy HH:mm:ss //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|"; string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dt > endDate) endDate = dt; if (dt < startDate) startDate = dt; for (int t = 1; t < values.Length; t++) { string subvalue = (string)values.GetValue(t); string[] subvals = subvalue.Split(sep2); if (subvals.Length == 2) { string varname = (string)subvals.GetValue(0); bool sfound = false; foreach (Trionic5Tools.SymbolHelper sh in sc) { if (sh.Varname == varname) { sfound = true; } } Trionic5Tools.SymbolHelper nsh = new Trionic5Tools.SymbolHelper(); nsh.Varname = varname; if (!sfound) sc.Add(nsh); } } } catch (Exception pE) { Console.WriteLine(pE.Message); } } } } } catch (Exception E) { Console.WriteLine(E.Message); } frmMatrixSelection sel = new frmMatrixSelection(); sel.SetSymbolList(sc); sel.SetXSelection(m_appSettings.LastXAxisFromMatrix); sel.SetYSelection(m_appSettings.LastYAxisFromMatrix); sel.SetZSelection(m_appSettings.LastZAxisFromMatrix); if (sel.ShowDialog() == DialogResult.OK) { // get selected for x, y and z int type = sel.GetViewType(); // <GS-31032011> 0 = mean values, 1 = minimum values, 2 = maximum values string x = sel.GetXAxisSymbol(); string y = sel.GetYAxisSymbol(); string z = sel.GetZAxisSymbol(); m_appSettings.LastXAxisFromMatrix = x; m_appSettings.LastYAxisFromMatrix = y; m_appSettings.LastZAxisFromMatrix = z; double xmin = Double.MaxValue; double xmax = Double.MinValue; double ymin = Double.MaxValue; double ymax = Double.MinValue; double zmin = Double.MaxValue; double zmax = Double.MinValue; //using (StreamReader sr = new StreamReader(ofd.FileName)) { //string line = string.Empty; char[] sep = new char[1]; char[] sep2 = new char[1]; //int linecount = 0; sep.SetValue('|', 0); sep2.SetValue('=', 0); //while ((line = sr.ReadLine()) != null) foreach(string line in alllines) { string[] values = line.Split(sep); if (values.Length > 0) { try { //dd/MM/yyyy HH:mm:ss //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|"; string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dt > endDate) endDate = dt; if (dt < startDate) startDate = dt; for (int t = 1; t < values.Length; t++) { string subvalue = (string)values.GetValue(t); string[] subvals = subvalue.Split(sep2); if (subvals.Length == 2) { string varname = (string)subvals.GetValue(0); double value = ConvertToDouble((string)subvals.GetValue(1)); if (value > 65535) value = 0; if (value < -65535) value = 0; if (varname == x) { // get max and min if (value > xmax) xmax = value; if (value < xmin) xmin = value; } else if (varname == y) { // get max and min if (value > ymax) ymax = value; if (value < ymin) ymin = value; } else if (varname == z) { // get max and min if (value > zmax) zmax = value; if (value < zmin) zmin = value; } } } } catch (Exception pE) { Console.WriteLine(pE.Message); } } } } // now we have it all if (xmin == xmax || ymin == ymax) { frmInfoBox info = new frmInfoBox("No data to display ... x or y axis contains no differentiated values"); return; } frmMatrixResult result = new frmMatrixResult(); result.SetViewType(type); // <GS-31032011> 0 = mean values, 1 = minimum values, 2 = maximum values // parse the file again and add the points DataTable dtresult = new DataTable(); // xmin = -0.8 // xmin = 2.01 double[] x_values = new double[16]; double[] y_values = new double[16]; // fill x and y axis for (int i = 0; i < 16; i++) { double xvalue = xmin; if(i>0) xvalue = xmin + i * ((xmax - xmin) / (15)); //Console.WriteLine("Adding: " + xvalue.ToString()); dtresult.Columns.Add(xvalue.ToString(), Type.GetType("System.Double")); x_values.SetValue(xvalue, i); // test: andersom? } for (int i = 0; i < 16; i++) { //double yvalue = ymin + ((ymax - ymin) / i); double yvalue = ymin; if (i > 0) yvalue = ymin + i * ((ymax - ymin) / (15)); y_values.SetValue(yvalue, i); // test: andersom? } for (int i = 0; i < 16; i++) { dtresult.Rows.Add(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } // table filled double _lastX = 0; double _lastY = 0; double _lastZ = 0; //using (StreamReader sr = new StreamReader(ofd.FileName)) { //string line = string.Empty; char[] sep = new char[1]; char[] sep2 = new char[1]; //int linecount = 0; sep.SetValue('|', 0); sep2.SetValue('=', 0); //while ((line = sr.ReadLine()) != null) foreach(string line in alllines) { string[] values = line.Split(sep); if (values.Length > 0) { try { //dd/MM/yyyy HH:mm:ss //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|"; string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dt > endDate) endDate = dt; if (dt < startDate) startDate = dt; for (int t = 1; t < values.Length; t++) { string subvalue = (string)values.GetValue(t); string[] subvals = subvalue.Split(sep2); if (subvals.Length == 2) { string varname = (string)subvals.GetValue(0); double value = ConvertToDouble((string)subvals.GetValue(1)); if (varname == x) { _lastX = value; } else if (varname == y) { _lastY = value; } else if (varname == z) { _lastZ = value; } } } } catch (Exception pE) { Console.WriteLine(pE.Message); } // add point to the datatable AddPointToDataTable(dtresult, _lastX, _lastY, _lastZ, xmin, xmax, ymin, ymax, zmin, zmax, type); } } } result.MaxValue = zmax; result.MinValue = zmin; result.SetXAxis(x_values); result.SetYAxis(y_values); result.SetXAxisName(x); result.SetYAxisName(y); result.SetZAxisName(z); if (m_appSettings.MapViewerType == MapviewerType.Fancy) result.UseNewMapViewer = true; result.SetTable(dtresult); string typedescr = " (Mean values)"; if (type == 1) typedescr = " (Minimum values)"; else if (type == 1) typedescr = " (Maximum values)"; result.Text = "Matrix [" + x + " : " + y + " : " + z + "]" + typedescr; //result.ShowDialog(); byte[] m_map_content = new byte[16 * 16 * 2]; int idx = 0; for (int i = 15; i >= 0; i--) { foreach (object o in dtresult.Rows[i].ItemArray) { double value = Convert.ToDouble(o); // now convert to int * 100 Int32 ivalue = 0; try { ivalue = Convert.ToInt32(value * 100); } catch (Exception E) { Console.WriteLine("Failed to convert to integer value: " + value.ToString()); } byte b1 = 0; byte b2 = 0; try { b1 = Convert.ToByte(ivalue / 256); b2 = Convert.ToByte(ivalue - (int)b1 * 256); } catch (Exception E) { Console.WriteLine("Failed to convert to byte value + " + ivalue.ToString()); } m_map_content[idx++] = b1; m_map_content[idx++] = b2; } } //<GS-28102010> for test, start a mapviewer as well result.ShowDialog(); //StartResultViewerForMatrix(x_values, y_values, x, y, z, dtresult, m_map_content); } } }
public bool DisassembleFile(bool AddOffset, long OffSetAddress, string inputfile, string outputfile, long startaddress, long endaddress, SymbolCollection symbols) { uint i, t, seg, adr; long addr, endaddr, adrcntr, trgaddr, trgaddr1, trgaddr2, trgaddr3, offaddr; byte ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10; //byte n1, n2, n3, n4; //uint infile = 0, outfile = 0, uint addoff = 0; string inname, outname, offsetval; //byte inname[80], outname[80], offsetval[40]; //byte str[80],cmd[80]; string str, cmd; str = string.Empty; for (int temp = 0; temp < 8; temp++) { A_reg.SetValue(0, temp); D_reg.SetValue(0, temp); } m_symbols = symbols; swap = 0; addr = offaddr = 0; inname = inputfile; //infile = 1; outname = outputfile; //outfile = 1; if (AddOffset) { addoff = 1; offaddr = OffSetAddress; } endaddr = endaddress; addr = startaddress; if (addr > endaddress) return false; /********************* DISASSEMBLY STARTS HERE *********************/ /* Read all the preceding words first */ adrcntr = 0L; StreamWriter sw = new StreamWriter(outname, false); FileStream fsbr = new FileStream(inname, FileMode.Open, FileAccess.Read); if (fsbr == null) return false; BinaryReader br = new BinaryReader(fsbr); if (br == null) { fsbr.Close(); sw.Close(); return false; } fsbr.Position = addr; adrcntr = addr; // start rtf file. sw.Write(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fswiss\fcharset0 Courier new;}}{\colortbl ;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;}{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\lang1033\f0\fs20 "); /* Parse starting from address addr */ bool issub = false; bool isjump = false; bool endsub = false; while (addr <= endaddr) { try { ch1 = br.ReadByte(); ch2 = br.ReadByte(); i = (uint)((ch1 << 8) + ch2); seg = (uint)(((addr + offaddr) & 0xffff0000) >> 16); adr = (uint)(((addr + offaddr) & 0xffff)); t = disasm(out str, addr, ch1, ch2, offaddr, br, out endsub, out issub, out isjump); if (t > 5) t = 5; string myline = string.Empty; switch (t) { case 0: case 1: //sw.WriteLine(seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + "\t\t\t\t" + str); myline = seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + "\t\t\t\t" + str; addr += 2L; break; case 2: fsbr.Position = addr + 2L; ch3 = br.ReadByte(); ch4 = br.ReadByte(); trgaddr = (long)ch3 * 256 + ch4; //sw.WriteLine(seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + "\t\t\t" + str); myline = seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + "\t\t\t" + str; addr += 4L; break; case 3: fsbr.Position = addr + 2L; ch3 = br.ReadByte(); ch4 = br.ReadByte(); ch5 = br.ReadByte(); ch6 = br.ReadByte(); trgaddr = (long)ch3 * 256 + ch4; trgaddr1 = (long)ch5 * 256 + ch6; //sw.WriteLine(seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + "\t\t" + str); myline = seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + "\t\t" + str; addr += 6L; break; case 4: fsbr.Position = addr + 2L; ch3 = br.ReadByte(); ch4 = br.ReadByte(); ch5 = br.ReadByte(); ch6 = br.ReadByte(); ch7 = br.ReadByte(); ch8 = br.ReadByte(); trgaddr = (long)ch3 * 256 + ch4; trgaddr1 = (long)ch5 * 256 + ch6; trgaddr2 = (long)ch7 * 256 + ch8; //sw.WriteLine(seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + " " + trgaddr2.ToString("X4") + "\t\t" + str); myline = seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + " " + trgaddr2.ToString("X4") + "\t\t" + str; addr += 8L; break; case 5: fsbr.Position = addr + 2L; ch3 = br.ReadByte(); ch4 = br.ReadByte(); ch5 = br.ReadByte(); ch6 = br.ReadByte(); ch7 = br.ReadByte(); ch8 = br.ReadByte(); ch9 = br.ReadByte(); ch10 = br.ReadByte(); trgaddr = (long)ch3 * 256 + ch4; trgaddr1 = (long)ch5 * 256 + ch6; trgaddr2 = (long)ch7 * 256 + ch8; trgaddr3 = (long)ch9 * 256 + ch10; //sw.WriteLine(seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + " " + trgaddr2.ToString("X4") + " " + trgaddr3.ToString("X4") + "\t\t" + str); myline = seg.ToString("X4") + adr.ToString("X4") + ": " + i.ToString("X4") + " " + trgaddr.ToString("X4") + " " + trgaddr1.ToString("X4") + " " + trgaddr2.ToString("X4") + " " + trgaddr3.ToString("X4") + "\t" + str; addr += 10L; break; default: br.Close(); fsbr.Close(); sw.Close(); return false; } sw.WriteLine(myline + @"\par"); } catch (Exception E) { Console.WriteLine(E.Message); addr++; } } sw.Write(@"\lang1043\par}"); br.Close(); fsbr.Close(); sw.Close(); return true; }
public Trionic5FileInformation() { m_SymbolCollection = new SymbolCollection(); m_AddressCollection = new AddressLookupCollection(); }
public ctrlRealtime() { InitializeComponent(); LoadExtraMeasurements(); SymbolCollection sc = new SymbolCollection(); SymbolHelper sh_fuel = new SymbolHelper(); sh_fuel.Varname = "Insp_mat!"; sh_fuel.Helptext = "Main fuel map"; sc.Add(sh_fuel); SymbolHelper sh_korr = new SymbolHelper(); //<GS-29112010> different for T5.2 sh_korr.Varname = "Adapt_korr!"; sh_korr.Helptext = "Fuel adaption"; sc.Add(sh_korr); SymbolHelper sh_fuel_mut = new SymbolHelper(); sh_fuel_mut.Varname = "FuelAdjustmentMap"; sh_fuel_mut.Helptext = "Autotune fuel"; sc.Add(sh_fuel_mut); SymbolHelper sh_knock = new SymbolHelper(); sh_knock.Varname = "Fuel_knock_mat!"; sh_knock.Helptext = "Knock fuel map"; sc.Add(sh_knock); SymbolHelper sh_injconst = new SymbolHelper(); sh_injconst.Varname = "Inj_konst!"; sh_injconst.Helptext = "Injector constant"; sc.Add(sh_injconst); btnMapEdit.Relevantsymbols = sc; try { sndplayer = new System.Media.SoundPlayer(); } catch (Exception E) { Console.WriteLine(E.Message); } }
/// <summary> /// Loads an binary file into the hexviewer /// </summary> /// <param name="filename"></param> public void LoadBinaryFile(string filename, SymbolCollection _symbols) { hexViewer1.LoadDataFromFile(filename, _symbols); }
private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) { // Stop monitoring if session is active ResizeControls(); bool _loggingWasActive = false; if (m_loggingActive) { _loggingWasActive = m_loggingActive; m_loggingActive = false; } if (_EnableAdvancedMode) btnMapEdit.Visible = true; digitalDisplayControl7.Visible = false; type = RealtimeMonitoringType.Fuel; SymbolCollection sc = new SymbolCollection(); // notify parent of changed tabpage, the realtime stuff should be filled differently in that case if (e.Page.Text == xtraTabPage1.Text) { type = RealtimeMonitoringType.Fuel; // fill with fuel map SymbolHelper sh_fuel = new SymbolHelper(); sh_fuel.Varname = "Insp_mat!"; sh_fuel.Helptext = "Main fuel map"; sc.Add(sh_fuel); SymbolHelper sh_korr = new SymbolHelper(); sh_korr.Varname = "Adapt_korr!"; sh_korr.Helptext = "Fuel adaption"; sc.Add(sh_korr); SymbolHelper sh_fuel_mut = new SymbolHelper(); sh_fuel_mut.Varname = "FuelAdjustmentMap"; sh_fuel_mut.Helptext = "Autotune fuel"; sc.Add(sh_fuel_mut); SymbolHelper sh_knock = new SymbolHelper(); sh_knock.Varname = "Fuel_knock_mat!"; sh_knock.Helptext = "Knock fuel map"; sc.Add(sh_knock); SymbolHelper sh_injconst = new SymbolHelper(); sh_injconst.Varname = "Inj_konst!"; sh_injconst.Helptext = "Injector constant"; sc.Add(sh_injconst); btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage2.Text) { type = RealtimeMonitoringType.Ignition; // fill with ignition maps SymbolHelper sh_ign = new SymbolHelper(); sh_ign.Varname = "Ign_map_0!"; sh_ign.Helptext = "Main ignition map"; sc.Add(sh_ign); SymbolHelper sh_ignwarmup = new SymbolHelper(); sh_ignwarmup.Varname = "Ign_map_4!"; sh_ignwarmup.Helptext = "Warmup ignition map"; sc.Add(sh_ignwarmup); SymbolHelper sh_ignknock = new SymbolHelper(); sh_ignknock.Varname = "Ign_map_2!"; sh_ignknock.Helptext = "Knock ignition map"; sc.Add(sh_ignknock); btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage3.Text) { type = RealtimeMonitoringType.Boost; SymbolHelper sh_boostrequest = new SymbolHelper(); sh_boostrequest.Varname = "Tryck_mat!"; sh_boostrequest.Helptext = "Boost request map"; sc.Add(sh_boostrequest); SymbolHelper sh_regkonmat = new SymbolHelper(); sh_regkonmat.Varname = "Reg_kon_mat!"; sh_regkonmat.Helptext = "Boost bias map"; sc.Add(sh_regkonmat); SymbolHelper sh_pfact = new SymbolHelper(); sh_pfact.Varname = "P_fors!"; sh_pfact.Helptext = "P factors"; sc.Add(sh_pfact); SymbolHelper sh_ifact = new SymbolHelper(); sh_ifact.Varname = "I_fors!"; sh_ifact.Helptext = "I factors"; sc.Add(sh_ifact); SymbolHelper sh_dfact = new SymbolHelper(); sh_dfact.Varname = "D_fors!"; sh_dfact.Helptext = "D factors"; sc.Add(sh_dfact); btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage4.Text) { type = RealtimeMonitoringType.Knock; SymbolHelper sh_knock_ref = new SymbolHelper(); sh_knock_ref.Varname = "Knock_ref_matrix!"; sh_knock_ref.Helptext = "Knock sensitivity"; sc.Add(sh_knock_ref); SymbolHelper sh_knock_count = new SymbolHelper(); sh_knock_count.Varname = "Knock_count_map"; sh_knock_count.Helptext = "Knock counter map"; sc.Add(sh_knock_count); SymbolHelper sh_ignknock = new SymbolHelper(); sh_ignknock.Varname = "Ign_map_2!"; sh_ignknock.Helptext = "Knock ignition map"; sc.Add(sh_ignknock); SymbolHelper sh_knock = new SymbolHelper(); sh_knock.Varname = "Fuel_knock_mat!"; sh_knock.Helptext = "Knock fuel map"; sc.Add(sh_knock); btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage5.Text) { type = RealtimeMonitoringType.Dashboard; btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage6.Text) { type = RealtimeMonitoringType.Settings; btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage7.Text) { type = RealtimeMonitoringType.Userdefined; // only show symbol that are in the watchlist // clear the map, it will be filled by itself System.Data.DataTable dtnew = new System.Data.DataTable(); if (gridControl4.DataSource == null) { dtnew.TableName = "RTSymbols"; dtnew.Columns.Add("SYMBOLNAME"); dtnew.Columns.Add("MINVALUE", Type.GetType("System.Double")); // autosense max and min! dtnew.Columns.Add("MAXVALUE", Type.GetType("System.Double")); dtnew.Columns.Add("VALUE", Type.GetType("System.Double")); dtnew.Columns.Add("PEAK", Type.GetType("System.Double")); gridControl4.DataSource = dtnew; } btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage8.Text) { type = RealtimeMonitoringType.EngineStatus; btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == xtraTabPage9.Text) { type = RealtimeMonitoringType.OnlineGraph; btnMapEdit.Relevantsymbols = sc; } else if (e.Page.Text == tabAutoTuneIgnition.Text) { type = RealtimeMonitoringType.AutotuneIgnition; } else if (e.Page.Text == tabAutoTune.Text) { type = RealtimeMonitoringType.AutotuneFuel; btnMapEdit.Visible = false; digitalDisplayControl7.Visible = true; } else if (e.Page.Text == tabUserMaps.Text) { type = RealtimeMonitoringType.UserMaps; btnMapEdit.Relevantsymbols = sc; // load the grid DataTable dt = new DataTable(); dt.TableName = "UserMaps"; dt.Columns.Add("Mapname"); dt.Columns.Add("Description"); if (File.Exists(Application.StartupPath + "\\UserMaps.xml")) { dt.ReadXml(Application.StartupPath + "\\UserMaps.xml"); } /*else { dt.Columns.Add("Mapname"); dt.Columns.Add("Description"); }*/ gridControl5.DataSource = dt; } if (e.PrevPage.Text == tabUserMaps.Text) { // save if (gridControl5.DataSource != null) { DataTable dt = (DataTable)gridControl5.DataSource; dt.WriteXml(Application.StartupPath + "\\UserMaps.xml"); } } if (onMonitorTypeChanged != null) { // disable all controls in the bottom to indicate we don't have data for them at this point. // next, when data is received for one of the controls, enable them again DisableGenericControls(); onMonitorTypeChanged(this, new RealtimeMonitoringEventArgs(type)); } if (_loggingWasActive) { m_loggingActive = true; m_logfileName = DetermineNewLogFileName(); } }
public void SetSymbols(SymbolCollection sc) { repositoryItemLookUpEdit1.DataSource = sc; }
public SelectSRAMSymbolEventArgs(int address, int length, string mapname, string filename1, string filename2, bool showdiffmap, SymbolCollection symColl, AddressLookupCollection adrColl) { this._address = address; this._length = length; this._mapname = mapname; this._filename1 = filename1; this._filename2 = filename2; this._showdiffmap = showdiffmap; this._symbols = symColl; this._addresses = adrColl; }
public Trionic5FileInformation() { m_SymbolCollection = new SymbolCollection(); m_AddressCollection = new AddressLookupCollection(); }