Exemplo n.º 1
0
        void acceptMap_onUpdateFuelMap(object sender, frmFuelMapAccept.UpdateFuelMapEventArgs e)
        {
            // write to ECU if possible
            if (m_connectedToECU)
            {
                if (e.Value == 0) return; // test for value 0... nothing todo
                if (m_AFRMap == null)
                {
                    m_AFRMap = new AFRMap();
                    m_AFRMap.onFuelmapCellChanged += new AFRMap.FuelmapCellChanged(m_AFRMap_onFuelmapCellChanged);
                    m_AFRMap.onCellLocked += new AFRMap.CellLocked(m_AFRMap_onCellLocked);
                    m_AFRMap.InitializeMaps(18 * 16, m_currentfile);
                }

                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_AFRMap.FuelMapInformation.GetOriginalFuelMap();
                double originalbyte = Convert.ToDouble(fuelmap[(y * 18) + e.X]);
                originalbyte *= (100 + e.Value) / 100;
                byte newFuelMapByte = Convert.ToByte(originalbyte);
                byte[] data2Write = new byte[1];
                data2Write[0] = newFuelMapByte;

                logger.Debug("Writing fuelmap");
                uint addresstowrite = (uint)GetSymbolAddressSRAM(m_symbols, m_appSettings.AutoTuneFuelMap) + (uint)(y * 18) + (uint)e.X; ;
                byte[] dataToSend = new byte[1];
                //dataToSend[0] = e.Cellvalue;
                if (!trionic7.WriteMapToSRAM(addresstowrite, data2Write))
                {
                    logger.Debug("Failed to write data to the ECU");
                }
                int fuelMapAddressFlash = (int)GetSymbolAddress(m_symbols, m_appSettings.AutoTuneFuelMap);
                fuelMapAddressFlash += (y * 18) + e.X;
                savedatatobinary(fuelMapAddressFlash, 1, data2Write, m_currentfile, false);
                UpdateChecksum(m_currentfile);
            }
        }
Exemplo n.º 2
0
        private void btnAutoTune_Click(object sender, EventArgs e)
        {
            //<GS-31012011> disable it immediately to prevent the user from multi-clicking the button and hence getting the system confused

            if (_currentEngineStatus.CurrentEngineTemp < 70)
            {
                frmInfoBox info = new frmInfoBox("Engine temperature of 70 degrees C not reached...");
                return;
            }

            btnAutoTune.Enabled = false;
            btnAutoTune.Text = "Wait...";
            System.Windows.Forms.Application.DoEvents();

            if (_autoTuning)
            {
                // switch OFF autotune
                //1. write data if needed?

                //2. Clear data that has been measured

                if (m_appSettings.DisableClosedLoopOnStartAutotune)
                {
                    SetLambdaControl(true);
                    SetE85Cal(true);
                    SetFCutCal(true);
                }

                SetStatusText("Autotune stopped.");
                btnAutoTune.ForeColor = Color.Empty;
                btnAutoTune.Text = "AutoTune";
                _autoTuning = false;
                ToggleRealtimePanel();

                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
                        WriteMapToSRAM(m_appSettings.AutoTuneFuelMap, m_AFRMap.GetOriginalFuelmap(), true);
                    }
                    else
                    {
                        // save the altered map into the binary
                        foreach (SymbolHelper sh in m_symbols)
                        {
                            if (sh.Varname == m_appSettings.AutoTuneFuelMap || sh.Userdescription == m_appSettings.AutoTuneFuelMap)
                            {
                                //<GS-28012011>
                                if (IsSoftwareOpen())
                                {
                                    int symbolnumber = GetSymbolNumberFromRealtimeList(GetSymbolNumber(m_symbols, sh.Varname), sh.Varname);
                                    sh.Symbol_number = symbolnumber;
                                }

                                byte[] mapdata = ReadMapFromSRAM(sh, true);
                                savedatatobinary((int)GetSymbolAddress(m_symbols, sh.Varname), sh.Length, mapdata, m_currentfile, false);
                                UpdateChecksum(m_currentfile);
                            }
                        }
                    }
                    // init the afrmaps values
                    m_AFRMap.InitAutoTuneVars(true, 18, 16);
                }
                else
                {
                    //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
                    try
                    {
                        logger.Debug("Getting differences in percentages");
                        double[] diffinperc = m_AFRMap.GetPercentualDifferences();

                        System.Data.DataTable dt = new System.Data.DataTable();
                        for (int i = 0; i < 18; i++)
                        {
                            dt.Columns.Add(i.ToString(), Type.GetType("System.Double"));
                        }
                        for (int i = 15; i >= 0; i--)
                        {
                            object[] arr = new object[18];

                            for (int j = 0; j < 18; j++)
                            {
                                arr.SetValue(diffinperc[(i * 18) + j], j);
                            }
                            dt.Rows.Add(arr);
                        }
                        frmFuelMapAccept acceptMap = new frmFuelMapAccept();
                        acceptMap.Text = "Select percent mutations to accept for map " + m_appSettings.AutoTuneFuelMap;
                        acceptMap.onUpdateFuelMap += new frmFuelMapAccept.UpdateFuelMap(acceptMap_onUpdateFuelMap);
                        acceptMap.X_axisvalues = GetXaxisValues(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap);
                        acceptMap.Y_axisvalues = GetYaxisValues(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap);
                        acceptMap.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows;
                        acceptMap.SetDataTable(dt);
                        acceptMap.ShowDialog();
                        System.Windows.Forms.Application.DoEvents();
                    }
                    catch (Exception E)
                    {
                        logger.Debug("Failed to stop autotune: " + E.Message);
                    }
                }
            }
            else
            {
                // switch ON autotune
                if (_softwareIsOpen)
                {
                    SetStatusText("Starting autotune...");
                    int _width = 18;
                    int _height = 16;
                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap, out _width, out _height);
                    if (m_AFRMap == null)
                    {
                        m_AFRMap = new AFRMap();
                        m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                        m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                        m_AFRMap.InitializeMaps(_width * _height, m_currentfile);
                    }

                    // fill BFuelCal.Map axis as integer values
                    m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                    m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                    m_AFRMap.InitAutoTuneVars(false, _width, _height); // this also clears the afr feedback map
                    // disable closed loop operation
                    if (m_appSettings.DisableClosedLoopOnStartAutotune)
                    {
                        // LambdaCal.ST_Enable?
                        SetLambdaControl(false);
                        SetE85Cal(false);
                        SetFCutCal(false);
                    }
                    // what's next?
                    // TODO: read the current fuel map into memory
                    byte[] fuelmap = new byte[18 * 16];
                    // is there something like spot adaption in T7?
                    bool _initOk = false;
                    foreach (SymbolHelper sh in m_symbols)
                    {
                        if (sh.Varname == m_appSettings.AutoTuneFuelMap || sh.Userdescription == m_appSettings.AutoTuneFuelMap)
                        {
                            fuelmap = ReadMapFromSRAM(sh, true);
                            //TODO: Fill AFRMaps with this?
                            m_AFRMap.SetCurrentFuelMap(fuelmap);
                            m_AFRMap.SetOriginalFuelMap(fuelmap);
                            m_AFRMap.AutoUpdateFuelMap = m_appSettings.AutoUpdateFuelMap;
                            m_AFRMap.CorrectionPercentage = m_appSettings.CorrectionPercentage;
                            m_AFRMap.AcceptableTargetErrorPercentage = m_appSettings.AcceptableTargetErrorPercentage;
                            m_AFRMap.CellStableTime_ms = m_appSettings.CellStableTime_ms;
                            m_AFRMap.MaximumAdjustmentPerCyclePercentage = m_appSettings.MaximumAdjustmentPerCyclePercentage;

                            _initOk = true;
                        }
                    }
                    if (_initOk)
                    {
                        _autoTuning = true;
                        SetStatusText("Autotune running...");
                        btnAutoTune.ForeColor = Color.Red;
                        btnAutoTune.Text = "Tuning...";
                    }
                    else
                    {
                        SetStatusText("Autotune init failed.");
                        // revert to closed loop
                        if (m_appSettings.DisableClosedLoopOnStartAutotune)
                        {
                            SetLambdaControl(true);
                            SetE85Cal(true);
                            SetFCutCal(true);
                        }
                    }
                }
                else
                {
                    frmInfoBox info = new frmInfoBox("Autotune is only available for OPEN binaries");
                }
            }
            btnAutoTune.Enabled = true;
            System.Windows.Forms.Application.DoEvents();
        }
Exemplo n.º 3
0
 void m_AFRMap_onFuelmapCellChanged(object sender, AFRMap.FuelmapChangedEventArgs e)
 {
     // seems that we need to adjust a value in the current fuelmap
     if (m_connectedToECU)
     {
         if (m_appSettings.AutoUpdateFuelMap)
         {
             if (_autoTuning)
             {
                 logger.Debug("Writing fuelmap");
                 uint addresstowrite = (uint)GetSymbolAddressSRAM(m_symbols, m_appSettings.AutoTuneFuelMap) + (uint)e.Mapindex;
                 byte[] dataToSend = new byte[1];
                 dataToSend[0] = e.Cellvalue;
                 if (!trionic7.WriteMapToSRAM(addresstowrite, dataToSend))
                 {
                     logger.Debug("Failed to write data to the ECU");
                 }
             }
         }
         else
         {
             // update the fuelinformation struct
         }
     }
 }
Exemplo n.º 4
0
        public frmMain(string[] args)
        {
            Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
            //System.Threading.Thread.CurrentThread.CurrentUICulture
            CultureInfo tci = new CultureInfo("nl-NL");
            Thread.CurrentThread.CurrentCulture = tci;
            splash = new frmSplash();
            splash.Show();
            System.Windows.Forms.Application.DoEvents();
            InitializeComponent();
            m_AFRMap = new AFRMap();
            m_AFRMap.onCellLocked += m_AFRMap_onCellLocked;
            m_AFRMap.onFuelmapCellChanged += m_AFRMap_onFuelmapCellChanged;

            try
            {
                sndplayer = new System.Media.SoundPlayer();
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
            if (args.Length > 0)
            {
                if (args[0].ToUpper().EndsWith(".BIN"))
                {
                    if(File.Exists(args[0]))
                    {
                        m_commandLineFile = args[0];
                        m_startFromCommandLine = true;
                    }
                }
            }

            m_DelegateUpdateRealTimeValue = UpdateRealtimeInformationValue;
            m_DelegateUpdateBDMProgress = ReportBDMProgress;
            m_DelegateUpdateMapViewer = UpdateMapViewer;

            m_DelegateUpdateStatus = updateStatusInBox;
            m_DelegateProgressStatus = SetProgressPercentage;
            m_DelegateCanFrame = trionic7_onCanFrame;

            trionic7.onReadProgress += trionicCan_onReadProgress;
            trionic7.onWriteProgress += trionicCan_onWriteProgress;
            trionic7.onCanInfo += trionicCan_onCanInfo;
            trionic7.onCanFrame += trionicCan_onCanFrame;

            try
            {
                RegistryKey TempKeyCM = null;
                TempKeyCM = Registry.ClassesRoot.CreateSubKey(@"SystemFileAssociations\.bin\shell\Edit in T7 Suite\command");
                string StartKey = System.Windows.Forms.Application.ExecutablePath + " \"%1\"";
                TempKeyCM.SetValue("", StartKey);
                TempKeyCM.Close();
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
            try
            {
                RegistryKey TempKeyCM = null;
                TempKeyCM = Registry.ClassesRoot.CreateSubKey(@"SystemFileAssociations\.bin\shell\Auto detect Trionic file type\command");
                string StartKey = System.Windows.Forms.Application.StartupPath + "\\SuiteLauncher.exe" + " \"%1\"";
                TempKeyCM.SetValue("", StartKey);
                TempKeyCM.Close();
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }

            try
            {
                // should be done only once!
                this.fio_callback = this.on_fio;
                BdmAdapter_SetFIOCallback(this.fio_callback);
                logger.Debug("BDM adapter callback set!");
                // should be done only once!

            }
            catch (Exception BDMException)
            {
                logger.Debug("BDM init failed: " + BDMException.Message);
            }

            try
            {
                m_DelegateStartReleaseNotePanel = this.StartReleaseNotesViewer;

            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }
Exemplo n.º 5
0
        private void LogWidebandAFR(float afr, float _lastRPM, float _lastLoad)
        {
            if (!m_appSettings.AutoCreateAFRMaps) return;
            try
            {
                if (_lastLoad != -1 && _lastRPM > 600 && afr >= 0 && afr < 25)
                {
                    int columns = 0;
                    int rows = 0;

                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, "BFuelCal.Map", out columns, out rows);
                    //TODO: calculate averages on the fly so we can display the AFR map live as well.
                    if (columns != 0)
                    {
                        if (m_AFRMap == null )
                        {
                            m_AFRMap = new AFRMap();
                            m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                            m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                            m_AFRMap.InitializeMaps(columns * rows, m_currentfile);
                        }

                        int rpmindex = LookUpIndexAxisRPMMap(_lastRPM, "BFuelCal.RpmYSP", 1);

                        int mapindex = LookUpIndexAxisRPMMap(_lastLoad, "BFuelCal.AirXSP", 1);
                        // get current counter
                        if (_currentEngineStatus.CurrentFuelcutStatus == 0) //Only do AddMeasurement if No FuelCut Active.
                        {
                            m_AFRMap.AddMeasurement(afr, rpmindex, mapindex, columns, rows);
                            UpdateFeedbackMaps();
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }
                }
            }
            catch (Exception E)
            {
                logger.Debug("LogWidebandAFR: " + E.Message);
            }
        }