VAGSuite.EDC17FileParser.CheckMap C# (CSharp) Метод

CheckMap() приватный Метод

private CheckMap ( int t, byte allBytes, SymbolCollection newSymbols, List newCodeBlocks ) : int
t int
allBytes byte
newSymbols SymbolCollection
newCodeBlocks List
Результат int
        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;
        }