Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
//DONE: Make a codeblock sequencer.
//DONE: Make sure SOI maps are detected correctly (see screenshot of 4 axis maps issue)
//DONE: Make filelength a variable
//DONE: Axis collection, browser and editor support (refresh open maps after editing an axis)
//DONE: Bugfix, create new project causes System.UnauthorizedAccessException because of default path to Application.StartupPath
//DONE: Compare should not show infobox about missing axis
//DONE: Compare should use correct file for axis and addresses
//DONE: Add axis units to mapviewer
//DONE: Dynograph (torque(Nm) = IQ * 6
//DONE: Add support for flipping maps upside down
//DONE: Find launch control map (limiter actually) 0x4c640, corrupt axis starts with 0x80 0x00 0x00 0x0A
//DONE: Add checksum support
//DONE: axis change in compare mode?
//DONE: undo button in mapviewer (read from file?)
//DONE: EDC15V: sometimes also has three repeating smoke maps (watch the index IDs, they might be shuffled)
/*DONE: Additional information about codeblocks AG/SG indicator
G038906019HJ 1,9l R4 EDC SG 5259 39S03217 0281010977 FFEWC400 038906019HJ 05/03 <-- Standard Getriebe codeblock 2 (normally manual)
G038906019HJ 1,9l R4 EDC SG 5259 39S03217 0281010977 FFEWE400 038906019HJ 05/03 <-- Standard Getriebe codeblock 3 (normally 4motion)
G038906019HJ 1,9l R4 EDC AG 5259 39S03217 0281010977 FFEWB400 038906019HJ 05/03 <-- Automat Getriebe codeblock 1 (normally automatic)
* ^ ^
* */
//DONE: ALSO use codeblock offset in codeblock synchronization option
//TEST: checksum issue with the ARL file (different structure), done for test!
//TEST: Userdescription for symbols + XML import/export
//HOLD: Find RPM limiter (ASZ @541A2 @641A2 and @741A2 value = 0x14B4 = 5300 rpm) <-- not very wise
//TEST: EDC15V: Don't forget the checksum for 1MB files
//TEST: EDC15V: Detect and fill codeBlocks
//HOLD: codeblocks: unreliable
//TODO: Rewrite XDF interface to TunerPro V5 XML specs (not documented...)
//TODO: Add EEPROM read/write support (K-line)
//TODO: KWP1281 support (K-line, slow init)
//TODO: Add EDC15P support ... 85% LoHi
//TODO: Add EDC15V support ... 70% LoHi 1MB, 512 Kb (IMPROVE SUPPORT + CHECKSUM)
//TODO: Add EDC15M support ... 10% LoHi (Opel?) (CHECKSUM)
//TODO: Add EDC15C support ... 1% LoHi (CHECKSUM)
//TODO: Add EDC16x support ... 5% HiLo (CHECKSUM)
//TODO: Add MSA15 support ... 25% LoHi (CHECKSUM)
//TODO: Add MSA6 support ... 0% 8-bit (CHECKSUM) length indicators only (like ME7 and EDC16)
//TODO: Add EDC17 support ... 1% (CHECKSUM)
//TODO: Add major program switches (MAP/MAF switch etc)
//TODO: Add better hex-diff viewer (HexWorkShop example)
//TODO: Compressormap plotter with GT17 and most used upgrade turbo maps, boost/airmass from comperssor map
//TODO: copy from excel into mapviewer
//TODO: A2L/Damos import
//TODO: EDC15V: Don't forget the checksum for 256kB files
//TODO: Check older EDC15V-5 files.. these seem to be different
//TODO: Checksums: determine type on file open and count how many correct in stead of how many false? 12 banks in edc15v?
//TODO: Smoke limiter repeater is seen as a map (3x13) this is incorrect. Fix please vw passat bin @4DC72.
// (remember issue with len2Skip, we loose SOI limiter)
//TODO: make partnumber/swid editable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars;
using DevExpress.Skins;
namespace VAGSuite
{
public delegate void DelegateStartReleaseNotePanel(string filename, string version);
public enum GearboxType : int
{
Automatic,
Manual,
FourWheelDrive
}
public enum EDCFileType : int
{
EDC15P,
EDC15P6, // different map structure
EDC15V,
EDC15M,
EDC15C,
EDC16,
EDC17, // 512Kb/2048Kb
MSA6,
MSA11,
MSA12,
MSA15,
Unknown
}
public enum EngineType : int
{
cc1200,
cc1400,
cc1600,
cc1900,
cc2500
}
public enum ImportFileType : int
{
XML,
A2L,
CSV,
AS2,
Damos
}
public partial class frmMain : DevExpress.XtraEditors.XtraForm
{
private AppSettings m_appSettings;
private msiupdater m_msiUpdater;
public DelegateStartReleaseNotePanel m_DelegateStartReleaseNotePanel;
private frmSplash splash;
public frmMain()
{
try
{
splash = new frmSplash();
splash.Show();
Application.DoEvents();
}
catch (Exception)
{
}
InitializeComponent();
try
{
m_DelegateStartReleaseNotePanel = new DelegateStartReleaseNotePanel(this.StartReleaseNotesViewer);
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}
}
private void StartReleaseNotesViewer(string xmlfilename, string version)
{
dockManager1.BeginUpdate();
DockPanel dp = dockManager1.AddPanel(DockingStyle.Right);
dp.ClosedPanel += new DockPanelEventHandler(dockPanel_ClosedPanel);
dp.Tag = xmlfilename;
ctrlReleaseNotes mv = new ctrlReleaseNotes();
mv.LoadXML(xmlfilename);
mv.Dock = DockStyle.Fill;
dp.Width = 500;
dp.Text = "Release notes: " + version;
dp.Controls.Add(mv);
dockManager1.EndUpdate();
}
private void btnBinaryCompare_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (Tools.Instance.m_currentfile != "")
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//openFileDialog1.Filter = "Binaries|*.bin;*.ori";
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
frmBinCompare bincomp = new frmBinCompare();
bincomp.Symbols = Tools.Instance.m_symbols;
bincomp.SetCurrentFilename(Tools.Instance.m_currentfile);
bincomp.SetCompareFilename(openFileDialog1.FileName);
bincomp.CompareFiles();
bincomp.ShowDialog();
}
}
else
{
MessageBox.Show("No file is currently opened, you need to open a binary file first to compare it to another one!");
}
}
private void btnOpenFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//openFileDialog1.Filter = "Binaries|*.bin;*.ori";
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
CloseProject();
m_appSettings.Lastprojectname = "";
OpenFile(openFileDialog1.FileName, true);
m_appSettings.LastOpenedType = 0;
}
}
private void OpenFile(string fileName, bool showMessage)
{
// don't allow multiple instances
lock (this)
{
btnOpenFile.Enabled = false;
btnOpenProject.Enabled = false;
try
{
Tools.Instance.m_currentfile = fileName;
FileInfo fi = new FileInfo(fileName);
Tools.Instance.m_currentfilelength = (int)fi.Length;
try
{
fi.IsReadOnly = false;
barReadOnly.Caption = "Ok";
}
catch (Exception E)
{
Console.WriteLine("Failed to remove read only flag: " + E.Message);
barReadOnly.Caption = "File is READ ONLY";
}
this.Text = "VAGEDCSuite [ " + Path.GetFileName(Tools.Instance.m_currentfile) + " ]";
Tools.Instance.m_symbols = new SymbolCollection();
Tools.Instance.codeBlockList = new List<CodeBlock>();
barFilenameText.Caption = Path.GetFileName(fileName);
Tools.Instance.m_symbols = DetectMaps(Tools.Instance.m_currentfile, out Tools.Instance.codeBlockList, out Tools.Instance.AxisList, showMessage, true);
gridControl1.DataSource = null;
Application.DoEvents();
gridControl1.DataSource = Tools.Instance.m_symbols;
//gridViewSymbols.BestFitColumns();
Application.DoEvents();
try
{
gridViewSymbols.ExpandAllGroups();
}
catch (Exception)
{
}
m_appSettings.Lastfilename = Tools.Instance.m_currentfile;
VerifyChecksum(fileName, !m_appSettings.AutoChecksum, false);
TryToLoadAdditionalSymbols(fileName, ImportFileType.XML, Tools.Instance.m_symbols, true);
}
catch (Exception)
{
}
btnOpenFile.Enabled = true;
btnOpenProject.Enabled = true;
}
}
private SymbolCollection DetectMaps(string filename, out List<CodeBlock> newCodeBlocks, out List<AxisHelper> newAxisHelpers, bool showMessage, bool isPrimaryFile)
{
IEDCFileParser parser = Tools.Instance.GetParserForFile(filename, isPrimaryFile);
newCodeBlocks = new List<CodeBlock>();
newAxisHelpers = new List<AxisHelper>();
SymbolCollection newSymbols = new SymbolCollection();
if (parser != null)
{
byte[] allBytes = File.ReadAllBytes(filename);
string boschnumber = parser.ExtractBoschPartnumber(allBytes);
string softwareNumber = parser.ExtractSoftwareNumber(allBytes);
partNumberConverter pnc = new partNumberConverter();
ECUInfo info = pnc.ConvertPartnumber(boschnumber,allBytes.Length);
//MessageBox.Show("Car: " + info.CarMake + "\nECU:" + info.EcuType);
//1) Vw Hardware Number: 38906019GF, Vw System Type: 1,9l R4 EDC15P, Vw Software Number: SG 1434;
//2) Vw Hardware Number: 38906019LJ, Vw System Type: 1,9l R4 EDC15P, Vw Software Number: SG 5934.
if (!info.EcuType.StartsWith("EDC15P") && !info.EcuType.StartsWith("EDC15VM") && info.EcuType != string.Empty && showMessage)
{
frmInfoBox infobx = new frmInfoBox("No EDC15P/VM file [" + info.EcuType + "] " + Path.GetFileName(filename));
}
if (info.EcuType == string.Empty)
{
Console.WriteLine("partnumber " + info.PartNumber + " unknown " + filename);
}
if (isPrimaryFile)
{
string partNo = parser.ExtractPartnumber(allBytes);
partNo = Tools.Instance.StripNonAscii(partNo);
softwareNumber = Tools.Instance.StripNonAscii(softwareNumber);
barPartnumber.Caption = partNo + " " + softwareNumber;
barAdditionalInfo.Caption = info.PartNumber + " " + info.CarMake + " " + info.EcuType + " " + parser.ExtractInfo(allBytes);
}
newSymbols = parser.parseFile(filename, out newCodeBlocks, out newAxisHelpers);
newSymbols.SortColumn = "Flash_start_address";
newSymbols.SortingOrder = GenericComparer.SortOrder.Ascending;
newSymbols.Sort();
//parser.NameKnownMaps(allBytes, newSymbols, newCodeBlocks);
//parser.FindSVBL(allBytes, filename, newSymbols, newCodeBlocks);
/*SymbolTranslator strans = new SymbolTranslator();
foreach (SymbolHelper sh in newSymbols)
{
sh.Description = strans.TranslateSymbolToHelpText(sh.Varname);
}*/
// check for must have maps... if there are maps missing, report it
if (showMessage && (parser is EDC15PFileParser || parser is EDC15P6FileParser))
{
string _message = string.Empty;
if (MapsWithNameMissing("EGR", newSymbols)) _message += "EGR maps missing" + Environment.NewLine;
if (MapsWithNameMissing("SVBL", newSymbols)) _message += "SVBL missing" + Environment.NewLine;
if (MapsWithNameMissing("Torque limiter", newSymbols)) _message += "Torque limiter missing" + Environment.NewLine;
if (MapsWithNameMissing("Smoke limiter", newSymbols)) _message += "Smoke limiter missing" + Environment.NewLine;
//if (MapsWithNameMissing("IQ by MAF limiter", newSymbols)) _message += "IQ by MAF limiter missing" + Environment.NewLine;
if (MapsWithNameMissing("Injector duration", newSymbols)) _message += "Injector duration maps missing" + Environment.NewLine;
if (MapsWithNameMissing("Start of injection", newSymbols)) _message += "Start of injection maps missing" + Environment.NewLine;
if (MapsWithNameMissing("N75 duty cycle", newSymbols)) _message += "N75 duty cycle map missing" + Environment.NewLine;
if (MapsWithNameMissing("Inverse driver wish", newSymbols)) _message += "Inverse driver wish map missing" + Environment.NewLine;
if (MapsWithNameMissing("Boost target map", newSymbols)) _message += "Boost target map missing" + Environment.NewLine;
if (MapsWithNameMissing("SOI limiter", newSymbols)) _message += "SOI limiter missing" + Environment.NewLine;
if (MapsWithNameMissing("Driver wish", newSymbols)) _message += "Driver wish map missing" + Environment.NewLine;
if (MapsWithNameMissing("Boost limit map", newSymbols)) _message += "Boost limit map missing" + Environment.NewLine;
if (MapsWithNameMissing("MAF correction", newSymbols)) _message += "MAF correction map missing" + Environment.NewLine;
if (MapsWithNameMissing("MAF linearization", newSymbols)) _message += "MAF linearization map missing" + Environment.NewLine;
if (MapsWithNameMissing("MAP linearization", newSymbols)) _message += "MAP linearization map missing" + Environment.NewLine;
if (_message != string.Empty)
{
frmInfoBox infobx = new frmInfoBox(_message);
}
}
if (isPrimaryFile)
{
barSymCount.Caption = newSymbols.Count.ToString() + " symbols";
if (MapsWithNameMissing("Launch control map", newSymbols))
{
btnActivateLaunchControl.Enabled = true;
}
else
{
btnActivateLaunchControl.Enabled = false;
}
btnActivateSmokeLimiters.Enabled = false;
try
{
if (Tools.Instance.codeBlockList.Count > 0)
{
if ((GetMapCount("Smoke limiter", newSymbols) / Tools.Instance.codeBlockList.Count) == 1)
{
btnActivateSmokeLimiters.Enabled = true;
}
else
{
btnActivateSmokeLimiters.Enabled = false;
}
}
}
catch (Exception)
{
}
}
}
return newSymbols;
}
private int GetMapCount(string varName, SymbolCollection newSymbols)
{
int mapCount = 0;
foreach (SymbolHelper sh in newSymbols)
{
if (sh.Varname.StartsWith(varName)) mapCount ++;
}
return mapCount;
}
private bool MapsWithNameMissing(string varName, SymbolCollection newSymbols)
{
foreach (SymbolHelper sh in newSymbols)
{
if(sh.Varname.StartsWith(varName)) return false;
}
return true;
}
private void gridView1_DoubleClick(object sender, EventArgs e)
{
//TODO: only if mouse on datarow?
object o = gridViewSymbols.GetFocusedRow();
if (o is SymbolHelper)
{
//SymbolHelper sh = (SymbolHelper)o;
StartTableViewer();
}
}
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
try
{
if (e.Column.Name == gcSymbolAddress.Name)
{
if (e.CellValue != null)
{
//e.DisplayText = Convert.ToInt32(e.CellValue).ToString("X8");
}
}
else if (e.Column.Name == gcSymbolXID.Name || e.Column.Name == gcSymbolYID.Name)
{
}
else if (e.Column.Name == gcSymbolLength.Name)
{
if (e.CellValue != null)
{
int len = Convert.ToInt32(e.CellValue);
len /= 2;
// e.DisplayText = len.ToString();
}
}
}
catch (Exception)
{
}
}
private void StartTableViewer()
{
if (gridViewSymbols.SelectedRowsCount > 0)
{
int[] selrows = gridViewSymbols.GetSelectedRows();
if (selrows.Length > 0)
{
int row = (int)selrows.GetValue(0);
if (row >= 0)
{
SymbolHelper sh = (SymbolHelper)gridViewSymbols.GetRow((int)selrows.GetValue(0));
if (sh.Flash_start_address == 0 && sh.Start_address == 0) return;
if (sh == null) return;
DevExpress.XtraBars.Docking.DockPanel dockPanel;
bool pnlfound = false;
pnlfound = CheckMapViewerActive(sh);
if (!pnlfound)
{
dockManager1.BeginUpdate();
try
{
MapViewerEx tabdet = new MapViewerEx();
tabdet.AutoUpdateIfSRAM = false;
tabdet.AutoUpdateInterval = 99999;
tabdet.SetViewSize(ViewSize.NormalView);
tabdet.Visible = false;
tabdet.Filename = Tools.Instance.m_currentfile;
tabdet.GraphVisible = true;
tabdet.Viewtype = m_appSettings.DefaultViewType;
tabdet.DisableColors = m_appSettings.DisableMapviewerColors;
tabdet.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows;
tabdet.GraphVisible = m_appSettings.ShowGraphs;
tabdet.IsRedWhite = m_appSettings.ShowRedWhite;
tabdet.SetViewSize(m_appSettings.DefaultViewSize);
tabdet.Map_name = sh.Varname;
tabdet.Map_descr = tabdet.Map_name;
tabdet.Map_cat = XDFCategories.Undocumented;
SymbolAxesTranslator axestrans = new SymbolAxesTranslator();
string x_axis = string.Empty;
string y_axis = string.Empty;
string x_axis_descr = string.Empty;
string y_axis_descr = string.Empty;
string z_axis_descr = string.Empty;
tabdet.X_axis_name = sh.X_axis_descr;
tabdet.Y_axis_name = sh.Y_axis_descr;
tabdet.Z_axis_name = sh.Z_axis_descr;
tabdet.XaxisUnits = sh.XaxisUnits;
tabdet.YaxisUnits = sh.YaxisUnits;
tabdet.X_axisAddress = sh.Y_axis_address;
tabdet.Y_axisAddress = sh.X_axis_address;
tabdet.Xaxiscorrectionfactor = sh.X_axis_correction;
tabdet.Yaxiscorrectionfactor = sh.Y_axis_correction;
tabdet.Xaxiscorrectionoffset = sh.X_axis_offset;
tabdet.Yaxiscorrectionoffset = sh.Y_axis_offset;
tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
dockPanel = dockManager1.AddPanel(DevExpress.XtraBars.Docking.DockingStyle.Right);
int dw = 650;
if (tabdet.X_axisvalues.Length > 0)
{
dw = 30 + ((tabdet.X_axisvalues.Length + 1) * 45);
}
if (dw < 400) dw = 400;
if (dw > 800) dw = 800;
dockPanel.FloatSize = new Size(dw, 900);
dockPanel.Tag = Tools.Instance.m_currentfile;
dockPanel.ClosedPanel += new DevExpress.XtraBars.Docking.DockPanelEventHandler(dockPanel_ClosedPanel);
int columns = 8;
int rows = 8;
int tablewidth = GetTableMatrixWitdhByName(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name, out columns, out rows);
int address = Convert.ToInt32(sh.Flash_start_address);
int sramaddress = 0;
if (address != 0)
{
tabdet.Map_address = address;
tabdet.Map_sramaddress = sramaddress;
int length = Convert.ToInt32(sh.Length);
tabdet.Map_length = length;
byte[] mapdata = new byte[sh.Length];
mapdata.Initialize();
mapdata = Tools.Instance.readdatafromfile(Tools.Instance.m_currentfile, address, length, Tools.Instance.m_currentFileType);
tabdet.Map_content = mapdata;
tabdet.Correction_factor = sh.Correction;// GetMapCorrectionFactor(tabdet.Map_name);
tabdet.Correction_offset = sh.Offset;// GetMapCorrectionOffset(tabdet.Map_name);
tabdet.IsUpsideDown = m_appSettings.ShowTablesUpsideDown;
tabdet.ShowTable(columns, true);
tabdet.Dock = DockStyle.Fill;
tabdet.onSymbolSave += new VAGSuite.MapViewerEx.NotifySaveSymbol(tabdet_onSymbolSave);
tabdet.onSymbolRead += new VAGSuite.MapViewerEx.NotifyReadSymbol(tabdet_onSymbolRead);
tabdet.onClose += new VAGSuite.MapViewerEx.ViewerClose(tabdet_onClose);
tabdet.onAxisEditorRequested += new MapViewerEx.AxisEditorRequested(tabdet_onAxisEditorRequested);
tabdet.onSliderMove +=new MapViewerEx.NotifySliderMove(tabdet_onSliderMove);
tabdet.onSplitterMoved +=new MapViewerEx.SplitterMoved(tabdet_onSplitterMoved);
tabdet.onSelectionChanged +=new MapViewerEx.SelectionChanged(tabdet_onSelectionChanged);
tabdet.onSurfaceGraphViewChangedEx += new MapViewerEx.SurfaceGraphViewChangedEx(tabdet_onSurfaceGraphViewChangedEx);
tabdet.onAxisLock +=new MapViewerEx.NotifyAxisLock(tabdet_onAxisLock);
tabdet.onViewTypeChanged +=new MapViewerEx.ViewTypeChanged(tabdet_onViewTypeChanged);
dockPanel.Text = "Symbol: " + tabdet.Map_name + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]";
bool isDocked = false;
if (!isDocked)
{
int width = 500;
if (tabdet.X_axisvalues.Length > 0)
{
width = 30 + ((tabdet.X_axisvalues.Length + 1) * 45);
}
if (width < 500) width = 500;
if (width > 800) width = 800;
dockPanel.Width = width;
}
dockPanel.Controls.Add(tabdet);
}
else
{
byte[] mapdata = new byte[sh.Length];
mapdata.Initialize();
}
tabdet.Visible = true;
}
catch (Exception newdockE)
{
Console.WriteLine(newdockE.Message);
}
Console.WriteLine("End update");
dockManager1.EndUpdate();
}
}
System.Windows.Forms.Application.DoEvents();
}
}
}
private bool CheckMapViewerActive(SymbolHelper sh)
{
bool retval = false;
try
{
foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
{
if (pnl.Text == "Symbol: " + sh.Varname + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]")
{
if (pnl.Tag.ToString() == Tools.Instance.m_currentfile)
{
if (isSymbolDisplaySameAddress(sh, pnl))
{
retval = true;
pnl.Show();
}
}
}
}
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}
return retval;
}
private bool isSymbolDisplaySameAddress(SymbolHelper sh, DockPanel pnl)
{
bool retval = false;
try
{
if (pnl.Text.StartsWith("Symbol: "))
{
foreach (Control c in pnl.Controls)
{
if (c is MapViewerEx)
{
MapViewerEx vwr = (MapViewerEx)c;
if (vwr.Map_address == sh.Flash_start_address) retval = true;
}
else if (c is DevExpress.XtraBars.Docking.DockPanel)
{
DevExpress.XtraBars.Docking.DockPanel tpnl = (DevExpress.XtraBars.Docking.DockPanel)c;
foreach (Control c2 in tpnl.Controls)
{
if (c2 is MapViewerEx)
{
MapViewerEx vwr2 = (MapViewerEx)c2;
if (vwr2.Map_address == sh.Flash_start_address) retval = true;
}
}
}
else if (c is DevExpress.XtraBars.Docking.ControlContainer)
{
DevExpress.XtraBars.Docking.ControlContainer cntr = (DevExpress.XtraBars.Docking.ControlContainer)c;
foreach (Control c3 in cntr.Controls)
{
if (c3 is MapViewerEx)
{
MapViewerEx vwr3 = (MapViewerEx)c3;
if (vwr3.Map_address == sh.Flash_start_address) retval = true;
}
}
}
}
}
}
catch (Exception E)
{
Console.WriteLine("isSymbolDisplaySameAddress error: " + E.Message);
}
return retval;
}
void tabdet_onAxisEditorRequested(object sender, MapViewerEx.AxisEditorRequestedEventArgs e)
{
// start axis editor
foreach (SymbolHelper sh in Tools.Instance.m_symbols)
{
if (sh.Varname == e.Mapname)
{
if (e.Axisident == MapViewerEx.AxisIdent.X_Axis) StartAxisViewer(sh, Axis.XAxis);
else if (e.Axisident == MapViewerEx.AxisIdent.Y_Axis) StartAxisViewer(sh, Axis.YAxis);
break;
}
}
}
void tabdet_onClose(object sender, EventArgs e)
{
// close the corresponding dockpanel
if (sender is MapViewerEx)
{
MapViewerEx tabdet = (MapViewerEx)sender;
string dockpanelname = "Symbol: " + tabdet.Map_name + " [" + Path.GetFileName(tabdet.Filename) + "]";
string dockpanelname3 = "Symbol difference: " + tabdet.Map_name + " [" + Path.GetFileName(tabdet.Filename) + "]";
foreach (DevExpress.XtraBars.Docking.DockPanel dp in dockManager1.Panels)
{
if (dp.Text == dockpanelname)
{
dockManager1.RemovePanel(dp);
break;
}
else if (dp.Text == dockpanelname3)
{
dockManager1.RemovePanel(dp);
break;
}
}
}
}
void tabdet_onSymbolRead(object sender, MapViewerEx.ReadSymbolEventArgs e)
{
if (sender is MapViewerEx)
{
MapViewerEx mv = (MapViewerEx)sender;
mv.Map_content = Tools.Instance.readdatafromfile(e.Filename, (int)GetSymbolAddress(Tools.Instance.m_symbols, e.SymbolName), GetSymbolLength(Tools.Instance.m_symbols, e.SymbolName), Tools.Instance.m_currentFileType);
int cols = 0;
int rows = 0;
GetTableMatrixWitdhByName(e.Filename, Tools.Instance.m_symbols, e.SymbolName, out cols, out rows);
mv.IsRAMViewer = false;
mv.OnlineMode = false;
mv.ShowTable(cols, true);
mv.IsRAMViewer = false;
mv.OnlineMode = false;
System.Windows.Forms.Application.DoEvents();
}
}
void tabdet_onSymbolSave(object sender, MapViewerEx.SaveSymbolEventArgs e)
{
if (sender is MapViewerEx)
{
// juiste filename kiezen
MapViewerEx tabdet = (MapViewerEx)sender;
string note = string.Empty;
if (m_appSettings.RequestProjectNotes && Tools.Instance.m_CurrentWorkingProject != "")
{
//request a small note from the user in which he/she can denote a description of the change
frmChangeNote changenote = new frmChangeNote();
changenote.ShowDialog();
note = changenote.Note;
}
SaveDataIncludingSyncOption(e.Filename, e.SymbolName, e.SymbolAddress, e.SymbolLength, e.SymbolDate, true, note);
}
}
private void SaveDataIncludingSyncOption(string fileName, string varName, int address, int length, byte[] data, bool useNote, string note)
{
Tools.Instance.savedatatobinary(address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
if (m_appSettings.CodeBlockSyncActive)
{
// check for other symbols with the same length and the same END address
if (fileName == Tools.Instance.m_currentfile)
{
int codeBlockOffset = -1;
foreach (SymbolHelper sh in Tools.Instance.m_symbols)
{
if (sh.Flash_start_address == address && sh.Length == length)
{
if (sh.CodeBlock > 0)
{
foreach (CodeBlock cb in Tools.Instance.codeBlockList)
{
if (cb.CodeID == sh.CodeBlock)
{
codeBlockOffset = address - cb.StartAddress;
break;
}
}
}
break;
}
}
foreach (SymbolHelper sh in Tools.Instance.m_symbols)
{
bool shSaved = false;
if (sh.Length == length)
{
if (sh.Flash_start_address != address)
{
if ((sh.Flash_start_address & 0x0FFFF) == (address & 0x0FFFF))
{
//
// if (MessageBox.Show("Do you want to save " + sh.Varname + " at address " + sh.Flash_start_address.ToString("X8") + " as well?", "Codeblock synchronizer", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Tools.Instance.savedatatobinary((int)sh.Flash_start_address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
shSaved = true;
}
}
// also check wether codeblock start + offset is equal
}
}
if (!shSaved && codeBlockOffset >= 0)
{
if (sh.Length == length)
{
if (sh.Flash_start_address != address)
{
// determine codeblock offset for this symbol
if (sh.CodeBlock > 0)
{
foreach (CodeBlock cb in Tools.Instance.codeBlockList)
{
if (cb.CodeID == sh.CodeBlock)
{
int thiscodeBlockOffset = (int)sh.Flash_start_address - cb.StartAddress;
if (thiscodeBlockOffset == codeBlockOffset)
{
// save this as well
Tools.Instance.savedatatobinary((int)sh.Flash_start_address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
}
break;
}
}
}
}
}
}
}
}
}
UpdateRollbackForwardControls();
VerifyChecksum(fileName, false, false);
}
private void SaveAxisDataIncludingSyncOption(int address, int length, byte[] data, string fileName, bool useNote, string note)
{
Tools.Instance.savedatatobinary(address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
if (m_appSettings.CodeBlockSyncActive)
{
// check for other symbols with the same length and the same END address
if (fileName == Tools.Instance.m_currentfile)
{
foreach (SymbolHelper sh in Tools.Instance.m_symbols)
{
if (sh.X_axis_address != address)
{
if ((sh.X_axis_address & 0x0FFFF) == (address & 0x0FFFF))
{
if (sh.X_axis_length * 2 == length)
{
Tools.Instance.savedatatobinary(sh.X_axis_address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
}
}
}
else if (sh.Y_axis_address != address)
{
if ((sh.Y_axis_address & 0x0FFFF) == (address & 0x0FFFF))
{
if (sh.Y_axis_length * 2 == length)
{
Tools.Instance.savedatatobinary(sh.Y_axis_address, length, data, fileName, useNote, note, Tools.Instance.m_currentFileType);
}
}
}
}
}
}
UpdateRollbackForwardControls();
VerifyChecksum(Tools.Instance.m_currentfile, false, false);
}
private void VerifyChecksum(string filename, bool showQuestion, bool showInfo)
{
string chkType = string.Empty;
barChecksum.Caption = "---";
ChecksumResultDetails result = new ChecksumResultDetails();
if (m_appSettings.AutoChecksum)
{
result = Tools.Instance.UpdateChecksum(filename, false);
if (showInfo)
{
if (result.CalculationOk)
{
if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002";
else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString();
frmInfoBox info = new frmInfoBox("Checksums are correct [" + chkType + "]");
}
else
{
if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002";
else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString();
frmInfoBox info = new frmInfoBox("Checksums are INCORRECT [" + chkType + "]");
}
}
}
else
{
result = Tools.Instance.UpdateChecksum(filename, true);
if (!result.CalculationOk)
{
if (showQuestion && result.TypeResult != ChecksumType.Unknown)
{
if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002";
else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString();
frmChecksumIncorrect frmchk = new frmChecksumIncorrect();
frmchk.ChecksumType = chkType;
frmchk.NumberChecksums = result.NumberChecksumsTotal;
frmchk.NumberChecksumsFailed = result.NumberChecksumsFail;
frmchk.NumberChecksumsPassed = result.NumberChecksumsOk;
if(frmchk.ShowDialog() == DialogResult.OK)
//if (MessageBox.Show("Checksums are invalid. Do you wish to correct them?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
result = Tools.Instance.UpdateChecksum(filename, false);
}
}
else if (showInfo && result.TypeResult == ChecksumType.Unknown)
{
frmInfoBox info = new frmInfoBox("Checksum for this filetype is not yet implemented");
}
}
else
{
if (showInfo)
{
if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002";
else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString();
frmInfoBox info = new frmInfoBox("Checksums are correct [" + chkType + "]");
}
}
}
if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2";
else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002";
if (!result.CalculationOk)
{
barChecksum.Caption = "Checksum failed" + chkType;
}
else
{
barChecksum.Caption = "Checksum Ok" + chkType;
}
Application.DoEvents();
}
private double GetMapCorrectionOffset(string mapname)
{
return 0;
}
private int GetTableMatrixWitdhByName(string filename, SymbolCollection curSymbols, string symbolname, out int columns, out int rows)
{
columns = GetSymbolWidth(curSymbols, symbolname);
rows = GetSymbolHeight(curSymbols, symbolname);
return columns;
}
private int GetSymbolWidth(SymbolCollection curSymbolCollection, string symbolname)
{
foreach (SymbolHelper sh in curSymbolCollection)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.Y_axis_length;
}
}
return 0;
}
private int GetSymbolHeight(SymbolCollection curSymbolCollection, string symbolname)
{
foreach (SymbolHelper sh in curSymbolCollection)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.X_axis_length;
}
}
return 0;
}
private int GetSymbolLength(SymbolCollection curSymbolCollection, string symbolname)
{
foreach (SymbolHelper sh in curSymbolCollection)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.Length;
}
}
return 0;
}
private Int64 GetSymbolAddress(SymbolCollection curSymbolCollection, string symbolname)
{
foreach (SymbolHelper sh in curSymbolCollection)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.Flash_start_address;
}
}
return 0;
}
private double GetMapCorrectionFactor(string symbolname)
{
double returnvalue = 1;
return returnvalue;
}
private int[] GetYaxisValues(string filename, SymbolCollection curSymbols, string symbolname)
{
int xlen = GetSymbolHeight(curSymbols, symbolname);
int xaddress = GetXAxisAddress(curSymbols, symbolname);
int[] retval = new int[xlen];
retval.Initialize();
if(xaddress > 0)
{
retval = Tools.Instance.readdatafromfileasint(filename, xaddress, xlen, Tools.Instance.m_currentFileType);
}
return retval;
}
private int GetXAxisAddress(SymbolCollection curSymbols, string symbolname)
{
foreach (SymbolHelper sh in curSymbols)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.X_axis_address;
}
}
return 0;
}
private int GetYAxisAddress(SymbolCollection curSymbols, string symbolname)
{
foreach (SymbolHelper sh in curSymbols)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname)
{
return sh.Y_axis_address;
}
}
return 0;
}
private int[] GetXaxisValues(string filename, SymbolCollection curSymbols, string symbolname)
{
int ylen = GetSymbolWidth(curSymbols, symbolname);
int yaddress = GetYAxisAddress(curSymbols, symbolname);
int[] retval = new int[ylen];
retval.Initialize();
if (yaddress > 0)
{
retval = Tools.Instance.readdatafromfileasint(filename, yaddress, ylen, Tools.Instance.m_currentFileType);
}
return retval;
}
void dockPanel_ClosedPanel(object sender, DevExpress.XtraBars.Docking.DockPanelEventArgs e)
{
if (sender is DockPanel)
{
DockPanel pnl = (DockPanel)sender;
foreach (Control c in pnl.Controls)
{
if (c is HexViewer)
{
HexViewer vwr = (HexViewer)c;
vwr.CloseFile();
}
else if (c is DevExpress.XtraBars.Docking.DockPanel)
{
DevExpress.XtraBars.Docking.DockPanel tpnl = (DevExpress.XtraBars.Docking.DockPanel)c;
foreach (Control c2 in tpnl.Controls)
{
if (c2 is HexViewer)
{
HexViewer vwr2 = (HexViewer)c2;
vwr2.CloseFile();
}
}
}
else if (c is DevExpress.XtraBars.Docking.ControlContainer)
{
DevExpress.XtraBars.Docking.ControlContainer cntr = (DevExpress.XtraBars.Docking.ControlContainer)c;
foreach (Control c3 in cntr.Controls)
{
if (c3 is HexViewer)
{
HexViewer vwr3 = (HexViewer)c3;
vwr3.CloseFile();
}
}
}
}
dockManager1.RemovePanel(pnl);
}
}
private void btnCompareFiles_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//openFileDialog1.Filter = "Binaries|*.bin;*.ori";
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string compareFile = openFileDialog1.FileName;
CompareToFile(compareFile);
}
}
private void CompareToFile(string filename)
{
if (Tools.Instance.m_symbols.Count > 0)
{
dockManager1.BeginUpdate();
try
{
DevExpress.XtraBars.Docking.DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
CompareResults tabdet = new CompareResults();
tabdet.ShowAddressesInHex = true;
tabdet.SetFilterMode(true);
tabdet.Dock = DockStyle.Fill;
tabdet.Filename = filename;
tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelect);
dockPanel.Controls.Add(tabdet);
dockPanel.Text = "Compare results: " + Path.GetFileName(filename);
dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Left, 1);
dockPanel.Width = 500;
SymbolCollection compare_symbols = new SymbolCollection();
List<CodeBlock> compare_blocks = new List<CodeBlock>();
List<AxisHelper> compare_axis = new List<AxisHelper>();
compare_symbols = DetectMaps(filename, out compare_blocks, out compare_axis, false, false);
System.Windows.Forms.Application.DoEvents();
Console.WriteLine("ori : " + Tools.Instance.m_symbols.Count.ToString());
Console.WriteLine("comp : " + compare_symbols.Count.ToString());
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")); //0
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");
dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
dt.Columns.Add("Userdescription");
dt.Columns.Add("MissingInOriFile", Type.GetType("System.Boolean"));
dt.Columns.Add("MissingInCompareFile", Type.GetType("System.Boolean"));
dt.Columns.Add("CodeBlock1", Type.GetType("System.Int32"));
dt.Columns.Add("CodeBlock2", Type.GetType("System.Int32"));
string category = "";
string ht = string.Empty;
double diffperc = 0;
int diffabs = 0;
double diffavg = 0;
int percentageDone = 0;
int symNumber = 0;
XDFCategories cat = XDFCategories.Undocumented;
XDFSubCategory subcat = XDFSubCategory.Undocumented;
if (compare_symbols.Count > 0)
{
CompareResults cr = new CompareResults();
cr.ShowAddressesInHex = true;
cr.SetFilterMode(true);
foreach (SymbolHelper sh_compare in compare_symbols)
{
foreach (SymbolHelper sh_org in Tools.Instance.m_symbols)
{
if ((sh_compare.Flash_start_address == sh_org.Flash_start_address) || (sh_compare.Varname == sh_org.Varname))
{
// compare
if (!CompareSymbolToCurrentFile(sh_compare.Varname, (int)sh_compare.Flash_start_address, sh_compare.Length, filename, out diffperc, out diffabs, out diffavg, sh_compare.Correction))
{
dt.Rows.Add(sh_compare.Varname, sh_compare.Start_address, sh_compare.Flash_start_address, sh_compare.Length, sh_compare.Length, sh_compare.Varname, false, 0, diffperc, diffabs, diffavg, category, "", sh_org.Symbol_number, sh_compare.Symbol_number, "", false, false, sh_org.CodeBlock, sh_compare.CodeBlock);
}
}
}
}
tabdet.CompareSymbolCollection = compare_symbols;
tabdet.OriginalSymbolCollection = Tools.Instance.m_symbols;
tabdet.OriginalFilename = Tools.Instance.m_currentfile;
tabdet.CompareFilename = filename;
tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
tabdet.gridControl1.DataSource = dt.Copy();
}
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}
dockManager1.EndUpdate();
}
}
private bool SymbolExists(string symbolname)
{
foreach (SymbolHelper sh in Tools.Instance.m_symbols)
{
if (sh.Varname == symbolname || sh.Userdescription == symbolname) return true;
}
return false;
}
private void StartCompareMapViewer(string SymbolName, string Filename, int SymbolAddress, int SymbolLength, SymbolCollection curSymbols, int symbolnumber)
{
try
{
SymbolHelper sh = FindSymbol(curSymbols, SymbolName);
DevExpress.XtraBars.Docking.DockPanel dockPanel;
bool pnlfound = false;
foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
{
if (pnl.Text == "Symbol: " + SymbolName + " [" + Path.GetFileName(Filename) + "]")
{
if (pnl.Tag.ToString() == Filename) // <GS-10052011>
{
dockPanel = pnl;
pnlfound = true;
dockPanel.Show();
}
}
}
if (!pnlfound)
{
dockManager1.BeginUpdate();
try
{
dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
dockPanel.Tag = Filename;// Tools.Instance.m_currentfile; changed 24/01/2008
MapViewerEx tabdet = new MapViewerEx();
tabdet.AutoUpdateIfSRAM = false;// m_appSettings.AutoUpdateSRAMViewers;
tabdet.AutoUpdateInterval = 99999;
tabdet.SetViewSize(ViewSize.NormalView);
//tabdet.IsHexMode = barViewInHex.Checked;
tabdet.Viewtype = m_appSettings.DefaultViewType;
tabdet.DisableColors = m_appSettings.DisableMapviewerColors;
tabdet.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows;
tabdet.GraphVisible = m_appSettings.ShowGraphs;
tabdet.IsRedWhite = m_appSettings.ShowRedWhite;
tabdet.SetViewSize(m_appSettings.DefaultViewSize);
tabdet.Filename = Filename;
tabdet.Map_name = SymbolName;
tabdet.Map_descr = tabdet.Map_name;
tabdet.Map_cat = XDFCategories.Undocumented;
tabdet.X_axisvalues = GetXaxisValues(Filename, curSymbols, tabdet.Map_name);
tabdet.Y_axisvalues = GetYaxisValues(Filename, curSymbols, tabdet.Map_name);
SymbolAxesTranslator axestrans = new SymbolAxesTranslator();
string x_axis = string.Empty;
string y_axis = string.Empty;
string x_axis_descr = string.Empty;
string y_axis_descr = string.Empty;
string z_axis_descr = string.Empty;
tabdet.X_axis_name = sh.X_axis_descr;
tabdet.Y_axis_name = sh.Y_axis_descr;
tabdet.Z_axis_name = sh.Z_axis_descr;
tabdet.XaxisUnits = sh.XaxisUnits;
tabdet.YaxisUnits = sh.YaxisUnits;
tabdet.X_axisAddress = sh.Y_axis_address;
tabdet.Y_axisAddress = sh.X_axis_address;
tabdet.Xaxiscorrectionfactor = sh.X_axis_correction;
tabdet.Yaxiscorrectionfactor = sh.Y_axis_correction;
//tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, curSymbols, tabdet.Map_name);
//tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, curSymbols, tabdet.Map_name);
int columns = 8;
int rows = 8;
int tablewidth = GetTableMatrixWitdhByName(Filename, curSymbols, tabdet.Map_name, out columns, out rows);
int address = Convert.ToInt32(SymbolAddress);
if (address != 0)
{
tabdet.Map_address = address;
int length = SymbolLength;
tabdet.Map_length = length;
byte[] mapdata = Tools.Instance.readdatafromfile(Filename, address, length, Tools.Instance.m_currentFileType);
tabdet.Map_content = mapdata;
tabdet.Correction_factor = sh.Correction;
tabdet.Correction_offset = sh.Offset;// GetMapCorrectionOffset(tabdet.Map_name);
tabdet.IsUpsideDown = m_appSettings.ShowTablesUpsideDown;
tabdet.ShowTable(columns, true);
tabdet.Dock = DockStyle.Fill;
tabdet.onSymbolSave += new VAGSuite.MapViewerEx.NotifySaveSymbol(tabdet_onSymbolSave);
tabdet.onSymbolRead += new VAGSuite.MapViewerEx.NotifyReadSymbol(tabdet_onSymbolRead);
tabdet.onClose += new VAGSuite.MapViewerEx.ViewerClose(tabdet_onClose);
tabdet.onSliderMove += new MapViewerEx.NotifySliderMove(tabdet_onSliderMove);
tabdet.onSplitterMoved += new MapViewerEx.SplitterMoved(tabdet_onSplitterMoved);
tabdet.onSelectionChanged += new MapViewerEx.SelectionChanged(tabdet_onSelectionChanged);
tabdet.onSurfaceGraphViewChangedEx += new MapViewerEx.SurfaceGraphViewChangedEx(tabdet_onSurfaceGraphViewChangedEx);
tabdet.onAxisLock += new MapViewerEx.NotifyAxisLock(tabdet_onAxisLock);
tabdet.onViewTypeChanged += new MapViewerEx.ViewTypeChanged(tabdet_onViewTypeChanged);
//dockPanel.DockAsTab(dockPanel1);
dockPanel.Text = "Symbol: " + SymbolName + " [" + Path.GetFileName(Filename) + "]";
dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Right, 1);
bool isDocked = false;
// Try to dock to same symbol
foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
{
if (pnl.Text.StartsWith("Symbol: " + SymbolName) && pnl != dockPanel && (pnl.Visibility == DevExpress.XtraBars.Docking.DockVisibility.Visible))
{
dockPanel.DockAsTab(pnl, 0);
isDocked = true;
break;
}
}
if (!isDocked)
{
int width = 500;
if (tabdet.X_axisvalues.Length > 0)
{
width = 30 + ((tabdet.X_axisvalues.Length + 1) * 45);
}
if (width < 500) width = 500;
if (width > 800) width = 800;
dockPanel.Width = width;
}
dockPanel.Controls.Add(tabdet);
}
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}
dockManager1.EndUpdate();
System.Windows.Forms.Application.DoEvents();
}
}
catch (Exception startnewcompareE)
{
Console.WriteLine(startnewcompareE.Message);
}
}
private SymbolHelper FindSymbol(SymbolCollection curSymbols, string SymbolName)
{
foreach (SymbolHelper sh in curSymbols)
{
if (sh.Varname == SymbolName || sh.Userdescription == SymbolName) return sh;
}
return new SymbolHelper();
}
void tabdet_onSymbolSelect(object sender, CompareResults.SelectSymbolEventArgs e)
{
if (!e.ShowDiffMap)
{
DumpDockWindows();
if (SymbolExists(e.SymbolName))
{
StartTableViewer(e.SymbolName, e.CodeBlock1);
}
//DumpDockWindows();
foreach (SymbolHelper sh in e.Symbols)
{
if (sh.Varname == e.SymbolName || sh.Userdescription == e.SymbolName)
{
string symName = e.SymbolName;
if ((e.SymbolName.StartsWith("2D") || e.SymbolName.StartsWith("3D")) && sh.Userdescription != string.Empty) symName = sh.Userdescription;
StartCompareMapViewer(symName, e.Filename, e.SymbolAddress, e.SymbolLength, e.Symbols, e.Symbolnumber2);
break;
}
}
DumpDockWindows();
}
else
{
// show difference map
foreach (SymbolHelper sh in e.Symbols)
{
if (sh.Varname == e.SymbolName || sh.Userdescription == e.SymbolName)
{
StartCompareDifferenceViewer(sh, e.Filename, e.SymbolAddress);
break;
}
}
}
}
private void StartCompareDifferenceViewer(SymbolHelper sh, string Filename, int SymbolAddress)
{
DevExpress.XtraBars.Docking.DockPanel dockPanel;
bool pnlfound = false;
foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
{
if (pnl.Text == "Symbol difference: " + sh.Varname + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]")
{
dockPanel = pnl;
pnlfound = true;
dockPanel.Show();
}
}
if (!pnlfound)
{
dockManager1.BeginUpdate();
try
{
dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
dockPanel.Tag = Tools.Instance.m_currentfile;
MapViewerEx tabdet = new MapViewerEx();
tabdet.Map_name = sh.Varname;
tabdet.IsDifferenceViewer = true;
tabdet.AutoUpdateIfSRAM = false;
tabdet.AutoUpdateInterval = 999999;
tabdet.Viewtype = m_appSettings.DefaultViewType;
tabdet.DisableColors = m_appSettings.DisableMapviewerColors;
tabdet.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows;
tabdet.GraphVisible = m_appSettings.ShowGraphs;
tabdet.IsRedWhite = m_appSettings.ShowRedWhite;
tabdet.SetViewSize(m_appSettings.DefaultViewSize);
tabdet.Filename = Filename;
tabdet.Map_descr = tabdet.Map_name;
tabdet.Map_cat = XDFCategories.Undocumented;
tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
SymbolAxesTranslator axestrans = new SymbolAxesTranslator();
string x_axis = string.Empty;
string y_axis = string.Empty;
string x_axis_descr = string.Empty;
string y_axis_descr = string.Empty;
string z_axis_descr = string.Empty;
tabdet.X_axis_name = sh.X_axis_descr;
tabdet.Y_axis_name = sh.Y_axis_descr;
tabdet.Z_axis_name = sh.Z_axis_descr;
tabdet.XaxisUnits = sh.XaxisUnits;
tabdet.YaxisUnits = sh.YaxisUnits;
tabdet.X_axisAddress = sh.Y_axis_address;
tabdet.Y_axisAddress = sh.X_axis_address;
tabdet.Xaxiscorrectionfactor = sh.X_axis_correction;
tabdet.Yaxiscorrectionfactor = sh.Y_axis_correction;
tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name);
//tabdet.Map_sramaddress = GetSymbolAddressSRAM(SymbolName);
int columns = 8;
int rows = 8;
int tablewidth = GetTableMatrixWitdhByName(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name, out columns, out rows);
int address = Convert.ToInt32(SymbolAddress);
if (address != 0)
{
tabdet.Map_address = address;
int length = sh.Length;
tabdet.Map_length = length;
byte[] mapdata = Tools.Instance.readdatafromfile(Filename, address, length, Tools.Instance.m_currentFileType);
byte[] mapdataorig = Tools.Instance.readdatafromfile(Filename, address, length, Tools.Instance.m_currentFileType);
byte[] mapdata2 = Tools.Instance.readdatafromfile(Tools.Instance.m_currentfile, (int)GetSymbolAddress(Tools.Instance.m_symbols, sh.Varname), GetSymbolLength(Tools.Instance.m_symbols, sh.Varname), Tools.Instance.m_currentFileType);
tabdet.Map_original_content = mapdataorig;
tabdet.Map_compare_content = mapdata2;
if (mapdata.Length == mapdata2.Length)
{
for (int bt = 0; bt < mapdata2.Length; bt += 2)
{
int value1 = Convert.ToInt16(mapdata.GetValue(bt)) * 256 + Convert.ToInt16(mapdata.GetValue(bt + 1));
int value2 = Convert.ToInt16(mapdata2.GetValue(bt)) * 256 + Convert.ToInt16(mapdata2.GetValue(bt + 1));
value1 = Math.Abs((int)value1 - (int)value2);
byte v1 = (byte)(value1 / 256);
byte v2 = (byte)(value1 - (int)v1 * 256);
mapdata.SetValue(v1, bt);
mapdata.SetValue(v2, bt + 1);
}
tabdet.Map_content = mapdata;
tabdet.UseNewCompare = true;
tabdet.Correction_factor = sh.Correction;
tabdet.Correction_offset = sh.Offset;
tabdet.IsUpsideDown = m_appSettings.ShowTablesUpsideDown;
tabdet.ShowTable(columns, true);
tabdet.Dock = DockStyle.Fill;
tabdet.onClose += new MapViewerEx.ViewerClose(tabdet_onClose);
dockPanel.Text = "Symbol difference: " + sh.Varname + " [" + Path.GetFileName(Filename) + "]";
bool isDocked = false;
if (!isDocked)
{
dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Right, 0);
if (m_appSettings.AutoSizeNewWindows)
{
if (tabdet.X_axisvalues.Length > 0)
{
dockPanel.Width = 30 + ((tabdet.X_axisvalues.Length + 1) * 45);
}
else
{
//dockPanel.Width = this.Width - dockSymbols.Width - 10;
}
}
if (dockPanel.Width < 400) dockPanel.Width = 400;
// dockPanel.Width = 400;
}
dockPanel.Controls.Add(tabdet);
}
else
{
frmInfoBox info = new frmInfoBox("Map lengths don't match...");
}
}
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}
dockManager1.EndUpdate();
}
}
private void DumpDockWindows()
{
foreach(DockPanel dp in dockManager1.Panels)
{
Console.WriteLine(dp.Text);
}
}
private void StartTableViewer(string symbolname, int codeblock)
{
int rtel = 0;
bool _vwrstarted = false;
try
{
if (Tools.Instance.GetSymbolAddressLike(Tools.Instance.m_symbols, symbolname) > 0)
{
//Console.WriteLine("Option one");
gridViewSymbols.ActiveFilter.Clear(); // clear filter
gridViewSymbols.ApplyFindFilter("");
SymbolCollection sc = (SymbolCollection)gridControl1.DataSource;
rtel = 0;
foreach (SymbolHelper sh in sc)
{
if (sh.Varname.StartsWith(symbolname) && sh.CodeBlock == codeblock)
{
try
{
int rhandle = gridViewSymbols.GetRowHandle(rtel);
gridViewSymbols.OptionsSelection.MultiSelect = true;
gridViewSymbols.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
gridViewSymbols.ClearSelection();
gridViewSymbols.SelectRow(rhandle);
//gridViewSymbols.SelectRows(rhandle, rhandle);
gridViewSymbols.MakeRowVisible(rhandle, true);
gridViewSymbols.FocusedRowHandle = rhandle;
//gridViewSymbols.SelectRange(rhandle, rhandle);
_vwrstarted = true;
StartTableViewer();
break;
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
rtel++;
}
if (!_vwrstarted)
{
rtel = 0;
foreach (SymbolHelper sh in sc)
{
if (sh.Userdescription.StartsWith(symbolname) && sh.CodeBlock == codeblock)
{
try
{
int rhandle = gridViewSymbols.GetRowHandle(rtel);
gridViewSymbols.OptionsSelection.MultiSelect = true;
gridViewSymbols.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
gridViewSymbols.ClearSelection();
gridViewSymbols.SelectRow(rhandle);
//gridViewSymbols.SelectRows(rhandle, rhandle);
gridViewSymbols.MakeRowVisible(rhandle, true);
gridViewSymbols.FocusedRowHandle = rhandle;
//gridViewSymbols.SelectRange(rhandle, rhandle);
_vwrstarted = true;
StartTableViewer();
break;
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
rtel++;
}
}
}
else
{
//Console.WriteLine("Option two");
gridViewSymbols.ActiveFilter.Clear(); // clear filter
SymbolCollection sc = (SymbolCollection)gridControl1.DataSource;
rtel = 0;
foreach (SymbolHelper sh in sc)
{
if (sh.Userdescription.StartsWith(symbolname) && sh.CodeBlock == codeblock)
{
try
{
int rhandle = gridViewSymbols.GetRowHandle(rtel);
gridViewSymbols.OptionsSelection.MultiSelect = true;
gridViewSymbols.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
gridViewSymbols.ClearSelection();
gridViewSymbols.SelectRow(rhandle);
//gridViewSymbols.SelectRows(rhandle, rhandle);
gridViewSymbols.MakeRowVisible(rhandle, true);
gridViewSymbols.FocusedRowHandle = rhandle;
//gridViewSymbols.SelectRange(rhandle, rhandle);
_vwrstarted = true;
StartTableViewer();
break;
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
rtel++;
}
}
}
catch (Exception)
{
frmInfoBox info = new frmInfoBox("There seems to be a problem opening this map, do you have a file opened?");
}
}
private bool CompareSymbolToCurrentFile(string symbolname, int address, int length, string filename, out double diffperc, out int diffabs, out double diffavg, double correction)
{
diffperc = 0;
diffabs = 0;
diffavg = 0;
double totalvalue1 = 0;
double totalvalue2 = 0;
bool retval = true;
if (address > 0)
{
int curaddress = (int)GetSymbolAddress(Tools.Instance.m_symbols, symbolname);
int curlength = GetSymbolLength(Tools.Instance.m_symbols, symbolname);
byte[] curdata = Tools.Instance.readdatafromfile(Tools.Instance.m_currentfile, curaddress, curlength, Tools.Instance.m_currentFileType);
byte[] compdata = Tools.Instance.readdatafromfile(filename, address, length, Tools.Instance.m_currentFileType);
if (curdata.Length != compdata.Length)
{
Console.WriteLine("Lengths didn't match: " + symbolname);
return false;
}
for (int offset = 0; offset < curdata.Length; offset += 2)
{
int ival1 = Convert.ToInt32(curdata.GetValue(offset)) * 256 + Convert.ToInt32(curdata.GetValue(offset + 1));
int ival2 = Convert.ToInt32(compdata.GetValue(offset)) * 256 + Convert.ToInt32(compdata.GetValue(offset + 1)) ;
if (ival1 != ival2)
{
retval = false;
diffabs++;
}
totalvalue1 += Convert.ToDouble(ival1);
totalvalue2 += Convert.ToDouble(ival2);
}
if (curdata.Length > 0)
{
totalvalue1 /= (curdata.Length/2);
totalvalue2 /= (compdata.Length/2);
}
}
diffavg = Math.Abs(totalvalue1 - totalvalue2) * correction;
diffperc = (diffabs * 100) / (length /2);
return retval;
}
private void btnTestFiles_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
frmBrowseFiles browse = new frmBrowseFiles();
browse.Show();
/*EDC15P_EEPROM eeprom = new EDC15P_EEPROM();
eeprom.LoadFile(@"D:\Prive\Audi\TDI\spare eeprom\spare eeprom.bin");
Console.WriteLine("key: " + eeprom.Key.ToString());
Console.WriteLine("odo: " + eeprom.Mileage.ToString());
Console.WriteLine("vin: " + eeprom.Vin);
Console.WriteLine("immo: " + eeprom.Immo);
Console.WriteLine("immoact: " + eeprom.ImmoActive.ToString());*/
/*
EDC15PTuner tuner = new EDC15PTuner();
tuner.TuneEDC15PFile(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, 400, 170);*/
//D:\Prive\ECU\audi\BinCollection
//
//ParseDirectory(@"D:\Prive\Audi");
//ParseDirectory(@"D:\Prive\ECU\audi");
/*
if (Directory.Exists(@"D:\Prive\Audi\TDI"))