Beispiel #1
0
        private async void Flashfull()
        {
            Checksums_Signatures ChecksumsSignatures = new Checksums_Signatures();
            bool success = true;

            using (EdiabasNet ediabas = StartEdiabas())
            {
                await Task.Run(() =>
                {
                    if (!RequestSecurityAccess(ediabas))
                    {
                        success = false;
                        this.Dispatcher.Invoke(() =>
                        {
                            statusTextBlock.Text = "Security Access Denied";
                        });
                    }
                });

                uint eraseStart = 0x2060000;
                uint eraseBlock = 0xA0000;
                uint flashStart = 0x2060000;
                uint flashEnd   = 0x20FFF3F;

                uint flashMPCStart = 0;
                uint flashMPCEnd   = 0x6FFFF;

                if (Global.diagProtocol == "BMW-FAST")
                {
                    if (!ExecuteJob(ediabas, "normaler_datenverkehr", "nein;nein;ja"))
                    {
                        return;
                    }
                    if (!ExecuteJob(ediabas, "normaler_datenverkehr", "ja;nein;nein"))
                    {
                        return;
                    }
                }

                this.Dispatcher.Invoke(() =>
                {
                    statusTextBlock.Text = "Erasing Flash";
                });
                await Task.Run(() => success = EraseECU(ediabas, eraseBlock, eraseStart));

                byte[] toFlash = null;

                toFlash = ChecksumsSignatures.CorrectProgramChecksums(Global.openedFlash, Global.openedMPC);
                toFlash = ChecksumsSignatures.SignMS45Program(toFlash, Global.openedMPC).Skip(0x60000).Take(0x9FF40).ToArray();



                this.Dispatcher.Invoke(() =>
                {
                    statusTextBlock.Text = "Flashing External Program";
                });
                await Task.Run(() => success = FlashBlock(ediabas, toFlash, flashStart, flashEnd));


                toFlash = null;
                toFlash = Global.openedMPC;

                this.Dispatcher.Invoke(() =>
                {
                    statusTextBlock.Text = "Flashing Internal Program";
                });

                await Task.Run(() => success = FlashBlock(ediabas, toFlash, flashMPCStart, flashMPCEnd));

                if (success)
                {
                    await Task.Run(() =>
                    {
                        if (Global.diagProtocol != "BMW-FAST")
                        {
                            if (!ExecuteJob(ediabas, "diagnose_mode", "DEFAULT;PC9600"))
                            {
                                success = false;
                                return;
                            }
                            if (!ExecuteJob(ediabas, "SET_PARAMETER", ";9600"))
                            {
                                success = false;
                                return;
                            }
                        }
                        else
                        {
                            if (!ExecuteJob(ediabas, "normaler_datenverkehr", "ja;nein;ja"))
                            {
                                success = false;
                                return;
                            }
                        }

                        if (!ExecuteJob(ediabas, "FLASH_PROGRAMMIER_STATUS_LESEN", String.Empty))
                        {
                            success = false;
                            return;
                        }

                        this.Dispatcher.Invoke(() =>
                        {
                            statusTextBlock.Text = "Checking signature";
                        });
                        if (!ExecuteJob(ediabas, "FLASH_SIGNATUR_PRUEFEN", "Programm;64"))
                        {
                            this.Dispatcher.Invoke(() =>
                            {
                                statusTextBlock.Text = "Signature check failed";
                            });
                            success = false;

                            if (!ExecuteJob(ediabas, "STEUERGERAETE_RESET", String.Empty))
                            {
                                return;
                            }
                            return;
                        }
                        if (!ExecuteJob(ediabas, "FLASH_PROGRAMMIER_STATUS_LESEN", String.Empty))
                        {
                            success = false;
                            return;
                        }
                        this.Dispatcher.Invoke(() =>
                        {
                            statusTextBlock.Text = "Resetting ECU";
                        });
                        if (!ExecuteJob(ediabas, "STEUERGERAETE_RESET", String.Empty))
                        {
                            return;
                        }
                    });

                    if (success)
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            statusTextBlock.Text = "Flash successful";
                        });
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            statusTextBlock.Text = "Flash failed";
                        });
                    }
                }
                IdentDME();
                return;
            }
        }