Exemplo n.º 1
0
        /*
         *
         * 0x320000 to 0x3FFFFF = 0x020000 to 0x0FFFFF
         *
         * -> E  id = 000FFFFE timestamp = 00000000 len = 8 data =ce 7a bb 32 ff f0 10 00 (Read 10(16) bytes from 32fff0)
         * <- E  id = 00800021 timestamp = 016A9E14 len = 8 data =8f 7a fb 32 ff f0 ae 1b
         * <- E  id = 00800021 timestamp = 016A9E23 len = 8 data =09 db 00 de 1b db 00 7e
         * <- E  id = 00800021 timestamp = 016A9E33 len = 8 data =4f 23 db 00 44 44 44 44
         *
         * In flash:
         * 02FFF0: ae 1b db 00 de 1b db 00 7e 23 db 00 44 44 44 44
         *
         *
         * -> E  id = 000FFFFE timestamp = 00000000 len = 8 data =ce 7a bb 33 00 00 10 00
         * <- E  id = 00800021 timestamp = 016F837F len = 8 data =8f 7a fb 33 00 00 f3 f8
         * <- E  id = 00800021 timestamp = 016F837F len = 8 data =09 8b c7 f7 f8 19 8c f7
         * <- E  id = 00800021 timestamp = 016F838E len = 8 data =4f 8e 18 8c db 00 9a 3d
         *
         * In flash:
         * 030000: f3 f8 8b c7 f7 f8 19 8c f7 8e 18 8c db 00 9a 3d          * */

        private void button9_Click(object sender, EventArgs e)
        {
            /*SaveFileDialog sfd = new SaveFileDialog();
             * sfd.Filter = "Binary files|*.bin";
             * if (sfd.ShowDialog() == DialogResult.OK)
             * {
             *  _cancomms.ReadEprom(sfd.FileName, 1000);
             * }*/
            // try to read the flash contents

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Binary files|*.bin";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                _cancomms.EnterProgrammingMode();
                if (_cancomms.SendSBL())
                {
                    _cancomms.StartSBL();
                    Thread.Sleep(500);
                    byte[] _data    = new byte[0x100000];
                    int    totalIdx = 0;
                    AddToLogItem("Reading flash data... stand by");


                    int offset = 0x8000;
                    for (int iBlock = 0; iBlock < 0xF800; iBlock++) // was 10000
                    {
                        if (this.IsDisposed)
                        {
                            break;
                        }
                        if (_AppExiting)
                        {
                            break;
                        }
                        Application.DoEvents();

                        int   startAddress = offset + (iBlock * 0x10);
                        int   endAddress   = offset + (iBlock * 0x10) + 0x10;
                        float percentage   = (float)iBlock * 100 / 0x10000;
                        //AddToLogItem("Reading flash data... stand by " + iBlock.ToString() + "/256 [" + startAddress.ToString("X8") + "-" + endAddress.ToString("X8") + "]");
                        byte[] _smalldata = _cancomms.ReadFlash(startAddress, endAddress, percentage);
                        string strDebug   = startAddress.ToString("X8") + " - ";
                        for (int i = 0; i < _smalldata.Length; i++)
                        {
                            strDebug += _smalldata[i].ToString("X2") + " ";
                            _data[startAddress + i] = _smalldata[i];
                        }
                        label5.Text        = percentage.ToString("F2") + " % done";
                        progressBar1.Value = Convert.ToInt32(percentage);
                        //AddToLogItem(strDebug);
                    }
                    File.WriteAllBytes(sfd.FileName, _data);
                    Console.WriteLine("Leaving secondary bootloader");
                    _cancomms.LeaveProgrammingMode();
                }
                else
                {
                    AddToLogItem("Failed to upload secondary bootloader, please reset ECU");
                }
            }
        }