public void OpenCanLoaderFile() { // UInt32 crc32 = 0xffffffff; totalsize = 0; String Pathname = null; String[] filter = { "*.s19;*.glo;*.hex" }; //if (openhexFileDialog.ShowDialog() == null) //{ // return; //} openFileDialog_HEXFILE.ShowDialog(); if (openFileDialog_HEXFILE.FileName.EndsWith(".s19") || openFileDialog_HEXFILE.FileName.EndsWith(".glo") || openFileDialog_HEXFILE.FileName.EndsWith(".hex")) { //Pathname = openhexFileDialog.getFilterPath() + "\\" + openhexFileDialog.getFileName(); Pathname = openFileDialog_HEXFILE.FileName; if (testUser.ReadFile(Pathname) == 0)//文件解析成功 { textBox_totalframe.Text = (UserExplainFile.Flash_SectionNum).ToString(); for (int i = 0; i < UserExplainFile.CurSecNum; i++) { totalsize += UserExplainFile.flash_Data[i].SectionDataNum; } totalsize += UserExplainFile.flash_Data[UserExplainFile.CurSecNum].SectionDataNum; textBox_totalsize.Text = totalsize.ToString(); gCrc32 = 0xffffffff; for (int i = 0; i < UserExplainFile.CurSecNum; i++) { gCrc32 = CHECKSUM.CRC32_MPEG_2(gCrc32, UserExplainFile.GetSectionData(i).data, (ushort)UserExplainFile.flash_Data[i].SectionDataNum); } gCrc32 = CHECKSUM.CRC32_MPEG_2(gCrc32, UserExplainFile.GetSectionData(UserExplainFile.CurSecNum).data, (ushort)UserExplainFile.flash_Data[UserExplainFile.CurSecNum].SectionDataNum); // gCrc32 = crc32; 文件CRC32.Text = gCrc32.ToString("X8"); } else { MessageBox.Show("文件解析失败"); textBox_totalframe.Text = ("0"); } } else { MessageBox.Show("文件类型错误"); } }
public void run() { //在任务里进行下载 while (true) { switch (updateStep) { case 0: //发送F6 固件信息 firmdata[0] = 0xf6; firmdata[1] = 0; //默认值 firmdata[2] = 0; //默认值 firmdata[3] = (byte)(totalsize); //totalsize firmdata[4] = (byte)(totalsize >> 8); //totalsize firmdata[5] = (byte)(totalsize >> 16); //totalsize firmdata[6] = (byte)(UserExplainFile.Flash_SectionNum & 0x00ff); //totalframe firmdata[7] = (byte)(UserExplainFile.Flash_SectionNum >> 8); //totalframe firmdata[8] = (byte)gCrc32; //crc32 firmdata[9] = (byte)(gCrc32 >> 8); //crc32 firmdata[10] = (byte)(gCrc32 >> 16); //crc32 firmdata[11] = (byte)(gCrc32 >> 24); //crc32 firmdata[12] = 0x00; //默认值 firmdata[13] = 0x00; //默认值 firmdata[14] = 0x00; //默认值 firmdata[15] = 0x00; //默认值 firmdata[16] = 0x00; //默认值 WriteflashCommandAPI(0x11, firmdata); updateStep = 4; Cycletimer = 300; break; case 1: downflashdata = UserExplainFile.GetSectionData(gLoadingSection); // WriteflashDataAPI(0xf7, UserExplainFile.flash_Data[gLoadingSection].SectionDataNum+3, (int)gLoadingSection, downflashdata.data); WriteflashDataAPI(0xf7, 0x80 + 3, (int)gLoadingSection, downflashdata.data); updateStep = 4; Cycletimer = 300; break; case 2: break; case 3: ReadReceiveRS485Data(); //发完进行读取 txCmdData[0] = 0xf4; txCmdData[1] = 0x00; WriteflashCommandAPI(2, txCmdData); if (cmdF4reply == 0x00) { cmdF4reply = 0xff; updateStep = 2; } break; case 4: ReadReceiveRS485Data(); //发完进行读取 if (cmdF6reply == 0x00) { cmdF6reply = 0xff; updateStep = 1; } if (cmdF7reply == 0x00) { gTimeOut = 0; cmdF7reply = 0xff; updateStep = 1; gLoadingSection += 1; if (gLoadingSection >= UserExplainFile.Flash_SectionNum) { updateStep = 2; } } else if (gTimeOut++ > 60) { gTimeOut = 0; updateStep = 1; } Cycletimer = 50; break; case 5: ReadReceiveRS485Data(); //发完进行读取 if (cmdF1reply == 0x00) { cmdF1reply = 0xff; MessageBox.Show("enter boot success"); updateStep = 2; } break; case 6: ReadReceiveRS485Data(); //发完进行读取 if (cmdF5reply == 0x00) { cmdF5reply = 0xff; updateStep = 2; } break; case 7: ReadReceiveRS485Data(); //发完进行读取 if (cmdF4reply == 0x00) { cmdF4reply = 0xff; updateStep = 2; } break; } Thread.Sleep(Cycletimer); } }