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 } }
private void LoadLH24File(string filename, out SymbolCollection symbols, out AxisCollection axis) { // Get axis table from the binary // find 0x00 0x08 0x018 0x20 0x28 0x2E 0x32 to find the addresstable int readstate = 0; int lookuptablestartaddress = 0x00; int axisaddress = 0; readstate = 0; axis = new AxisCollection(); m_tempaxis = new AxisCollection(); symbols = new SymbolCollection(); FileStream fs = new FileStream(filename, FileMode.Open); using (BinaryReader br = new BinaryReader(fs)) { for (int t = 0; t < fs.Length; t++) { byte b = br.ReadByte(); //00 02 05 07 switch (readstate) { case 0: if (b == 0x00) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 1: Console.WriteLine("readstate = 1"); if (b == 0x08) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 2: Console.WriteLine("readstate = 2 @ address: " + t.ToString("X4")); if (b == 0x18) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 3: Console.WriteLine("readstate = 3 @ address: " + t.ToString("X4")); if (b == 0x20) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 4: Console.WriteLine("readstate = 4 @ address: " + t.ToString("X4")); if (b == 0x28) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 5: Console.WriteLine("readstate = 5 @ address: " + t.ToString("X4")); if (b == 0x2E) { readstate++; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 6: Console.WriteLine("readstate = 6 @ address: " + t.ToString("X4")); if (b == 0x32) { readstate++; t += 21; fs.Seek(21, SeekOrigin.Current); lookuptablestartaddress = t + 1; //fs.Position = fs.Position + 21; } else { lookuptablestartaddress = 0x00; readstate = 0; } break; case 7: Console.WriteLine("readstate = 7 @ address: " + t.ToString("X4")); // we're reading addresses now if (b < 0x30 || b > 0x3F) { // end of table... stop reading readstate = 9; } else { axisaddress = (int)b * 256; readstate = 8; } break; case 8: axisaddress += (int)b; AxisHelper ah = new AxisHelper(); Console.WriteLine("Axis address: " + axisaddress.ToString("X4")); ah.Addressinfile = axisaddress; m_tempaxis.Add(ah); axisaddress = 0; readstate = 7; break; case 9: break; default: break; } } } fs.Close(); fs.Dispose(); // now read all axis addresses upto the end marker SetProgressPercentage("Adding axis", 40); SymbolCollection m_Unknown_symbols = new SymbolCollection(); foreach (AxisHelper ah in m_tempaxis) { // get the address information for this axus //Console.WriteLine("Filling information for axis at address: " + ah.Addressinfile.ToString("X4")); if (FillAxisInformation(filename, ah)) { axis.Add(ah); } else { SymbolHelper sh = new SymbolHelper(); sh.Flash_start_address = ah.Addressinfile; sh.Varname = sh.Flash_start_address.ToString("X4"); m_Unknown_symbols.Add(sh); // later we have to add length to it based on next found value } } // add secondary (Y) axis stuff that may not be in the lookup table m_tempaxis = new AxisCollection(); foreach (AxisHelper ah in axis) { int newaxisstart = ah.Addressinfile + ah.Length + 2; if (Helpers.Instance.CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length)) { //Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4")); AxisHelper ahnew = new AxisHelper(); ahnew.Addressinfile = newaxisstart; m_tempaxis.Add(ahnew); } } SetProgressPercentage("Adding axis, 2nd run", 50); // alsnog toevoegen aan collectie foreach (AxisHelper ahnew in m_tempaxis) { if (FillAxisInformation(filename, ahnew)) { axis.Add(ahnew); } } SetProgressPercentage("Analyzing structure", 60); foreach (SymbolHelper sh in m_Unknown_symbols) { sh.Length = Helpers.Instance.FindFirstAddressInLists(sh.Flash_start_address, m_axis, m_Unknown_symbols) - sh.Flash_start_address; sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length); sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length); m_symbols.Add(sh); } // now determine the gaps in the axis structure SetProgressPercentage("Determining maps", 80); axis.SortColumn = "Addressinfile"; axis.SortingOrder = GenericComparer.SortOrder.Ascending; axis.Sort(); int address = 0; int length = 0; AxisHelper previousAxisHelper = new AxisHelper(); int symbolnumber = 0; foreach (AxisHelper ah in axis) { /*SymbolHelper shaxis = new SymbolHelper(); shaxis.Flash_start_address = ah.Addressinfile; shaxis.Varname = shaxis.Flash_start_address.ToString("X4"); shaxis.Length = ah.Length; _workingFile.Symbols.Add(shaxis);*/ if (address != 0) { // is there a gap? int endofpreviousaxis = address + length + 2; if (endofpreviousaxis < ah.Addressinfile) { int gaplen = ah.Addressinfile - endofpreviousaxis; //Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); //Console.WriteLine("AXIS: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); /*if (endofpreviousaxis == 0xFCC5) { Console.WriteLine("PREV AXIS ADDRESS: "+ previousAxisHelper.Addressinfile.ToString("X4")); Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); }*/ // Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); SymbolHelper sh = new SymbolHelper(); sh.Varname = endofpreviousaxis.ToString("X4"); sh.Length = gaplen; sh.Symbol_number = symbolnumber++; sh.Flash_start_address = endofpreviousaxis; sh.Cols = Helpers.Instance.DetermineColumnsInMapByLength(sh.Length); sh.Rows = Helpers.Instance.DetermineRowsInMapByLength(sh.Length); /*if (sh.Length == 256) { sh.Cols = 16; sh.Rows = 16; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC43) { // there are 4 maps with this size in Motronic 4.3 // the one that had lots of 127 values in it is the VE map // and has a correction factor of 1/127 (lambda = 1) // the others are ignition maps and have a correction factor of 0.75 ?? if (FileTools.Instance.MapContainsMostly(filename, sh, 127)) { sh.Varname = "VE map"; sh.Category = "Fuel"; } else { sh.Varname = "Ignition map"; sh.Category = "Ignition"; } } } else if (sh.Length == 144) { sh.Cols = 12; sh.Rows = 12; } else if (sh.Length == 128) { sh.Cols = 16; sh.Rows = 8; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC43) { sh.Varname = "Boost map"; sh.Category = "Boost"; } } else if (sh.Length == 84) { sh.Cols = 7; sh.Rows = 12; } else if (sh.Length == 80) { sh.Cols = 5; sh.Rows = 16; } else if (sh.Length == 70) { sh.Cols = 7; sh.Rows = 10; } else if (sh.Length == 64) { sh.Cols = 8; sh.Rows = 8; } else if (sh.Length == 50) { sh.Cols = 10; sh.Rows = 5; } else if (sh.Length == 48) { sh.Cols = 8; sh.Rows = 6; } else if (sh.Length == 42) { sh.Cols = 6; sh.Rows = 7; } else if (sh.Length == 40) { sh.Cols = 8; sh.Rows = 5; } else { sh.Cols = sh.Length; sh.Rows = 1; }*/ symbols.Add(sh); } } length = ah.Length; address = ah.Addressinfile; previousAxisHelper = ah; } // try to determine ignition maps probablility SymbolCollection ignition_maps = new SymbolCollection(); foreach (SymbolHelper sh in symbols) { if (sh.Varname == "Ignition map") { sh.Average_value = Helpers.Instance.DetermineAverageMapValue(filename, sh); ignition_maps.Add(sh); } } ignition_maps.SortColumn = "Average_value"; ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending; ignition_maps.Sort(); if (ignition_maps.Count == 3) { ignition_maps[0].Varname = "Ignition map: Warmup"; Console.WriteLine("Warmup map avg: " + ignition_maps[0].Average_value.ToString("F3") + " address: " + ignition_maps[0].Flash_start_address.ToString()); ignition_maps[1].Varname = "Ignition map: Normal"; Console.WriteLine("Normal map avg: " + ignition_maps[1].Average_value.ToString("F3") + " address: " + ignition_maps[1].Flash_start_address.ToString()); ignition_maps[2].Varname = "Ignition map: Knocking"; Console.WriteLine("Knock map avg: " + ignition_maps[2].Average_value.ToString("F3") + " address: " + ignition_maps[2].Flash_start_address.ToString()); } foreach (SymbolHelper sh in ignition_maps) { foreach (SymbolHelper shorg in symbols) { if (sh.Flash_start_address == shorg.Flash_start_address) { shorg.Varname = sh.Varname; break; } } } SetProgressPercentage("Sorting data", 90); // sort the symbol on length, biggest on top symbols.SortColumn = "Length"; symbols.SortingOrder = GenericComparer.SortOrder.Descending; symbols.Sort(); }
private void 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(); }
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(); }