Exemple #1
0
 /// <summary>
 /// Reposition the Gridlines.
 /// </summary>
 public void Reposition(AxisCollection Axes)
 {
     try
     {
         foreach (GridLine tmpGridLine in gridLines)
         {
             tmpGridLine.line.Dispose();
         }
         gridLines.Clear();
         if (enabled)
         {
             foreach (Axis axis in Axes)
             {
                 if (axis.IsGridShow)
                 {
                     foreach (AxisLabel al in axis.labelsCollection)
                     {
                         GridLine gl = new GridLine(chartArea, axis.GridColor);
                         gridLines.Add(gl);
                         gl.Reposition(al);
                     }
                 }
             }
         }
     }
     catch { }
 }
Exemple #2
0
        public void GetAxisValues(string m_currentfile, SymbolCollection symbols, AxisCollection axis, string symbolname, int address, int rows, int cols, out int[] Xaxis, out int[] Yaxis, out string xdescr, out string ydescr)
        {
            xdescr = "";
            ydescr = "";
            Yaxis  = new int[rows];
            for (int i = 0; i < Yaxis.Length; i++)
            {
                Yaxis.SetValue(i, i);
            }
            Xaxis = new int[cols];
            for (int i = 0; i < Xaxis.Length; i++)
            {
                Xaxis.SetValue(i, i);
            }

            // let's see if there are leading axis info to this table

            foreach (AxisHelper ah in axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    // this is an axis for this table...
                    // see if there is another one that leads
                    int[]  yaxis;
                    string y_descr = string.Empty;
                    if (Helpers.Instance.AxisHasLeadingAxis(axis, ah.Addressinfile, out yaxis, out y_descr))
                    {
                        Yaxis  = yaxis;
                        ydescr = y_descr;
                        Xaxis  = ah.Values;
                        if (ah.Descr != string.Empty)
                        {
                            xdescr = ah.Descr;
                        }
                        else
                        {
                            xdescr = ah.Identifier.ToString();
                        }
                    }
                    else
                    {
                        Xaxis = ah.Values;
                        if (ah.Descr != string.Empty)
                        {
                            xdescr = ah.Descr;
                        }
                        else
                        {
                            xdescr = ah.Identifier.ToString();
                        }
                        Yaxis = new int[rows];
                        for (int i = 0; i < Yaxis.Length; i++)
                        {
                            Yaxis.SetValue(i, i);
                        }
                    }
                }
            }
        }
Exemple #3
0
        private bool CheckForAxisPresent(string filename, int startaddress, AxisCollection axis, int lengthOfPreviousAxis)
        {
            bool       retval = false;
            FileStream fs     = new FileStream(filename, FileMode.Open);

            fs.Position = startaddress;
            using (BinaryReader br = new BinaryReader(fs))
            {
                int id     = (int)br.ReadByte();
                int length = (int)br.ReadByte();
                if (id >= 0x03 && id <= 0x70 && length > 1 && length < 32)
                {
                    // now also check wether a new axis starts (more likely) at the location AFTER this,
                    // that is, if we assume that the data here is actually a 2D map in stead of an axis
                    fs.Position = startaddress + lengthOfPreviousAxis;
                    int id2  = (int)br.ReadByte();
                    int len2 = (int)br.ReadByte();
                    if (id2 == 0x3A || id2 == 0x37 || id2 == 0x36 || id2 == 0x3F || id2 == 0x03 || id2 == 0x04 || id2 == 0x07 || id2 == 0x2E || id2 == 0x30 || id2 == 0x33 || id2 == 0x5C || id2 == 0x6D || id2 == 0x8B || id2 == 0x99)
                    {
                        if (len2 > 1 && len2 < 32)
                        {
                            int pos = startaddress + lengthOfPreviousAxis;
                            //Console.WriteLine("Overruled axis detection at : " + pos.ToString("X4"));
                            return(false);
                        }
                    }

                    if (!Helpers.Instance.AxisPresentInCollection(startaddress, axis))
                    {
                        retval = true;
                    }
                }
            }
            return(retval);
        }
Exemple #4
0
        public bool AxisHasLeadingAxis(AxisCollection axis, int address, out int[] xaxis, out string y_descr)
        {
            bool retval = false;

            y_descr = string.Empty;
            xaxis   = new int[1];
            xaxis.SetValue(0, 0);
            foreach (AxisHelper ah in axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    retval = true;
                    xaxis  = ah.Values;
                    if (ah.Descr != string.Empty)
                    {
                        y_descr = ah.Descr;
                    }
                    else
                    {
                        y_descr = ah.Identifier.ToString();
                    }
                }
            }
            return(retval);
        }
Exemple #5
0
        public int FindFirstAddressInLists(int address, AxisCollection axis, SymbolCollection m_Unknown_symbols)
        {
            FileInfo fi       = new FileInfo(FileTools.Instance.Currentfile);
            int      maxvalue = (int)fi.Length;
            int      retval   = maxvalue;

            Console.WriteLine("Searching for address : " + address.ToString("X4"));
            foreach (AxisHelper ah in axis)
            {
                if (ah.Addressinfile < maxvalue && ah.Addressinfile < retval && ah.Addressinfile > address)
                {
                    retval = ah.Addressinfile;
                    Console.WriteLine("Ret val is now: " + retval.ToString("X4"));
                }
            }
            foreach (SymbolHelper sh in m_Unknown_symbols)
            {
                if (sh.Flash_start_address < maxvalue && sh.Flash_start_address < retval && sh.Flash_start_address > address)
                {
                    retval = sh.Flash_start_address;
                    Console.WriteLine("Ret val is now: " + retval.ToString("X4"));
                }
            }
            return(retval);
        }
        static void DisplayUnits(Workbook workbook)
        {
            #region #DisplayUnits
            Worksheet worksheet = workbook.Worksheets["chartTask7"];
            workbook.Worksheets.ActiveWorksheet = worksheet;

            // Create a chart and specify its location.
            Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
            chart.TopLeftCell     = worksheet.Cells["F2"];
            chart.BottomRightCell = worksheet.Cells["N17"];

            // Change the scale of the value axis.
            AxisCollection axisCollection = chart.PrimaryAxes;
            Axis           valueAxis      = axisCollection[1];
            valueAxis.Scaling.AutoMax = false;
            valueAxis.Scaling.Max     = 8000000;
            valueAxis.Scaling.AutoMin = false;
            valueAxis.Scaling.Min     = 0;

            // Specify display units for the value axis.
            valueAxis.DisplayUnits.UnitType  = DisplayUnitType.Thousands;
            valueAxis.DisplayUnits.ShowLabel = true;

            // Set the chart style.
            chart.Style = ChartStyle.ColorBevel;
            chart.Views[0].VaryColors = true;

            // Hide the legend.
            chart.Legend.Visible = false;
            #endregion #DisplayUnits
        }
Exemple #7
0
        private SciChartSurface CreateSurface()
        {
            var series = new FastLineRenderableSeries()
            {
                Stroke     = Colors.Red,
                DataSeries = GetDataSeries()
            };

            var xAxes = new AxisCollection()
            {
                new NumericAxis()
            };

            var yAxes = new AxisCollection()
            {
                new NumericAxis()
            };

            var surface = new SciChartSurface()
            {
                ChartTitle       = "Rendered In Memory",
                XAxes            = xAxes,
                YAxes            = yAxes,
                RenderableSeries = new ObservableCollection <IRenderableSeries>()
                {
                    series
                },
                Annotations =
                    new AnnotationCollection()
                {
                    new BoxAnnotation()
                    {
                        X1         = 10,
                        X2         = 30,
                        Y1         = 10,
                        Y2         = 40,
                        Background = new SolidColorBrush(Colors.Green),
                    },
                    new VerticalLineAnnotation()
                    {
                        X1              = 35,
                        Stroke          = new SolidColorBrush(Colors.Yellow),
                        StrokeThickness = 3,
                        ShowLabel       = true,
                        LabelPlacement  = LabelPlacement.Axis
                    }
                }
            };

            ThemeManager.SetTheme(surface, "Chrome");

            surface.Width  = 800;
            surface.Height = 400;

            return(surface);
        }
Exemple #8
0
 public void FlipAxes(AxisCollection axes)
 {
     using (ParentSurface.SuspendUpdates())
     {
         foreach (var axis in axes)
         {
             axis.FlipCoordinates = !axis.FlipCoordinates;
         }
     }
 }
Exemple #9
0
        public string GetAxisHeaderCaption(string queryname, int axis, int cellindex)
        {
            if (!queries.ContainsKey(queryname))
            {
                throw new ArgumentException(nameof(queryname));
            }

            CellSet        cs   = cellsets[queryname];
            AxisCollection axes = cs.Axes;

            if (axis < 0 || axis >= axes.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(axis));
            }
            if (cellindex < 0 || cellindex >= cs.Cells.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(cellindex));
            }

            if (!axesheadercaptions.ContainsKey(queryname))
            {
                axesheadercaptions.Add(
                    queryname,
                    new Dictionary <int, string[]>()
                    );
            }

            if (!axesheadercaptions[queryname].ContainsKey(axis))
            {
                axesheadercaptions[queryname].Add(axis, new string[axes[axis].Positions.Count]);
            }

            int tile = 1;

            for (int i = 0; i < axis; i++)
            {
                tile *= axes[i].Positions.Count;
            }
            int axisheaderindex = (cellindex / tile) % axes[axis].Positions.Count;

            try
            {
                if (axesheadercaptions[queryname][axis][axisheaderindex] == null)
                {
                    axesheadercaptions[queryname][axis][axisheaderindex] = string.Join(" | ", axes[axis].Positions[axisheaderindex].Members.Cast <Member>().Select(m => m.Caption));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(axesheadercaptions[queryname][axis][axisheaderindex]);
        }
Exemple #10
0
 public bool AxisPresentInCollection(int address, AxisCollection axis)
 {
     foreach (AxisHelper ah in axis)
     {
         if (ah.Addressinfile == address)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #11
0
 public SelectSymbolEventArgs(int address, int length, string mapname, string filename, bool showdiffmap, SymbolCollection symColl, AxisCollection axis, int symbolnumber1, int symbolnumber2)
 {
     this._address       = address;
     this._length        = length;
     this._mapname       = mapname;
     this._filename      = filename;
     this._showdiffmap   = showdiffmap;
     this._symbols       = symColl;
     this._axis          = axis;
     this._symbolnumber1 = symbolnumber1;
     this._symbolnumber2 = symbolnumber2;
 }
Exemple #12
0
        public override FileInformation ParseFile()
        {
            m_fileInfo = new FileInformation();
            SymbolCollection symbols = new SymbolCollection();
            AxisCollection   axis    = new AxisCollection();

            LoadLH242File(m_currentFile, out symbols, out axis);
            m_symbols = symbols;
            m_axis    = axis;

            m_fileInfo.Symbols = symbols;
            m_fileInfo.Axis    = axis;
            return(m_fileInfo);
        }
Exemple #13
0
 private void CreateChartArea()
 {
     if (IsInRunMode)
     {
         device      = GraphicEngine.GraphicEngine.CreateDevice();
         series      = new SeriesCollection();
         Axes        = new AxisCollection();
         annotations = new AnnotationCollection();
         Padding     = new Padding(50);
         //
         //  Initialize();
         //OnPaint(null);
     }
 }
        static void ChangeChartAppearance(Workbook workbook)
        {
            #region #ChangeChartAppearance
            Worksheet worksheet = workbook.Worksheets["chartTask7"];
            workbook.Worksheets.ActiveWorksheet = worksheet;

            // Create a chart and specify its location.
            Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
            chart.TopLeftCell     = worksheet.Cells["F2"];
            chart.BottomRightCell = worksheet.Cells["N17"];

            // Add and format the chart title.
            chart.Title.SetValue("Сountries with the largest forest area");
            chart.Title.Font.Color = Color.FromArgb(0x34, 0x5E, 0x25);

            // Set no fill for the plot area.
            chart.PlotArea.Fill.SetNoFill();

            // Apply the gradient fill to the chart area.
            chart.Fill.SetGradientFill(ShapeGradientType.Linear, Color.FromArgb(0xFD, 0xEA, 0xDA), Color.FromArgb(0x77, 0x93, 0x3C));
            ShapeGradientFill gradientFill = chart.Fill.GradientFill;
            gradientFill.Stops.Add(0.78f, Color.FromArgb(0xB7, 0xDE, 0xE8));
            gradientFill.Angle = 90;

            // Set the picture fill for the data series.
            chart.Series[0].Fill.SetPictureFill("Pictures\\PictureFill.png");

            // Customize the axis appearance.
            AxisCollection axisCollection = chart.PrimaryAxes;
            foreach (Axis axis in axisCollection)
            {
                axis.MajorTickMarks = AxisTickMarks.None;
                axis.Outline.SetSolidFill(Color.FromArgb(0x34, 0x5E, 0x25));
                axis.Outline.Width = 1.25;
            }
            // Change the scale of the value axis.
            Axis valueAxis = axisCollection[1];
            valueAxis.Scaling.AutoMax = false;
            valueAxis.Scaling.Max     = 8000000;
            valueAxis.Scaling.AutoMin = false;
            valueAxis.Scaling.Min     = 0;
            // Specify display units for the value axis.
            valueAxis.DisplayUnits.UnitType  = DisplayUnitType.Thousands;
            valueAxis.DisplayUnits.ShowLabel = true;

            // Hide the legend.
            chart.Legend.Visible = false;
            #endregion #ChangeChartAppearance
        }
Exemple #15
0
        public SymbolHelper GetLeadingAxis(AxisCollection axis, int address)
        {
            SymbolHelper retval = new SymbolHelper();

            foreach (AxisHelper ah in axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    retval.Y_axis_address = ah.Addressinfile;
                    retval.Y_axis_length  = ah.Length;
                }
            }
            return(retval);
        }
Exemple #16
0
        private bool AxisHasLeadingAxis(AxisCollection axis, int address, out int axisaddress)
        {
            bool retval = false;

            axisaddress = 0;
            foreach (AxisHelper ah in m_axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    retval      = true;
                    axisaddress = ah.Addressinfile;
                }
            }
            return(retval);
        }
Exemple #17
0
        private void InitStandards()
        {
            Content             = new ContentCollection();
            AxisCollection      = new AxisCollection();
            Dr3dLightCollection = new Dr3dLightCollection();
            SeriesCollection    = new SeriesCollection();

            //	AxisCollection.Inserted      += new ZipStream.CollectionWithEvents.CollectionChange (AxisCollection_Inserted);
            //    AxisCollection.Removed       += new ZipStream.CollectionWithEvents.CollectionChange (AxisCollection_Removed);
            //	Dr3dLightCollection.Inserted += new ZipStream.CollectionWithEvents.CollectionChange (Dr3dLightCollection_Inserted);
            //    Dr3dLightCollection.Removed  += new ZipStream.CollectionWithEvents.CollectionChange (Dr3dLightCollection_Removed);
            //	SeriesCollection.Inserted    += new ZipStream.CollectionWithEvents.CollectionChange (SeriesCollection_Inserted);
            //	SeriesCollection.Removed     += new ZipStream.CollectionWithEvents.CollectionChange (SeriesCollection_Removed);
            Content.Inserted += Content_Inserted;
            Content.Removed  += Content_Removed;
        }
Exemple #18
0
        public ChartControlViewModelDesign()
        {
            //
            IsAnnotationsVisible   = true;
            IsToZoomXAxisOnly      = false;
            IsAntialiasingEnabled  = true;
            StrokeThickness        = 1;
            SelectedResamplingMode = ResamplingMode.MinMax;
            IsMarkersVisible       = false;

            //
            InitializeCommands();

            //
            DiscreteSeries = new ObservableCollection <IChartSeriesViewModel>();
            AnalogSeries   = new ObservableCollection <IChartSeriesViewModel>();

            DiscreteSeriesAdditionalData = new ObservableCollection <ISeriesAdditionalData>();
            AnalogSeriesAdditionalData   = new ObservableCollection <ISeriesAdditionalData>();

            RpdAnalogSeriesViewModels   = new ObservableCollection <IRpdChartSeriesViewModel>();
            RpdDiscreteSeriesViewModels = new ObservableCollection <IDiscreteChartSeriesViewModel>();


            YAxes = new AxisCollection()
            {
                new NumericAxis()
                {
                    Id            = ChartControlViewModel.MainYAxisId,
                    IsPrimaryAxis = true,
                    AutoRange     = AutoRange.Once,
                    AxisAlignment = AxisAlignment.Left,
                }
            };

            ColorsBrush         = new ObservableCollection <SolidColorBrush>();
            AllThemes           = new string[] { };
            StrokeThicknesses   = new int[] { };
            SharedXVisibleRange = new DateRange(DateTime.Now, DateTime.Now + TimeSpan.FromMinutes(12));
            AutoRange           = new AutoRange();
            BindingTest         = new object();
            ChartModifiers      = new ObservableCollection <IChartModifier>();
            Bookmarks           = new ObservableCollection <ChartBookmarkViewModel>();

            GenerateSampleData();
        }
Exemple #19
0
        public void GetAxisDescr(AxisCollection axis, int address, out string xdescr, out string ydescr)
        {
            xdescr = "";
            ydescr = "";

            // let's see if there are leading axis info to this table

            foreach (AxisHelper ah in axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    // this is an axis for this table...
                    // see if there is another one that leads
                    int[]  yaxis;
                    string y_descr = string.Empty;
                    if (Helpers.Instance.AxisHasLeadingAxis(axis, ah.Addressinfile, out yaxis, out y_descr))
                    {
                        ydescr = y_descr;
                        if (ah.Descr != string.Empty)
                        {
                            xdescr = ah.Descr;
                        }
                        else
                        {
                            xdescr = ah.Identifier.ToString();
                        }
                    }
                    else
                    {
                        if (ah.Descr != string.Empty)
                        {
                            xdescr = ah.Descr;
                        }
                        else
                        {
                            xdescr = ah.Identifier.ToString();
                        }
                    }
                }
            }
        }
        private void ParseCSVFile(string sourcefile, SymbolCollection symbols, AxisCollection axis, bool applyOffset)
        {
            // parses information from a CSV file
            char[] sep = new char[1];
            sep.SetValue(',', 0);
            if (File.Exists(sourcefile))
            {
                string[] lines = File.ReadAllLines(sourcefile);
                //"ID","Address","Name","Size","Organization","Description","Units","X Units","Y Units","Scale","X Scale","Y Scale","Value min","Value max","Value min*1","Value max*1",
                //"A0","0x15b28","Übertragungsfunktionskoeffizient","1x1","16 Bit (LoHi)","","-","-","-","1.9073486328125E-6","1.0","1.0","0.0308074951171875","0.0308074951171875","0x3f18","0x3f18",
                foreach (string line in lines)
                {
                    string[] values        = line.Split(sep);
                    int      addressinFile = Convert.ToInt32(values.GetValue(1).ToString().Trim().Replace("0x", ""), 16);
                    string   name          = values.GetValue(2).ToString().Trim();
                    string   description   = values.GetValue(5).ToString().Trim();
                    foreach (SymbolHelper sh in symbols)
                    {
                        if (sh.Flash_start_address == addressinFile)
                        {
                            sh.Varname /*.UserDescription*/ = ReplaceForeignCharacters(name);
                            sh.Description = ReplaceForeignCharacters(description);
                            if (sh.Varname /*.UserDescription*/.Contains("."))
                            {
                                try
                                {
                                    sh.Category = sh.Varname /*.UserDescription*/.Substring(0, sh.Varname /*.UserDescription*/.IndexOf("."));
                                }
                                catch (Exception cE)
                                {
                                    Console.WriteLine("Failed to assign category to symbol: " + sh.Varname + " err: " + cE.Message);
                                }
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemple #21
0
        private void LoadLH24File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // Get axis table from the binary
            // find 0x00 0x08 0x018 0x20 0x28 0x2E 0x32 to find the addresstable
            int readstate = 0;
            int lookuptablestartaddress = 0x00;
            int axisaddress             = 0;

            readstate  = 0;
            axis       = new AxisCollection();
            m_tempaxis = new AxisCollection();
            symbols    = new SymbolCollection();



            FileStream fs = new FileStream(filename, FileMode.Open);

            using (BinaryReader br = new BinaryReader(fs))
            {
                for (int t = 0; t < fs.Length; t++)
                {
                    byte b = br.ReadByte();
                    //00 02 05 07

                    switch (readstate)
                    {
                    case 0:
                        if (b == 0x00)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 1:
                        Console.WriteLine("readstate = 1");
                        if (b == 0x08)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 2:
                        Console.WriteLine("readstate = 2 @ address: " + t.ToString("X4"));
                        if (b == 0x18)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 3:
                        Console.WriteLine("readstate = 3 @ address: " + t.ToString("X4"));
                        if (b == 0x20)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 4:
                        Console.WriteLine("readstate = 4 @ address: " + t.ToString("X4"));
                        if (b == 0x28)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 5:
                        Console.WriteLine("readstate = 5 @ address: " + t.ToString("X4"));
                        if (b == 0x2E)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 6:
                        Console.WriteLine("readstate = 6 @ address: " + t.ToString("X4"));
                        if (b == 0x32)
                        {
                            readstate++;
                            t += 21;
                            fs.Seek(21, SeekOrigin.Current);
                            lookuptablestartaddress = t + 1;
                            //fs.Position = fs.Position + 21;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 7:
                        Console.WriteLine("readstate = 7 @ address: " + t.ToString("X4"));
                        // we're reading addresses now
                        if (b < 0x30 || b > 0x3F)
                        {
                            // end of table... stop reading
                            readstate = 9;
                        }
                        else
                        {
                            axisaddress = (int)b * 256;
                            readstate   = 8;
                        }
                        break;

                    case 8:
                        axisaddress += (int)b;
                        AxisHelper ah = new AxisHelper();
                        Console.WriteLine("Axis address: " + axisaddress.ToString("X4"));

                        ah.Addressinfile = axisaddress;
                        m_tempaxis.Add(ah);
                        axisaddress = 0;
                        readstate   = 7;
                        break;

                    case 9:
                        break;

                    default:
                        break;
                    }
                }
            }
            fs.Close();
            fs.Dispose();
            // now read all axis addresses upto the end marker
            SetProgressPercentage("Adding axis", 40);

            SymbolCollection m_Unknown_symbols = new SymbolCollection();

            foreach (AxisHelper ah in m_tempaxis)
            {
                // get the address information for this axus
                //Console.WriteLine("Filling information for axis at address: " + ah.Addressinfile.ToString("X4"));
                if (FillAxisInformation(filename, ah))
                {
                    axis.Add(ah);
                }
                else
                {
                    SymbolHelper sh = new SymbolHelper();
                    sh.Flash_start_address = ah.Addressinfile;
                    sh.Varname             = sh.Flash_start_address.ToString("X4");
                    m_Unknown_symbols.Add(sh);
                    // later we have to add length to it based on next found value
                }
            }
            // add secondary (Y) axis stuff that may not be in the lookup table
            m_tempaxis = new AxisCollection();
            foreach (AxisHelper ah in axis)
            {
                int newaxisstart = ah.Addressinfile + ah.Length + 2;
                if (Helpers.Instance.CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length))
                {
                    //Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4"));
                    AxisHelper ahnew = new AxisHelper();
                    ahnew.Addressinfile = newaxisstart;
                    m_tempaxis.Add(ahnew);
                }
            }
            SetProgressPercentage("Adding axis, 2nd run", 50);

            // alsnog toevoegen aan collectie
            foreach (AxisHelper ahnew in m_tempaxis)
            {
                if (FillAxisInformation(filename, ahnew))
                {
                    axis.Add(ahnew);
                }
            }
            SetProgressPercentage("Analyzing structure", 60);

            foreach (SymbolHelper sh in m_Unknown_symbols)
            {
                sh.Length = Helpers.Instance.FindFirstAddressInLists(sh.Flash_start_address, m_axis, m_Unknown_symbols) - sh.Flash_start_address;
                sh.Cols   = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                sh.Rows   = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                m_symbols.Add(sh);
            }

            // now determine the gaps in the axis structure
            SetProgressPercentage("Determining maps", 80);

            axis.SortColumn   = "Addressinfile";
            axis.SortingOrder = GenericComparer.SortOrder.Ascending;
            axis.Sort();
            int        address            = 0;
            int        length             = 0;
            AxisHelper previousAxisHelper = new AxisHelper();
            int        symbolnumber       = 0;

            foreach (AxisHelper ah in axis)
            {
                /*SymbolHelper shaxis = new SymbolHelper();
                 * shaxis.Flash_start_address = ah.Addressinfile;
                 * shaxis.Varname = shaxis.Flash_start_address.ToString("X4");
                 * shaxis.Length = ah.Length;
                 * _workingFile.Symbols.Add(shaxis);*/

                if (address != 0)
                {
                    // is there a gap?
                    int endofpreviousaxis = address + length + 2;

                    if (endofpreviousaxis < ah.Addressinfile)
                    {
                        int gaplen = ah.Addressinfile - endofpreviousaxis;
                        //Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                        //Console.WriteLine("AXIS: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());

                        /*if (endofpreviousaxis == 0xFCC5)
                         * {
                         *  Console.WriteLine("PREV AXIS ADDRESS: "+ previousAxisHelper.Addressinfile.ToString("X4"));
                         *  Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                         * }*/
                        //                        Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                        SymbolHelper sh = new SymbolHelper();
                        sh.Varname       = endofpreviousaxis.ToString("X4");
                        sh.Length        = gaplen;
                        sh.Symbol_number = symbolnumber++;

                        sh.Flash_start_address = endofpreviousaxis;
                        sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                        sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);

                        /*if (sh.Length == 256)
                         * {
                         *  sh.Cols = 16;
                         *  sh.Rows = 16;
                         *  if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC43)
                         *  {
                         *      // there are 4 maps with this size in Motronic 4.3
                         *      // the one that had lots of 127 values in it is the VE map
                         *      // and has a correction factor of 1/127 (lambda = 1)
                         *      // the others are ignition maps and have a correction factor of 0.75 ??
                         *      if (FileTools.Instance.MapContainsMostly(filename, sh, 127))
                         *      {
                         *          sh.Varname = "VE map";
                         *          sh.Category = "Fuel";
                         *      }
                         *      else
                         *      {
                         *          sh.Varname = "Ignition map";
                         *          sh.Category = "Ignition";
                         *      }
                         *
                         *
                         *  }
                         * }
                         * else if (sh.Length == 144)
                         * {
                         *  sh.Cols = 12;
                         *  sh.Rows = 12;
                         * }
                         * else if (sh.Length == 128)
                         * {
                         *  sh.Cols = 16;
                         *  sh.Rows = 8;
                         *  if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC43)
                         *  {
                         *      sh.Varname = "Boost map";
                         *      sh.Category = "Boost";
                         *  }
                         * }
                         * else if (sh.Length == 84)
                         * {
                         *  sh.Cols = 7;
                         *  sh.Rows = 12;
                         * }
                         * else if (sh.Length == 80)
                         * {
                         *  sh.Cols = 5;
                         *  sh.Rows = 16;
                         * }
                         * else if (sh.Length == 70)
                         * {
                         *  sh.Cols = 7;
                         *  sh.Rows = 10;
                         * }
                         * else if (sh.Length == 64)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 8;
                         * }
                         * else if (sh.Length == 50)
                         * {
                         *  sh.Cols = 10;
                         *  sh.Rows = 5;
                         * }
                         * else if (sh.Length == 48)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 6;
                         * }
                         * else if (sh.Length == 42)
                         * {
                         *  sh.Cols = 6;
                         *  sh.Rows = 7;
                         * }
                         * else if (sh.Length == 40)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 5;
                         * }
                         * else
                         * {
                         *  sh.Cols = sh.Length;
                         *  sh.Rows = 1;
                         * }*/
                        symbols.Add(sh);
                    }
                }
                length             = ah.Length;
                address            = ah.Addressinfile;
                previousAxisHelper = ah;
            }
            // try to determine ignition maps probablility
            SymbolCollection ignition_maps = new SymbolCollection();

            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Varname == "Ignition map")
                {
                    sh.Average_value = Helpers.Instance.DetermineAverageMapValue(filename, sh);
                    ignition_maps.Add(sh);
                }
            }
            ignition_maps.SortColumn   = "Average_value";
            ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending;
            ignition_maps.Sort();
            if (ignition_maps.Count == 3)
            {
                ignition_maps[0].Varname = "Ignition map: Warmup";
                Console.WriteLine("Warmup map avg: " + ignition_maps[0].Average_value.ToString("F3") + " address: " + ignition_maps[0].Flash_start_address.ToString());
                ignition_maps[1].Varname = "Ignition map: Normal";
                Console.WriteLine("Normal map avg: " + ignition_maps[1].Average_value.ToString("F3") + " address: " + ignition_maps[1].Flash_start_address.ToString());
                ignition_maps[2].Varname = "Ignition map: Knocking";
                Console.WriteLine("Knock map avg: " + ignition_maps[2].Average_value.ToString("F3") + " address: " + ignition_maps[2].Flash_start_address.ToString());
            }
            foreach (SymbolHelper sh in ignition_maps)
            {
                foreach (SymbolHelper shorg in symbols)
                {
                    if (sh.Flash_start_address == shorg.Flash_start_address)
                    {
                        shorg.Varname = sh.Varname;
                        break;
                    }
                }
            }

            SetProgressPercentage("Sorting data", 90);
            // sort the symbol on length, biggest on top
            symbols.SortColumn   = "Length";
            symbols.SortingOrder = GenericComparer.SortOrder.Descending;
            symbols.Sort();
        }
        private void ParseDamosFile(string sourcefile, SymbolCollection symbols, AxisCollection axis, bool applyOffset)
        {
            // parses information from .damos file
            char[] sep = new char[1];
            sep.SetValue(',', 0);
            int    symbolindex        = 0;
            bool   _nextLineIsAddress = false;
            bool   _isAxisType        = false;
            bool   _isMapType         = false;
            string currMapName        = string.Empty;

            if (File.Exists(sourcefile))
            {
                string[] lines = File.ReadAllLines(sourcefile, Encoding.GetEncoding("ISO-8859-1"));
                foreach (string line in lines)
                {
                    string[] values = line.Split(sep);
                    // check if 1st value is numeric and number of values >= 4
                    if (values.Length >= 2)
                    {
                        if (_nextLineIsAddress)
                        {
                            // $C8FE,$C8FE
                            //Console.WriteLine(line);
                            if (line.StartsWith("$"))
                            {
                                _nextLineIsAddress = false;
                                int fromAddress = 0;
                                int uptoAddress = 0;
                                try
                                {
                                    fromAddress = Convert.ToInt32(values.GetValue(0).ToString().Trim().Replace("$", ""), 16);
                                    uptoAddress = Convert.ToInt32(values.GetValue(1).ToString().Trim().Replace("$", ""), 16);
                                    if (applyOffset)
                                    {
                                        if (uptoAddress < 0x10000)
                                        {
                                            uptoAddress += 0xDE;
                                            fromAddress += 0xDE;
                                        }
                                        else
                                        {
                                            uptoAddress -= 0x01;
                                            fromAddress -= 0x01;
                                        }
                                    }
                                    if (fromAddress != 0 && uptoAddress != 0)
                                    {
                                        bool _fnd = false;
                                        foreach (SymbolHelper sh in symbols)
                                        {
                                            if (sh.Flash_start_address == uptoAddress)
                                            {
                                                sh.Varname /*.UserDescription*/ = currMapName;
                                                //Console.WriteLine("Userdescription for : " + sh.Varname);
                                                if (sh.Varname /*.UserDescription*/.Contains("."))
                                                {
                                                    try
                                                    {
                                                        sh.Category = sh.Varname /*.UserDescription*/.Substring(0, sh.Varname /*UserDescription*/.IndexOf("."));
                                                    }
                                                    catch (Exception cE)
                                                    {
                                                        Console.WriteLine("Failed to assign category to symbol: " + sh.Varname + " err: " + cE.Message);
                                                    }
                                                }
                                                if (sh.Length == 0x3B)
                                                {
                                                    //sh.Cols = 9;
                                                    //sh.Rows = 5;
                                                    sh.Length = 42;
                                                    sh.Cols   = 7;
                                                    sh.Rows   = 6; // overrule PID maps
                                                }
                                                _fnd = true;
                                                break;
                                            }
                                        }
                                        foreach (AxisHelper ah in axis)
                                        {
                                            if (ah.Addressinfile == uptoAddress)
                                            {
                                                ah.Descr      = currMapName;
                                                ah.M44DamosID = symbolindex;
                                                _fnd          = true;
                                                break;
                                            }
                                        }
                                        if (!_fnd)
                                        {
                                            SymbolHelper sh = new SymbolHelper();
                                            sh.Varname = uptoAddress.ToString("X4");
                                            sh.Varname /*.UserDescription*/ = currMapName;
                                            sh.Flash_start_address          = uptoAddress;
                                            sh.Length = uptoAddress - fromAddress + 1;
                                            if (sh.Length == 1) // if offset ... settings are distorted, we need another damos file for this
                                            {
                                                //Console.WriteLine("Len 1: " + currMapName + " " + " at " + sh.Flash_start_address.ToString("X8"));
                                                sh.Varname /*.UserDescription*/ = "Settings and options." + sh.Varname /*.UserDescription*/;
                                            }
                                            if (sh.Length <= 0x100)
                                            {
                                                // Console.WriteLine("Adding : " + sh.Varname);
                                                if (sh.Varname /*.UserDescription*/.Contains("."))
                                                {
                                                    try
                                                    {
                                                        sh.Category = sh.Varname /*.UserDescription*/.Substring(0, sh.Varname /*.UserDescription*/.IndexOf("."));
                                                    }
                                                    catch (Exception cE)
                                                    {
                                                        Console.WriteLine("Failed to assign category to symbol: " + sh.Varname + " err: " + cE.Message);
                                                    }
                                                }
                                                if (sh.Length > 1 || !applyOffset)
                                                {
                                                    symbols.Add(sh);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception E)
                                {
                                    Console.WriteLine("Failed to interpret " + line + " as addressline: " + E.Message);
                                }
                            }
                        }

                        else if (!line.StartsWith("/"))
                        {
                            if (values.Length >= 4)
                            {
                                _isMapType  = false;
                                _isAxisType = false;
                                if (Int32.TryParse(values.GetValue(0).ToString(), out symbolindex))
                                {
                                    currMapName = values.GetValue(3).ToString().Replace("{", "").Replace("}", "").Trim();
                                    currMapName = ReplaceForeignCharacters(currMapName);

                                    /* if (currMapName == "Erhohung Luftvorsteuerung b Kat-Heizung")
                                     * {
                                     *   Console.WriteLine("Erhohung Luftvorsteuerung b Kat-Heizung");
                                     * }*/
                                    _nextLineIsAddress = true;

                                    int mapType = 0;
                                    if (values.Length > 4)
                                    {
                                        if (Int32.TryParse(values.GetValue(4).ToString(), out mapType))
                                        {
                                            // mapType 6 means support points... try to add these later to the maps
                                            if (mapType == 6)
                                            {
                                                _isAxisType = true;
                                            }
                                            else
                                            {
                                                _isMapType = true;
                                            }
                                        }
                                    }

                                    /*else
                                     * {
                                     *  // toevoegen?
                                     *  currMapName = values.GetValue(3).ToString().Replace("{", "").Replace("}", "").Trim();
                                     *  currMapName = ReplaceForeignCharacters(currMapName);
                                     *  Console.WriteLine("Ignoring: " + currMapName);
                                     * // _nextLineIsAddress = true;
                                     * }*/
                                }
                            }
                        }
                        if (_isAxisType)
                        {
                            /*if (line.StartsWith("/SPX"))
                             * {
                             *  _isAxisType = false;
                             *  // which one did it belong to?
                             *  try
                             *  {
                             *      int axisID = Convert.ToInt32(values.GetValue(1));
                             *      // assign it to the current map
                             *      foreach (AxisHelper ah in axis)
                             *      {
                             *          if (ah.Descr == currMapName)
                             *          {
                             *              ah.M44DamosID = axisID;
                             *          }
                             *      }
                             *  }
                             *  catch (Exception E)
                             *  {
                             *      Console.WriteLine("Failed to determine axisID: " + line);
                             *  }
                             * }*/
                        }
                        if (_isMapType)
                        {
                            if (line.StartsWith("/SPX"))
                            {
                                // which one did it belong to?
                                try
                                {
                                    int axisID = Convert.ToInt32(values.GetValue(5));
                                    // assign it to the current map
                                    foreach (SymbolHelper sh in symbols)
                                    {
                                        if (sh.Varname /*.UserDescription*/ == currMapName)
                                        {
                                            sh.M44DamosXAxisID = axisID;
                                            break;
                                        }
                                    }
                                }
                                catch (Exception E)
                                {
                                    Console.WriteLine("Failed to determine map X axisID: " + line);
                                }
                            }
                            else if (line.StartsWith("/SPY"))
                            {
                                _isMapType = false; // we got it.
                                // which one did it belong to?
                                try
                                {
                                    int axisID = Convert.ToInt32(values.GetValue(5));
                                    // assign it to the current map
                                    foreach (SymbolHelper sh in symbols)
                                    {
                                        if (sh.Varname /*.UserDescription*/ == currMapName)
                                        {
                                            sh.M44DamosYAxisID = axisID;
                                            break;
                                        }
                                    }
                                }
                                catch (Exception E)
                                {
                                    Console.WriteLine("Failed to determine map Y axisID: " + line);
                                }
                            }
                        }
                    }
                }

                // now link all axis and maps together
                foreach (SymbolHelper sh in symbols)
                {
                    if (sh.M44DamosXAxisID > 0)
                    {
                        foreach (AxisHelper ah in axis)
                        {
                            if (ah.M44DamosID == sh.M44DamosYAxisID && sh.Rows == ah.Length) // length
                            {
                                sh.X_axis_address = ah.Addressinfile;
                                sh.X_axis_length  = ah.Length;
                                //ah.CalculateRealValues();
                                // sh.XDescr = ah.Descr;
                                break;
                            }
                        }
                    }
                    if (sh.M44DamosYAxisID > 0)
                    {
                        foreach (AxisHelper ah in axis)
                        {
                            if (ah.M44DamosID == sh.M44DamosXAxisID && sh.Cols == ah.Length)
                            {
                                sh.Y_axis_address = ah.Addressinfile;
                                sh.Y_axis_length  = ah.Length;
                                //ah.CalculateRealValues();
                                // sh.YDescr = ah.Descr;
                                break;
                            }
                        }
                    }
                }
            }
        }
        public void FillSymbolCollection(string sourcefile, SourceType type, SymbolCollection symbols, AxisCollection axis, bool applyOffset)
        {
            switch (type)
            {
            case SourceType.CSV:
                ParseCSVFile(sourcefile, symbols, axis, applyOffset);
                break;

            case SourceType.Damos:
                ParseDamosFile(sourcefile, symbols, axis, applyOffset);
                break;
            }
        }
Exemple #24
0
        public TrackToShow()
        {
            XAxisCollection = new AxisCollection();
            YAxis = new NumericAxis
            {
                DrawMajorTicks = false,
                AxisAlignment = AxisAlignment.Left,
                FlipCoordinates = true,
                MinimalZoomConstrain = 1,
                Name = "yAxisDesign",
            };

            HasCurves = false;
            ChartModifier = new ModifierGroup();

            SeriesModifier = new SeriesSelectionModifier
            {
                ReceiveHandledEvents = true
            };
            ScaleModifier = new ScaleFactorModifier
            {
                ReceiveHandledEvents = true
            };
            ZoomPanModifier = new ZoomPanModifierExtension
            {
                ReceiveHandledEvents = true,
                ClipModeX = ClipMode.None,
                ExecuteOn = ExecuteOn.MouseLeftButton,
                IsEnabled = true,
                XyDirection = XyDirection.YDirection,
                ZoomExtentsY = true
            };

            LegendModifier = new LegendModifier
            {
                GetLegendDataFor = SourceMode.AllSeries
            };
            MouseWheelModifier = new MouseWheelZoomModifier
            {
                ReceiveHandledEvents = true,
                XyDirection = XyDirection.YDirection
            };
            ZoomModifier = new ZoomExtentsModifier
            {
                ReceiveHandledEvents = true,
                XyDirection = XyDirection.YDirection
            };
            TooltipModifierObject = new TooltipModifier
            {
                UseInterpolation = true
            };

            TooltipModifierObject.TooltipLabelTemplate = GetTooltipLabelTemplate();

            ChartModifier.ChildModifiers.Add(SeriesModifier);
            ChartModifier.ChildModifiers.Add(ScaleModifier);
            ChartModifier.ChildModifiers.Add(ZoomPanModifier);
            ChartModifier.ChildModifiers.Add(LegendModifier);
            ChartModifier.ChildModifiers.Add(MouseWheelModifier);
            ChartModifier.ChildModifiers.Add(ZoomModifier);
            ChartModifier.ChildModifiers.Add(TooltipModifierObject);
            ChartModifier.ChildModifiers.Add(ExtendedTooltipModifier);
        }
Exemple #25
0
        private void LoadLH242File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // parse the file and find the sequence 22 A2 E0 C2 E0 90 MM MM in which MM MM is the map table pointer
            axis       = new AxisCollection();
            m_tempaxis = new AxisCollection();
            symbols    = new SymbolCollection();
            Int32 MapTablePointer = GetLH242MapTablepointer(filename);

            if (MapTablePointer != 0)
            {
                //MessageBox.Show("LH242 maptable pointer: " + MapTablePointer.ToString("X4"));
                // read map addresses from this point on until we find an invalid address or 0x00 0x00
                FileStream fs = new FileStream(filename, FileMode.Open);
                fs.Position = MapTablePointer;
                using (BinaryReader br = new BinaryReader(fs))
                {
                    bool invalidAddress = false;
                    while (!invalidAddress)
                    {
                        int   val        = Convert.ToInt32((byte)br.ReadByte());
                        int   val2       = Convert.ToInt32((byte)br.ReadByte());
                        Int32 addressfnd = (val * 256) + val2;
                        if (addressfnd > 0 && addressfnd < 0x8000)
                        {
                            //if (Helpers.Instance.CheckForAxisPresent(filename, addressfnd))
                            //{
                            AxisHelper ah = new AxisHelper();
                            ah.Addressinfile = addressfnd;
                            ah.IsLH242       = true;
                            m_tempaxis.Add(ah);

                            /*}
                             * else
                             * {
                             *  SymbolHelper sh = new SymbolHelper();
                             *  sh.Varname = addressfnd.ToString("X4");
                             *  sh.Flash_start_address = addressfnd;
                             *  symbols.Add(sh);
                             * }*/
                        }
                        else
                        {
                            invalidAddress = true;
                        }
                    }
                }
                fs.Close();
                fs.Dispose();
                // check all axis for a second axis and mapdata
                SymbolCollection m_Unknown_symbols = new SymbolCollection();
                foreach (AxisHelper ah in m_tempaxis)
                {
                    // get the address information for this axus
                    //Console.WriteLine("Filling information for axis at address: " + ah.Addressinfile.ToString("X4"));
                    if (FillAxisInformation(filename, ah))
                    {
                        axis.Add(ah);
                    }
                    else
                    {
                        SymbolHelper sh = new SymbolHelper();
                        sh.Flash_start_address = ah.Addressinfile;
                        sh.Varname             = sh.Flash_start_address.ToString("X4");
                        m_Unknown_symbols.Add(sh);
                        // later we have to add length to it based on next found value
                    }
                }

                // copied from old routine
                m_tempaxis = new AxisCollection();
                foreach (AxisHelper ah in axis)
                {
                    int newaxisstart = ah.Addressinfile + ah.Length + 2;
                    if (Helpers.Instance.CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length))
                    {
                        //Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4"));
                        AxisHelper ahnew = new AxisHelper();
                        ahnew.IsLH242       = true;
                        ahnew.Addressinfile = newaxisstart;
                        m_tempaxis.Add(ahnew);
                    }
                }
                // alsnog toevoegen aan collectie
                foreach (AxisHelper ahnew in m_tempaxis)
                {
                    if (FillAxisInformation(filename, ahnew))
                    {
                        axis.Add(ahnew);
                    }
                }
                SetProgressPercentage("Analyzing structure", 60);

                foreach (SymbolHelper sh in m_Unknown_symbols)
                {
                    sh.Length = Helpers.Instance.FindFirstAddressInLists(sh.Flash_start_address, m_axis, m_Unknown_symbols) - sh.Flash_start_address;
                    sh.Cols   = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                    sh.Rows   = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                    if (sh.Length <= 0x200)
                    {
                        m_symbols.Add(sh);
                    }
                }

                SetProgressPercentage("Determining maps", 70);


                axis.SortColumn   = "Addressinfile";
                axis.SortingOrder = GenericComparer.SortOrder.Ascending;
                axis.Sort();
                int        address            = 0;
                int        length             = 0;
                AxisHelper previousAxisHelper = new AxisHelper();
                int        symbolnumber       = 0;
                foreach (AxisHelper ah in axis)
                {
                    /*SymbolHelper shaxis = new SymbolHelper();
                     * shaxis.Flash_start_address = ah.Addressinfile;
                     * shaxis.Varname = shaxis.Flash_start_address.ToString("X4");
                     * shaxis.Length = ah.Length;
                     * _workingFile.Symbols.Add(shaxis);*/

                    if (address != 0)
                    {
                        // is there a gap?
                        int endofpreviousaxis = address + length + 2;

                        if (endofpreviousaxis < ah.Addressinfile)
                        {
                            int gaplen = ah.Addressinfile - endofpreviousaxis;
                            Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                            //Console.WriteLine("AXIS: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());

                            /*if (endofpreviousaxis == 0xFCC5)
                             * {
                             *  Console.WriteLine("PREV AXIS ADDRESS: "+ previousAxisHelper.Addressinfile.ToString("X4"));
                             *  Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                             * }*/
                            //                        Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                            SymbolHelper sh = new SymbolHelper();
                            sh.Varname       = endofpreviousaxis.ToString("X4");
                            sh.Length        = gaplen;
                            sh.Symbol_number = symbolnumber++;

                            sh.Flash_start_address = endofpreviousaxis;
                            sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                            sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                            if (sh.Length == 0x100)
                            {
                                sh.Category = "Fuel";
                                sh.Varname  = "VE map";
                            }
                            symbols.Add(sh);
                        }
                    }
                    length             = ah.Length;
                    address            = ah.Addressinfile;
                    previousAxisHelper = ah;
                }
                // try to determine ignition maps probablility

                /*SymbolCollection ignition_maps = new SymbolCollection();
                 * foreach (SymbolHelper sh in symbols)
                 * {
                 *  if (sh.Varname == "Ignition map")
                 *  {
                 *      sh.Average_value = DetermineAverageMapValue(filename, sh);
                 *      ignition_maps.Add(sh);
                 *  }
                 * }
                 * ignition_maps.SortColumn = "Average_value";
                 * ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending;
                 * ignition_maps.Sort();
                 * if (ignition_maps.Count == 3)
                 * {
                 *  ignition_maps[0].Varname = "Ignition map: Warmup";
                 *  Console.WriteLine("Warmup map avg: " + ignition_maps[0].Average_value.ToString("F3") + " address: " + ignition_maps[0].Flash_start_address.ToString());
                 *  ignition_maps[1].Varname = "Ignition map: Normal";
                 *  Console.WriteLine("Normal map avg: " + ignition_maps[1].Average_value.ToString("F3") + " address: " + ignition_maps[1].Flash_start_address.ToString());
                 *  ignition_maps[2].Varname = "Ignition map: Knocking";
                 *  Console.WriteLine("Knock map avg: " + ignition_maps[2].Average_value.ToString("F3") + " address: " + ignition_maps[2].Flash_start_address.ToString());
                 * }
                 * foreach (SymbolHelper sh in ignition_maps)
                 * {
                 *  foreach (SymbolHelper shorg in symbols)
                 *  {
                 *      if (sh.Flash_start_address == shorg.Flash_start_address)
                 *      {
                 *          shorg.Varname = sh.Varname;
                 *          break;
                 *      }
                 *  }
                 * }*/

                SetProgressPercentage("Sorting data", 80);

                // sort the symbol on length, biggest on top
                symbols.SortColumn   = "Length";
                symbols.SortingOrder = GenericComparer.SortOrder.Descending;
                symbols.Sort();
                // end of copy
            }
        }
Exemple #26
0
        private void LoadM210File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // Get axis table from the binary
            // find 0x00 0x08 0x018 0x20 0x28 0x2E 0x32 to find the addresstable
            int readstate = 0;
            int lookuptablestartaddress = 0x00;
            int axisaddress             = 0;

            readstate  = 0;
            axis       = new AxisCollection();
            m_tempaxis = new AxisCollection();
            symbols    = new SymbolCollection();



            FileStream fs = new FileStream(filename, FileMode.Open);

            using (BinaryReader br = new BinaryReader(fs))
            {
                for (int t = 0; t < fs.Length; t++)
                {
                    byte b = br.ReadByte();
                    //00 02 05 07

                    switch (readstate)
                    {
                    case 0:
                        if (b == 0x00)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 1:
                        Console.WriteLine("readstate = 1");
                        if (b == 0x00)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 2:
                        Console.WriteLine("readstate = 2 @ address: " + t.ToString("X4"));
                        if (b == 0x02)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 3:
                        Console.WriteLine("readstate = 3 @ address: " + t.ToString("X4"));
                        if (b == 0x00)
                        {
                            readstate++;
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 4:
                        Console.WriteLine("readstate = 4 @ address: " + t.ToString("X4"));
                        if (b == 0x02)
                        {
                            readstate++;
                            lookuptablestartaddress = t + 1;
                            Console.WriteLine("lookuptablestartaddress" + fs.Position.ToString("X8"));
                        }
                        else
                        {
                            lookuptablestartaddress = 0x00;
                            readstate = 0;
                        }
                        break;

                    case 5:
                        //Console.WriteLine("readstate = 5 @ address: " + t.ToString("X4"));
                        // we're reading addresses now
                        if (b < 0xC8)
                        {
                            // end of table... stop reading
                            readstate = 7;
                        }
                        else
                        {
                            axisaddress = (int)b * 256;
                            readstate   = 6;
                        }
                        break;

                    case 6:
                        axisaddress += (int)b;
                        AxisHelper ah = new AxisHelper();
                        Console.WriteLine("Axis address: " + axisaddress.ToString("X4"));

                        ah.Addressinfile = axisaddress;
                        m_tempaxis.Add(ah);
                        axisaddress = 0;
                        readstate   = 5;
                        break;

                    case 7:
                        break;

                    default:
                        break;
                    }
                }
            }
            fs.Close();
            fs.Dispose();
            // now read all axis addresses upto the end marker
            SetProgressPercentage("Adding axis", 40);

            Console.WriteLine("Found addresses: " + m_tempaxis.Count);

            int duplicates = 0;

            foreach (AxisHelper ah in m_tempaxis)
            {
                int found = 0;
                foreach (AxisHelper bh in m_tempaxis)
                {
                    if (ah.Addressinfile == bh.Addressinfile)
                    {
                        ++found;
                    }
                }

                if (found > 1)
                {
                    Console.WriteLine((found - 1) + " duplicates for address " + ah.Addressinfile.ToString("X4"));
                    ++duplicates;
                }
            }

            Console.WriteLine("Duplicate addresses found: " + duplicates);


            SymbolCollection m_Unknown_symbols = new SymbolCollection();

            foreach (AxisHelper ah in m_tempaxis)
            {
                // get the address information for this axis
                //Console.WriteLine("Filling information for axis at address: " + ah.Addressinfile.ToString("X4"));
                ah.IsM210 = true;
                if (FillAxisInformation(filename, ah))
                {
                    axis.Add(ah);
                }
                else
                {
                    Console.WriteLine("Unknown symbol at: " + ah.Addressinfile);
                    SymbolHelper sh = new SymbolHelper();
                    sh.Flash_start_address = ah.Addressinfile;
                    sh.Varname             = sh.Flash_start_address.ToString("X4");
                    m_Unknown_symbols.Add(sh);
                    // later we have to add length to it based on next found value
                }
            }
            // add secondary (Y) axis stuff that may not be in the lookup table
            m_tempaxis = new AxisCollection();
            foreach (AxisHelper ah in axis)
            {
                int newaxisstart = ah.Addressinfile + ah.Length + 2;
                if (CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length))
                {
                    //Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4"));
                    AxisHelper ahnew = new AxisHelper();
                    ahnew.Addressinfile = newaxisstart;
                    m_tempaxis.Add(ahnew);
                }
            }
            SetProgressPercentage("Adding axis, 2nd run", 50);

            // alsnog toevoegen aan collectie
            foreach (AxisHelper ahnew in m_tempaxis)
            {
                ahnew.IsM210 = true;
                if (FillAxisInformation(filename, ahnew))
                {
                    axis.Add(ahnew);
                }
            }
            SetProgressPercentage("Analyzing structure", 60);

            foreach (SymbolHelper sh in m_Unknown_symbols)
            {
                sh.Length = Helpers.Instance.FindFirstAddressInLists(sh.Flash_start_address, m_axis, m_Unknown_symbols) - sh.Flash_start_address;
                sh.Cols   = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                sh.Rows   = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                m_symbols.Add(sh);
            }

            // now determine the gaps in the axis structure
            SetProgressPercentage("Determining maps", 80);

            axis.SortColumn   = "Addressinfile";
            axis.SortingOrder = GenericComparer.SortOrder.Ascending;
            axis.Sort();
            int        address            = 0;
            int        length             = 0;
            AxisHelper previousAxisHelper = new AxisHelper();
            int        symbolnumber       = 0;

            foreach (AxisHelper ah in axis)
            {
                /*SymbolHelper shaxis = new SymbolHelper();
                 * shaxis.Flash_start_address = ah.Addressinfile;
                 * shaxis.Varname = shaxis.Flash_start_address.ToString("X4");
                 * shaxis.Length = ah.Length;
                 * _workingFile.Symbols.Add(shaxis);*/

                //Console.WriteLine("axis address: " + ah.Addressinfile.ToString("X4"));

                if (address != 0)
                {
                    // is there a gap?
                    int endofpreviousaxis = address + length + 2;

                    if (ah.Addressinfile == 0xC88B)
                    {
                        Console.WriteLine("endofpreviousaxis " + endofpreviousaxis.ToString("X4") + "address " + address.ToString("X4") + "length " + length.ToString("X4"));
                    }

                    if (endofpreviousaxis < ah.Addressinfile)
                    {
                        int gaplen = ah.Addressinfile - endofpreviousaxis;
                        //Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                        //Console.WriteLine("AXIS: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());

                        /*if (endofpreviousaxis == 0xFCC5)
                         * {
                         *  Console.WriteLine("PREV AXIS ADDRESS: "+ previousAxisHelper.Addressinfile.ToString("X4"));
                         *  Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                         * }*/
                        //                        Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString());
                        SymbolHelper sh = new SymbolHelper();
                        sh.Varname       = endofpreviousaxis.ToString("X4");
                        sh.Length        = gaplen;
                        sh.Symbol_number = symbolnumber++;

                        sh.Flash_start_address = endofpreviousaxis;
                        sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                        sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                        if (sh.Length == 144)
                        {
                            sh.Cols = 12;
                            sh.Rows = 12;

                            // there are 4 maps with this size in Motronic 4.3
                            // the one that had lots of 127 values in it is the VE map
                            // and has a correction factor of 1/127 (lambda = 1)
                            // the others are ignition maps and have a correction factor of 0.75 ??
                            if (FileTools.Instance.LeftSideLowerThanRightSide(filename, sh, 12, 12))
                            {
                                sh.Varname  = "Fuel correction map";
                                sh.Category = "Fuel";
                            }
                            else
                            {
                                sh.Varname  = "Ignition map";
                                sh.Category = "Ignition";
                            }
                        }

                        /*
                         * else if (sh.Length == 144)
                         * {
                         *  sh.Cols = 12;
                         *  sh.Rows = 12;
                         * }
                         * else if (sh.Length == 128)
                         * {
                         *  sh.Cols = 16;
                         *  sh.Rows = 8;
                         *  if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC43)
                         *  {
                         *      sh.Varname = "Boost map";
                         *      sh.Category = "Boost";
                         *  }
                         * }
                         * else if (sh.Length == 84)
                         * {
                         *  sh.Cols = 7;
                         *  sh.Rows = 12;
                         * }
                         * else if (sh.Length == 80)
                         * {
                         *  sh.Cols = 5;
                         *  sh.Rows = 16;
                         * }
                         * else if (sh.Length == 70)
                         * {
                         *  sh.Cols = 7;
                         *  sh.Rows = 10;
                         * }
                         * else if (sh.Length == 64)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 8;
                         * }
                         * else if (sh.Length == 50)
                         * {
                         *  sh.Cols = 10;
                         *  sh.Rows = 5;
                         * }
                         * else if (sh.Length == 48)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 6;
                         * }
                         * else if (sh.Length == 42)
                         * {
                         *  sh.Cols = 6;
                         *  sh.Rows = 7;
                         * }
                         * else if (sh.Length == 40)
                         * {
                         *  sh.Cols = 8;
                         *  sh.Rows = 5;
                         * }
                         * else
                         * {
                         *  sh.Cols = sh.Length;
                         *  sh.Rows = 1;
                         * }*/
                        symbols.Add(sh);
                    }
                }
                length             = ah.Length;
                address            = ah.Addressinfile;
                previousAxisHelper = ah;
            }

            Console.WriteLine("Found symbols: " + symbols.Count);


            //add injector constant
            SymbolHelper sym = new SymbolHelper();

            sym.Varname  = "Injector constant";
            sym.Category = "Constants";
            sym.Length   = 1;
            //sh.Symbol_number = symbolnumber++;

            sym.Flash_start_address = 0xA005; //NOTE: this applies only for custom modified binary!
            sym.Cols = 1;
            sym.Rows = 1;
            symbols.Add(sym);


            foreach (SymbolHelper sh in symbols)
            {
                string xdescr = "";
                string ydescr = "";
                Helpers.Instance.GetAxisDescr(axis, sh.Flash_start_address, out xdescr, out ydescr);

                //Console.WriteLine("xdescr " + xdescr + " " + "ydescr " + ydescr);

                if (xdescr == "Coolant temperature [Unknown]" || ydescr == "Coolant temperature [Unknown]")
                {
                    sh.Category = "Temperature compensation";
                }
                else if (xdescr == "Coolant temp ADC value [raw ADC]" && ydescr == "")
                {
                    sh.Category = "Temperature compensation";
                    sh.Varname  = "Coolant sensor linearization";
                }
                else if (xdescr == "Battery voltage [Volt]" || ydescr == "Battery voltage [Volt]")
                {
                    sh.Category = "Battery voltage compensation";
                }

                if (sh.Flash_start_address == 0xC887)
                {
                    sh.Varname = "Engine running RPM limit";
                }
                if (sh.Flash_start_address == 0xC975)
                {
                    sh.Varname = "Cranking enrichment";
                }

                if (sh.Flash_start_address == 0xD047 ||
                    sh.Flash_start_address == 0xD063 ||
                    sh.Flash_start_address == 0xD35D ||
                    sh.Flash_start_address == 0xD379)
                {
                    sh.Varname = "Temperature compensation";
                }
            }

            // try to determine ignition maps probablility
            SymbolCollection ignition_maps = new SymbolCollection();

            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Varname == "Ignition map")
                {
                    sh.Average_value = Helpers.Instance.DetermineAverageMapValue(filename, sh);
                    ignition_maps.Add(sh);
                }
            }
            ignition_maps.SortColumn   = "Average_value";
            ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending;
            ignition_maps.Sort();
            if (ignition_maps.Count == 3)
            {
                ignition_maps[0].Varname = "Ignition map: Warmup";
                Console.WriteLine("Warmup map avg: " + ignition_maps[0].Average_value.ToString("F3") + " address: " + ignition_maps[0].Flash_start_address.ToString());
                ignition_maps[1].Varname = "Ignition map: Normal";
                Console.WriteLine("Normal map avg: " + ignition_maps[1].Average_value.ToString("F3") + " address: " + ignition_maps[1].Flash_start_address.ToString());
                ignition_maps[2].Varname = "Ignition map: Knocking";
                Console.WriteLine("Knock map avg: " + ignition_maps[2].Average_value.ToString("F3") + " address: " + ignition_maps[2].Flash_start_address.ToString());
            }
            foreach (SymbolHelper sh in ignition_maps)
            {
                foreach (SymbolHelper shorg in symbols)
                {
                    if (sh.Flash_start_address == shorg.Flash_start_address)
                    {
                        shorg.Varname = sh.Varname;
                        break;
                    }
                }
            }

            //findMapGroups(filename);

            SetProgressPercentage("Sorting data", 90);
            // sort the symbol on length, biggest on top
            symbols.SortColumn   = "Length";
            symbols.SortingOrder = GenericComparer.SortOrder.Descending;
            symbols.Sort();
        }
Exemple #27
0
        public SymbolHelper GetYAxisSymbol(string m_currentfile, SymbolCollection symbols, AxisCollection axis, string symbolname, int address)
        {
            SymbolHelper retval = new SymbolHelper();

            foreach (AxisHelper ah in axis)
            {
                int endaddress = ah.Addressinfile + ah.Length + 2;
                if (endaddress == address)
                {
                    // this is an axis for this table...
                    // see if there is another one that leads
                    int[]  yaxis;
                    string y_descr = string.Empty;
                    retval = GetLeadingAxis(axis, ah.Addressinfile);
                }
            }
            return(retval);
        }
Exemple #28
0
        /// <summary>
        /// Initializes the various properties of the class
        /// </summary>
        private void Init()
        {
            // Initialize colorSets
            //ColorSets = new ColorSets();

            // Initialize tooltip
            ToolTips = new ToolTipCollection();

            // Initialize title list
            Titles = new TitleCollection();

            // Initialize legend list
            Legends = new LegendCollection();

            // Initialize trendLine list
            TrendLines = new TrendLineCollection();

            // Initialize AxesX list
            AxesX = new AxisCollection();

            // Initialize AxesY list
            AxesY = new AxisCollection();

            // Initialize Series list
            Series = new DataSeriesCollection();

            // Initialize PlotArea
            PlotArea = new PlotArea() { Chart = this };

            // Attach event handler on collection changed event with ToolTip collection
            ToolTips.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ToolTips_CollectionChanged);

            // Attach event handler on collection changed event with Title collection
            Titles.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Titles_CollectionChanged);

            // Attach event handler on collection changed event with Legend collection
            Legends.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Legends_CollectionChanged);

            // Attach event handler on collection changed event with TrendLines collection
            TrendLines.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(TrendLines_CollectionChanged);

            // Attach event handler on collection changed event with DataSeries collection
            Series.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Series_CollectionChanged);

            // Attach event handler on collection changed event with axisX collection
            (AxesX as AxisCollection).CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AxesX_CollectionChanged);

            // Attach event handler on collection changed event with AxisY collection
            (AxesY as AxisCollection).CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AxesY_CollectionChanged);
        }