采用TCP协议的PIC32MZ ethernet bootloader
扫描二维码
随时随地手机看文章
趁热打铁,在上一PIC32MZ UDP ethernet bootloader的基础上我又完成了采用TCP协议的PIC32MZ ethernet bootloader。两款ethernet bootloader基本架构都一样,数据包格式也一样。TCP ethernet bootloader 也分两部分,我将他们命名为PhnLoader_v4.0和PhnBoot_v4.0。
PhnLoader_v4.0
PhnLoader_v4.0 是PC端host 程序。
运行环境:Window + .NET Framework 4.5
开发语言: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");