コード例 #1
0
ファイル: frmMain.cs プロジェクト: mattiasclaesson/T7Suite
        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);
            }
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: mattiasclaesson/T7Suite
        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();
        }