コード例 #1
0
ファイル: frmMain.cs プロジェクト: MelvisR/T5SuiteII
        private void SyncMaps(SyncOption which_direction)
        {
            //synchronize maps with the ECU
            //frmInfoBox info = new frmInfoBox("Still needs to be implemented");
            // sync ECU with binary file
            int cnt = 0;
            _ecuConnection.ProhibitRead = true;
            Thread.Sleep(100);
            if (_ecuConnection.Opened)
            {
                if (m_CurrentWorkingProject != string.Empty)
                {
                    m_ProjectLog.WriteLogbookEntry(LogbookEntryType.SynchronizationStarted, which_direction.ToString());
                }
                foreach (Trionic5Tools.SymbolHelper sh in m_trionicFile.GetFileInfo().SymbolCollection)
                {
                    if (sh.Flash_start_address > 0)
                    {
                        cnt++;
                    }
                }
                int currcnt = 0;
                //frmProgress progress = new frmProgress();
                //progress.SetProgress("Synchronizing ECU with binary");
                //progress.SetProgressPercentage(0);
                //progress.Show();
                //preventUpdatePaint = true;
                foreach (Trionic5Tools.SymbolHelper sh in m_trionicFile.GetFileInfo().SymbolCollection)
                {
                    if (sh.Flash_start_address > 0)
                    {
                        currcnt++;
                        int percentage = (currcnt * 100) / cnt;
                        //progress.SetProgressPercentage(percentage);
                        SetStatusText("Sync: " + percentage.ToString() + "%");
                        SetTaskProgress(percentage, true);
                        // <GS-08022011> if the user switch offline in the meantime
                        // stop sync action to prevent damage to data
                        if (_ECUmode == OperationMode.ModeOffline) break;
                        //if (_APPmode == OperationMode.ModeOffline) break;
                        // read ECU map
                        if (sh.Start_address > 0 && sh.Length > 0)
                        {
                            //progress.SetProgress("Verifying " + sh.Varname);
                            Console.WriteLine("map: " + sh.Varname);
                            Thread.Sleep(50);
                            byte[] symboldataECU = _ecuConnection.ReadSymbolDataNoProhibitRead(sh.Varname, (uint)sh.Start_address, (uint)sh.Length);

                            byte[] symboldataBIN = m_trionicFile.ReadData((uint)sh.Flash_start_address, (uint)sh.Length);
                            bool data_matches = true;
                            if (symboldataBIN.Length == symboldataECU.Length)
                            {
                                for (int t = 0; t < symboldataBIN.Length; t++)
                                {
                                    if ((byte)symboldataBIN.GetValue(t) != (byte)symboldataECU.GetValue(t))
                                    {
                                        data_matches = false;
                                        break;
                                    }
                                }
                                if (!data_matches)
                                {
                                    if (which_direction == SyncOption.ToECU)
                                    {
                                        //progress.SetProgress("Writing " + sh.Varname + " to ECU");
                                        // <GS-08022011> if the user switch offline in the meantime
                                        // stop sync action to prevent damage to data
                                        if (_ECUmode == OperationMode.ModeOffline) break;
                                        //if (_APPmode == OperationMode.ModeOffline) break;
                                        _ecuConnection.WriteSymbolDataForced(sh.Start_address, sh.Length, symboldataBIN);
                                    }
                                    else
                                    {
                                        // <GS-08022011> if the user switch offline in the meantime
                                        // stop sync action to prevent damage to data
                                        if (_ECUmode == OperationMode.ModeOffline) break;
                                        //if (_APPmode == OperationMode.ModeOffline) break;
                                        m_trionicFile.WriteDataNoCounterIncrease(symboldataECU, (uint)sh.Flash_start_address);
                                    }
                                }
                            }
                        }
                    }
                }
                SetStatusText("Synchronized");
                SetTaskProgress(0, false);
                //              progress.Close();
                //                preventUpdatePaint = false;
            }
            _ecuConnection.ProhibitRead = false;
        }