Пример #1
0
        public void WriteFlash(PagesOfCode poc)
        {
            // Czy jest kod do zapisania?
            if ((poc == null) || (poc.PageCount == 0))
            {
                Console.WriteLine("[Warning!] No flash data to write. ");
                return;
            }

            //Pomiar czasu zapisu
            DateTime startT = DateTime.Now;

            Console.WriteLine("  0%                          100%");
            Console.WriteLine("  V                            V");
            Console.Write("  ");
            //For every page

            int lastnum = 0;
            int pagenum = 0;

            //Dla kadej strony
            foreach (PageOfCode page in poc.Pages)
            {
                pagenum++;
                //Jeżeli strona nie istnieje to pomijamy
                if (page != null)
                {
                    //Określamy nr strony w pamięci
                    if (page.number >= ((device.FlashSize - this.bootloaderSize) / device.FlashPageSize))
                    {
                        Console.WriteLine("[Warning!] Chip out of memory. Page {0} cannot be written. Aborting operation.", page.number);
                        break;;  //Nie nadpiszemy bootloadera
                    }

                    //Programujemy
                    WriteFlashPage(page);

                    if (OnFlashPageWriteSuccess != null)
                    {
                        OnFlashPageWriteSuccess(page.number, poc.PageCount);
                    }
                }
                //Obliczenia do wyświetlania paska postępu
                int newnum = (int)((float)30 * (pagenum - 1) / (poc.PageCount - 1));
                for (int i = 0; i < (newnum - lastnum); i++)
                {
                    Console.Write("|");
                }
                lastnum = newnum;
            }


            //Enable rww section
            EnableRRW();

            TimeSpan time = DateTime.Now.Subtract(startT);

            Console.WriteLine("\n Writing time: {0}, {1}s {2}ms.", time.Minutes, time.Seconds, time.Milliseconds);
            Console.WriteLine("\nFlash write operation. [OK]");
        }
Пример #2
0
        public static PagesOfCode ImportRawBinary(string filename, int pagesize)
        {
            FileStream  fs  = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
            PagesOfCode poc = new PagesOfCode((int)(1 + (fs.Length / pagesize)));

            try
            {
                int        byteCounter = pagesize;
                int        pageNumber  = 0;
                PageOfCode page        = new PageOfCode();

                //Analiza każdej linii
                while (fs.Position != fs.Length)
                {
                    byteCounter--;
                    page.code.Add((byte)fs.ReadByte());
                    if (byteCounter == 0)
                    {
                        poc.InsertPage(page, pageNumber);
                        pageNumber++;
                        byteCounter = pagesize;
                        page        = new PageOfCode();
                    }
                }
                if (byteCounter != 0)
                {
                    while (byteCounter != 0)
                    {
                        page.code.Add(0x00);
                        byteCounter--;
                    }
                    poc.InsertPage(page, pageNumber);
                }
            }
            catch (Exception exc)
            {
                fs.Close();
                throw new Exception("File read error:" + exc.Message);
            }

            fs.Close();
            return(poc);
        }
Пример #3
0
        public static PagesOfCode ImportRawBinaryDiff(string oldFile, string newFile, int pagesize)
        {
            FileStream oldF = new FileStream(oldFile, FileMode.Open, FileAccess.Read, FileShare.None);
            FileStream newF = new FileStream(newFile, FileMode.Open, FileAccess.Read, FileShare.None);

            PagesOfCode poc = new PagesOfCode((int)(1 + (newF.Length / pagesize)));

            try
            {
                int         pageNumber = 0;
                List <byte> buffer     = new List <byte>(pagesize);
                bool        diff       = false;

                //Analiza każdego bajtu nowego pliku
                while (newF.Position != newF.Length)
                {
                    for (int i = 0; i < pagesize; i++)
                    {
                        int newB = newF.ReadByte();
                        int oldB = oldF.ReadByte();

                        if (newB == -1)
                        {
                            //Dopełnienie strony
                            buffer.Add(0x00);
                        }
                        else
                        if (oldB == -1)
                        {
                            buffer.Add((byte)newB);
                        }
                        else
                        {
                            if (newB != oldB)
                            {
                                diff = true;
                            }
                            buffer.Add((byte)newB);
                        }

                        if (buffer.Count == pagesize)
                        {
                            if (diff)
                            {
                                PageOfCode page = new PageOfCode();
                                page.code = buffer;
                                poc.InsertPage(page, pageNumber);
                            }
                            pageNumber++;
                            buffer = new List <byte>(pagesize);
                            diff   = false;
                        }
                    }
                }
                if (buffer.Count != 0)
                {
                    for (int i = 0; i < (pagesize - buffer.Count); i++)
                    {
                        buffer.Add(0x00);
                    }
                    PageOfCode page = new PageOfCode();
                    page.code = buffer;
                    poc.InsertPage(page, pageNumber);
                }
            }
            catch (Exception exc)
            {
                newF.Close();
                oldF.Close();
                throw new Exception("Files read error:" + exc.Message);
            }

            newF.Close();
            oldF.Close();
            return(poc);
        }