Ejemplo 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

            }
        }
Ejemplo n.º 2
0
        private void ParseME700File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // parse the file and look for 0xE6 0xFC ?? ?? 0xF2 0xFD indicators for starters
            symbols = new SymbolCollection();
            axis = new AxisCollection();
            byte[] allBytes = File.ReadAllBytes(filename);
            int state = 0;
            for (int t = 0; t < allBytes.Length; t++)
            {
                switch (state)
                {
                    case 0:
                        if (allBytes[t] == 0xE6) state++;
                        break;
                    case 1:
                        if (allBytes[t] == 0xFC) state++;
                        break;
                    case 2:
                        //Console.WriteLine(allBytes[t + 2].ToString("X2") + " " + allBytes[t + 3].ToString("X2") + " " + allBytes[t + 1].ToString("X2") + allBytes[t].ToString("X2"));
                        if (allBytes[t + 2] == 0xF2 && allBytes[t + 3] == 0xFD)
                        {
                            SymbolHelper sh = new SymbolHelper();
                            sh.IsSixteenbits = true; // allways for ME7
                            sh.Varname = t.ToString("X8");
                            int address = Convert.ToInt32(allBytes[t + 1]) * 256;
                            address += Convert.ToInt32(allBytes[t]);
                            address += 0x10000;

                            if (address == 0x1196A)
                            {
                                Console.WriteLine("Found 1196A");
                            }
                            int ylength = (allBytes[address] + Convert.ToInt32(allBytes[address + 1]) * 256);
                            int xlength = (allBytes[address + 2] + Convert.ToInt32(allBytes[address + 3]) * 256);
                            sh.Length = ylength * xlength * 2;
                            if (sh.Length > 0 && sh.Length <= 0x200 && sh.Length != 0x90) // 0x90 length is not a map
                            {
                                sh.Y_axis_address = address/*sh.Flash_start_address*/ + 4;
                                sh.X_axis_address = address/*sh.Flash_start_address*/ + 4 + (2 * ylength);

                                sh.X_axis_length = xlength;
                                sh.Y_axis_length = ylength * 2;
                                sh.Flash_start_address = address + 4 + ylength * 2 + xlength * 2;
                                if (!CollectionContainsAddress(symbols, sh.Flash_start_address))
                                {
                                    symbols.Add(sh);
                                    /*if (sh.Flash_start_address == 0x1196A)
                                    {
                                        Console.WriteLine("Found 1196A");
                                    }*/
                                }
                                //Console.WriteLine("Address: " + address.ToString("X8"));

                            }

                        }
                        state = 0;
                        break;
                }
            }

            int IgnitionMapAddress = GetIgnitionMapAddress(allBytes);
            if (IgnitionMapAddress <= 0) IgnitionMapAddress = GetIgnitionMapAddress521KBFiles(allBytes);
            if (IgnitionMapAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                //sh.UserDescription = "Ignition map";
                sh.Varname = "Ignition.Ignition map [KFZW]";

                //sh.Description = "Main ignition map";
                sh.X_axis_length = 12;
                sh.Y_axis_length = 16;
                sh.Length = 0xC0;
                sh.X_axis_address = IgnitionMapAddress;
                sh.Y_axis_address = IgnitionMapAddress;
                sh.Flash_start_address = IgnitionMapAddress;
                symbols.Add(sh);
                sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                //sh.UserDescription = "Secondary ignition map";
                sh.Varname = "Ignition.Secondary ignition map [KFZW2]";
                sh.X_axis_length = 12;
                sh.Y_axis_length = 16;
                sh.Length = 0xC0;
                sh.X_axis_address = IgnitionMapAddress + 0xC0;
                sh.Y_axis_address = IgnitionMapAddress + 0xC0;
                sh.Flash_start_address = IgnitionMapAddress + 0xC0;
                symbols.Add(sh);
            }

            int LambdaRequestMapAddress = GetLambdaRequestMap(allBytes);

            if (LambdaRequestMapAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                // sh.UserDescription = "Lambda driver demand map";
                sh.Varname = "Fuel.Lambda driver demand map [LAMFA]";

                sh.X_axis_length = 6;
                sh.Y_axis_length = 15;
                sh.Length = 15 * 6;
                sh.X_axis_address = LambdaRequestMapAddress + 2;
                sh.Y_axis_address = LambdaRequestMapAddress + 17;
                sh.Flash_start_address = LambdaRequestMapAddress + 23 +7;
                symbols.Add(sh);
            }
            else
            {
                LambdaRequestMapAddress = GetLambdaRequestMap512KBFiles(allBytes);
                if (LambdaRequestMapAddress > 0)
                {
                    SymbolHelper sh = new SymbolHelper();
                    sh.IsSixteenbits = false;
                    // sh.UserDescription = "Lambda driver demand map";
                    sh.Varname = "Fuel.Lambda driver demand map [LAMFA]";
                    sh.X_axis_length = 6;
                    sh.Y_axis_length = 10;
                    sh.Length = 10 * 6;
                    sh.X_axis_address = LambdaRequestMapAddress + 2;
                    sh.Y_axis_address = LambdaRequestMapAddress + 12;
                    sh.Flash_start_address = LambdaRequestMapAddress +18 + 6;

                    /*sh.X_axis_length = 10;
                    sh.Y_axis_length = 6;
                    sh.Length = 10 * 6;
                    sh.X_axis_address = LambdaRequestMapAddress + 2;
                    sh.Y_axis_address = LambdaRequestMapAddress + 12;
                    sh.Flash_start_address = LambdaRequestMapAddress + 18;*/
                    symbols.Add(sh);
                }
            }

            int VEMapAddress = GetVEMap(allBytes);  //KFKHFM
            if (VEMapAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                sh.Varname = "Airmass.Air mass meter correction [KFKHFM]";
                sh.X_axis_length = 14;
                sh.Y_axis_length = 14;
                sh.Length = 14 * 14;
                sh.X_axis_address = VEMapAddress + 2;
                sh.Y_axis_address = VEMapAddress + 16;
                sh.Flash_start_address = VEMapAddress + 30;
                symbols.Add(sh);
            }

            int enrichmentMapAddress = GetEnrichmentMap(allBytes); //KFLBTS
            if (enrichmentMapAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                sh.Varname = "Fuel.Enrichment delta map [KFFDLBTS]";
                sh.X_axis_length = 16;
                sh.Y_axis_length = 12;
                sh.Length = 12 * 16;
                sh.X_axis_address = enrichmentMapAddress;
                sh.Y_axis_address = enrichmentMapAddress;
                sh.Flash_start_address = enrichmentMapAddress;
                symbols.Add(sh);

                sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                sh.Varname = "Fuel.Enrichment map [KFLBTS]";
                sh.X_axis_length = 16;
                sh.Y_axis_length = 12;
                sh.Length = 12 * 16;
                sh.X_axis_address = enrichmentMapAddress + 0xC0;
                sh.Y_axis_address = enrichmentMapAddress + 0xC0;
                sh.Flash_start_address = enrichmentMapAddress + 0xC0;
                symbols.Add(sh);

            }
            int KFLDIMX_Address = GetKFLDIMXMap(allBytes);
            if (KFLDIMX_Address > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = true;
                sh.Varname = "Boost.Boost control map (I limit) [KFLDIMX]";
                sh.X_axis_length = 8;
                sh.Y_axis_length = 16 * 2;
                sh.Length = 8 * 16;
                if (allBytes.Length == 0x80000)
                {
                    // small files have axis
                    sh.X_axis_address = KFLDIMX_Address + 4;
                    sh.Y_axis_address = KFLDIMX_Address + 4 + 8 * 2;
                    sh.Flash_start_address = KFLDIMX_Address + 4 + 8 * 2 + 16 * 2;
                }
                else
                {
                    sh.X_axis_address = KFLDIMX_Address;
                    sh.Y_axis_address = KFLDIMX_Address;
                    sh.Flash_start_address = KFLDIMX_Address;
                    // symbols.Add(sh);
                    /*sh = new SymbolHelper();
                    sh.IsSixteenbits = true;
                    sh.Varname = "Boost.Map for linearisation boost pressure = f(TV) [KFLDRL]";
                    sh.X_axis_length = 10;
                    sh.Y_axis_length = 16 * 2;
                    sh.Length = 10 * 16;
                    sh.X_axis_address = LDRXN_Address + 0x100;
                    sh.Y_axis_address = LDRXN_Address + 0x100;
                    sh.Flash_start_address = LDRXN_Address + 0x100;*/
                    // works only for the file we have a2l for
                }

                symbols.Add(sh);
            }

            int KFMIOPAddress = GetKFMIOPMap(allBytes);
            if (KFMIOPAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = true;
                sh.Varname = "Torque.Optimum engine torque map [KFMIOP]";
                sh.MapAllowsNegatives = false;
                sh.X_axis_length = 11;
                sh.Y_axis_length = 16 * 2;
                sh.Length = 11 * 16;
                sh.X_axis_address = KFMIOPAddress;
                sh.Y_axis_address = KFMIOPAddress;
                sh.Flash_start_address = KFMIOPAddress;
                symbols.Add(sh);
            }

            int LDRXNAddress = GetLDRXNMap(allBytes);
            if (LDRXNAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = true;
                sh.Varname = "Boost.Maximum load boost control [LDRXN]";
                sh.MapAllowsNegatives = false;
                sh.X_axis_length = 16;
                sh.Y_axis_length = 1 * 2;
                sh.Length = 16;
                sh.X_axis_address = LDRXNAddress;
                sh.Y_axis_address = LDRXNAddress;
                sh.Flash_start_address = LDRXNAddress;
                symbols.Add(sh);
            }
            int KFLDHBNAddress = GetKFLDHBNMap(allBytes);
            if (KFLDHBNAddress > 0)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.IsSixteenbits = false;
                sh.Varname = "Boost.Boost control limitation compression ratio turbocharger [KFLDHBN]";
                sh.MapAllowsNegatives = false;
                sh.X_axis_length = 8;
                sh.Y_axis_length = 8;
                sh.Length = 8 * 8;
                sh.X_axis_address = KFLDHBNAddress;
                sh.Y_axis_address = KFLDHBNAddress;
                sh.Flash_start_address = KFLDHBNAddress;
                symbols.Add(sh);
            }
            symbols.SortColumn = "Flash_start_address";
            symbols.SortingOrder = GenericComparer.SortOrder.Ascending;
            symbols.Sort();
            int countx180 = 0;
            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Length == 0x200)
                {
                    sh.Varname = "Boost.Target load map [KFMIRL]";
                }
                else if (sh.Length == 0x180)
                {
                    if (countx180 == 0) sh.Varname = "Throttle.Accelerator pedal map [KFPED]";
                    else if (countx180 == 1) sh.Varname = "Boost.Target load map [KFMIRL]";
                    countx180++;
                }
                else if (sh.Length == 0x100)
                {
                    sh.Varname = "Throttle.Accelerator pedal map AUT reverse [KFPEDR]";
                }
                else if (sh.Length == 0xF0)
                {
                    sh.Varname = "Torque.Engine drag torque map [KFMDS]";
                }
                else if (sh.Length == 0x60)
                {
                    sh.Varname = "Cruise.Speed offset for cruise control [KFVOFFS]";
                }
                else if (sh.Length == 0xC0 && sh.X_axis_length == 6 && sh.Y_axis_length == 32)
                {
                    sh.Varname = "Airmass.Normalized airmass flow via the throttle [KFMSNWDK]";
                }
                else if (sh.Length == 0x70 && sh.X_axis_length == 8 && sh.Y_axis_length == 14)
                {
                    sh.Varname = "Lambda.Lambda delay time [KFLRST]";
                }
                if (sh.Category == "Undocumented" || sh.Category == "")
                {
                    if (sh.Varname.Contains("."))
                    {
                        try
                        {
                            sh.Category = sh.Varname.Substring(0, sh.Varname.IndexOf("."));
                        }
                        catch (Exception cE)
                        {
                            Console.WriteLine("Failed to assign category to symbol: " + sh.Varname + " err: " + cE.Message);
                        }
                    }

                }
            }
        }
Ejemplo n.º 3
0
        private void LoadME7File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // this should detect the 4 different file types for ME7 (ME7.0 512Kb, ME7.0 1024Kb, ME7.0.1 version A and ME7.0.1 version B)
            // and parse them with a different algorithm.

            symbols = new SymbolCollection();
            axis = new AxisCollection();
            SetProgressPercentage("Analyzing structure", 30);

            byte[] allBytes = File.ReadAllBytes(filename);

            if (findSequence(allBytes, 0, new byte[7] { 0x4d, 0x45, 0x37, 0x5F, 0x35, 0x30, 0x30 }, new byte[7] { 1, 1, 1, 1, 1, 1, 1 }) > 0)
            {
                ParseME701File(filename, out symbols, out axis);
            }
            else
            {
                ParseME700File(filename, out symbols, out axis);
            }

            SetProgressPercentage("Sorting data", 90);
            // sort the symbol on length, biggest on top
            symbols.SortColumn = "Length";
            symbols.SortingOrder = GenericComparer.SortOrder.Descending;
            symbols.Sort();
        }
Ejemplo n.º 4
0
        private void LoadMotronic18File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            // Get axis table from the binary
            // $E328
            // find sequence 00 02 05 07
            int readstate = 0;
            int lookuptablestartaddress = 0x00;
            int axisaddress = 0;
            readstate = 0;
            axis = new AxisCollection();
            m_tempaxis = new AxisCollection();
            SymbolCollection m_tempSymbols = new SymbolCollection();
            symbols = new SymbolCollection();
            byte[] _fileParameters = new byte[256];
            int _fileParameterIndex = 0;

            byte[] datacheck = FileTools.Instance.readdatafromfile(filename, 0, 16, false);
            bool _fileValid = false;
            foreach (byte b in datacheck)
            {
                if (b != 0xFF) _fileValid = true;
            }
            if (!_fileValid)
            {
                frmInfoBox info = new frmInfoBox("This is not a M1.8 binary. These file types are not supported.");
                return;
            }
            int _fuelAndIgnitionAddress = 0;
            FileStream fs = new FileStream(filename, FileMode.Open);
            fs.Position = 0x7900;
            using (BinaryReader br = new BinaryReader(fs))
            {
                for (int t = 0x7900; t < fs.Length; t++)
                {
                    byte b = br.ReadByte();
                    //00 02 05 07

                    switch (readstate)
                    {
                        case 0:
                            // we're reading addresses now
                            if (b == 0xFF)
                            {
                                // end of table... stop reading
                                readstate = 2;
                            }
                            else
                            {
                                axisaddress = (int)b * 256;
                                readstate = 1;
                            }
                            break;
                        case 1:
                            axisaddress += (int)b;
                            if (axisaddress > 0x2000)
                            {
                                AxisHelper ah = new AxisHelper();
                                ah.IsM18 = true;
                                 Console.WriteLine("Axis address: " + axisaddress.ToString("X4"));
                                if (m_tempaxis.Count == 0) _fuelAndIgnitionAddress = axisaddress;
                                ah.Addressinfile = axisaddress;
                                m_tempaxis.Add(ah);
                            }
                            axisaddress = 0;
                            readstate = 0;
                            break;
                        case 2:
                            break;
                        default:
                            break;

                    }
                }
            }
            fs.Close();
            fs.Dispose();

            SetProgressPercentage("Analyzing structure", 30);
            // from here, read 3 times 0F and find the limiters from there

            //Console.WriteLine("Speed limiter: " + _fileParameters[118].ToString() + " km/h");

            // now read all axis addresses upto the end marker
            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))
                {
                    if (!Helpers.Instance.AxisPresentInCollection(ah.Addressinfile, axis))
                    {
                        axis.Add(ah);
                        Console.WriteLine("Added axis: " + ah.Addressinfile.ToString("X4"));
                    }
                }
                else
                {
                    Console.WriteLine("What to do with : " + ah.Addressinfile.ToString("X4"));
                    SymbolHelper sh = new SymbolHelper();
                    sh.Flash_start_address = ah.Addressinfile;
                    m_tempSymbols.Add(sh);
                }

            }
            SetProgressPercentage("Adding axis", 40);

            // 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;
                Console.WriteLine("Axis: " + ah.Addressinfile.ToString("X4") + " " + ah.Length.ToString());
                if (CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length))
                {
                    Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4"));
                    AxisHelper ahnew = new AxisHelper();
                    ahnew.IsM18 = true;
                    ahnew.Addressinfile = newaxisstart;
                    m_tempaxis.Add(ahnew);
                }
            }
            SetProgressPercentage("Adding axis, 2nd run", 60);
            // alsnog toevoegen aan collectie
            foreach (AxisHelper ahnew in m_tempaxis)
            {

                if (FillAxisInformation(filename, ahnew))
                {
                    if (!Helpers.Instance.AxisPresentInCollection(ahnew.Addressinfile, axis))
                    {
                        Console.WriteLine("Add to axis (3rd): " + ahnew.Addressinfile.ToString("X4"));
                        axis.Add(ahnew);
                    }
                }
            }

            // first pointer in the stack points to fuel and ignition maps!
            if (_fuelAndIgnitionAddress > 0)
            {

                SymbolHelper shfuel = new SymbolHelper();
                shfuel.Flash_start_address = _fuelAndIgnitionAddress;
                shfuel.Length = 256;
                shfuel.Varname = "Ignition map";
                shfuel.Cols = 16;
                shfuel.Rows = 16;
                shfuel.Category = "Ignition";
                symbols.Add(shfuel);

                // we need to manually add some axis to it as well.
                SymbolHelper shignition = new SymbolHelper();
                shignition.Flash_start_address = _fuelAndIgnitionAddress + 256;
                shignition.Length = 256;
                shignition.Cols = 16;
                shignition.Rows = 16;
                shignition.Varname = "VE map";
                shignition.Category = "Fuel";
                // we need to manually add some axis to it as well.
                symbols.Add(shignition);
            }

            // now determine the gaps in the axis structure

            axis.SortColumn = "Addressinfile";
            axis.SortingOrder = GenericComparer.SortOrder.Ascending;
            axis.Sort();

            //<GS-01032011> to correctly determine the LAST map in the sequence with this algoritm
            // we need to insert a dummy axis at the first address AFTER the data
            // check whether the two last axis in the collection join up to form a 3D map
            // otherwise its just a 2D map
            if (axis.Count > 2)
            {
                AxisHelper ah = new AxisHelper();
                ah.IsM18 = true;
                ah.Length = 0;
                ah.Descr = "Dummy";
                if (axis[axis.Count - 2].Addressinfile + axis[axis.Count - 2].Length + 2 == axis[axis.Count - 1].Addressinfile)
                {
                    // 3D map
                    ah.Addressinfile = axis[axis.Count - 2].Addressinfile + 4 + axis[axis.Count - 2].Length + axis[axis.Count - 1].Length + (axis[axis.Count - 2].Length * axis[axis.Count - 1].Length);
                }
                else
                {
                    // 2D map
                    ah.Addressinfile = axis[axis.Count - 1].Addressinfile + 2 + axis[axis.Count - 1].Length;
                }
                Console.WriteLine("Added dummy axis: " + ah.Addressinfile.ToString("X4"));
                axis.Add(ah);
            }

            int address = 0;
            int length = 0;
            AxisHelper previousAxisHelper = new AxisHelper();
            int symbolnumber = 0;
            SetProgressPercentage("Determing maps", 80);

            m_tempSymbols.SortColumn = "Flash_start_address";
            m_tempSymbols.SortingOrder = GenericComparer.SortOrder.Ascending;
            m_tempSymbols.Sort();
            int tempLen = 8; // assume first maplength = 8;
            int _previousAddress = 0;
            foreach (SymbolHelper shtest in m_tempSymbols)
            {
                SymbolHelper sh = new SymbolHelper();
                sh.Varname = shtest.Flash_start_address.ToString("X4");
                if (_previousAddress != 0)
                {
                    tempLen = sh.Flash_start_address - _previousAddress;
                }
                else
                {
                    _previousAddress = sh.Flash_start_address;
                }
                sh.Flash_start_address = shtest.Flash_start_address;
                sh.Length = tempLen;
                sh.Symbol_number = symbolnumber++;
                symbols.Add(sh);
            }
            int _mapLengthDiff = 0;
            bool _issueMapFound = false;
            AxisHelper _lastRPMSupportPointAxis = new AxisHelper();
            foreach (AxisHelper ah in axis)
            {
                if (address != 0)
                {
                    // is there a gap?
                    //Console.WriteLine("Handling axis: " + ah.Addressinfile.ToString("X4"));
                    int endofpreviousaxis = address + length + 2;

                    if (endofpreviousaxis < ah.Addressinfile)
                    {
                        int gaplen = ah.Addressinfile - endofpreviousaxis;

                        // check whether there are symbol address in between
                        bool _symbolfound = false;
                        foreach (SymbolHelper shtemp in symbols)
                        {
                            if (shtemp.Flash_start_address >= endofpreviousaxis && shtemp.Flash_start_address + shtemp.Length <= endofpreviousaxis + gaplen)
                            {
                                _symbolfound = true;
                                //Console.WriteLine("GAP OVERRULED: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString() + " by " + shtemp.Flash_start_address.ToString("X4") + " " + shtemp.Length.ToString("X4"));
                                // add the axis as a symbol in that case
                                SymbolHelper shnew = new SymbolHelper();
                                shnew.Flash_start_address = ah.Addressinfile;
                                shnew.Length = 8;// gaplen;// ah.Length;
                                shnew.Varname = /*"NEW: "  +*/ shnew.Flash_start_address.ToString("X4");
                                symbols.Add(shnew);
                                if (gaplen > shnew.Length)
                                {
                                    Console.WriteLine("might be more symbols after " + shtemp.Flash_start_address.ToString("X4"));
                                }
                                break;
                            }
                        }

                        //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;
                        if (_mapLengthDiff > 0)
                        {
                            sh.Length = _mapLengthDiff;
                            _mapLengthDiff = 0;
                        }
                        sh.Symbol_number = symbolnumber++;

                        sh.Flash_start_address = endofpreviousaxis;
                        /*if (sh.Length == 256)
                        {
                            sh.Cols = 16;
                            sh.Rows = 16;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                // 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, 4, 10))
                                {
                                    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;
                            sh.Varname = "Warmup fuel correction";
                            //sh.Category = "Examining";
                            sh.Category = "Fuel";
                        }
                        else if (sh.Length == 128)
                        {
                            sh.Cols = 16;
                            sh.Rows = 8;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                sh.Varname = "Boost map";
                                sh.Category = "Boost";
                            }
                        }

                        else if (sh.Length == 84)
                        {
                            sh.Cols = 7;
                            sh.Rows = 12;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                sh.Varname = "Dwell angle characteristic map";
                                //sh.Category = "Examining";
                                sh.Category = "Ignition";
                            }
                        }
                        else if (sh.Length == 80)
                        {
                            sh.Cols = 5;
                            sh.Rows = 16;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                sh.Varname = "Cylinder compensation";
                                sh.Category = "Correction";
                            }
                        }
                        else if (sh.Length == 70)
                        {
                            sh.Cols = 7;
                            sh.Rows = 10;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                sh.Varname = "Cranking fuel enrichment";
                                sh.Category = "Cranking";
                            }
                        }
                        else if (sh.Length == 64)
                        {
                            sh.Cols = 8;
                            sh.Rows = 8;
                            // there's one map with this length that has 0x30 ID for axis and this is the MAF to Load conversion map
                            SymbolHelper shxaxis = Helpers.Instance.GetXaxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address);
                            SymbolHelper shyaxis = Helpers.Instance.GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address);
                            if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x30)
                            {
                                if (FileTools.Instance.FirstColumnForTableAveragesLessThan(filename, sh, 50, 8))
                                {
                                    sh.Varname = "MAF to Load conversion map";
                                    sh.Category = "MAF";
                                }
                            }
                            //<GS-28022011> this needs more work.. some bins don't have overboost
                            //these bins have no boost map either and have a different amount of 64 byte length maps

                            else if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x3B )
                            {
                                sh.Varname = "Overboost map";
                                sh.Category = "Boost";
                            }
                            else if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x40 && FileTools.Instance.readdatafromfile(filename, shyaxis.Y_axis_address, 1)[0] == 0x3B)
                            {
                                if (!FileTools.Instance.MapContainsMostly(filename, sh, 0, 0, 90) && FileTools.Instance.FirstColumnForTableAveragesLessThan(filename, sh, 50, 8))
                                {
                                    sh.Varname = "Acceleration correction";
                                    sh.Category = "Fuel";
                                }
                            }
                        }
                        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;
                            if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18)
                            {
                                sh.Varname = "Idle fuel map";
                                sh.Category = "Fuel";
                            }
                        }
                        else if (sh.Length == 24)
                        {
                            sh.Cols = sh.Length;
                            sh.Rows = 0;

                            //SymbolHelper tsh = GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address);
                            float[] xaxis;
                            float[] yaxis;
                            string xdescr;
                            string ydescr;
                            Helpers.Instance.GetAxisValues(filename, symbols, axis, sh.Varname, sh.Flash_start_address, sh.Rows, sh.Cols, out xaxis, out yaxis, out xdescr, out ydescr);
                            //Console.WriteLine(sh.Varname + " " + xaxis.Length.ToString() + " " + yaxis.Length.ToString());
                            if (sh.Length != xaxis.Length * yaxis.Length)
                            {
                                // in that case we're at the point where maps are not longer in sync with axis
                                Console.WriteLine("Offset found for sync problem: " + sh.Flash_start_address.ToString("X6"));
                                _mapLengthDiff = sh.Length - (xaxis.Length);
                                _issueMapFound = true;
                                _symbolfound = false;
                            }
                        }
                        else if (sh.Length == 16)
                        {
                            sh.Cols = sh.Length;
                            sh.Rows = 1;

                            //SymbolHelper tsh = GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address);
                            float[] xaxis;
                            float[] yaxis;
                            string xdescr;
                            string ydescr;
                            Helpers.Instance.GetAxisValues(filename, symbols, axis, sh.Varname, sh.Flash_start_address, sh.Rows, sh.Cols, out xaxis, out yaxis, out xdescr, out ydescr);
                            //Console.WriteLine(sh.Varname + " " + xaxis.Length.ToString() + " " + yaxis.Length.ToString());

                            if (FileTools.Instance.MapContainsMostly(filename, sh, 127, 20, 50) && xaxis.Length == 16)
                            {
                                sh.Varname = "WOT enrichment";
                                sh.Category = "Fuel";
                            }
                            else if (xaxis.Length == 16 && FileTools.Instance.MapContainsMostly(filename, sh, 55, 4, 30))
                            {
                                sh.Varname = "WOT ignition";
                                sh.Category = "Examining";
                            }
                        }
                        else if (sh.Length == 8)
                        {
                            if (_issueMapFound)
                            {
                                sh.Cols = sh.Length;
                                sh.Rows = 1;
                                // one of these maps should be the MAF limit map... which one though
                            }
                        }
                        else
                        {
                            SymbolHelper shxaxis = Helpers.Instance.GetXaxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address);
                            if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x38 && shxaxis.X_axis_length == sh.Length)
                            {
                                sh.Category = "Temperature compensation";
                            }
                            else
                            {
                                //Console.WriteLine(sh.Varname + " len: " + sh.Length.ToString("X2") + " axis len: " + shxaxis.X_axis_length.ToString("X2"));
                            }
                            sh.Cols = sh.Length;
                            sh.Rows = 1;
                        }*/
                        if (!_symbolfound)
                        {
                            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.SortColumn = "Flash_start_address";
            //ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending;
            ignition_maps.SortingOrder = GenericComparer.SortOrder.Ascending;
            ignition_maps.Sort();
            if (ignition_maps.Count == 3)
            {
                ignition_maps[0].Varname = "Ignition map: wide open throttle";
                ignition_maps[1].Varname = "Ignition map: part throttle";
                ignition_maps[2].Varname = "Ignition map: knock/limp home";

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

            SymbolCollection cylinderCompensationMaps = new SymbolCollection();
            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Varname == "Cylinder compensation")
                {
                    cylinderCompensationMaps.Add(sh);
                }
            }
            cylinderCompensationMaps.SortColumn = "Flash_start_address";
            cylinderCompensationMaps.SortingOrder = GenericComparer.SortOrder.Ascending;
            cylinderCompensationMaps.Sort();

            if (cylinderCompensationMaps.Count == 5)
            {
                cylinderCompensationMaps[0].Varname = "Cylinder compensation #1";
                cylinderCompensationMaps[1].Varname = "Cylinder compensation #2";
                cylinderCompensationMaps[2].Varname = "Cylinder compensation #3";
                cylinderCompensationMaps[3].Varname = "Cylinder compensation #4";
                cylinderCompensationMaps[4].Varname = "Cylinder compensation #5";
            }
            foreach (SymbolHelper sh in cylinderCompensationMaps)
            {
                foreach (SymbolHelper shorg in symbols)
                {
                    if (sh.Flash_start_address == shorg.Flash_start_address)
                    {
                        shorg.Varname = sh.Varname;
                        break;
                    }
                }
            }

            int _8lengthmapcount = 0;
            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Length == 8) _8lengthmapcount++;
            }
            int idx = 7;
            if (_8lengthmapcount < 25) idx = 5;
            //else idx = 7;
            if (_8lengthmapcount > 10)
            {
                symbols.SortColumn = "Flash_start_address";
                symbols.SortingOrder = GenericComparer.SortOrder.Descending;
                symbols.Sort();
                int tidx = 0;
                foreach (SymbolHelper sh in symbols)
                {
                    if (sh.Length == 8) tidx++;
                    if (tidx == idx)
                    {
                        sh.Varname = "MAF limit";
                        sh.Category = "MAF";
                    }
                    if (tidx == idx + 3)
                    {
                        sh.Varname = "Internal load limiter";
                        sh.Category = "Examining";
                    }
                }
            }
            LoadMotronic18Limiters();*/

            //TestSymbolListIntegrety(symbols, axis);

            SetProgressPercentage("Sorting data", 90);
            // sort the symbol on length, biggest on top
            symbols.SortColumn = "Length";
            symbols.SortingOrder = GenericComparer.SortOrder.Descending;
            symbols.Sort();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
        private void LoadMotronic44File(string filename, out SymbolCollection symbols, out AxisCollection axis)
        {
            //frmInfoBox info = new frmInfoBox("Motronic 4.4 support is not yet implemented");
            // get the list from the file
            // Get axis table from the binary
            // find sequence 00 02 04 00 02 00
            // if the next byte is 00 then we should read on 00 02 04 07 09 and then start
            // otherwise start immediately

            AxisCollection m_gatheredaxisaddress = new AxisCollection();

            int readstate = 0;
            int lookuptablestartaddress = 0x00;
            int axisaddress = 0;
            readstate = 0;
            axis = new AxisCollection();
            m_tempaxis = new AxisCollection();
            symbols = new SymbolCollection();
            SetProgressPercentage("Loading addressmap", 20);

            LoadMotronic44ThirdAxisTable(filename, out m_tempaxis);
            Console.WriteLine("Entries from LoadMotronic44ThirdAxisTable: " + m_tempaxis.Count.ToString());
            foreach (AxisHelper ah in m_tempaxis)
            {
               // DumpAxis(ah);
                if (ah.Addressinfile == 0xF962) Console.WriteLine("Det in third axis!");
                m_gatheredaxisaddress.Add(ah);
            }

            m_tempaxis = new AxisCollection();

            LoadMotronic44MapTable(filename, out m_tempaxis);

            // DEBUG
            foreach (AxisHelper ah in m_tempaxis)
            {
                //DumpAxis(ah);
                if (ah.Addressinfile == 0xF962) Console.WriteLine("Det in maptable!");
                m_gatheredaxisaddress.Add(ah);
            }
            m_tempaxis.SortColumn = "Addressinfile";
            m_tempaxis.SortingOrder = GenericComparer.SortOrder.Ascending;
            m_tempaxis.Sort();

            Console.WriteLine("Entries from LoadMotronic44MapTable: " + m_tempaxis.Count.ToString());
            AxisCollection m_interpolatedAxis = new AxisCollection();
            foreach (AxisHelper ah in m_tempaxis)
            {
                if (ah.Addressinfile == 0xF962) Console.WriteLine("Det in maptable2!");
                m_gatheredaxisaddress.Add(ah);
            }

            // now read all axis addresses upto the end marker
            // now determine the gaps in the axis structure

            int bigmapcount = 0;
            for (int tel = 0; tel < m_tempaxis.Count - 1; tel++)
            {
                int length = m_tempaxis[tel + 1].Addressinfile - m_tempaxis[tel].Addressinfile;
                //Console.WriteLine("Symbol: " + m_tempaxis[tel].Addressinfile.ToString("X4") + "length: " + length.ToString());
                m_tempaxis[tel].Length = length;
                if (length > 0x0100)
                {
                    Console.WriteLine("Table is too big: " + m_tempaxis[tel].Addressinfile.ToString("X6") + " len: " + length.ToString("X4"));
                }
                SymbolHelper sh = new SymbolHelper();
                sh.Flash_start_address = m_tempaxis[tel].Addressinfile;
                sh.Length = m_tempaxis[tel].Length;

                sh.Varname = sh.Flash_start_address.ToString("X4");
                if (sh.Length == 0x100)
                {
                    string category = "Undocumented";
                    string units = "";
                    string xaxisunits = "";
                    string yaxisunits = "";
                    //TODO: fix the naming of maps here!
                    //sh.Varname = GetBigMapLowerPartName(bigmapcount++, sh.Flash_start_address, out category, out units, out xaxisunits, out yaxisunits);
                    sh.Category = category;
                    sh.XDescr = xaxisunits;
                    sh.YDescr = yaxisunits;
                    sh.ZDescr = units;

                }
                sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                symbols.Add(sh);
            }
            SetProgressPercentage("Adding axis", 30);

            m_tempaxis = new AxisCollection();
            LoadMotronic44AxisTable(filename, out m_tempaxis);

            // DEBUG
            Console.WriteLine("Entries from LoadMotronic44AxisTable: " + m_tempaxis.Count.ToString());
            if (m_tempaxis.Count > 16) // failsafe
            {
                foreach (AxisHelper ah in m_tempaxis)
                {
                    //DumpAxis(ah);
                    if (ah.Addressinfile == 0xF962) Console.WriteLine("Det in first axis!");
                    m_gatheredaxisaddress.Add(ah);
                }
            }

            bigmapcount = 0;
            m_tempaxis = new AxisCollection();
            LoadMotronicSecondaryMapTable(filename, out m_tempaxis);

            // DEBUG
            Console.WriteLine("Entries from LoadMotronicSecondaryMapTable: " + m_tempaxis.Count.ToString());
            foreach (AxisHelper ah in m_tempaxis)
            {
                if (ah.Addressinfile == 0xF962) Console.WriteLine("Det in second axis!");

                m_gatheredaxisaddress.Add(ah);
                //DumpAxis(ah);
            }

            // now add all axis to tempaxis
            m_tempaxis.Clear();
            foreach (AxisHelper ah in m_gatheredaxisaddress)
            {
                m_tempaxis.Add(ah);
            }

            m_tempaxis.SortColumn = "Addressinfile";
            m_tempaxis.SortingOrder = GenericComparer.SortOrder.Ascending;
            m_tempaxis.Sort();
            SetProgressPercentage("Analyzing structure", 40);

            for (int tel = 0; tel < m_tempaxis.Count - 1; tel++)
            {

                int length = m_tempaxis[tel + 1].Addressinfile - m_tempaxis[tel].Addressinfile;
                //Console.WriteLine("Symbol: " + m_tempaxis[tel].Addressinfile.ToString("X4") + "length: " + length.ToString());
                m_tempaxis[tel].Length = length;
                SymbolHelper sh = new SymbolHelper();
                sh.Flash_start_address = m_tempaxis[tel].Addressinfile;
                sh.Length = m_tempaxis[tel].Length;
                sh.Varname = sh.Flash_start_address.ToString("X4");
                if (sh.Length == 0x100)
                {
                    string category = "Undocumented";
                    int xaxisaddress = 0;
                    int yaxisaddress = 0;
                    string units = "";
                    string xaxisunits = string.Empty;
                    string yaxisunits = string.Empty;
                    //TODO: fix the naming of maps here!
                    //sh.Varname = GetBigMapUpperPartName(bigmapcount++, sh.Flash_start_address, m_axis, out category, out xaxisaddress, out yaxisaddress, out units, out xaxisunits, out yaxisunits);
                    sh.XDescr = xaxisunits;
                    sh.YDescr = yaxisunits;
                    sh.ZDescr = units;
                    if (xaxisaddress != 0)
                    {
                        sh.X_axis_address = xaxisaddress;
                        //sh.X_axis_length = cols;
                        //sh.XDescr =
                    }
                    if (yaxisaddress != 0)
                    {
                        sh.Y_axis_address = yaxisaddress;
                        //sh.Y_axis_length = rows;
                    }
                    sh.Category = category;
                    //TODO: add subcategory

                }
                sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length);
                sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length);
                symbols.Add(sh);
            }

            SetProgressPercentage("Determining maps", 50);

            axis.Clear();

            // see if there are axis in the symbol list.
            //foreach (SymbolHelper sh in symbols)
            foreach (AxisHelper sh in m_gatheredaxisaddress)
            {
                // read 3 bytes, 2 ID (actually SRAM address internally in uC)
                // 1 byte length
                byte[] axisheader = FileTools.Instance.readdatafromfile(filename, sh.Addressinfile, 3, false);
                int id = Convert.ToInt32(axisheader.GetValue(0)) * 256 + Convert.ToInt32(axisheader.GetValue(1));
                int length = Convert.ToInt32(axisheader.GetValue(2));
                if (IsKnownM44Id(id & 0x00FF) && length <= 32)
                {
                    // this is probably an axis, add it to the collection

                    AxisHelper ah = new AxisHelper();
                    ah.IsMotronic44 = true;
                    ah.Addressinfile = sh.Addressinfile;
                    if (FillAxisInformationM44(filename, ah))
                    {
                        //Console.WriteLine("Added M4.4 axis to collection: " + ah.Identifier.ToString("X4") + " adr: " + ah.Addressinfile.ToString("X4"));
                        if (ah.Identifier != 0)
                        {
                            if (ah.Length != 0 && (ah.Length % 2 == 0))
                            {
                                axis.Add(ah);
                                Console.WriteLine("Added axis to collection: " + ah.Addressinfile.ToString("X8") + " " + ah.Descr + " vals " + ah.Values.Length.ToString());
                            }
                            else
                            {
                                Console.WriteLine("Length was zero or uneven for axis: " + ah.Addressinfile.ToString("X8"));
                            }
                        }
                        else
                        {
                            Console.WriteLine("Identifier was zero for axis: " + ah.Addressinfile.ToString("X8"));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unable to fill axis information for axis: " + ah.Addressinfile.ToString("X8"));
                    }

                }
                else
                {
                    Console.WriteLine("Unknown identifier seen: " + id.ToString("X4"));
                }
            }

            Console.WriteLine("Final axis collection");

            SetProgressPercentage("Determining maps, 2nd run", 60);

            // now filter all unwanted stuff from the final collections
            // first copy all symbolhelpers to a temporary storage
            SymbolCollection sctemp = new SymbolCollection();
            foreach (SymbolHelper sh in symbols)
            {
                if (sh.Length <= 512 && sh.Length > 0)
                {
                    sctemp.Add(sh);
                }
            }
            // clear the final collection
            symbols.Clear();
            // do the same for the axis collection
            AxisCollection actemp = new AxisCollection();
            foreach (AxisHelper ah in axis)
            {
                if (ah.Length > 0 && ah.Length <= 32)
                {
                    actemp.Add(ah);
                }
            }
            axis.Clear();
            // now, add all the symbols that are not in the axis collection
            foreach (SymbolHelper sh in sctemp)
            {
                bool fnd = false;
                foreach (AxisHelper ah in actemp)
                {
                    if (ah.Addressinfile == sh.Flash_start_address)
                    {
                        // fnd = true; //<GS-20102009>
                        break;
                    }
                }
                if (!fnd)
                {
                    bool alreadyincollection = false;
                    foreach (SymbolHelper shtmp in symbols)
                    {
                        if (shtmp.Flash_start_address == sh.Flash_start_address)
                        {
                            alreadyincollection = true;
                        }
                    }
                    if (!alreadyincollection)
                    {
                        symbols.Add(sh);
                    }
                }
            }
            SetProgressPercentage("Determining maps, 3rd run", 70);

            // now add the final axis to the collection
            foreach (AxisHelper ah in actemp)
            {
                axis.Add(ah);
            }

            FileTools.Instance.Speedlimit = GetVehicleSpeedLimiter(filename);

            SetProgressPercentage("Sorting data", 80);
            symbols.SortColumn = "Length";
            symbols.SortingOrder = GenericComparer.SortOrder.Descending;
            symbols.Sort();
        }