private bool MapContainsNegativeValues(byte[] allBytes, SymbolHelper sh) { for (int i = 0; i < sh.Length; i += 2) { int currval = Convert.ToInt32(allBytes[sh.Flash_start_address + i + 1]) * 256 + Convert.ToInt32(allBytes[sh.Flash_start_address + i]); if (currval > 0xF000) { return(true); } } return(false); }
private bool AddToSymbolCollection(SymbolCollection newSymbols, SymbolHelper newSymbol, List <CodeBlock> newCodeBlocks) { //if (newSymbol.Length >= 800) return false; foreach (SymbolHelper sh in newSymbols) { if (sh.Flash_start_address == newSymbol.Flash_start_address) { // Console.WriteLine("Already in collection: " + sh.Flash_start_address.ToString("X8")); return(false); } } newSymbols.Add(newSymbol); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); return(true); }
public override void FindSVBL(byte[] allBytes, string filename, SymbolCollection newSymbols, List <CodeBlock> newCodeBlocks) { bool found = true; int offset = 0; while (found) { int SVBLAddress = Tools.Instance.findSequence(allBytes, offset, new byte[10] { 0xDF, 0x7A, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x7A }, new byte[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); if (SVBLAddress > 0) { //Console.WriteLine("Alternative SVBL " + SVBLAddress.ToString("X8")); SymbolHelper shsvbl = new SymbolHelper(); shsvbl.Category = "Detected maps"; shsvbl.Subcategory = "Limiters"; shsvbl.Flash_start_address = SVBLAddress - 2; // if value = 0xC3 0x00 -> two more back int[] testValue = Tools.Instance.readdatafromfileasint(filename, (int)shsvbl.Flash_start_address, 1, EDCFileType.EDC15M); if (testValue[0] == 0xC300) { shsvbl.Flash_start_address -= 2; } shsvbl.Varname = "SVBL Boost limiter [" + DetermineNumberByFlashBank(shsvbl.Flash_start_address, newCodeBlocks) + "]"; shsvbl.Length = 2; shsvbl.CodeBlock = DetermineCodeBlockByByAddress(shsvbl.Flash_start_address, newCodeBlocks); newSymbols.Add(shsvbl); offset = SVBLAddress + 1; } else { found = false; } } }
public int Add(SymbolHelper value) { return (List.Add(value)); }
public int IndexOf(SymbolHelper value) { return(List.IndexOf(value)); }
public void Remove(SymbolHelper value) { List.Remove(value); }
private bool AddToSymbolCollection(SymbolCollection newSymbols, SymbolHelper newSymbol, List<CodeBlock> newCodeBlocks) { if (newSymbol.Length >= 800) return false; foreach (SymbolHelper sh in newSymbols) { if (sh.Flash_start_address == newSymbol.Flash_start_address) { // Console.WriteLine("Already in collection: " + sh.Flash_start_address.ToString("X8")); return false; } } newSymbols.Add(newSymbol); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); return true; }
public override void FindSVBL(byte[] allBytes, string filename, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks) { bool found = true; int offset = 0; while (found) { int SVBLAddress = Tools.Instance.findSequence(allBytes, offset, new byte[10] { 0xDF, 0x7A, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x7A }, new byte[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); if (SVBLAddress > 0) { //Console.WriteLine("Alternative SVBL " + SVBLAddress.ToString("X8")); SymbolHelper shsvbl = new SymbolHelper(); shsvbl.Category = "Detected maps"; shsvbl.Subcategory = "Limiters"; shsvbl.Flash_start_address = SVBLAddress - 2; // if value = 0xC3 0x00 -> two more back int[] testValue = Tools.Instance.readdatafromfileasint(filename, (int)shsvbl.Flash_start_address, 1, EDCFileType.EDC15C); if (testValue[0] == 0xC300) shsvbl.Flash_start_address -= 2; shsvbl.Varname = "SVBL Boost limiter [" + DetermineNumberByFlashBank(shsvbl.Flash_start_address, newCodeBlocks) + "]"; shsvbl.Length = 2; shsvbl.CodeBlock = DetermineCodeBlockByByAddress(shsvbl.Flash_start_address, newCodeBlocks); newSymbols.Add(shsvbl); offset = SVBLAddress + 1; } else found = false; } }
private bool IsValidTemperatureAxis(byte[] allBytes, SymbolHelper sh, MapViewerEx.AxisIdent axisIdent) { bool retval = true; if (axisIdent == MapViewerEx.AxisIdent.X_Axis) { //read x axis values int offset = sh.X_axis_address; for (int i = 0; i < sh.X_axis_length; i++) { int val = Convert.ToInt32(allBytes[offset]) + Convert.ToInt32(allBytes[offset + 1]) * 256; double tempVal = (Convert.ToDouble(val) * 0.1) - 273.1; if (tempVal < -80 || tempVal > 200) retval = false; offset += 2; } } else if (axisIdent == MapViewerEx.AxisIdent.Y_Axis) { //read x axis values int offset = sh.Y_axis_address; for (int i = 0; i < sh.Y_axis_length; i++) { int val = Convert.ToInt32(allBytes[offset]) + Convert.ToInt32(allBytes[offset + 1]) * 256; double tempVal = (Convert.ToDouble(val) * 0.1) - 273.1; if (tempVal < -80 || tempVal > 200) retval = false; offset += 2; } } return retval; }
public override void FindSVBL(byte[] allBytes, string filename, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks) { bool found = true; int offset = 0; while (found) { int SVBLAddress = Tools.Instance.findSequence(allBytes, offset, new byte[10] { 0xDF, 0x7A, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x7A }, new byte[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); ///int SVBLAddress = Tools.Instance.findSequence(allBytes, offset, new byte[16] { 0xD2, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xC3, 0x00, 0x00 }, new byte[16] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1 }); if (SVBLAddress > 0) { //Console.WriteLine("Alternative SVBL " + SVBLAddress.ToString("X8")); SymbolHelper shsvbl = new SymbolHelper(); shsvbl.Category = "Detected maps"; shsvbl.Subcategory = "Limiters"; shsvbl.Flash_start_address = SVBLAddress - 2; //shsvbl.Flash_start_address = SVBLAddress + 16; // if value = 0xC3 0x00 -> two more back int[] testValue = Tools.Instance.readdatafromfileasint(filename, (int)shsvbl.Flash_start_address, 1, EDCFileType.EDC15P6); if (testValue[0] == 0xC300) shsvbl.Flash_start_address -= 2; shsvbl.Varname = "SVBL Boost limiter [" + DetermineNumberByFlashBank(shsvbl.Flash_start_address, newCodeBlocks) +"]"; shsvbl.Length = 2; shsvbl.CodeBlock = DetermineCodeBlockByByAddress(shsvbl.Flash_start_address, newCodeBlocks); newSymbols.Add(shsvbl); int MAPMAFSwitch = Tools.Instance.findSequence(allBytes, SVBLAddress - 0x100, new byte[8] { 0x41, 0x02, 0xFF, 0xFF, 0x00, 0x01, 0x01, 0x00 }, new byte[8] { 1, 1, 0, 0, 1, 1, 1, 1 }); if (MAPMAFSwitch > 0) { MAPMAFSwitch += 2; SymbolHelper mapmafsh = new SymbolHelper(); //mapmafsh.BitMask = 0x0101; mapmafsh.Category = "Detected maps"; mapmafsh.Subcategory = "Switches"; mapmafsh.Flash_start_address = MAPMAFSwitch; mapmafsh.Varname = "MAP/MAF switch (0 = MAF, 257/0x101 = MAP)" + DetermineNumberByFlashBank(shsvbl.Flash_start_address, newCodeBlocks); mapmafsh.Length = 2; mapmafsh.CodeBlock = DetermineCodeBlockByByAddress(mapmafsh.Flash_start_address, newCodeBlocks); newSymbols.Add(mapmafsh); Console.WriteLine("Found MAP MAF switch @ " + MAPMAFSwitch.ToString("X8")); } offset = SVBLAddress + 1; } else found = false; } }
private void FindMAPMAFSwitch(byte[] allBytes, string filename, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks) { foreach (CodeBlock cb in newCodeBlocks) { if (cb.CodeID > 0) { Console.WriteLine("codeblock " + cb.CodeID.ToString() + " address " + cb.StartAddress.ToString("X8") + " adrid " + cb.AddressID.ToString("X8")); int MAPMAFSwitch = cb.AddressID - 8; // read data if ((allBytes[MAPMAFSwitch] == 0x01 && allBytes[MAPMAFSwitch + 1] == 0x01) || (allBytes[MAPMAFSwitch ] == 0x00 && allBytes[MAPMAFSwitch + 1] == 0x00)) { // verify validity SymbolHelper mapmafsh = new SymbolHelper(); //mapmafsh.BitMask = 0x0101; mapmafsh.Category = "Detected maps"; mapmafsh.Subcategory = "Switches"; mapmafsh.Flash_start_address = MAPMAFSwitch; mapmafsh.Varname = "MAP/MAF switch (0 = MAF, 257/0x0101 = MAP)" + DetermineNumberByFlashBank(MAPMAFSwitch, newCodeBlocks); mapmafsh.Length = 2; mapmafsh.CodeBlock = DetermineCodeBlockByByAddress(mapmafsh.Flash_start_address, newCodeBlocks); newSymbols.Add(mapmafsh); } } } }
// we need to check AHEAD for selector maps // if these are present we may be facing a complex map structure // which we need to handle in a special way (selectors always have data like 00 01 00 02 00 03 00 04 etc) private bool CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks, out int len2Skip) { bool mapFound = false; bool retval = false; bool _dontGenMaps = false; len2Skip = 0; List<MapSelector> mapSelectors = new List<MapSelector>(); if (t < allBytes.Length - 0x100) { if (CheckAxisCount(t, allBytes, out mapSelectors) > 3) { // check for selectors as well, and count them in the process Console.WriteLine("Offset " + t.ToString("X8") + " has more than 3 consecutive axis"); /*foreach (MapSelector ms in mapSelectors) { Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); }*/ _dontGenMaps = true; } int xaxisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(xaxisid)) { int xaxislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); // Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); if (isValidLength(xaxislen, xaxisid)) { //Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); // misschien is er nog een as int yaxisid = (Convert.ToInt32(allBytes[t + 5 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 4 + (xaxislen * 2)]); int yaxislen = (Convert.ToInt32(allBytes[t + 7 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 6 + (xaxislen * 2)]); if (isAxisID(yaxisid) && isValidLength(yaxislen, yaxisid)) { // 3d map int zaxisid = (Convert.ToInt32(allBytes[t + 9 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 8 + (xaxislen * 2) + (yaxislen * 2)]); //Console.WriteLine("Valid YID: " + yaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + yaxislen.ToString("X2")); //Console.WriteLine(t.ToString("X8") + " XID: " + xaxisid.ToString("X4") + " XLEN: " + xaxislen.ToString("X2") + " YID: " + yaxisid.ToString("X4") + " YLEN: " + yaxislen.ToString("X2")); SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.Y_axis_length = yaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.Y_axis_ID = yaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Y_axis_address = t + 8 + (xaxislen * 2); newSymbol.Length = xaxislen * yaxislen * 2; newSymbol.Flash_start_address = t + 8 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(zaxisid)) { int zaxislen = (Convert.ToInt32(allBytes[t + 11 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 10 + (xaxislen * 2) + (yaxislen * 2)]); int zaxisaddress = t + 12 + (xaxislen * 2) + (yaxislen * 2); if (isValidLength(zaxislen, zaxisid)) { // newSymbol.Flash_start_address += 0x10; // dan altijd 16 erbij int len2skip = (4 + zaxislen * 2); if (len2skip < 16) len2skip = 16; // at least 16 bytes newSymbol.Flash_start_address += len2skip; len2Skip += (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2; if (!_dontGenMaps) { // this has something to do with repeating several times with the same axis set Console.WriteLine("Added " + len2skip.ToString() + " because of z axis " + newSymbol.Flash_start_address.ToString("X8")); // maybe there are multiple maps between the end of the map and the start of the next axis int nextMapAddress = findNextMap(allBytes, (int)(newSymbol.Flash_start_address + newSymbol.Length), newSymbol.Length * 10); if (nextMapAddress > 0) { // is it divisable by the maplength if (((nextMapAddress - newSymbol.Flash_start_address) % newSymbol.Length) == 0) { int numberOfrepeats = (int)(nextMapAddress - newSymbol.Flash_start_address) / newSymbol.Length; numberOfrepeats = zaxislen; if (numberOfrepeats > 1) { MapSelector ms = new MapSelector(); ms.NumRepeats = numberOfrepeats; ms.MapLength = newSymbol.Length; ms.StartAddress = zaxisaddress; ms.XAxisAddress = newSymbol.X_axis_address; ms.YAxisAddress = newSymbol.Y_axis_address; ms.XAxisLen = newSymbol.X_axis_length; ms.YAxisLen = newSymbol.Y_axis_length; ms.MapData = new int[zaxislen]; int boffset = 0; for (int ia = 0; ia < zaxislen; ia++) { int axisValue = Convert.ToInt32(allBytes[zaxisaddress + boffset]) + Convert.ToInt32(allBytes[zaxisaddress + boffset + 1]) * 256; ms.MapData.SetValue(axisValue, ia); boffset += 2; } ms.MapIndexes = new int[zaxislen]; for (int ia = 0; ia < zaxislen; ia++) { int axisValue = Convert.ToInt32(allBytes[zaxisaddress + boffset]) + Convert.ToInt32(allBytes[zaxisaddress + boffset + 1]) * 256; ms.MapIndexes.SetValue(axisValue, ia); boffset += 2; } // numberOfrepeats--; //int idx = 0; for (int maprepeat = 0; maprepeat < numberOfrepeats; maprepeat++) { // idx ++; SymbolHelper newGenSym = new SymbolHelper(); newGenSym.X_axis_length = newSymbol.X_axis_length; newGenSym.Y_axis_length = newSymbol.Y_axis_length; newGenSym.X_axis_ID = newSymbol.X_axis_ID; newGenSym.Y_axis_ID = newSymbol.Y_axis_ID; newGenSym.X_axis_address = newSymbol.X_axis_address; newGenSym.Y_axis_address = newSymbol.Y_axis_address; newGenSym.Flash_start_address = newSymbol.Flash_start_address + maprepeat * newSymbol.Length; newGenSym.Length = newSymbol.Length; newGenSym.Varname = "3D GEN " + newGenSym.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4") + " " + yaxisid.ToString("X4"); newGenSym.MapSelector = ms; // attach a mapselector to these maps // only add it if the map is not empty // otherwise we will cause confusion among users if (maprepeat > 0) { try { if (ms.MapIndexes[maprepeat] > 0) { retval = AddToSymbolCollection(newSymbols, newGenSym, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2) + (yaxislen * 2) + newGenSym.Length; t += (xaxislen * 2) + (yaxislen * 2) + newGenSym.Length; } } } catch (Exception) { } } else { retval = AddToSymbolCollection(newSymbols, newGenSym, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2) + (yaxislen * 2) + newGenSym.Length; t += (xaxislen * 2) + (yaxislen * 2) + newGenSym.Length; } } } } //Console.WriteLine("Indeed!"); // the first one will be added anyway.. add the second to the last } } } else { int maxisid = (Convert.ToInt32(allBytes[t + 13 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 12 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); int maxislen = (Convert.ToInt32(allBytes[t + 15 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 14 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); //maxislen *= 2; int maxisaddress = t + 16 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(maxisid)) { newSymbol.Flash_start_address += (maxislen * 2) + 4; } // special situation, handle selectors Console.WriteLine("Map start address = " + newSymbol.Flash_start_address.ToString("X8")); long lastFlashAddress = newSymbol.Flash_start_address; foreach (MapSelector ms in mapSelectors) { // check the memory size between the start of the map and the // start of the map selector long memsize = ms.StartAddress - lastFlashAddress; memsize /= 2; // in words int mapsize = Convert.ToInt32(memsize) / ms.NumRepeats; if ((xaxislen * yaxislen) == mapsize) { //Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); //Console.WriteLine("memsize = " + memsize.ToString() + " mapsize " + mapsize.ToString()); //Console.WriteLine("starting at address: " + lastFlashAddress.ToString("X8")); // first axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = newSymbol.X_axis_length; shGen2.Y_axis_length = newSymbol.Y_axis_length; shGen2.X_axis_ID = newSymbol.X_axis_ID; shGen2.Y_axis_ID = newSymbol.Y_axis_ID; shGen2.X_axis_address = newSymbol.X_axis_address; shGen2.Y_axis_address = newSymbol.Y_axis_address; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Correction = 0.023437; // TEST //shGen2.Varname = "Generated* " + shGen2.Flash_start_address.ToString("X8") + " " + ms.StartAddress.ToString("X8") + " " + ms.NumRepeats.ToString() + " " + i.ToString(); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; // Console.WriteLine("Set last address to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } else if ((zaxislen * maxislen) == mapsize) { // second axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = maxislen; shGen2.Y_axis_length = zaxislen; shGen2.X_axis_ID = maxisid; shGen2.Y_axis_ID = zaxisid; shGen2.X_axis_address = maxisaddress; shGen2.Y_axis_address = zaxisaddress; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Varname = "Generated** " + shGen2.Flash_start_address.ToString("X8"); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; //Console.WriteLine("Set last address 2 to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } //if(ms.NumRepeats } } } } newSymbol.Varname = "3D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4") + " " + yaxisid.ToString("X4"); //GUIDO len2Skip = (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; t += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; } } else { if (yaxisid > 0xC000 && yaxisid < 0xF000 && yaxislen <= 32) Console.WriteLine("Unknown map id: " + yaxisid.ToString("X4") + " len " + yaxislen.ToString("X4") + " at address " + t.ToString("X8")); SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Length = xaxislen * 2; newSymbol.Flash_start_address = t + 4 + (xaxislen * 2); newSymbol.Varname = "2D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4"); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; //GUIDO len2Skip += (xaxislen * 2); t += (xaxislen * 2); } // 2d map } } } } return mapFound; }
public void Insert(int index, SymbolHelper value) { List.Insert(index, value); }
public int IndexOf(SymbolHelper value) { return (List.IndexOf(value)); }
// EDC17 Little<->Bigendian compared to EDC16 private int CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List <CodeBlock> newCodeBlocks) { int retval = 0; // read LL LL int len1 = Convert.ToInt32(allBytes[t]) * 256 + Convert.ToInt32(allBytes[t + 1]); int len2 = Convert.ToInt32(allBytes[t + 2]) * 256 + Convert.ToInt32(allBytes[t + 3]); if (len1 == 1 && len2 == 1) { return(retval); } // BMW uses up to 40(0x28) for one axis. if ((len1 <= 64 && len2 <= 64) && (len1 > 0 && len2 >= 0)) { //Console.WriteLine("---New map-- t=" + t.ToString("X")); bool ok = true; int startX = t + 2; // For 0D-arrays if (len2 > 0) { startX += 2; // For 2D and 3D-arrays } for (int dX = startX; dX <= startX + len1 * 2 - 4; dX += 2) { int b1 = Convert.ToInt32(allBytes[dX]) * 256 + Convert.ToInt32(allBytes[dX + 1]); int b2 = Convert.ToInt32(allBytes[dX + 2]) * 256 + Convert.ToInt32(allBytes[dX + 3]); if (b1 >= b2) { ok = false; break; } } //Console.WriteLine("-----"); if (len2 > 0) { for (int dY = startX + len1 * 2; dY <= startX + len1 * 2 + len2 * 2 - 4; dY += 2) { int b1 = Convert.ToInt32(allBytes[dY]) * 256 + Convert.ToInt32(allBytes[dY + 1]); int b2 = Convert.ToInt32(allBytes[dY + 2]) * 256 + Convert.ToInt32(allBytes[dY + 3]); if (b1 >= b2) { ok = false; break; } } } if (ok) { //Console.WriteLine("--------------"); //for(int i=t; i<t+len1*len2*2;i++) // Console.Write(allBytes[t].ToString("X2")); //Console.WriteLine("----end----"); SymbolHelper sh = new SymbolHelper(); sh.X_axis_length = len1; if (len2 == 0) { sh.X_axis_address = t + 2; sh.Y_axis_address = t + 2; sh.Y_axis_length = 1; sh.Flash_start_address = t + 2 + len1 * 2; sh.Varname = "1D " + sh.Flash_start_address.ToString("X8"); sh.Is1D = true; } else { sh.X_axis_address = t + 4; sh.Y_axis_length = len2; sh.Y_axis_address = sh.X_axis_address + sh.X_axis_length * 2; sh.Flash_start_address = sh.Y_axis_address + sh.Y_axis_length * 2; if (sh.X_axis_length > 1 && sh.Y_axis_length > 1) { sh.Varname = "3D " + sh.Flash_start_address.ToString("X8"); sh.Is3D = true; } else { sh.Varname = "2D " + sh.Flash_start_address.ToString("X8"); sh.Is2D = true; } } sh.Length = sh.X_axis_length * sh.Y_axis_length * 2; //sh.Varname = sh.Flash_start_address.ToString("X8"); int length = (len1 + len2) * 2 + sh.Length + 4; sh.Currentdata = new byte[length]; Array.Copy(allBytes, t, sh.Currentdata, 0, length); AddToSymbolCollection(newSymbols, sh, newCodeBlocks); retval = (len1 + len2) * 2 + sh.Length; } } return(retval); }
// we need to check AHEAD for selector maps // if these are present we may be facing a complex map structure // which we need to handle in a special way (selectors always have data like 00 01 00 02 00 03 00 04 etc) private bool CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List <CodeBlock> newCodeBlocks, out int len2Skip) { len2Skip = 0; bool retval = false; bool mapFound = false; bool _dontGenMaps = false; List <MapSelector> mapSelectors = new List <MapSelector>(); if (t < allBytes.Length - 0x100) { if (CheckAxisCount(t, allBytes, out mapSelectors) > 3) { // check for selectors as well, and count them in the process Console.WriteLine("Offset " + t.ToString("X8") + " has more than 3 consecutive axis"); /*foreach (MapSelector ms in mapSelectors) * { * Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); * }*/ _dontGenMaps = true; } int xaxisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(xaxisid)) { int xaxislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); // Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); if (isValidLength(xaxislen, xaxisid)) { //Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); // misschien is er nog een as int yaxisid = (Convert.ToInt32(allBytes[t + 5 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 4 + (xaxislen * 2)]); int yaxislen = (Convert.ToInt32(allBytes[t + 7 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 6 + (xaxislen * 2)]); if (isAxisID(yaxisid) && isValidLength(yaxislen, yaxisid)) { // 3d map int zaxisid = (Convert.ToInt32(allBytes[t + 9 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 8 + (xaxislen * 2) + (yaxislen * 2)]); //Console.WriteLine("Valid YID: " + yaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + yaxislen.ToString("X2")); //Console.WriteLine(t.ToString("X8") + " XID: " + xaxisid.ToString("X4") + " XLEN: " + xaxislen.ToString("X2") + " YID: " + yaxisid.ToString("X4") + " YLEN: " + yaxislen.ToString("X2")); SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.Y_axis_length = yaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.Y_axis_ID = yaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Y_axis_address = t + 8 + (xaxislen * 2); newSymbol.Length = xaxislen * yaxislen * 2; newSymbol.Flash_start_address = t + 8 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(zaxisid)) { int zaxislen = (Convert.ToInt32(allBytes[t + 11 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 10 + (xaxislen * 2) + (yaxislen * 2)]); int zaxisaddress = t + 12 + (xaxislen * 2) + (yaxislen * 2); if (isValidLength(zaxislen, zaxisid)) { // newSymbol.Flash_start_address += 0x10; // dan altijd 16 erbij int len2skip = (4 + zaxislen * 2); if (len2skip < 16) { len2skip = 16; // at least 16 bytes } newSymbol.Flash_start_address += len2skip; if (!_dontGenMaps) { // this has something to do with repeating several times with the same axis set Console.WriteLine("Added " + len2skip.ToString() + " because of z axis " + newSymbol.Flash_start_address.ToString("X8")); } else { int maxisid = (Convert.ToInt32(allBytes[t + 13 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 12 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); int maxislen = (Convert.ToInt32(allBytes[t + 15 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 14 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); //maxislen *= 2; int maxisaddress = t + 16 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(maxisid)) { newSymbol.Flash_start_address += (maxislen * 2) + 4; } // special situation, handle selectors Console.WriteLine("Map start address = " + newSymbol.Flash_start_address.ToString("X8")); long lastFlashAddress = newSymbol.Flash_start_address; foreach (MapSelector ms in mapSelectors) { // check the memory size between the start of the map and the // start of the map selector long memsize = ms.StartAddress - lastFlashAddress; memsize /= 2; // in words if (ms.NumRepeats > 0) { int mapsize = Convert.ToInt32(memsize) / ms.NumRepeats; //Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); //Console.WriteLine("memsize = " + memsize.ToString() + " mapsize " + mapsize.ToString()); //Console.WriteLine("starting at address: " + lastFlashAddress.ToString("X8")); if ((xaxislen * yaxislen) == mapsize) { // first axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = newSymbol.X_axis_length; shGen2.Y_axis_length = newSymbol.Y_axis_length; shGen2.X_axis_ID = newSymbol.X_axis_ID; shGen2.Y_axis_ID = newSymbol.Y_axis_ID; shGen2.X_axis_address = newSymbol.X_axis_address; shGen2.Y_axis_address = newSymbol.Y_axis_address; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Correction = 0.023437; // TEST //shGen2.Varname = "Generated* " + shGen2.Flash_start_address.ToString("X8") + " " + ms.StartAddress.ToString("X8") + " " + ms.NumRepeats.ToString() + " " + i.ToString(); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; // Console.WriteLine("Set last address to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } else if ((zaxislen * maxislen) == mapsize) { // second axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = maxislen; shGen2.Y_axis_length = zaxislen; shGen2.X_axis_ID = maxisid; shGen2.Y_axis_ID = zaxisid; shGen2.X_axis_address = maxisaddress; shGen2.Y_axis_address = zaxisaddress; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Varname = "Generated** " + shGen2.Flash_start_address.ToString("X8"); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; //Console.WriteLine("Set last address 2 to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } } //if(ms.NumRepeats } } } } newSymbol.Varname = "3D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4") + " " + yaxisid.ToString("X4"); retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; t += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; } } else { if (yaxisid > 0xC000 && yaxisid < 0xF000 && yaxislen <= 32) { Console.WriteLine("Unknown map id: " + yaxisid.ToString("X4") + " len " + yaxislen.ToString("X4") + " at address " + t.ToString("X8")); } SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Length = xaxislen * 2; newSymbol.Flash_start_address = t + 4 + (xaxislen * 2); newSymbol.Varname = "2D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4"); //newSymbols.Add(newSymbol); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2); t += (xaxislen * 2); } // 2d map } } } } return(retval); }
private bool AddToSymbolCollection(SymbolCollection newSymbols, SymbolHelper newSymbol, List<CodeBlock> newCodeBlocks) { if (newSymbol.Length >= 800) return false; foreach (SymbolHelper sh in newSymbols) { if (sh.Flash_start_address == newSymbol.Flash_start_address) { // Console.WriteLine("Already in collection: " + sh.Flash_start_address.ToString("X8")); return false; } // not allowed to overlap /* else if (newSymbol.Flash_start_address > sh.Flash_start_address && newSymbol.Flash_start_address < (sh.Flash_start_address + sh.Length)) { Console.WriteLine("Overlapping map: " + sh.Flash_start_address.ToString("X8") + " " + sh.X_axis_length.ToString() + " x " + sh.Y_axis_length.ToString()); Console.WriteLine("Overlapping new: " + newSymbol.Flash_start_address.ToString("X8") + " " + newSymbol.X_axis_length.ToString() + " x " + newSymbol.Y_axis_length.ToString()); return false; }*/ } newSymbols.Add(newSymbol); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); return true; }
public bool Contains(SymbolHelper value) { // If value is not of type Int16, this will return false. return (List.Contains(value)); }
private int GetMaxAxisValue(byte[] allBytes, SymbolHelper sh, MapViewerEx.AxisIdent axisIdent) { int retval = 0; if (axisIdent == MapViewerEx.AxisIdent.X_Axis) { //read x axis values int offset = sh.X_axis_address; for (int i = 0; i < sh.X_axis_length; i++) { int val = Convert.ToInt32(allBytes[offset]) + Convert.ToInt32(allBytes[offset + 1]) * 256; if (val > retval) retval = val; offset += 2; } } else if (axisIdent == MapViewerEx.AxisIdent.Y_Axis) { //read x axis values int offset = sh.Y_axis_address; for (int i = 0; i < sh.Y_axis_length; i++) { int val = Convert.ToInt32(allBytes[offset]) + Convert.ToInt32(allBytes[offset + 1]) * 256; if (val > retval) retval = val; offset += 2; } } return retval; }
private bool CheckMapViewerActive(SymbolHelper sh) { bool retval = false; try { foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels) { if (pnl.Text == "Symbol: " + sh.Varname + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]") { if (pnl.Tag.ToString() == Tools.Instance.m_currentfile) { if (isSymbolDisplaySameAddress(sh, pnl)) { retval = true; pnl.Show(); } } } } } catch (Exception E) { Console.WriteLine(E.Message); } return retval; }
private bool MapIsEmpty(byte[] allBytes, SymbolHelper sh) { for (int i = 0; i < sh.Length; i += 2) { int currval = Convert.ToInt32(allBytes[sh.Flash_start_address + i + 1]) * 256 + Convert.ToInt32(allBytes[sh.Flash_start_address + i]); if (currval != 0) return false; } return true; }
private bool isSymbolDisplaySameAddress(SymbolHelper sh, DockPanel pnl) { bool retval = false; try { if (pnl.Text.StartsWith("Symbol: ")) { foreach (Control c in pnl.Controls) { if (c is MapViewerEx) { MapViewerEx vwr = (MapViewerEx)c; if (vwr.Map_address == sh.Flash_start_address) retval = true; } else if (c is DevExpress.XtraBars.Docking.DockPanel) { DevExpress.XtraBars.Docking.DockPanel tpnl = (DevExpress.XtraBars.Docking.DockPanel)c; foreach (Control c2 in tpnl.Controls) { if (c2 is MapViewerEx) { MapViewerEx vwr2 = (MapViewerEx)c2; if (vwr2.Map_address == sh.Flash_start_address) retval = true; } } } else if (c is DevExpress.XtraBars.Docking.ControlContainer) { DevExpress.XtraBars.Docking.ControlContainer cntr = (DevExpress.XtraBars.Docking.ControlContainer)c; foreach (Control c3 in cntr.Controls) { if (c3 is MapViewerEx) { MapViewerEx vwr3 = (MapViewerEx)c3; if (vwr3.Map_address == sh.Flash_start_address) retval = true; } } } } } } catch (Exception E) { Console.WriteLine("isSymbolDisplaySameAddress error: " + E.Message); } return retval; }
private bool MapContainsNegativeValues(byte[] allBytes, SymbolHelper sh) { for (int i = 0; i < sh.Length; i += 2) { int currval = Convert.ToInt32(allBytes[sh.Flash_start_address + i + 1]) * 256 + Convert.ToInt32(allBytes[sh.Flash_start_address + i]); if (currval > 0xF000) return true; } return false; }
//string Name, int address, int length, int axisID) private void StartAxisViewer(SymbolHelper symbol, Axis AxisToShow) { DevExpress.XtraBars.Docking.DockPanel dockPanel; dockManager1.BeginUpdate(); try { dockPanel = dockManager1.AddPanel(DevExpress.XtraBars.Docking.DockingStyle.Right); int dw = 650; dockPanel.FloatSize = new Size(dw, 900); dockPanel.Width = dw; dockPanel.Tag = Tools.Instance.m_currentfile; ctrlAxisEditor tabdet = new ctrlAxisEditor(); tabdet.FileName = Tools.Instance.m_currentfile; if (AxisToShow == Axis.XAxis) { tabdet.AxisID = symbol.Y_axis_ID; tabdet.AxisAddress = symbol.Y_axis_address; tabdet.Map_name = symbol.X_axis_descr + " (" + symbol.Y_axis_address.ToString("X8") + ")"; int[] values = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, symbol.Varname); float[] dataValues = new float[values.Length]; for (int i = 0; i < values.Length; i++) { float fValue = (float)Convert.ToDouble(values.GetValue(i)) * (float)symbol.X_axis_correction; dataValues.SetValue(fValue, i); } tabdet.CorrectionFactor = (float)symbol.X_axis_correction; tabdet.SetData(dataValues); dockPanel.Text = "Axis: (X) " + tabdet.Map_name + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]"; } else if (AxisToShow == Axis.YAxis) { tabdet.AxisID = symbol.X_axis_ID; tabdet.AxisAddress = symbol.X_axis_address; tabdet.Map_name = symbol.Y_axis_descr + " (" + symbol.X_axis_address.ToString("X8") + ")"; int[] values = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, symbol.Varname); float[] dataValues = new float[values.Length]; for (int i = 0; i < values.Length; i++) { float fValue = (float)Convert.ToDouble(values.GetValue(i)) * (float)symbol.Y_axis_correction; dataValues.SetValue(fValue, i); } tabdet.CorrectionFactor = (float)symbol.Y_axis_correction; tabdet.SetData(dataValues); dockPanel.Text = "Axis: (Y) " + tabdet.Map_name + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]"; } tabdet.onClose += new ctrlAxisEditor.ViewerClose(axis_Close); tabdet.onSave += new ctrlAxisEditor.DataSave(axis_Save); tabdet.Dock = DockStyle.Fill; dockPanel.Controls.Add(tabdet); } catch (Exception newdockE) { Console.WriteLine(newdockE.Message); } dockManager1.EndUpdate(); System.Windows.Forms.Application.DoEvents(); }
// we need to check AHEAD for selector maps // if these are present we may be facing a complex map structure // which we need to handle in a special way (selectors always have data like 00 01 00 02 00 03 00 04 etc) private bool CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks, out int len2Skip) { len2Skip = 0; bool retval = false; bool mapFound = false; bool _dontGenMaps = false; List<MapSelector> mapSelectors = new List<MapSelector>(); if (t < allBytes.Length - 0x100) { if (CheckAxisCount(t, allBytes, out mapSelectors) > 3) { // check for selectors as well, and count them in the process Console.WriteLine("Offset " + t.ToString("X8") + " has more than 3 consecutive axis"); /*foreach (MapSelector ms in mapSelectors) { Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); }*/ _dontGenMaps = true; } int xaxisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(xaxisid)) { int xaxislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); // Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); if (isValidLength(xaxislen, xaxisid)) { //Console.WriteLine("Valid XID: " + xaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + xaxislen.ToString("X2")); // misschien is er nog een as int yaxisid = (Convert.ToInt32(allBytes[t + 5 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 4 + (xaxislen * 2)]); int yaxislen = (Convert.ToInt32(allBytes[t + 7 + (xaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 6 + (xaxislen * 2)]); if (isAxisID(yaxisid) && isValidLength(yaxislen, yaxisid)) { // 3d map int zaxisid = (Convert.ToInt32(allBytes[t + 9 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 8 + (xaxislen * 2) + (yaxislen * 2)]); //Console.WriteLine("Valid YID: " + yaxisid.ToString("X4") + " @" + t.ToString("X8") + " len: " + yaxislen.ToString("X2")); //Console.WriteLine(t.ToString("X8") + " XID: " + xaxisid.ToString("X4") + " XLEN: " + xaxislen.ToString("X2") + " YID: " + yaxisid.ToString("X4") + " YLEN: " + yaxislen.ToString("X2")); SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.Y_axis_length = yaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.Y_axis_ID = yaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Y_axis_address = t + 8 + (xaxislen * 2); newSymbol.Length = xaxislen * yaxislen * 2; newSymbol.Flash_start_address = t + 8 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(zaxisid)) { int zaxislen = (Convert.ToInt32(allBytes[t + 11 + (xaxislen * 2) + (yaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 10 + (xaxislen * 2) + (yaxislen * 2)]); int zaxisaddress = t + 12 + (xaxislen * 2) + (yaxislen * 2); if (isValidLength(zaxislen, zaxisid)) { // newSymbol.Flash_start_address += 0x10; // dan altijd 16 erbij int len2skip = (4 + zaxislen * 2); if (len2skip < 16) len2skip = 16; // at least 16 bytes newSymbol.Flash_start_address += len2skip; if (!_dontGenMaps) { // this has something to do with repeating several times with the same axis set Console.WriteLine("Added " + len2skip.ToString() + " because of z axis " + newSymbol.Flash_start_address.ToString("X8")); } else { int maxisid = (Convert.ToInt32(allBytes[t + 13 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 12 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); int maxislen = (Convert.ToInt32(allBytes[t + 15 + (xaxislen * 2) + (yaxislen * 2) + (zaxislen * 2)]) * 256) + Convert.ToInt32(allBytes[t + 14 + (xaxislen * 2) + (yaxislen * 2) + zaxislen * 2]); //maxislen *= 2; int maxisaddress = t + 16 + (xaxislen * 2) + (yaxislen * 2); if (isAxisID(maxisid)) { newSymbol.Flash_start_address += (maxislen * 2) + 4; } // special situation, handle selectors Console.WriteLine("Map start address = " + newSymbol.Flash_start_address.ToString("X8")); long lastFlashAddress = newSymbol.Flash_start_address; foreach (MapSelector ms in mapSelectors) { if (ms.NumRepeats > 0) { // check the memory size between the start of the map and the // start of the map selector long memsize = ms.StartAddress - lastFlashAddress; memsize /= 2; // in words int mapsize = Convert.ToInt32(memsize) / ms.NumRepeats; //Console.WriteLine("selector: " + ms.StartAddress.ToString("X8") + " " + ms.MapLength.ToString() + " " + ms.NumRepeats.ToString()); //Console.WriteLine("memsize = " + memsize.ToString() + " mapsize " + mapsize.ToString()); //Console.WriteLine("starting at address: " + lastFlashAddress.ToString("X8")); if ((xaxislen * yaxislen) == mapsize) { // first axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = newSymbol.X_axis_length; shGen2.Y_axis_length = newSymbol.Y_axis_length; shGen2.X_axis_ID = newSymbol.X_axis_ID; shGen2.Y_axis_ID = newSymbol.Y_axis_ID; shGen2.X_axis_address = newSymbol.X_axis_address; shGen2.Y_axis_address = newSymbol.Y_axis_address; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Correction = 0.023437; // TEST //shGen2.Varname = "Generated* " + shGen2.Flash_start_address.ToString("X8") + " " + ms.StartAddress.ToString("X8") + " " + ms.NumRepeats.ToString() + " " + i.ToString(); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; // Console.WriteLine("Set last address to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } else if ((zaxislen * maxislen) == mapsize) { // second axis set for (int i = 0; i < ms.NumRepeats; i++) { SymbolHelper shGen2 = new SymbolHelper(); shGen2.MapSelector = ms; shGen2.X_axis_length = maxislen; shGen2.Y_axis_length = zaxislen; shGen2.X_axis_ID = maxisid; shGen2.Y_axis_ID = zaxisid; shGen2.X_axis_address = maxisaddress; shGen2.Y_axis_address = zaxisaddress; shGen2.Length = mapsize * 2; //shGen2.Category = "Generated"; long address = lastFlashAddress; shGen2.Flash_start_address = address; //shGen2.Varname = "Generated** " + shGen2.Flash_start_address.ToString("X8"); shGen2.Varname = "3D " + shGen2.Flash_start_address.ToString("X8") + " " + shGen2.X_axis_ID.ToString("X4") + " " + shGen2.Y_axis_ID.ToString("X4"); retval = AddToSymbolCollection(newSymbols, shGen2, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; t += (xaxislen * 2) + (yaxislen * 2) + shGen2.Length; } lastFlashAddress = address + mapsize * 2; //Console.WriteLine("Set last address 2 to " + lastFlashAddress.ToString("X8")); } lastFlashAddress += ms.NumRepeats * 4 + 4; } } //if(ms.NumRepeats } } } } newSymbol.Varname = "3D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4") + " " + yaxisid.ToString("X4"); retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; t += (xaxislen * 2) + (yaxislen * 2) + newSymbol.Length; } } else { if (yaxisid > 0xC000 && yaxisid < 0xF000 && yaxislen <= 32) Console.WriteLine("Unknown map id: " + yaxisid.ToString("X4") + " len " + yaxislen.ToString("X4") + " at address " + t.ToString("X8")); SymbolHelper newSymbol = new SymbolHelper(); newSymbol.X_axis_length = xaxislen; newSymbol.X_axis_ID = xaxisid; newSymbol.X_axis_address = t + 4; newSymbol.Length = xaxislen * 2; newSymbol.Flash_start_address = t + 4 + (xaxislen * 2); newSymbol.Varname = "2D " + newSymbol.Flash_start_address.ToString("X8") + " " + xaxisid.ToString("X4"); //newSymbols.Add(newSymbol); newSymbol.CodeBlock = DetermineCodeBlockByByAddress(newSymbol.Flash_start_address, newCodeBlocks); retval = AddToSymbolCollection(newSymbols, newSymbol, newCodeBlocks); if (retval) { mapFound = true; len2Skip += (xaxislen * 2); t += (xaxislen * 2); } // 2d map } } } } return mapFound; }
private void StartCompareDifferenceViewer(SymbolHelper sh, string Filename, int SymbolAddress) { DevExpress.XtraBars.Docking.DockPanel dockPanel; bool pnlfound = false; foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels) { if (pnl.Text == "Symbol difference: " + sh.Varname + " [" + Path.GetFileName(Tools.Instance.m_currentfile) + "]") { dockPanel = pnl; pnlfound = true; dockPanel.Show(); } } if (!pnlfound) { dockManager1.BeginUpdate(); try { dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500)); dockPanel.Tag = Tools.Instance.m_currentfile; MapViewerEx tabdet = new MapViewerEx(); tabdet.Map_name = sh.Varname; tabdet.IsDifferenceViewer = true; tabdet.AutoUpdateIfSRAM = false; tabdet.AutoUpdateInterval = 999999; tabdet.Viewtype = m_appSettings.DefaultViewType; tabdet.DisableColors = m_appSettings.DisableMapviewerColors; tabdet.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows; tabdet.GraphVisible = m_appSettings.ShowGraphs; tabdet.IsRedWhite = m_appSettings.ShowRedWhite; tabdet.SetViewSize(m_appSettings.DefaultViewSize); tabdet.Filename = Filename; tabdet.Map_descr = tabdet.Map_name; tabdet.Map_cat = XDFCategories.Undocumented; tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name); tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name); SymbolAxesTranslator axestrans = new SymbolAxesTranslator(); string x_axis = string.Empty; string y_axis = string.Empty; string x_axis_descr = string.Empty; string y_axis_descr = string.Empty; string z_axis_descr = string.Empty; tabdet.X_axis_name = sh.X_axis_descr; tabdet.Y_axis_name = sh.Y_axis_descr; tabdet.Z_axis_name = sh.Z_axis_descr; tabdet.XaxisUnits = sh.XaxisUnits; tabdet.YaxisUnits = sh.YaxisUnits; tabdet.X_axisAddress = sh.Y_axis_address; tabdet.Y_axisAddress = sh.X_axis_address; tabdet.Xaxiscorrectionfactor = sh.X_axis_correction; tabdet.Yaxiscorrectionfactor = sh.Y_axis_correction; tabdet.X_axisvalues = GetXaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name); tabdet.Y_axisvalues = GetYaxisValues(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name); //tabdet.Map_sramaddress = GetSymbolAddressSRAM(SymbolName); int columns = 8; int rows = 8; int tablewidth = GetTableMatrixWitdhByName(Tools.Instance.m_currentfile, Tools.Instance.m_symbols, tabdet.Map_name, out columns, out rows); int address = Convert.ToInt32(SymbolAddress); if (address != 0) { tabdet.Map_address = address; int length = sh.Length; tabdet.Map_length = length; byte[] mapdata = Tools.Instance.readdatafromfile(Filename, address, length, Tools.Instance.m_currentFileType); byte[] mapdataorig = Tools.Instance.readdatafromfile(Filename, address, length, Tools.Instance.m_currentFileType); byte[] mapdata2 = Tools.Instance.readdatafromfile(Tools.Instance.m_currentfile, (int)GetSymbolAddress(Tools.Instance.m_symbols, sh.Varname), GetSymbolLength(Tools.Instance.m_symbols, sh.Varname), Tools.Instance.m_currentFileType); tabdet.Map_original_content = mapdataorig; tabdet.Map_compare_content = mapdata2; if (mapdata.Length == mapdata2.Length) { for (int bt = 0; bt < mapdata2.Length; bt += 2) { int value1 = Convert.ToInt16(mapdata.GetValue(bt)) * 256 + Convert.ToInt16(mapdata.GetValue(bt + 1)); int value2 = Convert.ToInt16(mapdata2.GetValue(bt)) * 256 + Convert.ToInt16(mapdata2.GetValue(bt + 1)); value1 = Math.Abs((int)value1 - (int)value2); byte v1 = (byte)(value1 / 256); byte v2 = (byte)(value1 - (int)v1 * 256); mapdata.SetValue(v1, bt); mapdata.SetValue(v2, bt + 1); } tabdet.Map_content = mapdata; tabdet.UseNewCompare = true; tabdet.Correction_factor = sh.Correction; tabdet.Correction_offset = sh.Offset; tabdet.IsUpsideDown = m_appSettings.ShowTablesUpsideDown; tabdet.ShowTable(columns, true); tabdet.Dock = DockStyle.Fill; tabdet.onClose += new MapViewerEx.ViewerClose(tabdet_onClose); dockPanel.Text = "Symbol difference: " + sh.Varname + " [" + Path.GetFileName(Filename) + "]"; bool isDocked = false; if (!isDocked) { dockPanel.DockTo(dockManager1, DevExpress.XtraBars.Docking.DockingStyle.Right, 0); if (m_appSettings.AutoSizeNewWindows) { if (tabdet.X_axisvalues.Length > 0) { dockPanel.Width = 30 + ((tabdet.X_axisvalues.Length + 1) * 45); } else { //dockPanel.Width = this.Width - dockSymbols.Width - 10; } } if (dockPanel.Width < 400) dockPanel.Width = 400; // dockPanel.Width = 400; } dockPanel.Controls.Add(tabdet); } else { frmInfoBox info = new frmInfoBox("Map lengths don't match..."); } } } catch (Exception E) { Console.WriteLine(E.Message); } dockManager1.EndUpdate(); } }
public int Add(SymbolHelper value) { return(List.Add(value)); }
private bool MapSelectorIndexEmpty(SymbolHelper sh) { bool retval = true; if (sh.MapSelector != null) { foreach (int iTest in sh.MapSelector.MapIndexes) { if (iTest != 0) retval = false; } } return retval; }
private int CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks) { int retval = 0; // read LL LL int len1 = Convert.ToInt32(allBytes[t]) * 256 + Convert.ToInt32(allBytes[t + 1]); int len2 = Convert.ToInt32(allBytes[t + 2]) * 256 + Convert.ToInt32(allBytes[t + 3]); if (len1 < 32 && len2 < 32 && len1 > 0 && len2 > 0) { SymbolHelper sh = new SymbolHelper(); sh.X_axis_address = t + 4; sh.X_axis_length = len1; sh.Y_axis_address = sh.X_axis_address + sh.X_axis_length * 2; sh.Y_axis_length = len2; sh.Flash_start_address = sh.Y_axis_address + sh.Y_axis_length * 2; sh.Length = sh.X_axis_length * sh.Y_axis_length * 2; if (sh.X_axis_length > 1 && sh.Y_axis_length > 1) { sh.Varname = "3D " + sh.Flash_start_address.ToString("X8"); } else { sh.Varname = "2D " + sh.Flash_start_address.ToString("X8"); } AddToSymbolCollection(newSymbols, sh, newCodeBlocks); retval = (len1 + len2) * 2 + sh.Length ; } return retval; }
public bool Contains(SymbolHelper value) { // If value is not of type Int16, this will return false. return(List.Contains(value)); }
// EDC17 Little<->Bigendian compared to EDC16 private int CheckMap(int t, byte[] allBytes, SymbolCollection newSymbols, List<CodeBlock> newCodeBlocks) { int retval = 0; // read LL LL int len1 = Convert.ToInt32(allBytes[t]) * 256 + Convert.ToInt32(allBytes[t+1]); int len2 = Convert.ToInt32(allBytes[t+2]) * 256 + Convert.ToInt32(allBytes[t + 3]); if(len1 == 1 && len2 == 1) return retval; // BMW uses up to 40(0x28) for one axis. if ((len1 <= 64 && len2 <= 64) && (len1 > 0 && len2 >= 0)) { //Console.WriteLine("---New map-- t=" + t.ToString("X")); bool ok = true; int startX = t + 2; // For 0D-arrays if(len2 > 0) startX += 2; // For 2D and 3D-arrays for(int dX = startX;dX <= startX + len1 * 2 - 4;dX += 2) { int b1 = Convert.ToInt32(allBytes[dX]) * 256 + Convert.ToInt32(allBytes[dX+1]); int b2 = Convert.ToInt32(allBytes[dX+2]) * 256 + Convert.ToInt32(allBytes[dX + 3]); if(b1 >= b2) { ok = false; break; } } //Console.WriteLine("-----"); if(len2 > 0) { for(int dY = startX + len1 * 2;dY <= startX + len1 * 2 + len2 * 2 - 4;dY += 2) { int b1 = Convert.ToInt32(allBytes[dY]) * 256 + Convert.ToInt32(allBytes[dY + 1]); int b2 = Convert.ToInt32(allBytes[dY + 2]) * 256 + Convert.ToInt32(allBytes[dY + 3]); if(b1 >= b2) { ok = false; break; } } } if(ok) { //Console.WriteLine("--------------"); //for(int i=t; i<t+len1*len2*2;i++) // Console.Write(allBytes[t].ToString("X2")); //Console.WriteLine("----end----"); SymbolHelper sh = new SymbolHelper(); sh.X_axis_length = len1; if(len2 == 0) { sh.X_axis_address = t + 2; sh.Y_axis_address = t + 2; sh.Y_axis_length = 1; sh.Flash_start_address = t + 2 + len1*2; sh.Varname = "1D " + sh.Flash_start_address.ToString("X8"); sh.Is1D = true; } else { sh.X_axis_address = t + 4; sh.Y_axis_length = len2; sh.Y_axis_address = sh.X_axis_address + sh.X_axis_length * 2; sh.Flash_start_address = sh.Y_axis_address + sh.Y_axis_length * 2; if(sh.X_axis_length > 1 && sh.Y_axis_length > 1) { sh.Varname = "3D " + sh.Flash_start_address.ToString("X8"); sh.Is3D = true; } else { sh.Varname = "2D " + sh.Flash_start_address.ToString("X8"); sh.Is2D = true; } } sh.Length = sh.X_axis_length * sh.Y_axis_length * 2; //sh.Varname = sh.Flash_start_address.ToString("X8"); int length = (len1 + len2) * 2 + sh.Length + 4; sh.Currentdata = new byte[length]; Array.Copy(allBytes, t, sh.Currentdata, 0, length); AddToSymbolCollection(newSymbols, sh, newCodeBlocks); retval = (len1 + len2) * 2 + sh.Length; } } return retval; }