Esempio n. 1
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
            }
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
 /// <summary>
 /// Add a new axes to this chart area.
 /// </summary>
 /// <param name="axes"></param>
 public void AddAxes(Axis axes)
 {
     axes.ParentControl = this;
     Axes.Add(axes);
 }