Exemple #1
0
        private void ctrlRealtime1_onSwitchIgnitionTuningOnOff(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.
            // DO NOT support T5.2 anymore, because of lack of proper knock detection
            if (!props.IsTrionic55)
            {
                frmInfoBox info = new frmInfoBox("T5.2 is currently not supported for Autotuning Ignition");
                return;
            }

            _ecuConnection.StopECUMonitoring();
            Thread.Sleep(10);
            if (m_IgnitionMaps == null)
            {
                m_IgnitionMaps = new IgnitionMaps();
                m_IgnitionMaps.onIgnitionmapCellChanged += new IgnitionMaps.IgnitionmapCellChanged(m_IgnitionMaps_onIgnitionmapCellChanged);
                m_IgnitionMaps.onCellLocked += new IgnitionMaps.CellLocked(m_IgnitionMaps_onCellLocked);
                m_IgnitionMaps.TrionicFile = m_trionicFile;
                m_IgnitionMaps.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);
            // we have to check whether knock detection is turned on, otherwise we DO NOT start ignition autotune

            if (pgm_mod.Length > 3)
            {
                if (!e.SwitchOn)
                {
                    Thread.Sleep(100);
                    // user ended an ignition tuning session.. what todo ?
                    //TODO: ask the user whether he wants to merge the altered fuelmap into ECU memory!
                    // if he replies NO: revert to the previous ignition map (we still need to preserve a copy!)
                    if (MessageBox.Show("Keep adjusted ignition map?", "Question", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        _ecuConnection.WriteSymbolDataForced((int)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIgnitionMap()), (int)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIgnitionMap()), IntArrayToByteArray(m_IgnitionMaps.GetOriginalIgnitionmap()));
                    }
                    else
                    {
                        // user selected to keep this map, sync ignition map to the opened binary file! <GS-11042011>
                        byte[] bIgnMap = IntArrayToByteArray(m_IgnitionMaps.GetCurrentlyMutatedIgnitionMap());
                        m_trionicFile.WriteDataNoCounterIncrease(bIgnMap, (uint)m_trionicFileInformation.GetSymbolAddressFlash(m_trionicFileInformation.GetIgnitionMap()));
                    }
                    // init the ignitionmaps values
                    m_IgnitionMaps.InitAutoTuneVars(e.SwitchOn);
                    ctrlRealtime1.SetAutoTuneIgnitionButtonText("Autotune ignition");
                    SetStatusText("Idle");
                }
                else
                {

                    // init the afrmaps values
                    SetStatusText("Starting ignition autotune...");
                    System.Windows.Forms.Application.DoEvents();
                    m_IgnitionMaps.InitAutoTuneVars(e.SwitchOn);
                    byte[] ignitionmap;
                    ignitionmap = _ecuConnection.ReadSymbolData(m_trionicFileInformation.GetIgnitionMap(), (uint)m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIgnitionMap()), (uint)m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIgnitionMap()));
                    Thread.Sleep(50);

                    // TODO: Check whether there are cells that have more advance than the setting allows
                    if (m_appSettings.CapIgnitionMap) // <GS-05042011> added new option to cap off ignition map before commencing autotune
                    {
                        bool _writeMapToECU = false;
                        for (int i = 0; i < ignitionmap.Length; i += 2)
                        {
                            // get the value from the map
                            int advance = Convert.ToInt32(ignitionmap[i]) * 256 + Convert.ToInt32(ignitionmap[i + 1]);
                            if (advance > 32000) advance = -(65535 - advance);
                            //check against m_appSettings.GlobalMaximumIgnitionAdvance
                            if (advance > m_appSettings.GlobalMaximumIgnitionAdvance * 10)
                            {
                                advance = Convert.ToInt32(m_appSettings.GlobalMaximumIgnitionAdvance * 10);
                                // write into the map and indicate we have to update the map in the ECU
                                byte b1 = (byte)(advance / 256);
                                byte b2 = (byte)(advance - (int)(advance * 256));
                                ignitionmap[i] = b1;
                                ignitionmap[i + 1] = b2;
                                _writeMapToECU = true;
                            }
                        }
                        if (_writeMapToECU)
                        {
                            _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM(m_trionicFileInformation.GetIgnitionMap()), m_trionicFileInformation.GetSymbolLength(m_trionicFileInformation.GetIgnitionMap()), ignitionmap);
                            Thread.Sleep(50);
                        }
                    }

                    byte[] knockpressuremap;
                    if (props.IsTrionic55)
                    {
                        knockpressuremap = _ecuConnection.ReadSymbolData("Knock_press_tab!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Knock_press_tab!"), (uint)m_trionicFileInformation.GetSymbolLength("Knock_press_tab!"));
                    }
                    else
                    {
                        byte[] knock_press_value = _ecuConnection.ReadSymbolData("Knock_press!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Knock_press!"), (uint)m_trionicFileInformation.GetSymbolLength("Knock_press!"));
                        knockpressuremap = new byte[32];
                        for (int i = 0; i < knockpressuremap.Length; i += 2)
                        {
                            knockpressuremap[i] = 0;
                            knockpressuremap[i + 1] = knock_press_value[0];
                        }
                    }
                    Thread.Sleep(50);
                    m_IgnitionMaps.SetKnockPressTab(ByteArrayToIntArray(knockpressuremap));
                    m_IgnitionMaps.SetOriginalIgnitionMap(ByteArrayToIntArray(ignitionmap)); // for reverting back if the user chooses so after the session
                    m_IgnitionMaps.SetCurrentIgnitionMap(ByteArrayToIntArray(ignitionmap)); // for editing & display by autotune functions
                    ctrlRealtime1.SetAutoTuneIgnitionButtonText("Tuning...");
                    SetStatusText("Autotune ignition running...");
                }
                m_IgnitionMaps.CellStableTime_ms = m_appSettings.IgnitionCellStableTime_ms;
                m_IgnitionMaps.MinimumEngineSpeedForIgnitionTuning = m_appSettings.MinimumEngineSpeedForIgnitionTuning;
                m_IgnitionMaps.MaxumimIgnitionAdvancePerSession = m_appSettings.MaximumIgnitionAdvancePerSession;
                m_IgnitionMaps.IgnitionAdvancePerCycle = m_appSettings.IgnitionAdvancePerCycle;
                m_IgnitionMaps.IgnitionRetardFirstKnock = m_appSettings.IgnitionRetardFirstKnock;
                m_IgnitionMaps.IgnitionRetardFurtherKnocks = m_appSettings.IgnitionRetardFurtherKnocks;
                m_IgnitionMaps.GlobalMaximumIgnitionAdvance = m_appSettings.GlobalMaximumIgnitionAdvance;
                m_IgnitionMaps.IsAutoMappingActive = e.SwitchOn;
            }
            else
            {
                // could not read pgm_mod...wtf?
            }
            _ecuConnection.StartECUMonitoring();
        }
Exemple #2
0
 private void ctrlRealtime1_onRemoveSymbolFromMonitorList(object sender, ctrlRealtime.MapDisplayRequestEventArgs e)
 {
     _ecuConnection.RemoveSymbolFromWatchlist(e.MapName);
     // remove it from the usercollection as well (if present)
     foreach (Trionic5Tools.SymbolHelper sh in m_RealtimeUserSymbols)
     {
         if (sh.Varname == e.MapName)
         {
             m_RealtimeUserSymbols.Remove(sh);
             break;
         }
     }
     ctrlRealtime1.SetRealtimeSymbollist(m_RealtimeUserSymbols);
 }
Exemple #3
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();
        }
Exemple #4
0
        private void ctrlRealtime1_onOpenLogFileRequest(object sender, ctrlRealtime.OpenLogFileRequestEventArgs e)
        {
            // the realtime panel requests to open a log file
            // check whether the user has set this option to "ON"
            if (m_appSettings.AutoOpenLogFile)
            {
                // create a new logfile window and make it floating over the realtime panel
                // load the designated file
                ShowFloatingLog(e.Filename);

            }
        }
Exemple #5
0
 private void ctrlRealtime1_onProgramModeChange(object sender, ctrlRealtime.ProgramModeEventArgs e)
 {
     // we have to do something with the Pgm_mod stuff
     _ecuConnection.StopECUMonitoring();
     Thread.Sleep(100);
     byte[] pgm_mod = _ecuConnection.ReadSymbolData("Pgm_mod!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Pgm_mod!"), (uint)m_trionicFileInformation.GetSymbolLength("Pgm_mod!"));
     // Pgm_mod! BYTE bytenumber and mask
     if (pgm_mod.Length > e.ByteNumber)
     {
         if (e.Enable)
         {
             pgm_mod[e.ByteNumber] |= e.Mask;
             _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM("Pgm_mod!"), m_trionicFileInformation.GetSymbolLength("Pgm_mod!"), pgm_mod);
             Thread.Sleep(50);
         }
         else
         {
             pgm_mod[e.ByteNumber] &= (byte)(0xFF ^ e.Mask);
             _ecuConnection.WriteSymbolDataForced(m_trionicFileInformation.GetSymbolAddressSRAM("Pgm_mod!"), m_trionicFileInformation.GetSymbolLength("Pgm_mod!"), pgm_mod); Thread.Sleep(50);
         }
     }
     ctrlRealtime1.UpdateProgramModeButtons(_ecuConnection.ReadSymbolData("Pgm_mod!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Pgm_mod!"), (uint)m_trionicFileInformation.GetSymbolLength("Pgm_mod!")));
     _ecuConnection.StartECUMonitoring();
 }
Exemple #6
0
 private void ctrlRealtime1_onMonitorTypeChanged(object sender, ctrlRealtime.RealtimeMonitoringEventArgs e)
 {
     // the user selected a different type of realtime monitoring by changing the tabpage index.
     // now we need to reload the realtime monitoring list in the _ecuConnection object
     if (e.Type != RealtimeMonitoringType.UserMaps) // user maps should not alter the settings
     {
         FillRealtimePool(e.Type, false);
     }
 }
Exemple #7
0
 private void ctrlRealtime1_onMapDisplayRequested(object sender, ctrlRealtime.MapDisplayRequestEventArgs e)
 {
     // start a mapviewer (special one) that overlaps the realtime panel!
     // <GS-29112010> if the file is a Trionic 5.2 file, select the proper maps.
     string mapname = e.MapName;
     if (!props.IsTrionic55)
     {
         if (mapname == "Adapt_korr!") mapname = "Adapt_korr";
     }
     StartTableViewerFloating(mapname);
 }
Exemple #8
0
 private void ctrlRealtime1_onLoggingStarted(object sender, ctrlRealtime.LoggingEventArgs e)
 {
     if (m_CurrentWorkingProject != string.Empty)
     {
         m_ProjectLog.WriteLogbookEntry(LogbookEntryType.LogfileStarted, e.File);
     }
 }
Exemple #9
0
 private void ctrlRealtime1_onAutoTuneStateChanged(object sender, ctrlRealtime.AutoTuneEventArgs e)
 {
     btnToggleAutoTune.Enabled = e.Ready;
 }
Exemple #10
0
 private void ctrlRealtime1_onAddSymbolToMonitorList(object sender, ctrlRealtime.MapDisplayRequestEventArgs e)
 {
     // User added a symbol... maybe we need to keep track of these symbol ourselves and store it as a usercollection
     bool _fnd = false;
     foreach (Trionic5Tools.SymbolHelper sh in m_RealtimeUserSymbols)
     {
         if (sh.Varname == e.MapName)
         {
             _fnd = true;
         }
     }
     if (!_fnd)
     {
         Trionic5Tools.SymbolHelper shnew = new Trionic5Tools.SymbolHelper();
         shnew.Varname = e.MapName;
         shnew.Flash_start_address = m_trionicFileInformation.GetSymbolAddressFlash(e.MapName);
         shnew.Length = m_trionicFileInformation.GetSymbolLength(e.MapName);
         shnew.Start_address = m_trionicFileInformation.GetSymbolAddressSRAM(e.MapName);
         shnew.UserCorrectionFactor = e.CorrectionFactor;
         shnew.UserCorrectionOffset = e.CorrectionOffset;
         shnew.UseUserCorrection = e.UseUserCorrection;
         m_RealtimeUserSymbols.Add(shnew);
         _ecuConnection.AddSymbolToWatchlist(shnew, false);
         ctrlRealtime1.SetRealtimeSymbollist(m_RealtimeUserSymbols);
     }
 }