Exemplo n.º 1
0
        private void button_startdownload_Click(object sender, EventArgs e)
        {
            //timer_download.Enabled = true
            downflashdata = UserExplainFile.GetSectionData(gLoadingSection);
            if (downflashdata == null)
            {
                MessageBox.Show("文件未打开");
                return;
            }

            updateStep      = 0;
            gLoadingSection = 0;
        }
Exemplo n.º 2
0
        public static UserFileData GetSectionData(int Num)
        {
            UserFileData temp = new UserFileData();

            temp.CRC            = 0;
            temp.SectionDataNum = 0;
            temp.StartAddress   = 0xfffffff;

            if (Num >= UserConfig.FLASH_DATA_BUF_LENGTH)
            {
                return(temp);
            }

            return(flash_Data[Num]);
        }
Exemplo n.º 3
0
        public static void InitUserFile()
        {
            for (int i = 0; i < UserConfig.FLASH_DATA_BUF_LENGTH; i++)
            {
                flash_Data[i] = new UserFileData();

                UserExplainFile.flash_Data[i].StartAddress   = 0;
                UserExplainFile.flash_Data[i].SectionDataNum = 0;

                for (int k = 0; k < UserConfig.FLASH_DATA_BUF_SIZE; k++)
                {
                    UserExplainFile.flash_Data[i].data[k] = (byte)0xff;
                }
            }

            Flash_SectionNum = 0;
            CurSecNum        = 0xffffff;
            gFileState       = 0;
            System.Console.Write("初始化加载设备\n");
        }
Exemplo n.º 4
0
        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);
            }
        }