Ejemplo n.º 1
0
        /// <summary>
        /// Updates the page.
        /// </summary>
        /// <param name="subPageNumber">The sub page number.</param>
        /// <param name="pageData">The page data.</param>
        /// <returns></returns>
        private void UpdatePage(int subPageNumber, byte[] pageData)
        {
            if (subPageNumber < 0 || subPageNumber > _numberOfSubPages)
            {
                return;
            }
            IntPtr pagePtr = _pageCache[subPageNumber];

            unsafe
            {
                byte *ptr   = (byte *)pagePtr.ToPointer();
                bool  isSet = Hamming.IsEraseBitSet(0, ref pageData);
                for (int row = 0; row < 31; row++)
                {
                    int off = row * 42;
                    if (row != 0)
                    {
                        if (pageData[off] == 32 && isSet)
                        {
                            for (int col = 0; col < 42; col++)
                            {
                                if (ptr[off + col] != 32 && pageData[off + col] == 32)
                                {
                                    ptr[off + col] = 32;
                                }
                            }
                            continue;
                        }
                    }


                    off = row * 42;
                    int rowNr = Hamming.GetPacketNumber(off, ref pageData);
                    if (rowNr < 0)
                    {
                        continue;
                    }
                    for (int col = 0; col < 42; col++)
                    {
                        byte newData = pageData[off + col];
                        if (rowNr != 0)
                        {
                            if (ptr[off + col] != newData)
                            {
                                if (rowNr >= 1 && rowNr <= 24)
                                {
                                    if (col >= 2)
                                    {
                                        if (OddParity.IsCorrect(newData))
                                        {
                                            ptr[off + col] = newData;
                                        }
                                    }
                                    else if (Hamming.Decode[newData] != 0xff)
                                    {
                                        //bytes 0-1 = row/column, hamming 8/4 coded
                                        ptr[off + col] = newData;
                                    }
                                }
                                else
                                {
                                    //rows 25,26,27
                                    ptr[off + col] = newData;
                                }
                            }
                        }
                        else
                        {
                            //row 0
                            ptr[off + col] = newData;
                        }
                    }
                }
            }

            return;
        }
Ejemplo n.º 2
0
        private bool PageDiffers(byte[] pageData, int subPageNumber)
        {
            if (subPageNumber < 0 || subPageNumber > _numberOfSubPages)
            {
                return(false);
            }
            IntPtr pagePtr = _pageCache[subPageNumber];

            if (pagePtr == IntPtr.Zero)
            {
                return(false);
            }
            unsafe
            {
                byte *ptr   = (byte *)pagePtr.ToPointer();
                bool  isSet = Hamming.IsEraseBitSet(0, ref pageData);
                for (int row = 0; row < 31; row++)
                {
                    int off = row * 42;
                    if (row != 0)
                    {
                        if (pageData[off] == 32 && isSet)
                        {
                            for (int col = 0; col < 42; col++)
                            {
                                if (ptr[off + col] != 32 && pageData[off + col] == 32)
                                {
                                    return(true);
                                }
                            }
                            continue;
                        }
                    }


                    off = row * 42;
                    int rowNr = Hamming.GetPacketNumber(off, ref pageData);

                    if (rowNr < 0)
                    {
                        continue;
                    }
                    for (int col = 0; col < 42; col++)
                    {
                        byte newData = pageData[off + col];
                        if (rowNr != 0)
                        {
                            if (ptr[off + col] != newData)
                            {
                                if (rowNr >= 1 && rowNr <= 24)
                                {
                                    if (col >= 2)
                                    {
                                        if (OddParity.IsCorrect(newData))
                                        {
                                            // Trace.WriteLine(String.Format("2) {0:X}/{1} r:{2} c:{3} {4} {5:X}!={6:X}", _pageNumber, subPageNumber, row, col, _clearSubPage[subPageNumber], ptr[off + col], pageData[off + col]));
                                            return(true);
                                        }
                                    }
                                    else if (Hamming.Decode[newData] != 0xff)
                                    {
                                        //bytes 0-1 = row/column, hamming 8/4 coded

                                        //Trace.WriteLine(String.Format("3) {0:X}/{1} r:{2} c:{3} {4} {5:X}!={6:X}", _pageNumber, subPageNumber, row, col, _clearSubPage[subPageNumber], ptr[off + col], pageData[off + col]));
                                        return(true);
                                    }
                                }
                                else
                                {
                                    //rows 25,26,27

                                    //Trace.WriteLine(String.Format("4) {0:X}/{1} r:{2} c:{3} {4} {5:X}!={6:X}", _pageNumber, subPageNumber, row, col, _clearSubPage[subPageNumber], ptr[off + col], pageData[off + col]));
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }