/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { ProgressBar progressBar; int blockCnt = 0; Console.WriteLine("ConsoleUtility Test Program."); Console.WriteLine(""); // Test default progress Bar progressBar = new ProgressBar(); progressBar.Update(0.0,"Testing Default ProgressBar"); blockCnt = 15; for (int i = 0; i < blockCnt; i++) { Thread.Sleep(100); progressBar.Percent = (((Double)(i+1))/blockCnt); //Console.WriteLine(Console.CursorTop); } progressBar.Update(100.0,"Test Default ProgressBar complete."); // Test progress bar of specified length progressBar = new ProgressBar(40); progressBar.Update(0.0,"Testing ProgressBar(40)"); blockCnt = 6; for (int i = 0; i < blockCnt; i++) { Thread.Sleep(100); progressBar.Percent = (((Double)(i+1))/blockCnt); //Console.WriteLine(Console.CursorTop); if (i == 4) progressBar.Write(i.ToString() + "\n\n\n" + "\n"); } progressBar.Update(100.0,"Test ProgressBar(40) complete."); // Test progress bar of specified length and position progressBar = new ProgressBar(50,Position.RIGHT,Position.TOP); progressBar.Update(0.0,"Testing ProgressBar(50, RIGHT, TOP)"); blockCnt = 10; for (int i = 0; i < blockCnt; i++) { Thread.Sleep(300); progressBar.Percent = (((Double)(i+1))/blockCnt); //Console.WriteLine(Console.CursorTop); } progressBar.Update(100.0,"Test ProgressBar(50, RIGHT, TOP) complete."); return 0; }
public static void WriteLine(ProgressBar pb, String text) { pb.WriteLine(text); }
/// <summary> /// Function to transmit the application code via the SFT, which is now /// running on the device. This code is specific to the supplied SFT. /// If the the TI supplied SFT is modified or a different boot loader is /// used, this code will need to be modified. /// </summary> private static Boolean TransmitImage(Byte[] imageData, ImageHeader ackHeader) { ProgressBar progressBar; UInt32 blockCnt; try { // Console.WriteLine("Waiting for SENDIMG sequence..."); if (!SerialIO.waitForSequence("SENDIMG\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { Console.Write("UART response didnt match\n"); return false; } // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of magic number MySP.Write(String.Format("{0:X8}", ackHeader.magicNum)); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.startAddr)); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.byteCnt)); // 8 bytes of binary load address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.loadAddr)); // 8 bytes of flash address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.flashAddr)); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); //Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (!SerialIO.waitForSequence(" BEGIN\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return false; } //Console.WriteLine("BEGIN commmand received."); // Send the image data progressBar = new ProgressBar(); progressBar.Update(0.0,"Sending image over UART..."); blockCnt = ackHeader.byteCnt/128; for (int i = 0; i < (blockCnt*128); i+=128) { MySP.Write(imageData, i, 128); progressBar.Percent = (((Double)(i+1))/ackHeader.byteCnt); } // Write last (possibly partial) block MySP.Write(imageData, (Int32) (blockCnt*128),(Int32) (ackHeader.byteCnt - (blockCnt*128)) ); progressBar.Update(100.0,"Image data transmitted over UART."); //Console.WriteLine("Waiting for DONE..."); // Wait for first ^^^DONE\0 to indicate data received if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return false; } //Console.WriteLine("DONE received. All bytes of image data received..."); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } return true; }
/// <summary> /// Function to display progress bar when transmitting/erasing via SPI /// </summary> private static void DisplayProgressBar(uint totalSize, int chunksize, string loadingText, string verifyingText, string finishedText) { ProgressBar progressBar = new ProgressBar(); int sending, sent; progressBar.Update(0.0,loadingText); sending = 1; sent = 0; while(sending==1) { if (!SerialIO.waitForSequence(" DONE\0", "SENDING\0", MySP, cmdParams.verbose)) { if(totalSize < chunksize) { progressBar.Percent = 100; } else { progressBar.Percent =(Double)sent/(totalSize/chunksize); } if(progressBar.Percent >=1) { progressBar.Update(100.0,verifyingText); } sent++; } else { sending = 0; progressBar.Update(100,finishedText); } } }
/// <summary> /// Function to Transmit the UBL via the device ROM Serial boot /// </summary> private static void TransmitUBL(Byte[] imageData,UARTBOOT_Header ackHeader) { // Local Variables for building up output StringBuilder UBLsb; CRC32 MyCRC; ProgressBar progressBar; Int32 blockCnt; UBLsb = new StringBuilder(imageData.Length * 2); // Read the data from the UBL file into the appropriate structures for (int i=0; i<imageData.Length; i+=sizeof(UInt32)) { UBLsb.AppendFormat("{0:X8}", System.BitConverter.ToUInt32(imageData,i)); } // Create CRC object and use it to calculate the UBL file's CRC // Note that this CRC is not quite the standard CRC-32 algorithm // commonly in use since the final register value is not XOR'd // with 0xFFFFFFFF. As a result the CRC value returned here // will be the bitwise inverse of the standard CRC-32 value. MyCRC = new CRC32(0x04C11DB7, 0xFFFFFFFF, 0x00000000, true, 1, CRCType.ONESHOT, CRCCalcMethod.LUT); ackHeader.crcVal = MyCRC.CalculateCRC(imageData); ackHeader.byteCnt = (UInt32) imageData.Length; try { BOOTMESEQ: Console.WriteLine("\nWaiting for the "+devString+"..."); // Wait for the device to send the ^BOOTME/0 sequence if (SerialIO.waitForSequence(" BOOTME\0", " BOOTME\0", MySP, cmdParams.verbose)) Console.WriteLine("BOOTME commmand received. Returning ACK and header..."); else goto BOOTMESEQ; // Output 28 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of CRC data = ASCII string of 8 hex characters MySP.Write(ackHeader.crcVal.ToString("X8")); // 4 bytes of UBL data size = ASCII string of 4 hex characters (3800h = 14336d) MySP.Write(ackHeader.byteCnt.ToString("X4")); // 4 bytes of start address = ASCII string of 4 hex characters (>=0100h) MySP.Write(ackHeader.startAddr.ToString("X4")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the BEGIN sequence if (SerialIO.waitForSequence(" BEGIN\0", " BOOTME\0", MySP,true)) { Console.WriteLine("BEGIN commmand received. Sending CRC table..."); } else { goto BOOTMESEQ; } // Send the 1024 byte (256 word) CRC table progressBar = new ProgressBar(); progressBar.Update(0.0,"Sending CRC table..."); for (int i = 0; i < MyCRC.Length; i++) { MySP.Write(MyCRC[i].ToString("x8")); progressBar.Percent = (((Double)(i+1))/MyCRC.Length); } progressBar.Update(100.0,"CRC table sent."); Console.WriteLine("Waiting for DONE..."); // Wait for the first DONE sequence if (SerialIO.waitForSequence(" DONE\0", " BOOTME\0", MySP, cmdParams.verbose)) { Console.WriteLine("DONE received. Sending the UBL..."); } else { goto BOOTMESEQ; } // Send the contents of the UBL file (as hex text) progressBar = new ProgressBar(); progressBar.Update(0.0,"Sending UBL..."); blockCnt = UBLsb.Length/128; for (int i = 0; i < (blockCnt*128); i+=128) { MySP.Write(UBLsb.ToString(i,128)); progressBar.Percent = (((Double)(i+1))/UBLsb.Length); } // Write last (possibly partial) block MySP.Write(UBLsb.ToString(blockCnt*128,UBLsb.Length - (blockCnt*128) )); progressBar.Update(100.0,"UBL sent."); // Wait for the second DONE sequence if (SerialIO.waitForSequence(" DONE\0", " BOOTME\0", MySP, cmdParams.verbose)) { Console.WriteLine("DONE received. UBL was accepted."); } else { goto BOOTMESEQ; } } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } }