private int CheckAxisCount(int offset, byte[] allBytes, out List<MapSelector> mapSelectors) { int axisCount = 0; mapSelectors = new List<MapSelector>(); bool axisFound = true; int t = offset; while (axisFound) { axisFound = false; int axisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(axisid)) { int axislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); if (axislen > 0 && axislen < 32) { axisCount++; axisFound = true; t += 4 + (axislen * 2); } } } // search from offset 't' for selectors // maximum searchrange = 0x1000 int BytesToSearch = 5120 + 16; if (axisCount > 3) { while (BytesToSearch > 0) { int axisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(axisid)) { //Console.WriteLine("Checking address: " + t.ToString("X8")); int axislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); if (axislen <= 10) // more is not valid for selectors { // read & verify data (00 00 00 01 00 02 00 03 etc) bool selectorValid = true; int num = 0; uint prevSelector = 0; for (int i = 0; i < (axislen * 2); i += 2) { uint selValue = Convert.ToUInt32(allBytes[t + 4 + (axislen * 2) + i]) + Convert.ToUInt32(allBytes[t + 4 + (axislen * 2) + 1 + i]); //Console.WriteLine("Selval: " + selValue.ToString() + " num: " + num.ToString()); if (allBytes[t + 4 + (axislen * 2) + i] != 0) { selectorValid = false; break; } if (allBytes[t + 4 + (axislen * 2) + 1 + i] > 9) { selectorValid = false; break; } if (prevSelector > selValue) { selectorValid = false; break; } prevSelector = selValue; /*if (num != selValue) { // not a valid selector selectorValid = false; break; }*/ num++; } if (selectorValid) { // create a new selector //Console.WriteLine("Selector valid " + t.ToString("X8")); MapSelector newSel = new MapSelector(); newSel.NumRepeats = axislen; newSel.StartAddress = t; mapSelectors.Add(newSel); BytesToSearch = 5120 + 16; } } } t += 2; BytesToSearch -= 2; } } return axisCount; }
// 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; }
//SOI is selected on ECT! private double GetTemperatureSOIRange(MapSelector sh, int index) { double retval = index; if (sh.MapData != null) { if (sh.MapData.Length > index) { retval = (Convert.ToDouble(sh.MapData.GetValue(index)) * 0.1) - 273.1; } } return Math.Round(retval, 0); }
private int CheckAxisCount(int offset, byte[] allBytes, out List <MapSelector> mapSelectors) { int axisCount = 0; mapSelectors = new List <MapSelector>(); bool axisFound = true; int t = offset; while (axisFound) { axisFound = false; int axisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(axisid)) { int axislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); if (axislen > 0 && axislen < 32) { axisCount++; axisFound = true; t += 4 + (axislen * 2); } } } // search from offset 't' for selectors // maximum searchrange = 0x1000 int BytesToSearch = 5120 + 16; if (axisCount > 3) { while (BytesToSearch > 0) { int axisid = (Convert.ToInt32(allBytes[t + 1]) * 256) + Convert.ToInt32(allBytes[t]); if (isAxisID(axisid)) { //Console.WriteLine("Checking address: " + t.ToString("X8")); int axislen = (Convert.ToInt32(allBytes[t + 3]) * 256) + Convert.ToInt32(allBytes[t + 2]); if (axislen <= 10) // more is not valid for selectors { // read & verify data (00 00 00 01 00 02 00 03 etc) bool selectorValid = true; int num = 0; uint prevSelector = 0; for (int i = 0; i < (axislen * 2); i += 2) { uint selValue = Convert.ToUInt32(allBytes[t + 4 + (axislen * 2) + i]) + Convert.ToUInt32(allBytes[t + 4 + (axislen * 2) + 1 + i]); //Console.WriteLine("Selval: " + selValue.ToString() + " num: " + num.ToString()); if (allBytes[t + 4 + (axislen * 2) + i] != 0) { selectorValid = false; break; } if (allBytes[t + 4 + (axislen * 2) + 1 + i] > 9) { selectorValid = false; break; } if (prevSelector > selValue) { selectorValid = false; break; } prevSelector = selValue; /*if (num != selValue) * { * // not a valid selector * selectorValid = false; * break; * }*/ num++; } if (selectorValid) { // create a new selector //Console.WriteLine("Selector valid " + t.ToString("X8")); MapSelector newSel = new MapSelector(); newSel.NumRepeats = axislen; newSel.StartAddress = t; mapSelectors.Add(newSel); BytesToSearch = 5120 + 16; } } } t += 2; BytesToSearch -= 2; } } return(axisCount); }