Beispiel #1
0
        private bool OpenWorkingFile(string filename)
        {
            bool retval = false;
            if (File.Exists(filename))
            {
                m_trionicFile = new Trionic5File();

                m_trionicFile.LibraryPath = Application.StartupPath + "\\Binaries";

                m_trionicFile.SetAutoUpdateChecksum(m_appSettings.AutoChecksum);

                FileInfo fi = new FileInfo(filename); //<GS-07102010> remove read only flag if possible
                try
                {
                    fi.IsReadOnly = false;
                    btnReadOnly.Caption = "File access OK";
                }
                catch (Exception E)
                {
                    Console.WriteLine("Failed to remove read only flag: " + E.Message);
                    btnReadOnly.Caption = "File is READ ONLY";
                }

                m_trionicFile.onDecodeProgress += new IECUFile.DecodeProgress(m_trionicFile_onDecodeProgress);
                m_trionicFile.onTransactionLogChanged += new IECUFile.TransactionLogChanged(m_trionicFile_onTransactionLogChanged);
                m_trionicFile.SelectFile(filename);
                //m_trionicFileInformation = m_trionicFile.ParseTrionicFile(ofd.FileName);
                m_trionicFileInformation = m_trionicFile.ParseFile();
                props = m_trionicFile.GetTrionicProperties();
                // set indicators and menu items accoring to the file that has been opened
                if (props.IsTrionic55)
                {
                    barECUType.Caption = "T5.5";
                    // enable T5.5 maps
                    EnableT55Maps(true);
                }
                else
                {
                    barECUType.Caption = "T5.2";
                    EnableT55Maps(false);
                    // disable T5.5 maps
                }
                barECUSpeed.Caption = props.CPUspeed;
                if (props.RAMlocked)
                {
                    barECULocked.Caption = "RAM locked";
                }
                else
                {
                    barECULocked.Caption = "RAM unlocked";
                }
                if (CheckFileInLibrary(props.Partnumber))
                {
                    btnCompareToOriginalFile.Enabled = true;
                }
                else
                {
                    btnCompareToOriginalFile.Enabled = false;
                }
                _ecuConnection.MapSensorType = m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType);
                gridSymbols.DataSource = m_trionicFileInformation.SymbolCollection;
                barStaticItem2.Caption = "File: " + Path.GetFileName(m_trionicFileInformation.Filename);
                this.Text = "T5Suite Professional 2.0 [" + Path.GetFileName(m_trionicFileInformation.Filename) + "]";
                OpenGridViewGroups(gridSymbols, 0);
                // enable buttons
                barButtonItem4.Enabled = true;
                btnConnectECU.Enabled = true;
                btnSwitchMode.Enabled = true;
                //btnSynchronizeMaps.Enabled = true;
                btnTuneForE85Fuel.Enabled = true; //<GS-06042010> todo
                btnTuneToLargerInjectors.Enabled = true; //<GS-06042010> todo
                btnTuneToStage1.Enabled = true;
                btnTuneToStage2.Enabled = true;
                btnTuneToStage3.Enabled = true;
                btnTuneToStageX.Enabled = true;

                //            btnTuneToThreeBarSensor.Enabled = true;
                barConvertMapSensor.Enabled = true;
                btnBoostAdaptionWizard.Enabled = true;
                btnHardcodedRPMLimit.Enabled = true;
                if (m_trionicFileInformation.Has2DRegKonMat())
                {
                    btnChangeRegkonMatRange.Enabled = true;
                }
                else
                {
                    btnChangeRegkonMatRange.Enabled = false;
                }

                m_appSettings.Lastfilename = filename;
                ctrlRealtime1.Currentfile = filename;

                if (m_AFRMaps != null)
                {
                    m_AFRMaps.SaveMaps(); // first save changes that might have been done
                }

                m_AFRMaps = null;
                if (m_AFRMaps == null && m_appSettings.AlwaysCreateAFRMaps)
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }
                // add realtime symbollist to ctrlRealtime1
                Trionic5Tools.SymbolCollection _rtSymbols = new Trionic5Tools.SymbolCollection();
                foreach (Trionic5Tools.SymbolHelper symh in m_trionicFileInformation.SymbolCollection)
                {
                    if (symh.Start_address > 0 && (symh.Length >= 1 && symh.Length <= 4)) // <GS-29072010> was 1 & 2 only
                    {
                        _rtSymbols.Add(symh);
                    }
                }
                ctrlRealtime1.RealtimeSymbolCollection = _rtSymbols;
                try
                {
                    LoadUserDefinedRealtimeSymbols(); // try to load it
                }
                catch (Exception E)
                {
                    Console.WriteLine(E.Message);
                }
                LoadKnockMaps();
                SetTaskProgress(0, false);
                retval = true;
            }
            return retval;
        }
Beispiel #2
0
        void onAFRRefresh(object sender, MapViewer.ReadFromSRAMEventArgs e)
        {
            //Console.WriteLine("Refresh: " + e.Mapname);
            // reload target afr
            if (sender is IMapViewer)
            {
                IMapViewer mv = (IMapViewer)sender;
                if (m_AFRMaps == null )
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }

                if (e.Mapname == "TargetAFR")
                {
                    mv.Map_content = m_AFRMaps.GetTargetAFRMapinBytes();
                }
                else if (e.Mapname == "FeedbackAFR" )
                {
                    mv.Map_content = m_AFRMaps.GetFeedbackAFRMapinBytes();
                }
                else if (e.Mapname == "FeedbackvsTargetAFR")
                {
                    mv.Map_content = m_AFRMaps.GetDifferenceMapinBytes();
                }
                else if (e.Mapname == "IdleTargetAFR")
                {
                    mv.Map_content = m_AFRMaps.GetIdleTargetAFRMapinBytes();
                }
                else if (e.Mapname == "IdleFeedbackAFR")
                {
                    mv.Map_content = m_AFRMaps.GetIdleFeedbackAFRMapinBytes();
                }
                else if (e.Mapname == "IdleFeedbackvsTargetAFR")
                {
                    mv.Map_content = m_AFRMaps.GetIdleDifferenceMapinBytes();
                }
                mv.ShowTable(mv.X_axisvalues.Length, true);
            }
        }
Beispiel #3
0
        void onTargetAFRMapSave(object sender, MapViewer.SaveSymbolEventArgs e)
        {
            if (sender is IMapViewer)
            {
                IMapViewer tabdet = (IMapViewer)sender;
                // get data from mapviewer
                if (m_AFRMaps == null )
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }

                if (e.SymbolName == "TargetAFR")
                {
                    m_AFRMaps.SetTargetAFRMapInBytes(e.SymbolDate);
                    m_AFRMaps.SaveMaps();
                    tabdet.Map_content = m_AFRMaps.LoadTargetAFRMapInBytes();
                }
                else if (tabdet.Map_name == "FeedbackAFR" || tabdet.Map_name == "FeedbackvsTargetAFR")
                {
                    if (tabdet.ClearData)
                    {
                        tabdet.ClearData = false;
                        // delete stuff
                        string foldername = Path.Combine(Path.GetDirectoryName(m_trionicFile.GetFileInfo().Filename), "AFRMaps");

                        if (File.Exists(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-AFRFeedbackmap.afr")))
                        {
                            File.Delete(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-AFRFeedbackmap.afr"));
                        }
                        if (File.Exists(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-AFRFeedbackCountermap.afr")))
                        {
                            File.Delete(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-AFRFeedbackCountermap.afr"));
                        }
                        m_AFRMaps.InitializeMaps();
                        // reshow

                        if (tabdet.Map_name == "FeedbackAFR")
                        {
                            tabdet.Map_content = m_AFRMaps.GetFeedbackAFRMapinBytes();
                        }
                        else if (tabdet.Map_name == "FeedbackvsTargetAFR")
                        {
                            tabdet.Map_content = m_AFRMaps.GetDifferenceMapinBytes();
                        }
                        tabdet.ShowTable(tabdet.X_axisvalues.Length, true);

                    }
                    else
                    {
                        // only done on clear?
                        m_AFRMaps.SaveMaps();
                    }
                    // reload data
                    UpdateMapViewers(_currentEngineSpeed, _currentThrottlePosition, _currentBoostLevel, _currentBoostTarget);
                }

                if (e.SymbolName == "IdleTargetAFR")
                {
                    m_AFRMaps.SetIdleTargetAFRMapInBytes(e.SymbolDate);
                    m_AFRMaps.SaveIdleMaps();
                    tabdet.Map_content = m_AFRMaps.LoadIdleTargetAFRMapInBytes();
                }
                else if (tabdet.Map_name == "IdleFeedbackAFR" || tabdet.Map_name == "IdleFeedbackvsTargetAFR")
                {
                    if (tabdet.ClearData)
                    {
                        tabdet.ClearData = false;
                        // delete stuff
                        string foldername = Path.Combine(Path.GetDirectoryName(m_trionicFile.GetFileInfo().Filename), "AFRMaps");
                        if (File.Exists(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-idleAFRFeedbackmap.afr")))
                        {
                            File.Delete(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-idleAFRFeedbackmap.afr"));
                        }
                        if (File.Exists(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-idleAFRFeedbackCountermap.afr")))
                        {
                            File.Delete(Path.Combine(foldername, Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-idleAFRFeedbackCountermap.afr"));
                        }
                        m_AFRMaps.InitializeMaps();

                        if (tabdet.Map_name == "IdleFeedbackAFR")
                        {
                            tabdet.Map_content = m_AFRMaps.GetIdleFeedbackAFRMapinBytes();
                        }
                        else if (tabdet.Map_name == "IdleFeedbackvsTargetAFR")
                        {
                            tabdet.Map_content = m_AFRMaps.GetIdleDifferenceMapinBytes();
                        }
                        tabdet.ShowTable(tabdet.X_axisvalues.Length, true);
                    }
                    else
                    {
                        // only done on clear?
                        m_AFRMaps.SaveIdleMaps();
                    }
                    // reload data
                    UpdateMapViewers(_currentEngineSpeed, _currentThrottlePosition, _currentBoostLevel, _currentBoostTarget);
                }
            }
        }
Beispiel #4
0
        void m_AFRMaps_onFuelmapCellChanged(object sender, AFRMaps.FuelmapChangedEventArgs e)
        {
            // seems that we need to adjust a value in the current fuelmap
            if (_ecuConnection.Opened)
            {
                if (m_appSettings.AutoUpdateFuelMap)
                {
                    if (m_AFRMaps.IsAutoMappingActive)
                    {
                        // then go!
                        byte[] write = new byte[1];
                        write[0] = e.Cellvalue;

                        if (!props.IsTrionic55)
                        {
                            _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr") + e.Mapindex, 1, write);
                        }
                        else
                        {
                            _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()) + e.Mapindex, 1, write);
                        }
                        // now clear that data in the afrfeedback map because the settings for that cell have changed
                        // note: we don't use the feedback map for alteration, just for user feedback
                        // m_AFRMaps.ClearAFRFeedbackMapCell(e.Mapindex); //<GS-23122009>
                    }
                }
                else
                {
                    // update the fuelinformation struct
                }
            }
        }
Beispiel #5
0
 void m_AFRMaps_onIdleFuelmapCellChanged(object sender, AFRMaps.IdleFuelmapChangedEventArgs e)
 {
     //TODO: <GS-28102010> afmaken
     // seems that we need to adjust a value in the current idle fuelmap
     if (_ecuConnection.Opened)
     {
         if (m_appSettings.AutoUpdateFuelMap && m_appSettings.AllowIdleAutoTune)
         {
             if (m_AFRMaps.IsAutoMappingActive)
             {
                 // then go!
                 byte[] write = new byte[1];
                 write[0] = e.Cellvalue;
                 _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()) + e.Mapindex, 1, write);
             }
         }
         else
         {
             // update the fuelinformation struct
         }
     }
 }
Beispiel #6
0
        private void UpdateFeedbackMaps()
        {
            try
            {
                // convert feedback map in memory to byte[] in stead of float[]
                if (m_AFRMaps == null)
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }

                byte[] current_map = m_AFRMaps.GetFeedBackmapInBytes();
                byte[] idlecurrent_map = m_AFRMaps.GetIdleFeedbackAFRMapinBytes();

                int rows = 0;
                int cols = 0;
                foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
                {
                    if (pnl.Text.StartsWith("Symbol: "))
                    {
                        foreach (Control c in pnl.Controls)
                        {
                            if (c is IMapViewer)
                            {
                                IMapViewer vwr = (IMapViewer)c;
                                if (vwr.Map_name == "FeedbackAFR")
                                {
                                    vwr.Map_content = current_map;
                                    vwr.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                    m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                    UpdateViewer(vwr, cols, true);
                                    //vwr.ShowTable(cols, true);
                                }
                                else if (vwr.Map_name == "FeedbackvsTargetAFR")
                                {
                                    vwr.Map_content = m_AFRMaps.GetDifferenceMapinBytes();
                                    vwr.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                    m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                    UpdateViewer(vwr, cols, true);
                                }
                                if (vwr.Map_name == "IdleFeedbackAFR")
                                {
                                    vwr.Map_content = idlecurrent_map;
                                    vwr.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                    UpdateViewer(vwr, 12, true);
                                }
                                else if (vwr.Map_name == "IdleFeedbackvsTargetAFR")
                                {
                                    vwr.Map_content = m_AFRMaps.GetIdleDifferenceMapinBytes();
                                    vwr.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                    UpdateViewer(vwr, 12, true);
                                }
                            }
                            else if (c is DevExpress.XtraBars.Docking.DockPanel)
                            {
                                DevExpress.XtraBars.Docking.DockPanel tpnl = (DevExpress.XtraBars.Docking.DockPanel)c;
                                foreach (Control c2 in tpnl.Controls)
                                {
                                    if (c2 is IMapViewer)
                                    {
                                        IMapViewer vwr2 = (IMapViewer)c2;
                                        if (vwr2.Map_name == "FeedbackAFR")
                                        {
                                            vwr2.Map_content = current_map;
                                            vwr2.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                            m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                            UpdateViewer(vwr2, cols, true);
                                            //vwr.ShowTable(cols, true);
                                        }
                                        else if (vwr2.Map_name == "FeedbackvsTargetAFR")
                                        {
                                            vwr2.Map_content = m_AFRMaps.GetDifferenceMapinBytes();
                                            vwr2.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                            m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                            UpdateViewer(vwr2, cols, true);
                                        }
                                        if (vwr2.Map_name == "IdleFeedbackAFR")
                                        {
                                            vwr2.Map_content = idlecurrent_map;
                                            vwr2.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                            UpdateViewer(vwr2, 12, true);
                                        }
                                        else if (vwr2.Map_name == "IdleFeedbackvsTargetAFR")
                                        {
                                            vwr2.Map_content = m_AFRMaps.GetIdleDifferenceMapinBytes();
                                            vwr2.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                            UpdateViewer(vwr2, 12, true);
                                        }

                                    }
                                }
                            }
                            else if (c is DevExpress.XtraBars.Docking.ControlContainer)
                            {
                                DevExpress.XtraBars.Docking.ControlContainer cntr = (DevExpress.XtraBars.Docking.ControlContainer)c;
                                foreach (Control c3 in cntr.Controls)
                                {
                                    if (c3 is IMapViewer)
                                    {
                                        IMapViewer vwr3 = (IMapViewer)c3;
                                        if (vwr3.Map_name == "FeedbackAFR")
                                        {
                                            vwr3.Map_content = current_map;
                                            vwr3.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                            m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                            UpdateViewer(vwr3, cols, true);
                                            //vwr.ShowTable(cols, true);
                                        }
                                        else if (vwr3.Map_name == "FeedbackvsTargetAFR")
                                        {
                                            vwr3.Map_content = m_AFRMaps.GetDifferenceMapinBytes();
                                            vwr3.Afr_counter = m_AFRMaps.GetAFRCountermap();
                                            m_trionicFile.GetMapMatrixWitdhByName(m_trionicFileInformation.GetInjectionMap(), out cols, out rows);
                                            UpdateViewer(vwr3, cols, true);
                                        }
                                        if (vwr3.Map_name == "IdleFeedbackAFR")
                                        {
                                            vwr3.Map_content = idlecurrent_map;
                                            vwr3.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                            UpdateViewer(vwr3, 12, true);
                                        }
                                        else if (vwr3.Map_name == "IdleFeedbackvsTargetAFR")
                                        {
                                            vwr3.Map_content = m_AFRMaps.GetIdleDifferenceMapinBytes();
                                            vwr3.Afr_counter = m_AFRMaps.GetIdleAFRCountermap();
                                            UpdateViewer(vwr3, 12, true);
                                        }

                                    }
                                }
                            }
                        }

                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine("Refresh viewer with AFR data error: " + E.Message);
            }
        }
Beispiel #7
0
 void mv_onCellLocked(object sender, IMapViewer.CellLockedEventArgs e)
 {
     //TODO: if it is a map that can lock cells, do it
     //<GS-29032011>
     if (sender is IMapViewer)
     {
         IMapViewer mv = (IMapViewer)sender;
         if (mv.Map_name == "Ign_map_0!" || mv.Map_name == "Knock_count_map")
         {
             // lock/unlock ignition lock stuff
             if (m_IgnitionMaps == null)
             {
                 m_IgnitionMaps = new IgnitionMaps();
                 m_IgnitionMaps.onCellLocked += new IgnitionMaps.CellLocked(m_IgnitionMaps_onCellLocked);
                 m_IgnitionMaps.onIgnitionmapCellChanged += new IgnitionMaps.IgnitionmapCellChanged(m_IgnitionMaps_onIgnitionmapCellChanged);
                 m_IgnitionMaps.TrionicFile = m_trionicFile;
                 m_IgnitionMaps.InitializeMaps();
             }
             if (e.Locked) m_IgnitionMaps.LockCell(e.Columnindex, e.Rowindex);
             else m_IgnitionMaps.UnlockCell(e.Columnindex, e.Rowindex);
             mv.Ignition_lock_map = m_IgnitionMaps.GetIgnitionLockedMap();
             mv.ShowTable(mv.X_axisvalues.Length, true);
         }
         else if (mv.Map_name == "FeedbackAFR" || mv.Map_name == "FeedbackvsTargetAFR" || mv.Map_name == "TargetAFR" || mv.Map_name == "Insp_mat!" || mv.Map_name == "Inj_map_0!")
         {
             // lock/unlock AFR lock stuff
             if (m_AFRMaps == null)
             {
                 m_AFRMaps = new AFRMaps();
                 m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                 m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                 m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                 m_AFRMaps.TrionicFile = m_trionicFile;
                 m_AFRMaps.InitializeMaps();
             }
             if (e.Locked) m_AFRMaps.LockCell(e.Columnindex, e.Rowindex);
             else m_AFRMaps.UnlockCell(e.Columnindex, e.Rowindex);
             mv.AFR_lock_map = m_AFRMaps.GetAFRLockedMap();
             if (mv.Map_name == "FeedbackAFR" || mv.Map_name == "FeedbackvsTargetAFR" || mv.Map_name == "TargetAFR")
             {
                 mv.ShowTable(mv.X_axisvalues.Length, true);
             }
             else
             {
                 mv.ShowTable(mv.X_axisvalues.Length, false);
             }
         }
         else if (mv.Map_name == "IdleFeedbackAFR" || mv.Map_name == "IdleFeedbackvsTargetAFR" || mv.Map_name == "IdleTargetAFR" || mv.Map_name == m_trionicFileInformation.GetIdleFuelMap())
         {
             // lock/unlock AFR lock stuff
             if (m_AFRMaps == null)
             {
                 m_AFRMaps = new AFRMaps();
                 m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                 m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                 m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                 m_AFRMaps.TrionicFile = m_trionicFile;
                 m_AFRMaps.InitializeMaps();
             }
             if (e.Locked) m_AFRMaps.IdleLockCell(e.Columnindex, e.Rowindex);
             else m_AFRMaps.IdleUnlockCell(e.Columnindex, e.Rowindex);
             mv.IdleAFR_lock_map = m_AFRMaps.GetIdleAFRLockedMap();
             if (mv.Map_name == "IdleFeedbackAFR" || mv.Map_name == "IdleFeedbackvsTargetAFR" || mv.Map_name == "IdleTargetAFR")
             {
                 mv.ShowTable(mv.X_axisvalues.Length, true);
             }
             else
             {
                 mv.ShowTable(mv.X_axisvalues.Length, false);
             }
         }
     }
 }
Beispiel #8
0
        private void ctrlRealtime1_onSwitchClosedLoopOnOff(object sender, ctrlRealtime.ClosedLoopOnOffEventArgs e)
        {
            // toggle closed loop on /off based on e.SwitchOn
            //Fastest way to detect cell stability and such is in ECUConnection but we don't want that logic in there.
            //Design decision is to feed the AFRMaps object with the data and have that figure out what to do.
            _ecuConnection.StopECUMonitoring();
            Thread.Sleep(10);
            if (m_AFRMaps == null)
            {
                m_AFRMaps = new AFRMaps();
                m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                m_AFRMaps.TrionicFile = m_trionicFile;
                m_AFRMaps.InitializeMaps();
            }

            byte[] pgm_mod = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetProgramModeSymbol(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetProgramModeSymbol()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetProgramModeSymbol()));
            Thread.Sleep(50);
            // Pgm_mod! byte 0 bit 4  0x10 Lambda control on/off
            if (pgm_mod.Length > 3)
            {
                if (e.SwitchOn)
                {

                    // re-enable the enrichment factors
                    if (m_ProgramModeSettings.Lambdacontrol) pgm_mod[0] |= 0x10; // switch closed loop back on
                    //if (m_ProgramModeSettings.PurgeControl) pgm_mod[2] |= 0x20; // switch purge control back on
                    //if(m_ProgramModeSettings.AcclerationEnrichment) pgm_mod[1] |= 0x10; // acceleration enrichment back on
                    //if(m_ProgramModeSettings.DecelerationEnleanment) pgm_mod[1] |= 0x20; // deceleration enleanment back on
                    //if(m_ProgramModeSettings.WOTEnrichment) pgm_mod[0] |= 0x02; // WOT enrichment back on
                    //if(m_ProgramModeSettings.Fuelcut) pgm_mod[1] |= 0x04; // Fuelcut back on
                    //if (m_ProgramModeSettings.UseSeperateInjectionMapForIdle) pgm_mod[2] |= 0x02; // Idle map back on
                    //if(m_ProgramModeSettings.LoadControl) pgm_mod[3] |= 0x04; // load control back on
                    //if (pgm_mod.Length >= 5)
                    //{
                    //    if (m_ProgramModeSettings.NoFuelcutR12) pgm_mod[4] |= 0x04; // no fuelcut in R12 back on
                    //    if (m_ProgramModeSettings.ConstIdleIgnitionAngleGearOneAndTwo) pgm_mod[4] |= 0x02; // const ign angle back on
                    //}
                    // write Pgm_mod into ECU immediately!
                    if(m_appSettings.DisableClosedLoopOnStartAutotune) _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetProgramModeSymbol()), 1, pgm_mod); // <GS-12042010> set to length = 1 to prevent other changes
                    Thread.Sleep(100);

                    if (m_appSettings.AutoUpdateFuelMap)
                    {
                        //TODO: ask the user whether he wants to merge the altered fuelmap into ECU memory!
                        // if he replies NO: revert to the previous fuel map (we still need to preserve a copy!)
                        if (MessageBox.Show("Keep adjusted fuel map?", "Question", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            // save the original map back to the ECU
                            if (!props.IsTrionic55)
                            {
                                _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"), (int)m_trionicFileInformation.GetSymbolLength("Adapt_korr"), m_AFRMaps.GetOriginalFuelmap());
                            }
                            else
                            {
                                _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (int)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap()), m_AFRMaps.GetOriginalFuelmap());
                            }
                            // <GS-14032011> this should only be done when idlefuel map autotune is active as well
                            //
                            if (m_appSettings.AllowIdleAutoTune)
                            {
                                _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()), (int)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIdleFuelMap()), m_AFRMaps.GetIdleOriginalFuelmap());
                            }
                            // and write to the bin as well

                        }
                        else
                        {
                            // save the altered map into the binary
                            //TODO: <GS-03062010> this alters the syncdatetime in the file!!!
                            DateTime ecudt = _ecuConnection.GetMemorySyncDate();
                            DateTime filedt = m_trionicFile.GetMemorySyncDate();
                            bool _updateSync = false;
                            if (ecudt == filedt) _updateSync = true;
                            m_trionicFile.WriteData(_ecuConnection.ReadSymbolData(m_trionicFileInformation.GetInjectionMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap())), (uint)m_trionicFileInformation.GetSymbolAddressFlash(m_trionicFileInformation.GetInjectionMap()));
                            if (m_appSettings.AllowIdleAutoTune)
                            {
                                m_trionicFile.WriteData(_ecuConnection.ReadSymbolData(m_trionicFileInformation.GetIdleFuelMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIdleFuelMap())), (uint)m_trionicFileInformation.GetSymbolAddressFlash(m_trionicFileInformation.GetIdleFuelMap()));
                            }
                            if (_updateSync)
                            {
                                DateTime dtnow = DateTime.Now;
                                _ecuConnection.SetMemorySyncDate(dtnow);
                                m_trionicFile.SetMemorySyncDate(dtnow);
                                // now we should be in sync again
                            }
                        }

                        // init the afrmaps values
                        m_AFRMaps.InitAutoTuneVars(e.SwitchOn);
                    }
                    else
                    {
                        // <GS-02032010> Create a new form for this with multiselect grid!
                        //TODO: in that case, we've maintained the changes in the m_AFRMaps.FuelMapInformation struct
                        // we should now show the proposed changed (in percentages) to the user and let him/her
                        // decide which cells should be updated and which ones should be discarded
                        double[] diffinperc = m_AFRMaps.GetPercentualDifferences();

                        DataTable dt = new DataTable();
                        for (int i = 0; i < 16; i++)
                        {
                            dt.Columns.Add(i.ToString(), Type.GetType("System.Double"));
                        }

                        for (int i = 15; i >= 0; i--)
                        {
                            object[] arr = new object[16];

                            for (int j = 0; j < 16; j++)
                            {
                                arr.SetValue(diffinperc[(i * 16) + j], j);
                            }
                            dt.Rows.Add(arr);
                        }
                        frmFuelMapAccept acceptMap = new frmFuelMapAccept();
                        acceptMap.onUpdateFuelMap += new frmFuelMapAccept.UpdateFuelMap(acceptMap_onUpdateFuelMap);
                        acceptMap.onSyncDates += new frmFuelMapAccept.SyncDates(acceptMap_onSyncDates);
                        acceptMap.SetDataTable(dt);
                        acceptMap.ShowDialog();
                        DialogResult = DialogResult.None;
                        //TODO: <GS-28102010> Hoe hier ook te vragen voor Idle fuel map???
                        // voor nu maar even gewoon domweg schrijven
                        if (m_appSettings.AllowIdleAutoTune)
                        {
                            _ecuConnection.WriteSymbolData(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()), m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIdleFuelMap()), m_AFRMaps.GetIdleCurrentlyMutatedFuelMap());
                        }
                        Application.DoEvents();

                    }
                    ctrlRealtime1.SetAutoTuneButtonText("Autotune fuel");
                    SetStatusText("Idle");
                }
                else
                {

                    //TODO: disable the enrichment factors
                    // init the afrmaps values
                    SetStatusText("Starting autotune...");
                    System.Windows.Forms.Application.DoEvents();
                    if ((pgm_mod[0] & 0x10) > 0) m_ProgramModeSettings.Lambdacontrol = true;
                    else m_ProgramModeSettings.Lambdacontrol = false;
                    //if ((pgm_mod[2] & 0x20) > 0) m_ProgramModeSettings.PurgeControl = true;
                    //else m_ProgramModeSettings.PurgeControl = false;
                    // Purge control disable
                    //if ((pgm_mod[1] & 0x10) > 0) m_ProgramModeSettings.AcclerationEnrichment = true;
                    //else m_ProgramModeSettings.AcclerationEnrichment = false;
                    //if ((pgm_mod[1] & 0x20) > 0) m_ProgramModeSettings.DecelerationEnleanment = true;
                    //else m_ProgramModeSettings.DecelerationEnleanment = false;
                    //if ((pgm_mod[0] & 0x02) > 0) m_ProgramModeSettings.WOTEnrichment = true;
                    //else m_ProgramModeSettings.WOTEnrichment = false;
                    //if ((pgm_mod[1] & 0x04) > 0) m_ProgramModeSettings.Fuelcut = true;
                    //else m_ProgramModeSettings.Fuelcut = false;
                    //if ((pgm_mod[2] & 0x02) > 0) m_ProgramModeSettings.UseSeperateInjectionMapForIdle = true;
                    //else m_ProgramModeSettings.UseSeperateInjectionMapForIdle = false;
                    //if ((pgm_mod[3] & 0x04) > 0) m_ProgramModeSettings.LoadControl = true;
                    //else m_ProgramModeSettings.LoadControl = false;
                    //if (pgm_mod.Length >= 5)
                    //{
                    //    if ((pgm_mod[4] & 0x04) > 0) m_ProgramModeSettings.NoFuelcutR12 = true;
                    //    else m_ProgramModeSettings.NoFuelcutR12 = false;
                    //    if ((pgm_mod[4] & 0x02) > 0) m_ProgramModeSettings.ConstIdleIgnitionAngleGearOneAndTwo = true;
                    //    else m_ProgramModeSettings.ConstIdleIgnitionAngleGearOneAndTwo = false;
                    //}
                    // we have to restore this after coming out of autotune!
                    // now set to the needed settings for autotuning
                    pgm_mod[0] &= 0xEF; // switch closed loop off
                    //pgm_mod[2] &= 0xDF; // switch purge control off
                    //pgm_mod[1] &= 0xEF; // acceleration enrichment OFF
                    //pgm_mod[1] &= 0xDF; // deceleration enleanment OFF
                    //pgm_mod[0] &= 0xFD; // WOT enrichment OFF ??? Don't: because it will be on after autotune
                    //pgm_mod[2] &= 0xFD; // Idle map usage OFF (so always in main fuel map)
                    //pgm_mod[1] &= 0xFB; // turn fuelcut function in engine brake OFF
                    //pgm_mod[3] &= 0xFB; // turn load control OFF ??? Don't: because it will be on after autotune
                    //if (pgm_mod.Length >= 5)
                    //{
                    //    pgm_mod[4] |= 0x04; // turn off fuelcut in reverse, 1st and second gear (INVERTED)
                    //    pgm_mod[4] &= 0xFD; // turn off constant ignition angle at idle in 1st and second gear
                    //}

                    //Write Pgm_mod into ECU immediately
                    if (m_appSettings.DisableClosedLoopOnStartAutotune) _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetProgramModeSymbol()), 1/*m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetProgramModeSymbol())*/, pgm_mod); // <GS-12042010> set to 1 to prevent other changes
                    Thread.Sleep(100);

                    m_AFRMaps.InitAutoTuneVars(e.SwitchOn); // this also clears the afr feedback map
                    // and automatically show the autotune window (feedbackafr/fuel adjustment map)
                    // read ECU data for fuel correction!
                    //<GS-31032010> should be different for T5.2
                    //adaption data should NOT be merged and Adapt_korr should be used as the fuel map
                    byte[] fuelmap;
                    if (!props.IsTrionic55)
                    {
                        fuelmap = _ecuConnection.ReadSymbolData("Adapt_korr", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"), (uint)m_trionicFileInformation.GetSymbolLength("Adapt_korr"));
                        Thread.Sleep(50);
                    }
                    else
                    {

                        byte[] fuelcorrectiondata = _ecuConnection.ReadSymbolData("Adapt_korr", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"), (uint)m_trionicFileInformation.GetSymbolLength("Adapt_korr"));
                        Thread.Sleep(50);
                        // AND read the long term fuel trim
                        //byte[] longtermtrim = _ecuConnection.ReadSymbolData("Adapt_injfaktor!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_injfaktor!"), (uint)m_trionicFileInformation.GetSymbolLength("Adapt_injfaktor!"));
                        // and merge it into the main fuel map
                        // get the main fuel map
                        fuelmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetInjectionMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap()));
                        // if all adaption data is 128, don't update to save time
                        Thread.Sleep(50);
                        bool _doUpdateFuelMap = false;
                        for (int t = 0; t < fuelcorrectiondata.Length; t++)
                        {
                            if (Convert.ToInt32(fuelcorrectiondata[t]) != 0x80)
                            {
                                _doUpdateFuelMap = true;
                            }
                        }
                        //int itrim = Convert.ToInt32(longtermtrim[0]);
                        if (_doUpdateFuelMap)
                        {
                            SetStatusText("Updating fuelmaps...");
                            for (int t = 0; t < fuelcorrectiondata.Length; t++)
                            {
                                int corrval = Convert.ToInt32(fuelcorrectiondata[t]);
                                // ranges from 77 - 160?
                                int fuelmapvalue = Convert.ToInt32(fuelmap[t]);
                                fuelmapvalue *= corrval;
                                fuelmapvalue /= 128;
                                //fuelmapvalue *= itrim;
                                //fuelmapvalue /= 128;
                                // check boundaries
                                if (fuelmapvalue < 1) fuelmapvalue = 1;
                                if (fuelmapvalue > 254) fuelmapvalue = 254;
                                fuelmap[t] = Convert.ToByte(fuelmapvalue);
                            }

                            // save fuel map
                            _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (int)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap()), fuelmap);
                            Thread.Sleep(50);
                            for (int t = 0; t < fuelcorrectiondata.Length; t++)
                            {
                                fuelcorrectiondata[t] = 128; // reinit
                            }
                            _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"), (int)m_trionicFileInformation.GetSymbolLength("Adapt_korr"), fuelcorrectiondata);
                            Thread.Sleep(50);
                        }
                    }
                    if (m_appSettings.ResetFuelTrims)
                    {
                        // and write 128 to trim
                        byte[] longtermtrim = new byte[1];
                        longtermtrim[0] = 128;
                        _ecuConnection.WriteSymbolData((int)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_injfaktor!"), (int)m_trionicFileInformation.GetSymbolLength("Adapt_injfaktor!"), longtermtrim);
                        if (props.IsTrionic55)
                        {
                            // clear idle adaption (trim) as well
                            if(m_appSettings.AllowIdleAutoTune)
                            {
                                _ecuConnection.WriteSymbolData((int)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_inj_imat!"), (int)m_trionicFileInformation.GetSymbolLength("Adapt_inj_imat!"), longtermtrim);
                            }
                        }
                    }
                    // all done, adaptions have been made
                    m_AFRMaps.SetCurrentFuelMap(fuelmap);
                    m_AFRMaps.SetOriginalFuelMap(fuelmap);
                    byte[] idlefuelmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetIdleFuelMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIdleFuelMap()));
                    m_AFRMaps.SetIdleCurrentFuelMap(idlefuelmap);
                    m_AFRMaps.SetIdleOriginalFuelMap(idlefuelmap); //<GS-14032011> bugfix for erratic idle behaviour after autotune, this was filled with fuelmap in stead of idlefuelmap
                    m_AFRMaps.AutoUpdateFuelMap = m_appSettings.AutoUpdateFuelMap;
                    ctrlRealtime1.SetAutoTuneButtonText("Tuning...");
                    SetStatusText("Autotune fuel running...");
                }
                //TODO: If the afrmaps object does not contain a working fuelmap yet, create it
                if (!m_AFRMaps.HasValidFuelmap) // do always because map has been altered
                {
                    // insert the fuel map from SRAM now
                    byte[] fuelmap;
                    if (!props.IsTrionic55)
                    {
                        fuelmap = _ecuConnection.ReadSymbolData("Adapt_korr", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"), (uint)m_trionicFileInformation.GetSymbolLength("Adapt_korr"));
                    }
                    else
                    {
                        fuelmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetInjectionMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap()));
                    }
                    m_AFRMaps.SetCurrentFuelMap(fuelmap);
                }
                if (!m_AFRMaps.HasValidIdleFuelmap) // do always because map has been altered
                {
                    // insert the fuel map from SRAM now
                    byte[] idlefuelmap;
                    idlefuelmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetIdleFuelMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIdleFuelMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIdleFuelMap()));
                    m_AFRMaps.SetIdleCurrentFuelMap(idlefuelmap);
                }

                //the object should consider all constraints given in the autotune settings screen
                //so it should remember the ORIGINAL fuel map it started with to determine max-correction etc
                //also it should maintain a counter map for this to be able to monitor how many changes have been made
                //to the map
                //The original map should be 'updateable' (=able to delete and re-create from current sram) so that
                //the user will be able to force more correction onto the map
                m_AFRMaps.WideBandAFRSymbol = m_appSettings.WidebandLambdaSymbol;
                m_AFRMaps.AcceptableTargetErrorPercentage = m_appSettings.AcceptableTargetErrorPercentage;
                m_AFRMaps.AreaCorrectionPercentage = m_appSettings.AreaCorrectionPercentage;
                m_AFRMaps.AutoUpdateFuelMap = m_appSettings.AutoUpdateFuelMap;
                m_AFRMaps.CellStableTime_ms = m_appSettings.CellStableTime_ms;
                m_AFRMaps.CorrectionPercentage = m_appSettings.CorrectionPercentage;
                m_AFRMaps.DiscardClosedThrottleMeasurements = m_appSettings.DiscardClosedThrottleMeasurements;
                m_AFRMaps.DiscardFuelcutMeasurements = m_appSettings.DiscardFuelcutMeasurements;
                m_AFRMaps.EnrichmentFilter = m_appSettings.EnrichmentFilter;
                m_AFRMaps.FuelCutDecayTime_ms = m_appSettings.FuelCutDecayTime_ms;
                m_AFRMaps.MaximumAdjustmentPerCyclePercentage = m_appSettings.MaximumAdjustmentPerCyclePercentage;
                m_AFRMaps.MaximumAFRDeviance = m_appSettings.MaximumAFRDeviance;
                m_AFRMaps.MinimumAFRMeasurements = m_appSettings.MinimumAFRMeasurements;
                m_AFRMaps.IsAutoMappingActive = !e.SwitchOn; // closed loop OFF means automapping ON
                //ctrlRealtime1.SetAutoTuneButtonText("Tuning...");
            }
            else
            {
                // could not read pgm_mod...wtf?
            }
            _ecuConnection.StartECUMonitoring();
        }
Beispiel #9
0
        private void FeedInfoToAFRMaps(double rpm, double tps, double boost, double AFR, double IgnitionAdvance, bool KnockStatus, bool IdleMapActive)
        {
            if (tps == 9999) return; // ignore these readings, tps changed fast

            // failesafe
            if (m_AFRMaps == null)
            {
                m_AFRMaps = new AFRMaps();
                m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                m_AFRMaps.TrionicFile = m_trionicFile;
                m_AFRMaps.InitializeMaps();
            }
            if (m_IgnitionMaps == null)
            {
                m_IgnitionMaps = new IgnitionMaps();
                m_IgnitionMaps.onCellLocked +=new IgnitionMaps.CellLocked(m_IgnitionMaps_onCellLocked);
                m_IgnitionMaps.onIgnitionmapCellChanged +=new IgnitionMaps.IgnitionmapCellChanged(m_IgnitionMaps_onIgnitionmapCellChanged);
                m_IgnitionMaps.TrionicFile = m_trionicFile;
                m_IgnitionMaps.InitializeMaps();
            }

            if (_autoTuneAllowed  /*|| m_appSettings.DebugMode*/)
            {
                float targetAFR = m_AFRMaps.HandleRealtimeData(rpm, tps, boost, AFR, _idleMapActive);
                ctrlRealtime1.SetValue("TARGETAFR", (double)targetAFR);
            }
            else
            {
                ctrlRealtime1.SetValue("TARGETAFR", (double)m_AFRMaps.GetCurrentTargetAFR(rpm, boost));
            }
            if (!_ignitionIdleActive) // if idle map is active, we DO NOT tune ignition
            {
                m_IgnitionMaps.HandleRealtimeData(rpm, tps, boost, IgnitionAdvance, KnockStatus);
            }
            if (m_AFRMaps.IsAutoMappingActive)
            {
                // in that case, update the realtime control's data
                //TODO: <GS-28102010> afmaken, idle map tonen en updaten indien _idleMapActive true is
                ctrlRealtime1.UpdateMutatedFuelMap(m_AFRMaps.GetCurrentlyMutatedFuelMap(), m_AFRMaps.GetCurrentlyMutatedFuelMapCounter());
                ctrlRealtime1.UpdateFeedbackAFR(m_AFRMaps.GetFeedbackAFRMap(), m_AFRMaps.GetTargetAFRMap(), m_AFRMaps.GetAFRCountermap());
            }
            if (m_IgnitionMaps.IsAutoMappingActive)
            {
                // update ignition maps in UI
                ctrlRealtime1.UpdateMutatedIgnitionMap(m_IgnitionMaps.GetCurrentlyMutatedIgnitionMap(), m_IgnitionMaps.GetCurrentlyMutatedIgnitionMapCounter(), m_IgnitionMaps.GetIgnitionLockedMap());
            }
            ctrlRealtime1.RedoGrids();
        }
Beispiel #10
0
 private void btnNewAFRTargetMap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     // create a new map based on the injectors used
     //if (m_AFRMaps != null)
     {
         if (m_trionicFile != null)
         {
             if (m_AFRMaps == null)
             {
                 m_AFRMaps = new AFRMaps();
                 m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                 m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                 m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                 m_AFRMaps.TrionicFile = m_trionicFile;
                 m_AFRMaps.InitializeMaps();
             }
             m_AFRMaps.CreateTargetMap(props.InjectorType);
             ShowAfrMAP("TargetAFR", m_AFRMaps.LoadTargetAFRMapInBytes());
         }
     }
 }
Beispiel #11
0
        void acceptMap_onUpdateFuelMap(object sender, frmFuelMapAccept.UpdateFuelMapEventArgs e)
        {
            // write to ECU if possible
            //Console.WriteLine("Update fuel after accept");
            if (_ecuConnection.Opened)
            {
                if (e.Value == 0) return; // test for value 0... nothing todo

                //Console.WriteLine("x: " + e.X.ToString() + " y: " + e.Y.ToString() + " val: " + e.Value.ToString() + " syn: " + e.doSync.ToString());

                if (m_AFRMaps == null)
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }

                int y = 15 - e.Y;
                // first get the original map
                //_ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()) + e.Mapindex, 1, write);
                //byte[] fuelmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetInjectionMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetInjectionMap()));
                byte[] fuelmap = m_AFRMaps.FuelMapInformation.GetOriginalFuelMap();
                double originalbyte = Convert.ToDouble(fuelmap[(y * 16) + e.X]);
                originalbyte *= (100 + e.Value) / 100;
                byte newFuelMapByte = Convert.ToByte(originalbyte);
                byte[] data2Write = new byte[1];
                data2Write[0] = newFuelMapByte;

                int fuelMapAddress = m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetInjectionMap());
                if (!props.IsTrionic55)
                {
                    fuelMapAddress = m_trionicFileInformation.GetSymbolAddressSRAM("Adapt_korr"); // write to adapt_korr in stead of insp_mat
                }
                fuelMapAddress += (y * 16) + e.X;
                //Console.WriteLine("Writing data: " + data2Write[0].ToString("D3") + " to address: " + fuelMapAddress.ToString("X6") + " ori was: " + fuelmap[(y * 16) + e.X].ToString("D3"));
                //_ecuConnection.WriteData(data2Write, (uint)fuelMapAddress);
                _ecuConnection.WriteSymbolDataForced(fuelMapAddress, 1, data2Write);
                // and write to the current binary file as well
                //<GS-22032010> create a backup file first
                int fuelMapAddressFlash = m_trionicFileInformation.GetSymbolAddressFlash(m_trionicFileInformation.GetInjectionMap());
                fuelMapAddressFlash += (y * 16) + e.X;
                // only on the last update.
                m_trionicFile.WriteData(data2Write, (uint)fuelMapAddressFlash);
            }
        }
Beispiel #12
0
 private void btnIdleTargetAFRMap_ItemClick(object sender, ItemClickEventArgs e)
 {
     // als er nog geen aanwezig is, een nieuwe aanmaken
     if (m_AFRMaps == null)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
     }
     m_AFRMaps.CheckIdleTargetAFRMap();
     ShowIdleAfrMAP("IdleTargetAFR", m_AFRMaps.LoadIdleTargetAFRMapInBytes());
 }
Beispiel #13
0
 private void btnIdleAFRFeedbackMap_ItemClick(object sender, ItemClickEventArgs e)
 {
     // show feedback afr map if available
     if (m_AFRMaps == null)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
     }
     ShowIdleAfrMAP("IdleFeedbackAFR", m_AFRMaps.GetIdleFeedbackAFRMapinBytes());
 }
Beispiel #14
0
 private void btnIdleAFRErrorMap_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (m_AFRMaps == null)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
     }
     ShowIdleAfrMAP("IdleFeedbackvsTargetAFR", m_AFRMaps.GetIdleDifferenceMapinBytes());
 }
Beispiel #15
0
 private void btnAFRFeedbackmap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     // show feedback afr map if available
     if (m_AFRMaps == null)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
     }
     //SaveTargetAFRMap(Path.Combine(Path.GetDirectoryName(m_trionicFile.GetFileInfo().Filename), Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-feedbackafrtab.afr"), AFRMapInMemory);
     ShowAfrMAP("FeedbackAFR", m_AFRMaps.GetFeedbackAFRMapinBytes());
 }
Beispiel #16
0
 private void LoadAFRMapsForProject(string projectname)
 {
     string m_currentfile = string.Empty;
     if (File.Exists(m_appSettings.ProjectFolder + "\\" + projectname + "\\projectproperties.xml"))
     {
         DataTable projectprops = new DataTable("T5PROJECT");
         projectprops.Columns.Add("CARMAKE");
         projectprops.Columns.Add("CARMODEL");
         projectprops.Columns.Add("CARMY");
         projectprops.Columns.Add("CARVIN");
         projectprops.Columns.Add("NAME");
         projectprops.Columns.Add("BINFILE");
         projectprops.Columns.Add("VERSION");
         projectprops.ReadXml(m_appSettings.ProjectFolder + "\\" + projectname + "\\projectproperties.xml");
         // valid project, add it to the list
         if (projectprops.Rows.Count > 0)
         {
             m_currentfile = projectprops.Rows[0]["BINFILE"].ToString();
         }
     }
     if (m_currentfile != "" && m_appSettings.AlwaysCreateAFRMaps)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
         //TODO: initialize & reload if data available.
     }
 }
Beispiel #17
0
 private void btnAFRTargetmap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     // als er nog geen aanwezig is, een nieuwe aanmaken
     if (m_AFRMaps == null)
     {
         m_AFRMaps = new AFRMaps();
         m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
         m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
         m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
         m_AFRMaps.TrionicFile = m_trionicFile;
         m_AFRMaps.InitializeMaps();
     }
     m_AFRMaps.CheckTargetAFRMap();
     //float[] map = CreateDefaultTargetAFRMap();
     //SaveTargetAFRMap(Path.Combine(Path.GetDirectoryName(m_trionicFile.GetFileInfo().Filename), Path.GetFileNameWithoutExtension(m_trionicFile.GetFileInfo().Filename) + "-targetafr.afr"), map);
     ShowAfrMAP("TargetAFR", m_AFRMaps.LoadTargetAFRMapInBytes());
 }
Beispiel #18
0
        // center screen?
        private void StartTableViewerFloating(string symbolname)
        {
            bool _isAdjustmentMap = false;
            if (symbolname == "FuelAdjustmentMap")
            {
                symbolname = m_trionicFileInformation.GetInjectionMap();
                props = m_trionicFile.GetTrionicProperties();
                if (!props.IsTrionic55) symbolname = "Adapt_korr";
                _isAdjustmentMap = true;
                if (m_AFRMaps == null)
                {
                    m_AFRMaps = new AFRMaps();
                    m_AFRMaps.onFuelmapCellChanged += new AFRMaps.FuelmapCellChanged(m_AFRMaps_onFuelmapCellChanged);
                    m_AFRMaps.onIdleFuelmapCellChanged += new AFRMaps.IdleFuelmapCellChanged(m_AFRMaps_onIdleFuelmapCellChanged);
                    m_AFRMaps.onCellLocked += new AFRMaps.CellLocked(m_AFRMaps_onCellLocked);
                    m_AFRMaps.TrionicFile = m_trionicFile;
                    m_AFRMaps.InitializeMaps();
                }
                if (!m_AFRMaps.HasValidFuelmap)
                {
                    // insert the fuel map from SRAM now
                    byte[] fuelmap = _ecuConnection.ReadSymbolData(symbolname, (uint)m_trionicFileInformation.GetSymbolAddressSRAM(symbolname), (uint)m_trionicFileInformation.GetSymbolLength(symbolname));
                    m_AFRMaps.SetCurrentFuelMap(fuelmap);
                }

            }
            if (m_trionicFile == null)
            {
                frmInfoBox info = new frmInfoBox("You should open a binary file first");
                return;
            }
            if (!m_trionicFile.HasSymbol(symbolname))
            {
                frmInfoBox info = new frmInfoBox(symbolname + " is not present in the current file");
                return;
            }
            // make it 100% self-defining
            // the application shouldn't have any know how about the details
            // it should only define TUNING-FLOW
            // have this work in online mode as well, this should enable the user to work in online mode in the SRAM
            //itself when it is connected.
            if (!PanelExists(symbolname))
            {

                dockManager1.BeginUpdate();
                /*Rectangle r = Screen.GetWorkingArea(ctrlRealtime1);
                Point p = new Point(r.X + r.Width/2, r.Y + r.Height/2);
                System.Drawing.Point floatpoint = this.PointToScreen(p);*/
                System.Drawing.Point floatpoint = this.PointToClient(new System.Drawing.Point(dockSymbols.Location.X + dockSymbols.Width + 30, dockSymbols.Location.Y + 30));

                DockPanel dp = dockManager1.AddPanel(floatpoint);
                dp.ClosedPanel += new DockPanelEventHandler(dockPanel_ClosedPanel);
                dp.Tag = m_trionicFileInformation.Filename;
                //IMapViewer mv = new MapViewerEx();
                IMapViewer mv;
                if (m_appSettings.MapViewerType == MapviewerType.Fancy)
                {
                    mv = new MapViewerEx();
                }
                else if (m_appSettings.MapViewerType == MapviewerType.Normal)
                {
                    mv = new MapViewer();
                }
                else
                {
                    mv = new SimpleMapViewer();
                }
                mv.AutoUpdateChecksum = m_appSettings.AutoChecksum;
                mv.GraphVisible = m_appSettings.ShowGraphs;
                mv.SetViewSize((Trionic5Tools.ViewSize)m_appSettings.DefaultViewSize);
                if (m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType) == MapSensorType.MapSensor25)
                {
                    if (m_appSettings.DefaultViewType == ViewType.Decimal)
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Decimal;
                    }
                    else
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Easy;
                    }
                }
                else if (m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType) == MapSensorType.MapSensor30)
                {
                    if (m_appSettings.DefaultViewType == ViewType.Decimal)
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Decimal3Bar;
                    }
                    else
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Easy3Bar;
                    }
                }
                else if (m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType) == MapSensorType.MapSensor35)
                {
                    if (m_appSettings.DefaultViewType == ViewType.Decimal)
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Decimal35Bar;
                    }
                    else
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Easy35Bar;
                    }
                }
                else if (m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType) == MapSensorType.MapSensor40)
                {
                    if (m_appSettings.DefaultViewType == ViewType.Decimal)
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Decimal4Bar;
                    }
                    else
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Easy4Bar;
                    }
                }
                else if (m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType) == MapSensorType.MapSensor50)
                {
                    if (m_appSettings.DefaultViewType == ViewType.Decimal)
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Decimal5Bar;
                    }
                    else
                    {
                        mv.Viewtype = Trionic5Tools.ViewType.Easy5Bar;
                    }
                }
                mv.LoadSymbol(symbolname, m_trionicFile);

                if (_ecuConnection.Opened && _ECUmode == OperationMode.ModeOnline)
                {
                    if (_isAdjustmentMap)
                    {
                        mv.Map_content = m_AFRMaps.GetCurrentlyMutatedFuelMap();
                    }
                    else
                    {
                        mv.Map_content = _ecuConnection.ReadSymbolData(symbolname, (uint)m_trionicFileInformation.GetSymbolAddressSRAM(symbolname), (uint)m_trionicFileInformation.GetSymbolLength(symbolname));
                    }

                    mv.OnlineMode = true;
                }
                int cols = 1;
                int rows = 1;
                m_trionicFile.GetMapMatrixWitdhByName(symbolname, out cols, out rows);
               /* if (m_trionicFile.GetMapSensorType() == MapSensorType.MapSensor30)
                {
                    mv.Viewtype = Trionic5Tools.ViewType.Easy3Bar;
                }*/
                mv.ShowTable(cols, m_trionicFile.IsTableSixteenBits(symbolname));
                mv.Dock = DockStyle.Fill;
                mv.onClose += new IMapViewer.ViewerClose(OnCloseMapViewer);
                // what todo on a save action (sram/binary)
                mv.onSymbolSave += new IMapViewer.NotifySaveSymbol(mv_onSymbolSave);
                mv.onReadFromSRAM += new IMapViewer.ReadDataFromSRAM(mv_onReadFromSRAM);
                mv.onAxisEditorRequested += new IMapViewer.AxisEditorRequested(mv_onAxisEditorRequested);
                mv.onSelectionChanged += new IMapViewer.SelectionChanged(tabdet_onSelectionChanged);
                mv.onSurfaceGraphViewChangedEx += new IMapViewer.SurfaceGraphViewChangedEx(mv_onSurfaceGraphViewChangedEx);
                mv.onCellLocked += new IMapViewer.CellLocked(mv_onCellLocked);

                TryToAddOpenLoopTables(mv);
                mv.InitEditValues();

                //
                dp.Width = mv.DetermineWidth();
                dp.Text = Path.GetFileName(m_trionicFile.GetFileInfo().Filename) + " [" + symbolname + "]";
                //if (_ecuConnection.Opened && _APPmode == OperationMode.ModeOnline) dp.Text += " Online";
                dp.Controls.Add(mv);

                mv.GraphVisible = false;
                int dw = 650;
                if (mv.X_axisvalues.Length > 0)
                {
                    dw = 30 + ((mv.X_axisvalues.Length + 1) * 35);
                }
                if (dw < 400) dw = 400;
                dp.FloatSize = new Size(dw, 500);

                // now set it in the center of the screen!
                //int x = Screen.PrimaryScreen.WorkingArea.Width / 2 - dp.FloatSize.Width / 2;
                //int y = Screen.PrimaryScreen.WorkingArea.Height / 2 - dp.FloatSize.Height / 2;
                int x = this.Left + this.Width / 2 - dp.FloatSize.Width / 2;
                int y = this.Top + this.Height / 2 - dp.FloatSize.Height / 2;
                System.Drawing.Point realfloatpoint = new Point(x, y);//this.PointToClient(new System.Drawing.Point(dockSymbols.Location.X + dockSymbols.Width + 30, dockSymbols.Location.Y + 30));
                dp.FloatLocation = realfloatpoint;

                dockManager1.EndUpdate();
            }
            else
            {
                BringPanelToForeGround(symbolname);
                //TODO: Fuel adjustment map should be data-updated!
                /*if (_ecuConnection.Opened && _ECUmode == OperationMode.ModeOnline)
                {
                    if (_isAdjustmentMap)
                    {
                        mv.Map_content = m_AFRMaps.GetCurrentlyMutatedFuelMap();
                    }
                }*/
            }
            // update all mapviewers with a dummy value for test
            // UpdateMapViewers(3000, 100, 1.6);
        }