Exemplo n.º 1
0
 private void AddSymbolToTuningPackage(SymbolHelper sh)
 {
     // check whether already exists
     if (gridControl1.DataSource != null)
     {
         DataTable dt = (DataTable)gridControl1.DataSource;
         bool _found = false;
         foreach (DataRow dr in dt.Rows)
         {
             if (dr["Map"] != DBNull.Value)
             {
                 if (dr["Map"].ToString() == sh.Varname)
                 {
                     _found = true;
                     dr["Data"] = ConvertToByteArray(sh.Currentdata); // update ?
                 }
             }
         }
         if (!_found)
         {
             dt.Rows.Add(sh.Varname, sh.Length, ConvertToByteArray(sh.Currentdata));
         }
     }
     else
     {
         // nieuwe maken
         System.Data.DataTable dt = new System.Data.DataTable();
         dt.Columns.Add("Map");
         dt.Columns.Add("Length");
         dt.Columns.Add("Data");
         dt.Rows.Add(sh.Varname, sh.Length, ConvertToByteArray(sh.Currentdata));
         gridControl1.DataSource = dt;
     }
 }
Exemplo n.º 2
0
 private void gridControl1_DragDrop(object sender, DragEventArgs e)
 {
     // what symbol
     // kijken of het mag
     if (e.Data is System.Windows.Forms.DataObject)
     {
         object o = e.Data.GetData("CommonSuite.SymbolHelper");
         if (o is SymbolHelper)
         {
             SymbolHelper sh = (SymbolHelper)o;
             logger.Debug("Dropped: " + sh.Varname);
             AddSymbolToTuningPackage(sh);
         }
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
 private void btnUploadTuningPackage_ItemClick(object sender, ItemClickEventArgs e)
 {
     // upload a t7p file to the ECU
     if (m_currentfile != "")
     {
         if (CheckCANConnectivity())
         {
             OpenFileDialog ofd = new OpenFileDialog();
             ofd.Filter = "Trionic 7 packages|*.t7p";
             ofd.Multiselect = false;
             char[] sep = new char[1];
             sep.SetValue(',', 0);
             SymbolCollection scToImport = new SymbolCollection();
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 //TODO: create a list of maps to import .. maybe?
                 frmProgress progress = new frmProgress();
                 progress.SetProgress("Uploading tuning package...");
                 progress.Show();
                 using (StreamReader sr = new StreamReader(ofd.FileName))
                 {
                     string line = string.Empty;
                     SymbolHelper sh_Import = new SymbolHelper();
                     while ((line = sr.ReadLine()) != null)
                     {
                         if (line.StartsWith("symbol="))
                         {
                             //
                             sh_Import = new SymbolHelper();
                             sh_Import.Varname = line.Replace("symbol=", "");
                         }
                         else if (line.StartsWith("length="))
                         {
                             sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                         }
                         else if (line.StartsWith("data="))
                         {
                             //
                             try
                             {
                                 string dataBytes = line.Replace("data=", "");
                                 // split using ','
                                 string[] bytesInStrings = dataBytes.Split(sep);
                                 byte[] dataToInsert = new byte[sh_Import.Length];
                                 for (int t = 0; t < sh_Import.Length; t++)
                                 {
                                     byte b = Convert.ToByte(bytesInStrings[t], 16);
                                     dataToInsert.SetValue(b, t);
                                 }
                                 int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                                 if (addressInFile > 0)
                                 {
                                     if (sh_Import.Varname != "MapChkCal.ST_Enable")
                                     {
                                         progress.SetProgress("Uploading: " + sh_Import.Varname);
                                         WriteMapToSRAM(sh_Import.Varname, dataToInsert, false);
                                         System.Windows.Forms.Application.DoEvents();
                                         Thread.Sleep(1);
                                     }
                                 }
                             }
                             catch (Exception E)
                             {
                                 // add failure
                                 logger.Debug(E.Message);
                             }
                         }
                     }
                 }
                 if (progress != null) progress.Close();
             }
         }
         else
         {
             frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to upload a tuning package");
         }
     }
 }
Exemplo n.º 7
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);

            }
        }
Exemplo n.º 8
0
        private byte[] ReadSymbolFromSRAM(uint symbolnumber, string symbolname, uint sramaddress, int length, out bool _success)
        {
            byte[] data;
            data = new byte[1];
            data[0] = (byte)0xFF;
            _success = false;
            logger.Debug("Getting symbolnumber: " + symbolnumber.ToString() + " symbolname: " + symbolname);
            if (m_connectedToECU)
            {
                // test
                sramaddress = 0;
                if (sramaddress > 0)
                {
                    //logger.Debug("Get SRAM (1): " + sramaddress.ToString());
                    data = trionic7.ReadMapFromSRAM(sramaddress, length, out _success);
                    Thread.Sleep(0); //<GS-11022010>
                }
                else if (length == 1)
                {
                    _sw2.Reset();
                    _sw2.Start();
                    int sram = (int)GetSymbolAddressSRAM(m_symbols, symbolname);
                    logger.Debug("          Get single byte : " + sram.ToString());
                    SymbolHelper sh = new SymbolHelper();
                    sh.Length = 1;
                    sh.Start_address = sram;
                    m_prohibitReading = true;
                    data = trionic7.ReadMapFromSRAMVarLength(sh);
                    m_prohibitReading = false;
                    _success = true;
                    logger.Debug("          Get single byte Updated in " + _sw2.ElapsedMilliseconds.ToString() + " ms");
                    _sw2.Stop();
                }
                else
                {
                    _sw2.Reset();
                    _sw2.Start();
                    logger.Debug("          Get symbolnumber (2): " + symbolnumber.ToString());
                    data = trionic7.ReadSymbolNumber(symbolnumber, out _success);
                    logger.Debug("          Get symbolnumber (2) Updated in " + _sw2.ElapsedMilliseconds.ToString() + " ms");
                    _sw2.Stop();
                }
            }

            return data;
        }
Exemplo n.º 9
0
 public int IndexOf(SymbolHelper value)
 {
     return(List.IndexOf(value));
 }
Exemplo n.º 10
0
 public void Remove(SymbolHelper value)
 {
     List.Remove(value);
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 12
0
 public void Insert(int index, SymbolHelper value)
 {
     List.Insert(index, value);
 }
Exemplo n.º 13
0
        public byte[] ReadMapfromSRAM(SymbolHelper sh, bool showProgress)
        {
            byte[] completedata = new byte[sh.Length];
            try
            {
                byte[] data;
                int m_nrBytes = 64;
                int m_nrOfReads = 0;
                int m_nrOfRetries = 0;
                m_nrOfReads = sh.Length / m_nrBytes;
                if (((sh.Length) % 64) > 0) m_nrOfReads++;
                int bytecount = 0;
                KWPHandler.getInstance().requestSequrityAccess(false);
                for (int readcount = 0; readcount < m_nrOfReads; readcount++)
                {
                    if (showProgress)
                    {
                        CastProgressReadEvent((int)(readcount * 100 / m_nrOfReads));
                    }

                    m_nrOfRetries = 0;
                    int addresstoread = (int)sh.Start_address + (readcount * m_nrBytes);
                    logger.Debug("Reading 64 bytes from address: " + addresstoread.ToString("X6"));

                    while (!KWPHandler.getInstance().sendReadRequest((uint)(addresstoread), 64) && m_nrOfRetries < 20)
                    {
                        m_nrOfRetries++;
                    }
                    logger.Debug("Send command in " + m_nrOfRetries.ToString() + " retries");
                    m_nrOfRetries = 0;
                    Thread.Sleep(1);
                    while (!KWPHandler.getInstance().sendRequestDataByOffset(out data) && m_nrOfRetries < 20)
                    {
                        m_nrOfRetries++;
                    }
                    logger.Debug("Read data in " + m_nrOfRetries.ToString() + " retries");
                    logger.Debug("Read " + data.Length.ToString() + " bytes from CAN interface");
                    foreach (byte b in data)
                    {
                        // Console.Write(b.ToString("X2") + " ");
                        if (bytecount < completedata.Length)
                        {
                            completedata[bytecount++] = b;
                        }
                    }
                }
                //logger.Debug("Reading done");
            }
            catch (Exception E)
            {
                logger.Debug("Failed to read memory: " + E.Message);
            }
            return completedata;
        }
Exemplo n.º 14
0
        public byte[] ReadMapFromSRAMVarLength(SymbolHelper sh)
        {
            int varlength = 2;
            byte[] completedata = new byte[sh.Length];
            try
            {
                byte[] data;
                int m_nrBytes = varlength;
                int m_nrOfReads = 0;
                int m_nrOfRetries = 0;
                m_nrOfReads = sh.Length / m_nrBytes;
                if (((sh.Length) % varlength) > 0) m_nrOfReads++;
                int bytecount = 0;
                KWPHandler.getInstance().requestSequrityAccess(false); // no seq. access <GS-10022010>
                for (int readcount = 0; readcount < m_nrOfReads; readcount++)
                {
                    m_nrOfRetries = 0;
                    int addresstoread = (int)sh.Start_address + (readcount * m_nrBytes);
                    //LogHelper.Log("Reading 64 bytes from address: " + addresstoread.ToString("X6"));

                    while (!KWPHandler.getInstance().sendReadRequest(/*0xF04768*/(uint)(addresstoread), (uint)varlength) && m_nrOfRetries < 20)
                    {
                        m_nrOfRetries++;
                    }
                    logger.Debug("Send command in " + m_nrOfRetries.ToString() + " retries");
                    m_nrOfRetries = 0;
                    while (!KWPHandler.getInstance().sendRequestDataByOffset(out data) && m_nrOfRetries < 20)
                    {
                        m_nrOfRetries++;
                    }
                    logger.Debug("Read data in " + m_nrOfRetries.ToString() + " retries");
                    logger.Debug("Read " + data.Length.ToString() + " bytes from CAN interface");
                    foreach (byte b in data)
                    {
                        //Console.Write(b.ToString("X2") + " ");
                        if (bytecount < completedata.Length)
                        {
                            completedata[bytecount++] = b;
                        }
                    }
                }
            }
            catch (Exception E)
            {
                logger.Debug("Failed to read memory: " + E.Message);
            }
            return completedata;
        }
Exemplo n.º 15
0
 public bool Contains(SymbolHelper value)
 {
     // If value is not of type Int16, this will return false.
     return (List.Contains(value));
 }
Exemplo n.º 16
0
 public int Add(SymbolHelper value)
 {
     return (List.Add(value));
 }
Exemplo n.º 17
0
 public void Remove(SymbolHelper value)
 {
     List.Remove(value);
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 19
0
 public SymbolFileTuningPackage(SymbolHelper _sh_Import, int _addressInFile, byte[] _dataToInsert, bool _successful)
 {
     type = FileTuningPackType.SymbolTp;
     succesful = _successful;
     sh_Import = _sh_Import;
     addressInFile = _addressInFile;
     dataToInsert = _dataToInsert;
 }
Exemplo n.º 20
0
        private void File_EditTuningPackage(object sender, ItemClickEventArgs e)
        {
            if (tunpackeditWindow != null)
            {
                frmInfoBox info = new frmInfoBox("You have another tuning package edit window open, please close that first");
                return;
            }
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Trionic 7 packages|*.t7p";
            ofd.Multiselect = false;
            char[] sep = new char[1];
            sep.SetValue(',', 0);

            SymbolCollection scToImport = new SymbolCollection();
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("Map");
            dt.Columns.Add("Length");
            dt.Columns.Add("Data");

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //TODO: create a list of maps to import .. maybe?
                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    string line = string.Empty;
                    SymbolHelper sh_Import = new SymbolHelper();
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("symbol="))
                        {
                            //
                            sh_Import = new SymbolHelper();
                            sh_Import.Varname = line.Replace("symbol=", "");
                        }
                        else if (line.StartsWith("length="))
                        {
                            sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                        }
                        else if (line.StartsWith("data="))
                        {
                            //
                            try
                            {
                                string dataBytes = line.Replace("data=", "");
                                // split using ','
                                string[] bytesInStrings = dataBytes.Split(sep);
                                byte[] dataToInsert = new byte[sh_Import.Length];
                                for (int t = 0; t < sh_Import.Length; t++)
                                {
                                    byte b = Convert.ToByte(bytesInStrings[t], 16);
                                    dataToInsert.SetValue(b, t);
                                }
                                int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                                if (addressInFile > 0)
                                {
                                    //savedatatobinary(addressInFile, sh_Import.Length, dataToInsert, m_currentfile, true);
                                    // add successful
                                    dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), dataBytes);
                                }
                                else
                                {
                                    // add failure
                                    dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), dataBytes);
                                }
                            }
                            catch (Exception E)
                            {
                                // add failure
                                dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), "");
                                logger.Debug(E.Message);
                            }
                        }
                    }
                }
                tunpackeditWindow = new frmEditTuningPackage();
                tunpackeditWindow.FormClosed += new FormClosedEventHandler(edit_FormClosed);
                tunpackeditWindow.onMapSelected += new frmEditTuningPackage.MapSelected(edit_onMapSelected);
                tunpackeditWindow.SetFilename(ofd.FileName);
                tunpackeditWindow.SetDataTable(dt);
                tunpackeditWindow.Show();

            }
        }
Exemplo n.º 21
0
 private bool CanTransfer(SymbolHelper sh)
 {
     bool retval = false;
     if (sh.SmartVarname.Contains("."))
         retval = true;
     return retval;
 }
Exemplo n.º 22
0
 public int Add(SymbolHelper value)
 {
     return(List.Add(value));
 }
Exemplo n.º 23
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();
        }
Exemplo n.º 24
0
 public void Insert(int index, SymbolHelper value)
 {
     List.Insert(index, value);
 }
Exemplo n.º 25
0
        private byte[] ReadMapFromSRAM(SymbolHelper sh)
        {
            m_prohibitReading = true;
            bool success = false;
            int blockSize = 0x40;

            // we need security access for this

            logger.Debug("reading from address: " + sh.Start_address.ToString("X8") + " len: " + sh.Length.ToString());
            byte[] mapvalues = new byte[sh.Length];
            if (sh.Length < blockSize)
            {
                mapvalues = t8can.readMemory((int)sh.Start_address, sh.Length, out success);
                logger.Debug("ReadMapFromSRAM: " + success.ToString());
            }
            else
            {
                // 0x80 bytes at a time
                int nrReads = sh.Length / blockSize;
                if (sh.Length % blockSize > 0) nrReads++;
                int idx = 0;
                for (int i = 0; i < nrReads; i++)
                {
                    int address2read = (int)sh.Start_address + (i * blockSize);
                    int length2read = blockSize;
                    byte[] blockBytes = t8can.readMemory(address2read, length2read, out success);
                    Thread.Sleep(1);
                    logger.Debug("ReadMapFromSRAM: " + success.ToString());
                    // copy bytes to complete buffer
                    for (int j = 0; j < length2read; j++)
                    {
                        if (idx < mapvalues.Length)
                        {
                            mapvalues[idx++] = blockBytes[j];
                        }
                    }
                }
            }
            m_prohibitReading = false;
            return mapvalues;
        }
Exemplo n.º 26
0
 public bool Contains(SymbolHelper value)
 {
     // If value is not of type Int16, this will return false.
     return(List.Contains(value));
 }
Exemplo n.º 27
0
        private List<FileTuningPackage> ReadTuningPackageFile(bool encoded, string tpFile, out string binSwType, out string whitelist, out string blacklist, out string code)
        {
            char[] sep = new char[1];
            sep.SetValue(',', 0);
            binSwType = string.Empty;
            whitelist = string.Empty;
            blacklist = string.Empty;
            code = string.Empty;
            List<FileTuningPackage> lstTp = new List<FileTuningPackage>();

            using (StreamReader sr = new StreamReader(tpFile))
            {
                string line = string.Empty;
                string in_line = string.Empty;
                SymbolHelper sh_Import = new SymbolHelper();

                if (encoded)
                {
                    // Read signature
                    string signature = string.Empty;
                    string s = sr.ReadLine();
                    if (s != null && s.StartsWith("<SIGNATURE>"))
                    {
                        while ((s = sr.ReadLine()) != null)
                        {
                            if (s.StartsWith("</SIGNATURE>"))
                                break;
                            signature += s;
                        }
                    }
                }
                while ((in_line = sr.ReadLine()) != null)
                {
                    if (encoded)
                        line = Crypto.DecodeAES(in_line).Trim();
                    else
                        line = in_line.Trim();

                    if (line.StartsWith("packname="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("bintype="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("whitelist="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("blacklist="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("code="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("author="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("msg="))
                    {
                        // Do nothing
                    }
                    else if (line.StartsWith("binaction="))
                    {
                        string inS = line.Replace("binaction=", "");
                        FileTuningPackage binTP = new BinFileTuningPackage(inS);
                        lstTp.Add(binTP);
                    }
                    else if (line.StartsWith("searchreplace="))
                    {
                        string inS = line.Replace("searchreplace=", "");
                        FileTuningPackage srTP = new SearchReplaceTuningPackage(inS);
                        lstTp.Add(srTP);
                    }
                    else if (line.StartsWith("symbol="))
                    {
                        //
                        sh_Import = new SymbolHelper();
                        sh_Import.Varname = line.Replace("symbol=", "");
                    }
                    else if (line.StartsWith("length="))
                    {
                        sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                    }
                    else if (line.StartsWith("data="))
                    {
                        try
                        {
                            string dataBytes = line.Replace("data=", "");
                            // split using ','
                            string[] bytesInStrings = dataBytes.Split(sep);
                            byte[] dataToInsert = new byte[sh_Import.Length];
                            for (int t = 0; t < sh_Import.Length; t++)
                            {
                                byte b = Convert.ToByte(bytesInStrings[t], 16);
                                dataToInsert.SetValue(b, t);
                            }
                            int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                            if (addressInFile != 0)
                            {
                                FileTuningPackage fileTP = new SymbolFileTuningPackage(sh_Import, addressInFile, dataToInsert, true);
                                lstTp.Add(fileTP);
                            }
                            else
                            {
                                FileTuningPackage fileTP = new SymbolFileTuningPackage(sh_Import, addressInFile, dataToInsert, false);
                                lstTp.Add(fileTP);
                            }
                        }
                        catch (Exception E)
                        {
                            // add failure
                            byte[] dataToInsert = new byte[0];
                            FileTuningPackage fileTP = new SymbolFileTuningPackage(sh_Import, 0, dataToInsert, false);
                            lstTp.Add(fileTP);
                        }
                    }
                }
            }
            return lstTp;
        }
Exemplo n.º 28
0
        private byte[] ReadMapFromSRAM(SymbolHelper sh, bool showProgress)
        {
            m_prohibitReading = true;
            if (showProgress)
            {
                barProgress.EditValue = 0;
                barProgress.Caption = "Reading map from SRAM";
                barProgress.Visibility = BarItemVisibility.Always;
                System.Windows.Forms.Application.DoEvents();
            }

            byte[] completedata = trionic7.ReadMapfromSRAM(sh, showProgress);

            m_prohibitReading = false;
            if (showProgress)
            {
                barProgress.EditValue = 0;
                barProgress.Caption = "Idle";
                barProgress.Visibility = BarItemVisibility.Never;
                System.Windows.Forms.Application.DoEvents();
            }

            return completedata;
        }
Exemplo n.º 29
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;
        }
Exemplo n.º 30
0
        private bool ShouldTransferSymbol(SymbolHelper sh)
        {
            // FOR TESTING ONLY
            //return true;

            bool retval = false;
            if (sh.Varname.Contains(".") || sh.Userdescription.Contains(".")) retval = true;
            if (sh.Varname == "MapChkCal.ST_Enable" || sh.Userdescription == "MapChkCal.ST_Enable") retval = false;
            return retval;
        }
Exemplo n.º 31
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;
        }
Exemplo n.º 32
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;
         }
     }
 }
Exemplo n.º 33
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            // setup the export filters
            LogFilters filterhelper = new LogFilters();
            frmLogFilters frmfilters = new frmLogFilters();
            LogFilterCollection filters = filterhelper.GetFiltersFromRegistry();
            logger.Debug("filters: " + filters.Count);
            frmfilters.SetFilters(filters);
            if (gridControl1.DataSource != null)
            {
                DataTable dt = (DataTable)gridControl1.DataSource;

                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);
                    }
                }

            }
            frmfilters.SetSymbols(_sc);
            if (frmfilters.ShowDialog() == DialogResult.OK)
            {
                DialogResult = DialogResult.None;
                filterhelper.SaveFiltersToRegistry(frmfilters.GetFilters());
            }
        }
Exemplo n.º 34
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();
                }
            }
        }
Exemplo n.º 35
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;
        }
Exemplo n.º 36
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;
        }
Exemplo n.º 37
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);
        }
Exemplo n.º 38
0
        private void File_ImportTuningPackage_ItemClick(object sender, ItemClickEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Trionic 7 packages|*.t7p";
            ofd.Multiselect = false;
            char[] sep = new char[1];
            sep.SetValue(',', 0);

            SymbolCollection scToImport = new SymbolCollection();
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("Map");
            dt.Columns.Add("Result");

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //TODO: create a list of maps to import .. maybe?
                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    string line = string.Empty;
                    SymbolHelper sh_Import = new SymbolHelper();
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("symbol="))
                        {
                            //
                            sh_Import = new SymbolHelper();
                            sh_Import.Varname = line.Replace("symbol=", "");
                        }
                        else if (line.StartsWith("length="))
                        {
                            sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                        }
                        else if (line.StartsWith("data="))
                        {
                            //
                            try
                            {
                                string dataBytes = line.Replace("data=", "");
                                // split using ','
                                string[] bytesInStrings = dataBytes.Split(sep);
                                byte[] dataToInsert = new byte[sh_Import.Length];
                                for (int t = 0; t < sh_Import.Length; t++)
                                {
                                    byte b = Convert.ToByte(bytesInStrings[t], 16);
                                    dataToInsert.SetValue(b, t);
                                }
                                int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                                if (addressInFile > 0)
                                {
                                    if (_softwareIsOpen && sh_Import.Varname == "MapChkCal.ST_Enable")
                                    {
                                        dt.Rows.Add(sh_Import.Varname, "Skipped");
                                    }
                                    else
                                    {
                                        savedatatobinary(addressInFile, sh_Import.Length, dataToInsert, m_currentfile, true);
                                        // add successful
                                        dt.Rows.Add(sh_Import.Varname, "Success");
                                    }
                                }
                                else
                                {
                                    // add failure
                                    dt.Rows.Add(sh_Import.Varname, "Fail");
                                }
                            }
                            catch (Exception E)
                            {
                                // add failure
                                dt.Rows.Add(sh_Import.Varname, "Fail");
                                logger.Debug(E.Message);
                            }
                        }
                    }
                }
                UpdateChecksum(m_currentfile);
                frmImportResults res = new frmImportResults();
                res.SetDataTable(dt);
                res.ShowDialog();
            }
        }
Exemplo n.º 39
0
 public int IndexOf(SymbolHelper value)
 {
     return (List.IndexOf(value));
 }