private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            if (gridControl1.DataSource != null)
            {
                DataTable dt = (DataTable)gridControl1.DataSource;

                foreach (DataRow dr in dt.Rows)
                {
                    _symbolColors.SaveColorToRegistry(dr["SYMBOLNAME"].ToString(), Color.FromArgb(Convert.ToInt32(dr["COLOR"])));
                }

                int[] selrows = gridView1.GetSelectedRows();
                foreach (int rowhandle in selrows)
                {
                    DataRowView dv = (DataRowView)gridView1.GetRow(rowhandle);
                    if (dv != null)
                    {
                        SymbolHelper sh = new SymbolHelper();
                        sh.Varname = dv.Row["SYMBOLNAME"].ToString();
                        sh.Color   = Color.FromArgb(Convert.ToInt32(dv.Row["COLOR"]));
                        _sc.Add(sh);
                    }
                }
            }
            this.Close();
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            if (gridControl1.DataSource != null)
            {
                DataTable dt = (DataTable)gridControl1.DataSource;

                foreach (DataRow dr in dt.Rows)
                {
                    SaveColorToRegistry(dr["SYMBOLNAME"].ToString(), Color.FromArgb(Convert.ToInt32(dr["COLOR"])));
                }

                int[] selrows = gridView1.GetSelectedRows();
                foreach (int rowhandle in selrows)
                {
                    DataRowView dv = (DataRowView)gridView1.GetRow(rowhandle);
                    if (dv != null)
                    {
                        SymbolHelper sh = new SymbolHelper();
                        sh.Varname = dv.Row["SYMBOLNAME"].ToString();
                        sh.Color   = Color.FromArgb(Convert.ToInt32(dv.Row["COLOR"]));
                        _sc.Add(sh);
                    }
                }
            }

            /*
             * foreach (DevExpress.XtraEditors.Controls.CheckedListBoxItem item in checkedListBoxControl1.Items)
             * {
             *  if (item.CheckState == CheckState.Checked)
             *  {
             *      SymbolHelper sh = new SymbolHelper();
             *      sh.Varname = item.Value.ToString();
             *      _sc.Add(sh);
             *  }
             * }*/
            this.Close();
        }
        public SymbolCollection GetSelectedSymbolCollection()
        {
            // build a new collection based on the selected rows
            SymbolCollection scSelected = new SymbolCollection();
            if (gridControl1.DataSource != null)
            {
                //DataTable dt = (DataTable)gridControl1.DataSource;

                int[] selrows = gridView1.GetSelectedRows();
                foreach (int rowhandle in selrows)
                {
                    SymbolHelper sh = (SymbolHelper)gridView1.GetRow(rowhandle);
                    if (sh != null)
                    {
                        scSelected.Add(sh);
                    }
                }
            }
            return scSelected;
        }
Example #4
0
        public SymbolCollection GetSelectedSymbolCollection()
        {
            // build a new collection based on the selected rows
            SymbolCollection scSelected = new SymbolCollection();

            if (gridControl1.DataSource != null)
            {
                //DataTable dt = (DataTable)gridControl1.DataSource;


                int[] selrows = gridView1.GetSelectedRows();
                foreach (int rowhandle in selrows)
                {
                    SymbolHelper sh = (SymbolHelper)gridView1.GetRow(rowhandle);
                    if (sh != null)
                    {
                        scSelected.Add(sh);
                    }
                }
            }
            return(scSelected);
        }
Example #5
0
        private void btnViewMatrixFromLog_ItemClick(object sender, ItemClickEventArgs e)
        {
            // let the user select x axis, y axis and z axis symbols from the logfile
            //
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Trionic 7 logfiles|*.t7l";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                avgTable = null;
                string[] alllines = File.ReadAllLines(ofd.FileName);
                System.Windows.Forms.Application.DoEvents();
                DateTime startDate = DateTime.MaxValue;
                DateTime endDate = DateTime.MinValue;
                SymbolCollection sc = new 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 (SymbolHelper sh in sc)
                                            {
                                                if (sh.Varname == varname)
                                                {
                                                    sfound = true;
                                                }
                                            }
                                            SymbolHelper nsh = new SymbolHelper();
                                            nsh.Varname = varname;
                                            if (!sfound) sc.Add(nsh);
                                        }
                                    }
                                }
                                catch (Exception pE)
                                {
                                    logger.Debug(pE.Message);
                                }
                            }
                        }
                    }
                }
                catch (Exception E)
                {
                    logger.Debug(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)
                                {
                                    logger.Debug(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
                    System.Data.DataTable dtresult = new System.Data.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));
                        //logger.Debug("Adding: " + xvalue.ToString());
                        try
                        {
                            dtresult.Columns.Add(xvalue.ToString(), Type.GetType("System.Double"));
                        }
                        catch (Exception E)
                        {
                            logger.Debug("Failed to add column: " + E.Message);
                        }
                        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++)
                    {
                        try
                        {
                            dtresult.Rows.Add(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                        }
                        catch (Exception E)
                        {
                            logger.Debug("Failed to add empty row: " + E.Message);
                        }
                    }
                    // 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)
                                {
                                    logger.Debug(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);
                    result.UseNewMapViewer = m_appSettings.UseNewMapViewer;
                    result.SetTable(dtresult);
                    string typedescr = " (Mean values)";
                    if (type == 1) typedescr = " (Minimum values)";
                    else if (type == 2) typedescr = " (Maximum values)";
                    result.Text = "Matrix [" + x + " : " + y + " : " + z + "]" + typedescr;
                    result.Show();
                }
            }
        }
Example #6
0
 private void AddToSymbolCollection(SymbolCollection scToExport, string symbolName)
 {
     foreach (SymbolHelper sh in m_symbols)
     {
         if (sh.Varname == symbolName || sh.Userdescription == symbolName)
         {
             SymbolHelper shNew = new SymbolHelper();
             shNew.Start_address = sh.Start_address;
             shNew.Symbol_number = sh.Symbol_number;
             shNew.Symbol_number_ECU = sh.Symbol_number_ECU;
             shNew.Internal_address = sh.Internal_address;
             shNew.Varname = symbolName;
             shNew.Flash_start_address = sh.Flash_start_address;
             shNew.Length = sh.Length;
             shNew.Userdescription = symbolName;
             scToExport.Add(shNew);
             break;
         }
     }
 }
Example #7
0
        private void addToMyMapsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (gridViewSymbols.FocusedRowHandle >= 0)
            {
                SymbolHelper sh = (SymbolHelper)gridViewSymbols.GetRow(gridViewSymbols.FocusedRowHandle);
                SymbolCollection scmymaps = new SymbolCollection();
                SymbolHelper shnewmymap = new SymbolHelper();
                shnewmymap.Varname = sh.Varname;
                shnewmymap.Description = sh.Varname;
                shnewmymap.Category = "Directly added";
                scmymaps.Add(shnewmymap);
                string filename = System.Windows.Forms.Application.StartupPath + "\\mymaps.xml";
                if (File.Exists(filename))
                {
                    try
                    {
                        System.Xml.XmlDocument mymaps = new System.Xml.XmlDocument();
                        mymaps.Load(System.Windows.Forms.Application.StartupPath + "\\mymaps.xml");
                        foreach (System.Xml.XmlNode category in mymaps.SelectNodes("categories/category"))
                        {
                            foreach (System.Xml.XmlNode map in category.SelectNodes("map"))
                            {
                                SymbolHelper shmap = new SymbolHelper();
                                shmap.Varname = map.Attributes["symbol"].Value;
                                shmap.Category = category.Attributes["title"].Value;
                                shmap.Description = map.Attributes["title"].Value;
                                scmymaps.Add(shmap);
                            }
                        }
                    }
                    catch { }
                }
                // now save a new file
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
                doc.AppendChild(dec);// Create the root element
                XmlElement root = doc.CreateElement("categories");
                doc.AppendChild(root);

                scmymaps.SortColumn = "Category";
                scmymaps.SortingOrder = GenericComparer.SortOrder.Ascending;
                scmymaps.Sort();

                string previouscat = "";
                XmlElement title = doc.CreateElement("category");
                foreach (SymbolHelper shmm in scmymaps)
                {
                    if (shmm.Category != previouscat)
                    {
                        previouscat = shmm.Category;
                        title = doc.CreateElement("category");
                        title.SetAttribute("title", previouscat);
                        root.AppendChild(title);
                    }
                    XmlElement map = doc.CreateElement("map");
                    map.SetAttribute("symbol", shmm.Varname);
                    map.SetAttribute("title", shmm.Description);
                    title.AppendChild(map);
                }
                doc.Save(filename);
                if (ribbonControl1.Pages[3].Text == "My Maps")
                {
                    ribbonControl1.Pages.RemoveAt(3);
                }
                LoadMyMaps();
            }
        }
Example #8
0
        private void StartCompareToSRAMFile(string sramfilename)
        {
            SymbolCollection scdiff = new SymbolCollection();
            frmProgress progress = new frmProgress();
            progress.SetProgress("Comparing to SRAM snapshot");
            progress.Show();
            int cnt = 0;
            foreach (SymbolHelper sh in m_symbols)
            {
                int percentage = cnt * 100 / m_symbols.Count;
                cnt++;
                progress.SetProgressPercentage(percentage);

                if (sh.Flash_start_address > 0 && sh.Start_address > 0)
                {
                    // get sram content and binfile content for this symbol
                    string symbolname = sh.Varname;
                    if (symbolname.StartsWith("Symbol:")) symbolname = sh.Userdescription;

                    if (IsSymbolCalibration(symbolname))
                    {
                        int address = (int)sh.Flash_start_address;
                        if (IsSoftwareOpen()/*length > 0x10*/)
                        {
                            address = address - GetOpenFileOffset();// 0xEFFC34; // this should autodetect!!!
                            //tabdet.Map_address = address;
                            //tabdet.IsOpenSoftware = _softwareIsOpen;
                            //mapdata = readdatafromfile(m_currentfile, address, length);
                        }
                        if (address < m_currentfile_size)
                        {
                            byte[] sramsymbol = readdatafromSRAMfile(sramfilename, (int)sh.Start_address, (int)sh.Length);
                            byte[] flashsymbol = readdatafromfile(m_currentfile, address, (int)sh.Length);
                            int bdifferent = 0;
                            if (sh.Varname == "BFuelCal.Map")
                            {
                                logger.Debug("break!");
                            }
                            for (int btel = 0; btel < sh.Length; btel++)
                            {
                                if (sramsymbol[btel] != flashsymbol[btel])
                                {
                                    bdifferent++;
                                }
                            }
                            if (bdifferent > 0)
                            {
                                // symbol is not equal!
                                scdiff.Add(sh);
                            }
                        }
                    }
                }
            }
            progress.Close();
            dockManager1.BeginUpdate();
            try
            {
                DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                CompareResults tabdet = new CompareResults();
                tabdet.HideMissingSymbolIndicators();
                tabdet.Dock = DockStyle.Fill;
                tabdet.Filename = sramfilename;

                tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelectRAM);
                dockPanel.Controls.Add(tabdet);
                //dockPanel.DockAsTab(dockPanel1);
                dockPanel.Text = "SRAM <> BIN Compare results: " + Path.GetFileName(sramfilename);
                dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);
                dockPanel.Width = 700;
                //CompareSymbolTable(filename, compSymbols, compAddressLookup, tabdet.gridControl1);
                tabdet.CompareSymbolCollection = scdiff;

                System.Data.DataTable dt = new System.Data.DataTable();

                // T7
                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");

                foreach (SymbolHelper sh in scdiff)
                {
                    float diffperc = 0;
                    int diffabs = 0;
                    float diffavg = 0;
                    dt.Rows.Add(sh.Varname, sh.Start_address, sh.Flash_start_address, sh.Length, sh.Length, sh.Description, false, 0, diffperc, diffabs, diffavg, sh.Category.ToString().Replace("_", " "), sh.Subcategory.ToString().Replace("_", " "), sh.Symbol_number, sh.Symbol_number, sh.Userdescription);
                }
                tabdet.gridControl1.DataSource = dt;

                //tabdet.CompareAddressLookupCollection = compAddressLookup;
                tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
            dockManager1.EndUpdate();
        }
Example #9
0
        private void Actions_SearchMapContent_ItemClick(object sender, ItemClickEventArgs e)
        {
            // ask the user for which value to search and if searching should include symbolnames and/or symbol description
            if (ValidateFile())
            {
                SymbolCollection result_Collection = new SymbolCollection();
                frmSearchMaps searchoptions = new frmSearchMaps();
                if (searchoptions.ShowDialog() == DialogResult.OK)
                {
                    frmProgress progress = new frmProgress();
                    progress.SetProgress("Start searching data...");
                    progress.SetProgressPercentage(0);
                    progress.Show();
                    System.Windows.Forms.Application.DoEvents();
                    int cnt = 0;
                    foreach (SymbolHelper sh in m_symbols)
                    {
                        progress.SetProgress("Searching " + sh.Varname);
                        progress.SetProgressPercentage((cnt * 100) / m_symbols.Count);
                        bool hit_found = false;
                        if (searchoptions.UseSpecificMapLength)
                        {
                            if (sh.Length != (int)searchoptions.MapLength)
                            {
                                continue;
                            }
                        }
                        if (searchoptions.IncludeSymbolNames)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Varname.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Varname.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        if (searchoptions.IncludeSymbolDescription)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Description.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Description.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        // now search the symbol data
                        if (sh.Flash_start_address < m_currentfile_size)
                        {
                            byte[] symboldata = readdatafromfile(m_currentfile, (int)sh.Flash_start_address, sh.Length);
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (isSixteenBitTable(sh.Varname))
                                {
                                    for (int i = 0; i < symboldata.Length / 2; i += 2)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i)) * 256;
                                        value += Convert.ToInt32(symboldata.GetValue(i + 1));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < symboldata.Length; i++)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor.Length > symboldata.Length)
                                {
                                    // possible...
                                    string symboldataasstring = System.Text.Encoding.ASCII.GetString(symboldata);
                                    if (symboldataasstring.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }

                        if (hit_found)
                        {
                            // add to collection
                            result_Collection.Add(sh);
                        }
                        cnt++;
                    }
                    progress.Close();
                    if (result_Collection.Count == 0)
                    {
                        frmInfoBox info = new frmInfoBox("No results found...");
                    }
                    else
                    {
                        // start result screen
                        dockManager1.BeginUpdate();
                        try
                        {
                            SymbolTranslator st = new SymbolTranslator();
                            DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                            CompareResults tabdet = new CompareResults();
                            tabdet.ShowAddressesInHex = m_appSettings.ShowAddressesInHex;
                            tabdet.SetFilterMode(m_appSettings.ShowAddressesInHex);
                            tabdet.Dock = DockStyle.Fill;
                            tabdet.UseForFind = true;
                            tabdet.Filename = m_currentfile;
                            tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelectForFind);
                            dockPanel.Controls.Add(tabdet);
                            dockPanel.Text = "Search results: " + Path.GetFileName(m_currentfile);
                            dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);

                            dockPanel.Width = 700;

                            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"); //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"));
                            //string category = "";
                            string ht = string.Empty;
                            //double diffperc = 0;
                            //int diffabs = 0;
                            //double diffavg = 0;
                            XDFCategories cat = XDFCategories.Undocumented;
                            XDFSubCategory subcat = XDFSubCategory.Undocumented;
                            foreach (SymbolHelper shfound in result_Collection)
                            {
                                string helptext = st.TranslateSymbolToHelpText(shfound.Varname, out ht, out cat, out subcat, m_appSettings.ApplicationLanguage);
                                if (shfound.Varname.Contains("."))
                                {
                                    try
                                    {
                                        shfound.Category = shfound.Varname.Substring(0, shfound.Varname.IndexOf("."));
                                    }
                                    catch (Exception cE)
                                    {
                                        logger.Debug("Failed to assign category to symbol: " + shfound.Varname + " err: " + cE.Message);
                                    }
                                }
                                dt.Rows.Add(shfound.Varname, shfound.Start_address, shfound.Flash_start_address, shfound.Length, shfound.Length, helptext, false, 0, 0, 0, 0, shfound.Category, "", shfound.Symbol_number, shfound.Symbol_number);
                            }
                            tabdet.CompareSymbolCollection = result_Collection;
                            tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                            tabdet.gridControl1.DataSource = dt.Copy();

                        }
                        catch (Exception E)
                        {
                            logger.Debug(E.Message);
                        }
                        dockManager1.EndUpdate();

                    }

                }
            }
        }
Example #10
0
 private void SetupLogFilters()
 {
     // setup the export filters
     LogFilters filterhelper = new LogFilters();
     frmLogFilters frmfilters = new frmLogFilters();
     LogFilterCollection filters = filterhelper.GetFiltersFromRegistry();
     frmfilters.SetFilters(filters);
     SymbolCollection sc = new SymbolCollection();
     foreach (SymbolHelper sh in m_symbols)
     {
         //if (!sh.Varname.Contains("!")) sc.Add(sh);
         if (!IsSymbolCalibration(sh.Varname)) sc.Add(sh);
     }
     frmfilters.SetSymbols(sc);
     if (frmfilters.ShowDialog() == DialogResult.OK)
     {
         filterhelper.SaveFiltersToRegistry(frmfilters.GetFilters());
     }
 }
Example #11
0
 private void StartBitMaskViewer(SymbolHelper sh)
 {
     // check for SRAM file and/or connected ECU if symbol is outside flash area
     uint data = 0;
     if (sh.Flash_start_address > m_currentfile_size)
     {
         //TODO: Implement
         if (t8can.isOpen())
         {
             bool success = false;
             byte[] bdat = t8can.readMemory((int)sh.Flash_start_address, 2, out success);
             if (success)
             {
                 data = Convert.ToUInt32(bdat[0]) * 256;
                 data += Convert.ToUInt32(bdat[1]);
             }
             else
             {
                 MessageBox.Show("Symbol outside of flash boundary and failed to read symbol from ECU");
                 return;
             }
         }
         else
         {
             MessageBox.Show("Symbol outside of flash boundary and no connection to ECU available");
             return;
         }
     }
     else
     {
         byte[] bdat = readdatafromfile(m_currentfile, (int)sh.Flash_start_address, 2);
         data = Convert.ToUInt32(bdat[0]) * 256;
         data += Convert.ToUInt32(bdat[1]);
     }
     // get all other symbols with the same address
     SymbolCollection shview = new SymbolCollection();
     foreach (SymbolHelper shl in m_symbols)
     {
         if (shl.Flash_start_address == sh.Flash_start_address)
         {
             shview.Add(shl);
         }
     }
     // start a viewer with the collection and the real data
     frmBitmaskViewer view = new frmBitmaskViewer();
     view.SetInformation(shview, data);
     if (view.ShowDialog() == DialogResult.OK)
     {
         // save the data to the file && update checksum if set to auto
         byte[] bdata = new byte[2];
         byte b1 = Convert.ToByte(view.Data / 256);
         byte b2 = Convert.ToByte(view.Data - (int)b1 * 256);
         bdata.SetValue(b1, 0);
         bdata.SetValue(b2, 1);
         if (sh.Flash_start_address > m_currentfile_size)
         {
             // save to ECU ... if possible
         }
         else
         {
             savedatatobinary((int)sh.Flash_start_address, 2, bdata, m_currentfile, true);
             if (m_appSettings.AutoChecksum) UpdateChecksum(m_currentfile, true);
         }
     }
 }
Example #12
0
        private void exportAsTuningPackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // export selected maps as tuning package (name the file t7p)
            // get selected rows
            int[] selectedrows = gridViewSymbols.GetSelectedRows();
            SymbolCollection scToExport = new SymbolCollection();
            if (selectedrows.Length > 0)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Trionic 7 packages|*.t7p";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    int grouplevel = gridViewSymbols.GetRowLevel((int)selectedrows.GetValue(0));
                    if (grouplevel >= gridViewSymbols.GroupCount)
                    {
                        int[] selrows = gridViewSymbols.GetSelectedRows();
                        if (selrows.Length > 0)
                        {
                            for (int i = 0; i < selrows.Length; i++)
                            {
                                SymbolHelper sh = (SymbolHelper)gridViewSymbols.GetRow((int)selrows.GetValue(i));
                                // make a copy?
                                scToExport.Add(sh);
                            }

                            PackageExporter pe = new PackageExporter();
                            if (IsSoftwareOpen())
                            {
                                pe.AddressOffset = GetOpenFileOffset();
                            }
                            pe.ExportPackage(scToExport, m_currentfile, sfd.FileName);
                        }

                    }
                }

            }
        }
Example #13
0
        private void exportAsTuningPackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // well.. export the entire result set as a tuning package
            // export selected maps as tuning package (name the file t7p)
            // get selected rows

            //<GS-22022011> TODO: Let the user choose from which binary file he/she wants to export the data
            // the orginal file or the file that we compared to
            frmFileToExportSelection frmSelection = new frmFileToExportSelection();
            frmSelection.SetOriginalFileName(m_OriginalFilename);
            frmSelection.SetCompareFileName(m_CompareFilename);
            if (frmSelection.ShowDialog() == DialogResult.OK)
            {
                DataTable dt = (DataTable)gridControl1.DataSource;
                SymbolCollection scToExport = new SymbolCollection();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string varname = dr["SYMBOLNAME"].ToString();
                        if (varname.StartsWith("Symbolnumber")) varname = dr["Userdescription"].ToString();
                        if (!varname.StartsWith("Symbolnumber") && !varname.StartsWith("overrun") && !varname.StartsWith("Data_name") && !varname.StartsWith("MapChkCal"))
                        {
                            if (frmSelection.UseOriginalFile)
                            {
                                foreach (SymbolHelper sh in m_originalSymbolCollection)
                                {
                                    if (sh.SmartVarname == varname)
                                    {
                                        scToExport.Add(sh);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                foreach (SymbolHelper sh in m_compareSymbolCollection)
                                {
                                    if (sh.SmartVarname == varname)
                                    {
                                        scToExport.Add(sh);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    frmSymbolSelection symsel = new frmSymbolSelection();
                    symsel.SetSymbolCollection(scToExport);
                    symsel.SelectAllSymbols();
                    if (symsel.ShowDialog() == DialogResult.OK)
                    {
                        SymbolCollection scSelected = new SymbolCollection();
                        scSelected = symsel.GetSelectedSymbolCollection();
                        PackageExporter pe = new PackageExporter();
                        SaveFileDialog sfd = new SaveFileDialog();
                        sfd.Filter = "Trionic 7 packages|*.t7p";
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            if (frmSelection.UseOriginalFile)
                            {
                                pe.ExportPackage(scSelected, m_OriginalFilename, sfd.FileName);
                            }
                            else
                            {
                                pe.ExportPackage(scSelected, m_filename, sfd.FileName);
                            }
                        }
                    }
                }
            }
        }
Example #14
0
        public static bool TryToExtractPackedBinary(string filename, int filename_size, out SymbolCollection symbol_collection)
        {
            bool retval = true;
            byte[] compressedSymbolTable;
            //Test 15092009
            //int RealAddressTableOffset = GetAddrTableOffset(filename) + 7; // was 17
            int RealAddressTableOffset = GetAddrTableOffsetBySymbolTable(filename) + 7; // was 17 // <GS-22032010>

            //Test 15092009
            logger.Debug("Real symboltable offset: " + RealAddressTableOffset.ToString("X8"));

            int symboltableoffset = 0;
            symbol_collection = new SymbolCollection();
            CastProgressEvent("Unpacking file... ",5);

            bool compr_created = extractCompressedSymbolTable(filename, out symboltableoffset, out compressedSymbolTable);
            CastProgressEvent("Finding address table... ",15);

            byte[] searchsequence = new byte[9];
            searchsequence.SetValue((byte)0x00, 0);
            searchsequence.SetValue((byte)0x00, 1);
            searchsequence.SetValue((byte)0x00, 2);
            searchsequence.SetValue((byte)0x00, 3);
            searchsequence.SetValue((byte)0x00, 4);
            searchsequence.SetValue((byte)0x00, 5);
            searchsequence.SetValue((byte)0x00, 6);
            searchsequence.SetValue((byte)0x00, 7);
            searchsequence.SetValue((byte)0x20, 8);
            int AddressTableOffset = 0;//GetAddressTableOffset(searchsequence);

            FileStream fsread = new FileStream(filename, FileMode.Open, FileAccess.Read);
            using (BinaryReader br = new BinaryReader(fsread))
            {
                fsread.Seek(symboltableoffset, SeekOrigin.Begin);
                int adr_state = 0;
                while ((fsread.Position < filename_size) && (AddressTableOffset == 0))
                {
                    byte adrb = br.ReadByte();
                    switch (adr_state)
                    {
                        case 0:
                            if (adrb == (byte)searchsequence.GetValue(0))
                            {

                                adr_state++;
                            }
                            break;
                        case 1:
                            if (adrb == (byte)searchsequence.GetValue(1)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 1;
                            }
                            break;
                        case 2:
                            if (adrb == (byte)searchsequence.GetValue(2)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 2;
                            }
                            break;
                        case 3:
                            if (adrb == (byte)searchsequence.GetValue(3)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 3;
                            }
                            break;
                        case 4:
                            if (adrb == (byte)searchsequence.GetValue(4)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 4;
                            }
                            break;
                        case 5:
                            if (adrb == (byte)searchsequence.GetValue(5)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 5;
                            }
                            break;
                        case 6:
                            if (adrb == (byte)searchsequence.GetValue(6)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 6;
                            }
                            break;
                        case 7:
                            if (adrb == (byte)searchsequence.GetValue(7)) adr_state++;
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 7;
                            }
                            break;
                        case 8:
                            if (adrb == (byte)searchsequence.GetValue(8))
                            {
                                // found it
                                AddressTableOffset = (int)fsread.Position - 1;
                            }
                            else
                            {
                                adr_state = 0;
                                fsread.Position -= 8;
                            }
                            break;
                    }
                }

                if (AddressTableOffset > 0)
                {
                    AddressTableOffset = RealAddressTableOffset; // TEST 15092009
                    CastProgressEvent("Reading address table... ", 25);

                    fsread.Seek(AddressTableOffset - 17, SeekOrigin.Begin);
                    bool endoftable = false;
                    Int64 internal_address = 0;
                    int sramaddress = 0;
                    int symbollength = 0;
                    int bitmask = 0;
                    int symb_count = 0;
                    symbol_collection = new SymbolCollection();
                    while (!endoftable)
                    {
                        // steeds 10 karaketers
                        try
                        {
                            byte[] bytes = br.ReadBytes(10);
                            if (bytes.Length == 10)
                            {
                                // DumpBytesToConsole(bytes);
                                if ((Convert.ToInt32(bytes.GetValue(9)) != 0x00) /*|| (Convert.ToInt32(bytes.GetValue(6)) != 0x00)*/)
                                {
                                    endoftable = true;
                                    //MessageBox.Show("EOT: " + fsread.Position.ToString("X6"));
                                    logger.Debug("EOT: " + fsread.Position.ToString("X6"));
                                }
                                else
                                {
                                    //DumpBytesToConsole(bytes);

                                    internal_address = Convert.ToInt64(bytes.GetValue(0)) * 256 * 256;
                                    internal_address += Convert.ToInt64(bytes.GetValue(1)) * 256;
                                    internal_address += Convert.ToInt64(bytes.GetValue(2));

                                    /* if (bytes[1] == 0x7A && bytes[2] == 0xEE)
                                     {
                                         logger.Debug("suspicious");

                                         if (internal_address == 0x7AEE)
                                         {
                                             logger.Debug("break: " + fsread.Position.ToString("X8"));
                                         }
                                     }*/
                                    symbollength = Convert.ToInt32(bytes.GetValue(3)) * 256;
                                    symbollength += Convert.ToInt32(bytes.GetValue(4));

                                    bitmask = Convert.ToInt32(bytes.GetValue(5)) * 256;
                                    bitmask += Convert.ToInt32(bytes.GetValue(6));

                                    //                                                sramaddress = Convert.ToInt32(bytes.GetValue(7)) * 256 * 256;
                                    //                                                sramaddress += Convert.ToInt32(bytes.GetValue(8)) * 256;
                                    //                                                sramaddress += Convert.ToInt32(bytes.GetValue(9));
                                    SymbolHelper sh = new SymbolHelper();
                                    sh.Symbol_type = Convert.ToInt32(bytes.GetValue(7));
                                    sh.Varname = "Symbolnumber " + symbol_collection.Count.ToString();
                                    sh.Symbol_number = symbol_collection.Count;
                                    sh.Symbol_number_ECU = symbol_collection.Count;
                                    sh.Flash_start_address = internal_address;
                                    sh.Start_address = internal_address;
                                    sh.Length = symbollength;
                                    sh.BitMask = bitmask;
                                    /*if (internal_address == 0x0AE956)
                                    {
                                        DumpBytesToConsole(bytes);
                                    }*/
                                    //DumpToSymbolFile(sh.Varname + " : " + sh.Flash_start_address.ToString("X6"));

                                    symbol_collection.Add(sh);
                                    symb_count++;
                                    if (symb_count % 500 == 0)
                                    {
                                        CastProgressEvent("Symbol: " + sh.Varname, 5);
                                    }
                                }
                            }
                            else
                            {
                                endoftable = true;
                            }
                        }
                        catch (Exception E)
                        {
                            logger.Debug(E.Message);
                            retval = false;
                        }

                    }
                    if (compr_created)
                    {
                        CastProgressEvent("Decoding packed symbol table",30);

                        string[] allSymbolNames;
                        // Decompress the symbol table
                        TrionicSymbolDecompressor.ExpandComprStream(compressedSymbolTable, out allSymbolNames);
                        AddNamesToSymbols(symbol_collection, allSymbolNames);
                        CastProgressEvent("Idle", 0);
                    }
                }
                else
                {
                    MessageBox.Show("Could not find address table!");
                    retval = false;
                }
            }
            return retval;
        }
Example #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="languageID"></param>
        /// <param name="m_current_softwareversion"></param>
        /// <returns></returns>
        public SymbolCollection ExtractFile(string filename, int languageID, string m_current_softwareversion)
        {
            m_fileName = filename;
            FileInfo fi = new FileInfo(filename);
            m_Filelength = (int)fi.Length;
            SymbolTranslator translator = new SymbolTranslator();
            XDFCategories category = XDFCategories.Undocumented;
            XDFSubCategory subcat = XDFSubCategory.Undocumented;
            string help = string.Empty;
            try
            {
                fi.IsReadOnly = false;
            }
            catch (Exception E)
            {
                logger.Debug(String.Format("Failed to clear read-only flag: {0}", E.Message));
            }
            symbol_collection = new SymbolCollection();
            try
            {
                int sym_count = 0; // altered
                CastProgressEvent("Opening file", 0);
                try
                {
                    symbol_collection = new SymbolCollection();
                    if (filename != string.Empty)
                    {
                        if (File.Exists(filename))
                        {
                            if (!IsBinaryPackedVersion(filename, (int)fi.Length))
                            {
                                CastProgressEvent("Getting symbol list offset", 5);
                                int SymbolListOffSet = GetSymbolListOffSet(filename, (int)fi.Length);
                                if (SymbolListOffSet > 0)
                                {
                                    using (FileStream fsread = new FileStream(filename, FileMode.Open, FileAccess.Read))
                                    {
                                        using (BinaryReader br = new BinaryReader(fsread))
                                        {
                                            fsread.Seek(SymbolListOffSet, SeekOrigin.Begin);   // 0x15FA in 5168646.BIN
                                            string symbolname = "";
                                            bool endoftable = false;
                                            while (!endoftable)
                                            {
                                                byte b = br.ReadByte();
                                                switch (b)
                                                {
                                                    case 0xFF:              // 0xFF used to keep the start of each string 'word' aligned
                                                        break;
                                                    case 0x02:
                                                        endoftable = true;
                                                        break;
                                                    case 0x00:              // 0x00 end of Symbol name string
                                                        SymbolHelper sh = new SymbolHelper() { Varname = symbolname, Description = translator.TranslateSymbolToHelpText(symbolname, out help, out category, out subcat, languageID) };
                                                        if (sh.Varname.Contains("."))
                                                        {
                                                            try
                                                            {
                                                                sh.Category = sh.Varname.Substring(0, sh.Varname.IndexOf("."));
                                                            }
                                                            catch (Exception cE)
                                                            {
                                                                logger.Debug(String.Format("Failed to assign category to symbol: {0} err: {1}", sh.Varname, cE.Message));
                                                            }
                                                        }
                                                        sh.Internal_address = (int)fsread.Position - symbolname.Length - 1;
                                                        sh.Symbol_number = sym_count;
                                                        symbol_collection.Add(sh);
                                                        symbolname = "";
                                                        sym_count++;
                                                        if ((sym_count % 500) == 0)
                                                        {
                                                            CastProgressEvent(String.Format("Symbol: {0}", sh.Varname), 10);
                                                        }
                                                        break;
                                                    default:                // Another character in the Symbol name
                                                        symbolname += Convert.ToChar(b);
                                                        break;
                                                }
                                            }
                                            // now, try to get the addresses
                                            // 00 00 00 00 00 00 00 00 20 00 00 00 15 FA
                                            // 00 F0 75 3E 00 01 00 00 24 00 00 00 16 04
                                            // 00 F0 75 3F 00 01 00 00 24 00 00 00 16 10
                                            // 00 F0 75 40 00 01 00 00 24 00 00 00 16 1E
                                            // 00 F0 75 42 00 02 00 00 20 00 00 00 16 2C
                                            // 00 F0 75 44 00 02 00 00 ...
                                            if (symbol_collection.Count > 0)
                                            {
                                                sym_count = 0;
                                                CastProgressEvent("Searching address lookup table", 15);
                                                byte firstaddr_high = (byte)(symbol_collection[0].Internal_address >> 8);
                                                byte firstaddr_low = (byte)(symbol_collection[0].Internal_address);
                                                byte[] searchPattern = {
                                                                           0x00, 0x00, 0x00, 0x00,
                                                                           0x00, 0x00, 0x00, 0x00,
                                                                           0x20, 0x00, 0x00, 0x00,
                                                                           0x00, 0x00, 0x00, 0xF0
                                                                       };
                                                searchPattern.SetValue(firstaddr_high, 12);
                                                searchPattern.SetValue(firstaddr_low, 13);
                                                int addressTableOffset = bytePatternSearch(filename, searchPattern, 0);
                                                if (addressTableOffset != -1)
                                                {
                                                    fsread.Seek(addressTableOffset, SeekOrigin.Begin);
                                                    // steeds 14 karaketers
                                                    for (int t = 0; t < symbol_collection.Count; t++)
                                                    {
                                                        try
                                                        {
                                                            byte[] bytes = br.ReadBytes(14);
                                                            if (bytes.Length == 14)
                                                            {
                                                                int internal_address = 0;
                                                                for (int i = 0; i < 4; i++)
                                                                {
                                                                    internal_address <<= 8;
                                                                    internal_address |= Convert.ToInt32(bytes.GetValue(i + 10));
                                                                }
                                                                int symbollength = 0;
                                                                for (int i = 0; i < 2; i++)
                                                                {
                                                                    symbollength <<= 8;
                                                                    symbollength |= Convert.ToInt32(bytes.GetValue(i + 4));
                                                                }
                                                                int sramaddress = 0;
                                                                for (int i = 0; i < 4; i++)
                                                                {
                                                                    sramaddress <<= 8;
                                                                    sramaddress |= Convert.ToInt32(bytes.GetValue(i));
                                                                }
                                                                int realromaddress;
                                                                if (sramaddress > 0xF00000)
                                                                    realromaddress = sramaddress - 0xef02f0;
                                                                else
                                                                    realromaddress = 0;
                                                                foreach (SymbolHelper sh in symbol_collection)
                                                                {
                                                                    if (sh.Internal_address == internal_address)
                                                                    {
                                                                        /*if (sh.Varname == "BFuelCal.Map")
                                                                        {
                                                                            logger.Debug("Break for fuel map: " + internal_address.ToString("X6"));

                                                                        }*/
                                                                        if (sramaddress > 0 && sh.Flash_start_address == 0)
                                                                            sh.Start_address = sramaddress; // TEST
                                                                        if (realromaddress > 0 && sh.Varname.Contains("."))
                                                                            sh.Flash_start_address = realromaddress;
                                                                        else
                                                                            sh.Flash_start_address = sramaddress;
                                                                        sh.Length = symbollength;
                                                                        sym_count++;
                                                                        if ((sym_count % 500) == 0)
                                                                        {
                                                                            CastProgressEvent(String.Format("{0} : {1:X6}", sh.Varname, sh.Flash_start_address), 20);
                                                                        }
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        catch (Exception E)
                                                        {
                                                            logger.Debug(E.Message);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tryToDecodePackedBinary(filename, out symbol_collection, languageID))
                                                    {
                                                        logger.Debug("Failed to extract packed binary!"); //<GS-23022010>
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Application.DoEvents();
                                    logger.Debug("Couldn't find symboltable, file is probably packed!");//<GS-23022010>
                                }
                            }
                            else
                            {
                                tryToDecodePackedBinary(filename, out symbol_collection, languageID);
                            }
                            // try to load additional symboltranslations that the user entered
                            TryToLoadAdditionalSymbols(filename, symbol_collection, languageID);
                        }
                    }
                }
                catch (Exception eBin)
                {
                    logger.Debug("Failed to open binfile: " + eBin.Message);
                }
                CastProgressEvent("Decoding done", 55);
            }
            catch (Exception E)
            {
                logger.Debug(String.Format("TryOpenFile filed: {0} err: {1}", filename, E.Message));

            }
            return symbol_collection;
        }
Example #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="symbol_collection"></param>
        /// <param name="languageID"></param>
        /// <returns></returns>
        private bool tryToDecodePackedBinary(string filename, out SymbolCollection symbol_collection, int languageID)
        {
            bool retval = true;
            int addressTableOffset;
            byte[] compressedSymbolTable;
            bool compr_created = extractCompressedSymbolTable(filename, out addressTableOffset, out compressedSymbolTable);
            logger.Debug(String.Format("Compr_created: ", compr_created));
            CastProgressEvent("Searching address lookup table", 30);

            symbol_collection = new SymbolCollection();
            if (addressTableOffset != -1)
            {
                symbol_collection = new SymbolCollection();
                logger.Debug(String.Format("SOT: {0:X6}", addressTableOffset));
                using (FileStream fsread = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(fsread))
                    {
                        fsread.Seek(addressTableOffset, SeekOrigin.Begin);
                        int symb_count = 0;
                        bool endoftable = false;
                        while (!endoftable)
                        {
                            // steeds 10 karaketers - each address table entry is 10 bytes in size
                            try
                            {
                                byte[] bytes = br.ReadBytes(10);
                                if (bytes.Length == 10 && (Convert.ToInt32(bytes.GetValue(0)) != 0x53) && (Convert.ToInt32(bytes.GetValue(1)) != 0x43))     // "SC"
                                {
                                    Int64 internal_address = 0;
                                    for (int i = 0; i < 4; i++)
                                    {
                                        internal_address <<= 8;
                                        internal_address |= Convert.ToInt64(bytes.GetValue(i));
                                    }
                                    int symbollength = 0;
                                    if (symb_count == 0)
                                    {
                                        symbollength = 0x08;            // report only a few bytes of the compressed symbol
                                    }
                                    else
                                    {
                                        for (int i = 4; i < 6; i++)
                                        {
                                            symbollength <<= 8;
                                            symbollength |= Convert.ToInt32(bytes.GetValue(i));
                                        }
                                    }
                                    // might be damaged addresstable by MapTun.. correct it automatically
                                    if (internal_address == 0x00 && symbollength > 0 && symbol_collection.Count > 0)
                                    {
                                        internal_address = symbol_collection[symbol_collection.Count - 1].Start_address + symbol_collection[symbol_collection.Count - 1].Length;
                                        if (symbollength == 0x240 && (internal_address % 2) > 0)
                                            internal_address++;
                                        logger.Debug(String.Format("Corrected symbol with address: {0:X8} and len {1:X4}", internal_address, symbollength));
                                    }
                                    SymbolHelper sh = new SymbolHelper()
                                    {
                                        Symbol_number = symb_count,
                                        Symbol_type = Convert.ToInt32(bytes.GetValue(8)),
                                        Varname = String.Format("Symbolnumber {0}", symbol_collection.Count),
                                        Flash_start_address = internal_address,
                                        Start_address = internal_address,
                                        Length = symbollength
                                    };
                                    symbol_collection.Add(sh);
                                    if (symb_count % 500 == 0)
                                    {
                                        CastProgressEvent(String.Format("{0} : {1:X6}", sh.Varname, sh.Flash_start_address), 35);
                                    }
                                    symb_count++;
                                }
                                else
                                {
                                    //MessageBox.Show("EOT: " + fsread.Position.ToString("X6"));
                                    logger.Debug(String.Format("EOT: {0:X6}", fsread.Position));
                                    endoftable = true;
                                }
                            }
                            catch (Exception E)
                            {
                                logger.Debug(E.Message);
                                retval = false;
                            }
                        }
                    }
                }
                if (compr_created)
                {
                    //logger.Debug("Decoding packed symbol table");
                    CastProgressEvent("Decoding packed symbol table", 40);
                    string[] allSymbolNames;
                    TrionicSymbolDecompressor.ExpandComprStream(compressedSymbolTable, out allSymbolNames);
                    //logger.Debug("Adding names to symbols");
                    CastProgressEvent("Adding names to symbols", 45);
                    AddNamesToSymbols(symbol_collection, allSymbolNames, languageID);
                    CastProgressEvent("Cleaning up", 50);
                }
            }
            else
            {
                logger.Debug("Could not find address table!"); //<GS-23022010>
                retval = false;
            }
            return retval;
        }
Example #17
0
        void InitSkins()
        {
            /*
            ribbonControl1.ForceInitialize();
            BarButtonItem item;

            DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.BonusSkins).Assembly);
            DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.OfficeSkins).Assembly);

            foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins)
            {
                item = new BarButtonItem();
                item.Caption = cnt.SkinName;
                //iPaintStyle.AddItem(item);
                ribbonPageGroup13.ItemLinks.Add(item);
                item.ItemClick += new ItemClickEventHandler(OnSkinClick);
            }*/

            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);
            SymbolCollection symcol = new SymbolCollection();
            foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.Varname = cnt.SkinName;
                symcol.Add(sh);
            }
            symcol.SortColumn = "Varname";
            symcol.SortingOrder = GenericComparer.SortOrder.Ascending;
            symcol.Sort();
            foreach (SymbolHelper sh in symcol)
            {
                item = new BarButtonItem();
                item.Caption = sh.Varname;
                BarItemLink il = ribbonPageGroup13.ItemLinks.Add(item);
                if ((skinCount++ % 3) == 0) il.BeginGroup = true;

                item.ItemClick += new ItemClickEventHandler(OnSkinClick);
            }
            try
            {
                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)
            {
                logger.Debug(E.Message);
            }
            SetToolstripTheme();
        }
Example #18
0
        private void ConvertFileToDif(string filename, bool AutoExport)
        {
            System.Windows.Forms.Application.DoEvents();
            DateTime startDate = DateTime.MaxValue;
            DateTime endDate = DateTime.MinValue;
            try
            {
                SymbolCollection sc = new 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 (SymbolHelper sh in sc)
                                        {
                                            if (sh.Varname == varname || sh.Userdescription == varname)
                                            {
                                                sfound = true;
                                            }
                                        }
                                        SymbolHelper nsh = new SymbolHelper();
                                        nsh.Varname = varname;
                                        if (!sfound) sc.Add(nsh);
                                    }
                                }
                            }
                            catch (Exception pE)
                            {
                                logger.Debug(pE.Message);
                            }
                        }
                    }
                }

                if (AutoExport)
                {
                    foreach (SymbolHelper sh in sc)
                    {
                        sh.Color = GetColorFromRegistry(sh.Varname);
                    }
                    DifGenerator difgen = new DifGenerator();
                    difgen.AppSettings = m_appSettings;

                    //difgen.LowAFR = m_appSettings.WidebandLowAFR;
                    //difgen.HighAFR = m_appSettings.WidebandHighAFR;
                    //difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                    //difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                    difgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                    //difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                    difgen.UseWidebandInput = false;

                    difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress);
                    frmProgressLogWorks = new frmProgress();
                    frmProgressLogWorks.SetProgress("Exporting to LogWorks");
                    frmProgressLogWorks.Show();
                    System.Windows.Forms.Application.DoEvents();
                    try
                    {
                        difgen.ConvertFileToDif(filename, sc, startDate, endDate, m_appSettings.InterpolateLogWorksTimescale, m_appSettings.InterpolateLogWorksTimescale);
                    }
                    catch (Exception expE1)
                    {
                        logger.Debug(expE1.Message);
                    }
                    frmProgressLogWorks.Close();
                }
                else
                {

                    // show selection screen
                    frmPlotSelection plotsel = new frmPlotSelection();
                    foreach (SymbolHelper sh in sc)
                    {
                        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.AppSettings = m_appSettings;
                        //difgen.LowAFR = m_appSettings.WidebandLowAFR;
                        //difgen.HighAFR = m_appSettings.WidebandHighAFR;
                        //difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                        //difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                        difgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                        //difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                        difgen.UseWidebandInput = false;

                        difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress);
                        frmProgressLogWorks = new frmProgress();
                        frmProgressLogWorks.SetProgress("Exporting to LogWorks");
                        frmProgressLogWorks.Show();
                        System.Windows.Forms.Application.DoEvents();
                        try
                        {
                            if (difgen.ConvertFileToDif(filename, sc, startDate, endDate, m_appSettings.InterpolateLogWorksTimescale, m_appSettings.InterpolateLogWorksTimescale))
                            {
                                StartLogWorksWithCurrentFile(Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".dif");
                            }
                            else
                            {
                                frmInfoBox info = new frmInfoBox("No data was found to export!");
                            }
                        }
                        catch (Exception expE2)
                        {
                            logger.Debug(expE2.Message);
                        }
                        frmProgressLogWorks.Close();
                    }
                    TimeSpan ts = new TimeSpan(endDate.Ticks - startDate.Ticks);
                    //MessageBox.Show("LogFile should be " + ts.ToString());
                }
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }
Example #19
0
        void edit_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (sender is frmEditTuningPackage)
            {
                frmEditTuningPackage edit = (frmEditTuningPackage)sender;
                if (edit.WriteData)
                {
                    // save the package again with altered settings probably.
                    logger.Debug("We should write the tuning package here!");
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Trionic 7 packages|*.t7p";
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        System.Data.DataTable dt = edit.GetDataTable();
                        SymbolCollection scToExport = new SymbolCollection();
                        foreach (DataRow dr in dt.Rows)
                        {
                            SymbolHelper sh = new SymbolHelper();
                            sh.Varname = dr["Map"].ToString();
                            sh.Currentdata = ConvertTuningPackageDataToByteArray(dr["Data"].ToString());
                            sh.Flash_start_address = GetSymbolAddress(m_symbols, sh.Varname);
                            sh.Userdescription = GetUserDescription(m_symbols, sh.Varname);
                            sh.Length = GetSymbolLength(m_symbols, sh.Varname);
                            scToExport.Add(sh);

                        }
                        PackageExporter pe = new PackageExporter();
                        if (IsSoftwareOpen())
                        {
                            pe.AddressOffset = GetOpenFileOffset();
                        }
                        pe.ExportPackage(scToExport, m_currentfile, sfd.FileName);
                    }
                }
            }
            tunpackeditWindow = null;
        }
Example #20
0
        public static SymbolCollection FindSymbols(string filename, ref DateTime startDate, ref DateTime endDate)
        {
            SymbolCollection sc = new 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 (SymbolHelper sh in sc)
                                    {
                                        if (sh.Varname == varname || sh.Userdescription == varname)
                                        {
                                            sfound = true;
                                        }
                                    }
                                    SymbolHelper nsh = new SymbolHelper();
                                    nsh.Varname = varname;
                                    if (!sfound)
                                    {
                                        sc.Add(nsh);
                                    }
                                }
                            }
                        }
                        catch (Exception pE)
                        {
                            logger.Debug(pE.Message);
                        }
                    }
                }
            }
            return(sc);
        }
Example #21
0
 private SymbolCollection GetRealtimeNotificationSymbols()
 {
     SymbolCollection _symbols = new SymbolCollection();
     if (m_symbols != null)
     {
         foreach (SymbolHelper sh in m_symbols)
         {
             if (sh.Start_address > 0xF00000)
             {
                 _symbols.Add(sh);
             }
         }
     }
     return _symbols;
 }
Example #22
0
        private void SaveMyMaps(string filename)
        {
            if (gridControl1.DataSource != null)
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                DataTable dt = (DataTable)gridControl1.DataSource;
                XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
                doc.AppendChild(dec);// Create the root element
                XmlElement root = doc.CreateElement("categories");
                doc.AppendChild(root);

                SymbolCollection sc = new SymbolCollection();

                // first get all categories
                foreach (DataRow dr in dt.Rows)
                {
                    string category = dr["category"].ToString();
                    bool found = false;
                    foreach(SymbolHelper sh in sc)
                    {
                        if (sh.Varname == category) found = true;
                    }
                    if (!found)
                    {
                        SymbolHelper newsh = new SymbolHelper();
                        newsh.Varname = category;
                        sc.Add(newsh);
                    }
                }

                foreach (SymbolHelper sh in sc)
                {
                    XmlElement title = doc.CreateElement("category");
                    title.SetAttribute("title", sh.Varname);
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["category"].ToString() == sh.Varname)
                        {
                            XmlElement map = doc.CreateElement("map");
                            map.SetAttribute("symbol", dr["symbol"].ToString());
                            map.SetAttribute("title", dr["title"].ToString());
                            title.AppendChild(map);
                        }
                    }
                    root.AppendChild(title);
                }
                /*
                                    foreach (DataRow dr in dt.Rows)
                                    {
                                        XmlElement title = doc.CreateElement("category");
                                        title.SetAttribute("title", dr["category"].ToString());
                                        XmlElement map = doc.CreateElement("map");
                                        map.SetAttribute("symbol", dr["symbol"].ToString());
                                        map.SetAttribute("title", dr["title"].ToString());
                                        title.AppendChild(map);
                                        root.AppendChild(title);
                                    }
                 * */
                doc.Save(filename);

            }
        }