예제 #1
0
        public bool UpdateBootloader(string File)
        {
            Crc16Ccitt CRC = new Crc16Ccitt(InitialCrcValue.Zeros);

            FileInfo     bl   = new FileInfo(File);
            StreamReader Read = new StreamReader(File);

            if (Board == null)
            {
                LoadBoardInfo();
            }

            // load header of the bootloader file
            BootloaderImage img = BootloaderImage.Load(File);

            if (Board.Board != img.Board)
            {
                return(false);
            }
            else if (img.Revision != 0 && img.Revision != Board.BoardRevision)
            {
                return(false);
            }

            int Pages = (int)Math.Ceiling((double)bl.Length / Board.PageSize);

            for (int Page = 0; Page < Pages; Page++)
            {
                for (int Part = 0; Part < Board.PageSize / ChunkSize; Part++)
                {
                    byte[] Content = new byte[ChunkSize];

                    PacketPAGE packet = new PacketPAGE();
                    packet.Part       = (byte)Part;
                    packet.PageNumber = (byte)Page;
                    for (int i = 0; i < ChunkSize; i++)
                    {
                        if (i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize < (img.Length - 8))
                        {
                            Content[i] = img.Content[i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize];
                        }
                        else
                        {
                            Content[i] = 0;
                        }
                    }

                    packet.CRC16   = CRC.ComputeChecksum(Content);
                    packet.Payload = Content;

                    packet.Send(Comm);
                }
            }

            return(true);
        }
예제 #2
0
파일: XComm.cs 프로젝트: CallMeFoxie/XIDE
        public bool UpdateBootloader(string File)
        {
            Crc16Ccitt CRC = new Crc16Ccitt(InitialCrcValue.Zeros);

            FileInfo bl = new FileInfo(File);
            StreamReader Read = new StreamReader(File);

            if (Board == null)
                LoadBoardInfo();

            // load header of the bootloader file
            BootloaderImage img = BootloaderImage.Load(File);

            if(Board.Board != img.Board)
                return false;
            else if (img.Revision != 0 && img.Revision != Board.BoardRevision)
                return false;

            int Pages = (int)Math.Ceiling((double)bl.Length / Board.PageSize);

            for (int Page = 0; Page < Pages; Page++)
            {
                for (int Part = 0; Part < Board.PageSize / ChunkSize; Part++)
                {
                    byte[] Content = new byte[ChunkSize];

                    PacketPAGE packet = new PacketPAGE();
                    packet.Part = (byte)Part;
                    packet.PageNumber = (byte)Page;
                    for (int i = 0; i < ChunkSize; i++)
                    {
                        if(i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize < (img.Length - 8))
                            Content[i] = img.Content[i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize];
                        else
                            Content[i] = 0;
                    }

                    packet.CRC16 = CRC.ComputeChecksum(Content);
                    packet.Payload = Content;

                    packet.Send(Comm);
                }
            }

            return true;
        }