采用TCP協(xié)議的PIC32MZ ethernet bootloader
趁熱打鐵,在上一PIC32MZ UDP ethernet bootloader的基礎上我又完成了采用TCP協(xié)議的PIC32MZ ethernet bootloader。兩款ethernet bootloader基本架構都一樣,數(shù)據(jù)包格式也一樣。TCP ethernet bootloader 也分兩部分,我將他們命名為PhnLoader_v4.0和PhnBoot_v4.0。
PhnLoader_v4.0
PhnLoader_v4.0 是PC端host 程序。
運行環(huán)境:Window + .NET Framework 4.5
開發(fā)語言:C#
通信類型:TCP Server
IP 地址: 192.168.1.105
端口號: 8720
UI 如下:
主要代碼如下:
try{while(loaderReader.Peek()>=0){pBarLoading.PerformStep();recordLine=loaderReader.ReadLine();if(recordLine.Contains(EXTEND_TOKEN)==true){if(recordLine.Contains(USER_ID_TOKEN)==true){isNextLineUserID=true;continue;}//elseif(recordLine.Contains(CONFIG_BITS_TOKEN)==true)//{//constintADDR_U_START_INDEX=9;//constintADDR_U_LENGTH=4;//stringaddrU=recordLine.Substring(ADDR_U_START_INDEX,ADDR_U_LENGTH);//loaderUpperAddr=Convert.ToInt32(addrU,16)<<16;//isNextLineConfigBits=true;//continue;//}elseif(recordLine.Contains(PIC32_CONFIG_BITS_TOKEN)==true){constintADDR_U_START_INDEX=9;constintADDR_U_LENGTH=4;stringaddrU=recordLine.Substring(ADDR_U_START_INDEX,ADDR_U_LENGTH);loaderUpperAddr=Convert.ToInt32(addrU,16)<<16;isNextLineConfigBits=true;continue;}else{constintADDR_U_START_INDEX=9;constintADDR_U_LENGTH=4;stringaddrU=recordLine.Substring(ADDR_U_START_INDEX,ADDR_U_LENGTH);loaderUpperAddr=Convert.ToInt32(addrU,16)<<16;continue;}}elseif(recordLine.Contains(END_OF_HEX_FILE_TOKEN)==true){break;}if(isNextLineUserID){isNextLineUserID=false;//donothing;}elseif(isNextLineConfigBits){if(!DownloadConfigLine(recordLine)){Debug.WriteLine("Errorfoundduringconfigurationbitsprogramming");loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}isNextLineConfigBits=false;}else{if(!DownloadDataLine(recordLine)){Debug.WriteLine("Errorfoundduringdataprogramming");loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}}}}catch(Exceptionex){Debug.WriteLine("Error:"+ex.Message);textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Downloadingfailedrn");textBoxStatus.ForeColor=Color.Black;loaderServer.Close();loaderReader.Close();btnDownload.Enabled=true;return;}textBoxStatus.AppendText("Downloadingcompletedrn");