private void GenerateAndSaveNewFuelMap(IECUFile m_File) { TuningReferenceMaps _referenceMaps = new TuningReferenceMaps(); byte[] pressure_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_map_xaxis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Fuel_map_xaxis!")); byte[] rpm_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_map_yaxis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Fuel_map_yaxis!")); byte[] new_fuel_map = new byte[16 * 16]; int fuel_map_index = 0; for (int rpm_index = rpm_axis.Length - 2; rpm_index >= 0; rpm_index -= 2) { for (int pressure_index = 0; pressure_index < pressure_axis.Length; pressure_index ++) { int irpm = Convert.ToInt32(rpm_axis[rpm_index]) * 256; irpm += Convert.ToInt32(rpm_axis[rpm_index + 1]); irpm *= 10; int ipressure = Convert.ToInt32(pressure_axis[pressure_index]); double correctionFactor = 1; double pressure = ipressure; MapSensorType mapsensor = m_File.GetMapSensorType(false); if (mapsensor == MapSensorType.MapSensor30) correctionFactor = 1.2; else if (mapsensor == MapSensorType.MapSensor35) correctionFactor = 1.4; else if (mapsensor == MapSensorType.MapSensor40) correctionFactor = 1.6; else if (mapsensor == MapSensorType.MapSensor50) correctionFactor = 2.0; pressure *= correctionFactor; pressure -= 100; pressure /= 100; double fuel_correction = _referenceMaps.FuelCorrectionForPressureRpm(pressure, (double)irpm); // write ignition advance into the map fuel_correction -= 0.5; fuel_correction /= 0.00390625; Int32 icorrection = Convert.ToInt32(fuel_correction); if (icorrection > 255) icorrection = 255; new_fuel_map[fuel_map_index++] = (byte)icorrection; } } // now save the map m_File.WriteData(new_fuel_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Insp_mat!")); }
private void GenerateAndSaveNewIgnitionMap(IECUFile m_File, bool runsE85) { //TODO: Implement // get the axis TuningReferenceMaps _referenceMaps = new TuningReferenceMaps(); byte[] pressure_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0_x_axis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Ign_map_0_x_axis!")); byte[] rpm_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0_y_axis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Ign_map_0_y_axis!")); byte[] new_ignition_map = new byte[16 * 18 * 2]; int ign_map_index = 0; for (int rpm_index = rpm_axis.Length-2; rpm_index >=0; rpm_index -= 2) { for (int pressure_index = 0; pressure_index < pressure_axis.Length; pressure_index += 2) { int irpm = Convert.ToInt32(rpm_axis[rpm_index]) * 256; irpm += Convert.ToInt32(rpm_axis[rpm_index+1]); int ipressure = Convert.ToInt32(pressure_axis[pressure_index]) * 256; ipressure += Convert.ToInt32(pressure_axis[pressure_index + 1]); double correctionFactor = 1; double pressure = ipressure; MapSensorType mapsensor = m_File.GetMapSensorType(false); if (mapsensor == MapSensorType.MapSensor30) correctionFactor = 1.2; else if (mapsensor == MapSensorType.MapSensor35) correctionFactor = 1.4; else if (mapsensor == MapSensorType.MapSensor40) correctionFactor = 1.6; else if (mapsensor == MapSensorType.MapSensor50) correctionFactor = 2.0; pressure *= correctionFactor; pressure -= 100; pressure /= 100; double ignition_advance = _referenceMaps.GetIgnitionAdvanceForPressureRpm(pressure, (double)irpm); if (runsE85) ignition_advance = _referenceMaps.GetIgnitionAdvanceE85ForPressureRpm(pressure, (double)irpm); // write ignition advance into the map ignition_advance *= 10; // correction factor Int32 iAdvance = Convert.ToInt32(ignition_advance); byte v1 = (byte)(iAdvance / 256); byte v2 = (byte)(iAdvance - (int)v1 * 256); //Console.WriteLine("Writing data rpmidx : " + rpm_index.ToString() + " mapidx: " + pressure_index.ToString() + " ignidx: " + ign_map_index.ToString()); new_ignition_map[ign_map_index++] = v1; new_ignition_map[ign_map_index++] = v2; } } // now save the map m_File.WriteData(new_ignition_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0!")); m_File.WriteData(new_ignition_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_4!")); // save as warmup map as well }
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; }