public void FillGraph(double[] values, double[] injvalues, TurboType turbo) { DataTable chartdt = new DataTable(); chartdt.Columns.Add("X", Type.GetType("System.Double")); chartdt.Columns.Add("Y", Type.GetType("System.Double")); chartdt.Columns.Add("INJDC", Type.GetType("System.Double")); for (int i = 0; i < values.Length; i++) { chartdt.Rows.Add(Convert.ToDouble(x_axisvalues.GetValue(i)), values.GetValue(i), injvalues.GetValue(i)); } NChart chart = nChartControl1.Charts[0]; //NSeries series = (NSeries)chart.Series[0]; NSmoothLineSeries line = null; NSmoothLineSeries line2 = null; NSmoothLineSeries line3 = null; if (chart.Series.Count == 0) { line = (NSmoothLineSeries)chart.Series.Add(SeriesType.SmoothLine); } else { line = (NSmoothLineSeries)chart.Series[0]; } if (chart.Series.Count == 1) { line2 = (NSmoothLineSeries)chart.Series.Add(SeriesType.SmoothLine); } else { line2 = (NSmoothLineSeries)chart.Series[1]; } if (chart.Series.Count == 2) { line3 = (NSmoothLineSeries)chart.Series.Add(SeriesType.SmoothLine); } else { line3 = (NSmoothLineSeries)chart.Series[2]; } line.ClearDataPoints(); line2.ClearDataPoints(); line3.ClearDataPoints(); PressureToTorque ptt = new PressureToTorque(); foreach (DataRow dr in chartdt.Rows) { double power = 0; double torque = 0; torque = ptt.CalculateTorqueFromPressure(Convert.ToDouble(dr["Y"]), turbo); power = TorqueToPower(torque, Convert.ToDouble(dr["X"])); //power = line.AddDataPoint(new NDataPoint(Convert.ToDouble(dr["X"]), torque)); line2.AddDataPoint(new NDataPoint(Convert.ToDouble(dr["X"]), power)); line3.AddDataPoint(new NDataPoint(Convert.ToDouble(dr["X"]), Convert.ToDouble(dr["INJDC"]))); } nChartControl1.Refresh(); }
private void AddFilesToLibrary(string path) { Application.DoEvents(); DataTable dt = new DataTable("UserLib"); dt.Columns.Add("Filename"); dt.Columns.Add("FilenameNoPath"); dt.Columns.Add("EngineType"); dt.Columns.Add("Stage"); dt.Columns.Add("Injectors"); dt.Columns.Add("Mapsensor"); dt.Columns.Add("Torque"); dt.Columns.Add("E85", Type.GetType("System.Boolean")); dt.Columns.Add("T7Valve", Type.GetType("System.Boolean")); dt.Columns.Add("Partnumber"); dt.Columns.Add("SoftwareID"); dt.Columns.Add("CPU"); dt.Columns.Add("RAMlocked", Type.GetType("System.Boolean")); if (File.Exists(Application.StartupPath + "\\UserLib.xml")) { dt.ReadXml(Application.StartupPath + "\\UserLib.xml"); } string[] files = Directory.GetFiles(path, "*.bin", SearchOption.AllDirectories); foreach (string file in files) { FileInfo fi = new FileInfo(file); this.Text = "User library browser - " + Path.GetFileName(file); Application.DoEvents(); if (fi.Length == 0x20000 || fi.Length == 0x40000) { try { foreach (DataRow dr in dt.Rows) { if (dr["Filename"] != DBNull.Value) { if (dr["Filename"].ToString() == file) { dt.Rows.Remove(dr); break; } } } Trionic5File _file = new Trionic5File(); _file.SelectFile(file); Trionic5FileInformation m_trionicFileInformation = _file.ParseFile(); Trionic5Properties props = _file.GetTrionicProperties(); // get information about the file MapSensorType mapsensor = _file.GetMapSensorType(true); ECUFileType fileType = _file.DetermineFileType(); //t5p.Enginetype //t5p.Partnumber //t5p.CPUspeed //t5p.SoftwareID //t5p.RAMlocked //TuningStage _stage = m_trionicFile.DetermineTuningStage(out m_maxBoost); int injkonst = _file.GetSymbolAsInt("Inj_konst!"); bool m_E85 = false; int max_injection = _file.GetMaxInjection(); max_injection *= injkonst; // de maximale waarde uit fuel_map_x_axis! aub byte[] fuelxaxis = _file.ReadData((uint)m_trionicFileInformation.GetSymbolAddressFlash("Fuel_map_xaxis!"), (uint)m_trionicFileInformation.GetSymbolLength("Fuel_map_xaxis!")); int max_value_x_axis = Convert.ToInt32(fuelxaxis.GetValue(fuelxaxis.Length - 1)); if (mapsensor == MapSensorType.MapSensor30) { max_value_x_axis *= 120; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor35) { max_value_x_axis *= 140; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor40) { max_value_x_axis *= 160; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor50) { max_value_x_axis *= 200; max_value_x_axis /= 100; } //Console.WriteLine("max x: " + max_value_x_axis.ToString()); float max_support_boost = max_value_x_axis; max_support_boost /= 100; max_support_boost -= 1; float corr_inj = 1.4F / max_support_boost; corr_inj *= 100; //Console.WriteLine("corr_inj = " + corr_inj.ToString()); max_injection *= (int)corr_inj; max_injection /= 100; // dtReport.Rows.Add("Max injection: "+ max_injection.ToString()); if (max_injection > 7500) m_E85 = true; if (injkonst > 26) { m_E85 = true; } //TODO: nog extra controleren of er andere indicatoren zijn of er E85 gebruikt wordt // we kunnen dit aan de start verrijkingen zien en aan de ontstekingstijdstippen bij // vollast (ontsteking scherper), let op want dit laatste is bij W/M injectie ook zo. // de een na laatste waarde uit Eftersta_fak! geeft een duidelijke indicatie byte[] eftstafak = _file.ReadData((uint)m_trionicFileInformation.GetSymbolAddressFlash("Eftersta_fak!"), (uint)m_trionicFileInformation.GetSymbolLength("Eftersta_fak!")); if (eftstafak.Length == 15) { int eftstafakvalue = Convert.ToInt32(eftstafak.GetValue(13)); if (eftstafakvalue > 170) m_E85 = true; } if (m_E85) { max_injection *= 10; max_injection /= 14; // dtReport.Rows.Add("Probable fuel: E85"); } // get peak from insp_mat and multiply by injector constant InjectorType inj_type = InjectorType.Stock; if (max_injection > 5000) inj_type = InjectorType.Stock; else if (max_injection > 3500) inj_type = InjectorType.GreenGiants; else if (max_injection > 2000) inj_type = InjectorType.Siemens630Dekas; else if (max_injection > 1565) inj_type = InjectorType.Siemens875Dekas; else inj_type = InjectorType.Siemens1000cc; // Add info about T5/T7 valve int frek230 = _file.GetSymbolAsInt("Frek_230!"); int frek250 = _file.GetSymbolAsInt("Frek_250!"); bool T7Valve = false; if (fileType == ECUFileType.Trionic52File) { if (frek230 == 728 || frek250 == 935) { T7Valve = false; } else { T7Valve = true; } } else if (fileType == ECUFileType.Trionic55File) { if (frek230 == 90 || frek250 == 70) { T7Valve = false; } else { T7Valve = true; } } int torque = 0; float m_maxBoost = 0; TuningStage _stage = _file.DetermineTuningStage(out m_maxBoost); PressureToTorque ptt = new PressureToTorque(); torque = Convert.ToInt32(ptt.CalculateTorqueFromPressure(m_maxBoost, props.TurboType)); dt.Rows.Add(file, Path.GetFileName(file), props.Enginetype, _stage.ToString(), inj_type.ToString(), mapsensor.ToString(), torque.ToString(), m_E85, T7Valve, props.Partnumber, props.SoftwareID, props.CPUspeed, props.RAMlocked); } catch (Exception E) { Console.WriteLine(E.Message); } } } dt.WriteXml(Application.StartupPath + "\\UserLib.xml"); gridControl1.DataSource = dt; gridView1.BestFitColumns(); this.Text = "User library browser"; }
public TuningResult FreeTuneBinary(IECUFile m_File, double peakTorque, double peakBoost, bool tuneBasedOnTorque, MapSensorType mapType, TurboType turboType, InjectorType injectorType, BPCType valve, int rpmlimiter, int knockTime) { Trionic5Resume _localResume = new Trionic5Resume(); m_fileInformation = m_File.GetFileInfo(); string filename = m_fileInformation.Filename; // first set things right by running the tunetostagex wizard // generate a nice x_scale for ignition map (18 long) PressureToTorque ptt = new PressureToTorque(); double peak_boost = ptt.CalculatePressureFromTorque(peakTorque, turboType); if (!tuneBasedOnTorque) peak_boost = peakBoost; double peak_boost_request = peak_boost; double correction = 1.0; if (mapType == MapSensorType.MapSensor30) correction = 1.2; if (mapType == MapSensorType.MapSensor35) correction = 1.4; if (mapType == MapSensorType.MapSensor40) correction = 1.6; if (mapType == MapSensorType.MapSensor50) correction = 2.0; peak_boost_request *= 100; peak_boost_request += 100; peak_boost_request /= correction; peak_boost_request -= 100; peak_boost_request /= 100; double min_pressure = -1; double max_pressure = peak_boost; #region preparation /********* start of prepare phase *********/ string enginetp = readenginetype(filename); string partnumber = readpartnumber(filename); PartNumberConverter pnc = new PartNumberConverter(); ECUInformation ecuinfo = pnc.GetECUInfo(partnumber, enginetp); bool isLpt = true; if (ReadTunedToStageMarker(filename) > 0) { return TuningResult.TuningFailedAlreadyTuned; } else if (ReadThreeBarConversionMarker(filename) > 0) { return TuningResult.TuningFailedThreebarSensor; } Trionic5Properties t5p = m_File.GetTrionicProperties(); if (ecuinfo.Valid) { if (ecuinfo.Isaero || ecuinfo.Isfpt) { isLpt = false; } } if (t5p.MapSensorType != mapType) { ConvertFileToThreeBarMapSensor(m_fileInformation, t5p.MapSensorType, mapType); } // check injector type if (t5p.InjectorType != injectorType) { int inj_konst_diff = DetermineDifferenceInInjectorConstant(t5p.InjectorType, injectorType); AddToInjectorConstant(filename, inj_konst_diff); SetInjectorBatteryCorrectionMap(m_File, injectorType); //TODO: check this function for correctness! } /*if (injectorType == InjectorType.Stock) writebyteinfile(filename, GetSymbolAddress("Inj_konst!"), 19); else if (injectorType == InjectorType.GreenGiants) writebyteinfile(filename, GetSymbolAddress("Inj_konst!"), 18); else if (injectorType == InjectorType.Siemens630Dekas) writebyteinfile(filename, GetSymbolAddress("Inj_konst!"), 15); else if (injectorType == InjectorType.Siemens875Dekas) writebyteinfile(filename, GetSymbolAddress("Inj_konst!"), 13); else if (injectorType == InjectorType.Siemens875Dekas) writebyteinfile(filename, GetSymbolAddress("Inj_konst!"), 13);*/ t5p.TurboType = turboType; t5p.InjectorType = injectorType; t5p.MapSensorType = mapType; // determine stage?? int stage = 0; if (peak_boost < 1.2) stage = 1; else if (peak_boost < 1.3) stage = 2; else if (peak_boost < 1.4) stage = 3; else if (peak_boost < 1.5) stage = 4; else if (peak_boost < 1.6) stage = 5; else if (peak_boost < 1.7) stage = 6; else if (peak_boost < 1.8) stage = 7; else if (peak_boost < 1.9) stage = 8; else stage = 9; m_File.SetTrionicOptions(t5p); TuneToStage(filename, stage, peak_boost_request, 0.52, 1.0, 0.52, 1.54, 90, isLpt, turboType, injectorType, mapType); _localResume.ResumeTuning = m_resume.ResumeTuning.Copy(); /*********** end of prepare phase **************/ // set limiter, bpc valve type and knock time SetBPCValveType(filename, valve); _localResume.AddToResumeTable("Set BPC driving frequencies"); SetRPMLimiter(filename, rpmlimiter); _localResume.AddToResumeTable("Set RPM limiter"); SetKnockTime(filename, knockTime); _localResume.AddToResumeTable("Set knock time value"); #endregion // if mapsensor != stock and injectors are 630 cc or bigger if (mapType != MapSensorType.MapSensor25 && (injectorType == InjectorType.Siemens630Dekas || injectorType == InjectorType.Siemens875Dekas || injectorType == InjectorType.Siemens1000cc)) { // now scale it double step = (max_pressure - min_pressure) / 17; double[] axisforIgnitionMap = new double[18]; for (int i = 0; i < 18; i++) { axisforIgnitionMap.SetValue(min_pressure + (i * step), i); } byte[] actualAxis = new byte[36]; int j = 0; for (int i = 0; i < 18; i++) { double currValue = Convert.ToDouble(axisforIgnitionMap.GetValue(i)); currValue *= 100; currValue += 100; if (mapType == MapSensorType.MapSensor30) currValue /= 1.2; else if (mapType == MapSensorType.MapSensor35) currValue /= 1.4; else if (mapType == MapSensorType.MapSensor40) currValue /= 1.6; else if (mapType == MapSensorType.MapSensor50) currValue /= 2.0; int ival = Convert.ToInt32(currValue); byte v1 = (byte)(ival / 256); byte v2 = (byte)(ival - (int)v1 * 256); actualAxis.SetValue(v1, j++); actualAxis.SetValue(v2, j++); } m_File.WriteData(actualAxis, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0_x_axis!")); _localResume.AddToResumeTable("Generated and saved new ignition map x axis"); //Generate the ignition map based on the axis values GenerateAndSaveNewIgnitionMap(m_File, false); _localResume.AddToResumeTable("Generated and saved new ignition map"); min_pressure = -0.8; step = (max_pressure - min_pressure) / 15; // now setup x axis for fuel map double[] axisforFuelMap = new double[16]; for (int i = 0; i < 16; i++) { axisforFuelMap.SetValue(min_pressure + (i * step), i); } byte[] actualFuelAxis = new byte[16]; for (int i = 0; i < 16; i++) { double currValue = Convert.ToDouble(axisforFuelMap.GetValue(i)); currValue *= 100; currValue += 100; if (mapType == MapSensorType.MapSensor30) currValue /= 1.2; else if (mapType == MapSensorType.MapSensor35) currValue /= 1.4; else if (mapType == MapSensorType.MapSensor40) currValue /= 1.6; else if (mapType == MapSensorType.MapSensor50) currValue /= 2.0; int ival = Convert.ToInt32(currValue); if (ival > 255) ival = 255; actualFuelAxis.SetValue((byte)ival, i); } m_File.WriteData(actualFuelAxis, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_map_xaxis!")); _localResume.AddToResumeTable("Generated and saved new fuel map x axis"); //Generate the ignition map based on the axis values GenerateAndSaveNewFuelMap(m_File); _localResume.AddToResumeTable("Generated and saved new fuel map"); min_pressure = -0.3; step = (max_pressure - min_pressure) / 11; // now setup x axis for fuel map double[] axisforFuelKnockMap = new double[12]; for (int i = 0; i < 12; i++) { axisforFuelKnockMap.SetValue(min_pressure + (i * step), i); } byte[] actualFuelKnockAxis = new byte[12]; for (int i = 0; i < 12; i++) { double currValue = Convert.ToDouble(axisforFuelKnockMap.GetValue(i)); currValue *= 100; currValue += 100; if (mapType == MapSensorType.MapSensor30) currValue /= 1.2; else if (mapType == MapSensorType.MapSensor35) currValue /= 1.4; else if (mapType == MapSensorType.MapSensor40) currValue /= 1.6; else if (mapType == MapSensorType.MapSensor50) currValue /= 2.0; int ival = Convert.ToInt32(currValue); if (ival > 255) ival = 255; actualFuelKnockAxis.SetValue((byte)ival, i); } m_File.WriteData(actualFuelKnockAxis, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_knock_xaxis!")); _localResume.AddToResumeTable("Generated and saved new fuel knock map x axis"); //Generate the ignition map based on the axis values GenerateAndSaveNewFuelKnockMap(m_File); _localResume.AddToResumeTable("Generated and saved new fuel knock map"); // mesh up a boost request map for this.. already possible // adjust peak boost to be scaled for the mapsensor type SetBoostRequestMaps(turboType, injectorType, mapType, m_File.GetFileInfo().Filename, peak_boost_request, 100, isLpt); _localResume.AddToResumeTable("Generated boost request maps"); } m_resume.ResumeTuning = _localResume.ResumeTuning.Copy(); return TuningResult.TuningSuccess; }
private void AddFilesToLibrary(string path) { Application.DoEvents(); DataTable dt = new DataTable("UserLib"); dt.Columns.Add("Filename"); dt.Columns.Add("FilenameNoPath"); dt.Columns.Add("EngineType"); dt.Columns.Add("Stage"); dt.Columns.Add("Injectors"); dt.Columns.Add("Mapsensor"); dt.Columns.Add("Torque"); dt.Columns.Add("E85", Type.GetType("System.Boolean")); dt.Columns.Add("T7Valve", Type.GetType("System.Boolean")); dt.Columns.Add("Partnumber"); dt.Columns.Add("SoftwareID"); dt.Columns.Add("CPU"); dt.Columns.Add("RAMlocked", Type.GetType("System.Boolean")); if (File.Exists(Application.StartupPath + "\\UserLib.xml")) { dt.ReadXml(Application.StartupPath + "\\UserLib.xml"); } string[] files = Directory.GetFiles(path, "*.bin", SearchOption.AllDirectories); foreach (string file in files) { FileInfo fi = new FileInfo(file); this.Text = "User library browser - " + Path.GetFileName(file); Application.DoEvents(); if (fi.Length == 0x20000 || fi.Length == 0x40000) { try { foreach (DataRow dr in dt.Rows) { if (dr["Filename"] != DBNull.Value) { if (dr["Filename"].ToString() == file) { dt.Rows.Remove(dr); break; } } } Trionic5File _file = new Trionic5File(); _file.SelectFile(file); Trionic5FileInformation m_trionicFileInformation = _file.ParseFile(); Trionic5Properties props = _file.GetTrionicProperties(); // get information about the file MapSensorType mapsensor = _file.GetMapSensorType(true); ECUFileType fileType = _file.DetermineFileType(); //t5p.Enginetype //t5p.Partnumber //t5p.CPUspeed //t5p.SoftwareID //t5p.RAMlocked //TuningStage _stage = m_trionicFile.DetermineTuningStage(out m_maxBoost); int injkonst = _file.GetSymbolAsInt("Inj_konst!"); bool m_E85 = false; int max_injection = _file.GetMaxInjection(); max_injection *= injkonst; // de maximale waarde uit fuel_map_x_axis! aub byte[] fuelxaxis = _file.ReadData((uint)m_trionicFileInformation.GetSymbolAddressFlash("Fuel_map_xaxis!"), (uint)m_trionicFileInformation.GetSymbolLength("Fuel_map_xaxis!")); int max_value_x_axis = Convert.ToInt32(fuelxaxis.GetValue(fuelxaxis.Length - 1)); if (mapsensor == MapSensorType.MapSensor30) { max_value_x_axis *= 120; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor35) { max_value_x_axis *= 140; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor40) { max_value_x_axis *= 160; max_value_x_axis /= 100; } else if (mapsensor == MapSensorType.MapSensor50) { max_value_x_axis *= 200; max_value_x_axis /= 100; } //Console.WriteLine("max x: " + max_value_x_axis.ToString()); float max_support_boost = max_value_x_axis; max_support_boost /= 100; max_support_boost -= 1; float corr_inj = 1.4F / max_support_boost; corr_inj *= 100; //Console.WriteLine("corr_inj = " + corr_inj.ToString()); max_injection *= (int)corr_inj; max_injection /= 100; // dtReport.Rows.Add("Max injection: "+ max_injection.ToString()); if (max_injection > 7500) { m_E85 = true; } if (injkonst > 26) { m_E85 = true; } //TODO: nog extra controleren of er andere indicatoren zijn of er E85 gebruikt wordt // we kunnen dit aan de start verrijkingen zien en aan de ontstekingstijdstippen bij // vollast (ontsteking scherper), let op want dit laatste is bij W/M injectie ook zo. // de een na laatste waarde uit Eftersta_fak! geeft een duidelijke indicatie byte[] eftstafak = _file.ReadData((uint)m_trionicFileInformation.GetSymbolAddressFlash("Eftersta_fak!"), (uint)m_trionicFileInformation.GetSymbolLength("Eftersta_fak!")); if (eftstafak.Length == 15) { int eftstafakvalue = Convert.ToInt32(eftstafak.GetValue(13)); if (eftstafakvalue > 170) { m_E85 = true; } } if (m_E85) { max_injection *= 10; max_injection /= 14; // dtReport.Rows.Add("Probable fuel: E85"); } // get peak from insp_mat and multiply by injector constant InjectorType inj_type = InjectorType.Stock; if (max_injection > 5000) { inj_type = InjectorType.Stock; } else if (max_injection > 3500) { inj_type = InjectorType.GreenGiants; } else if (max_injection > 2000) { inj_type = InjectorType.Siemens630Dekas; } else if (max_injection > 1565) { inj_type = InjectorType.Siemens875Dekas; } else { inj_type = InjectorType.Siemens1000cc; } // Add info about T5/T7 valve int frek230 = _file.GetSymbolAsInt("Frek_230!"); int frek250 = _file.GetSymbolAsInt("Frek_250!"); bool T7Valve = false; if (fileType == ECUFileType.Trionic52File) { if (frek230 == 728 || frek250 == 935) { T7Valve = false; } else { T7Valve = true; } } else if (fileType == ECUFileType.Trionic55File) { if (frek230 == 90 || frek250 == 70) { T7Valve = false; } else { T7Valve = true; } } int torque = 0; float m_maxBoost = 0; TuningStage _stage = _file.DetermineTuningStage(out m_maxBoost); PressureToTorque ptt = new PressureToTorque(); torque = Convert.ToInt32(ptt.CalculateTorqueFromPressure(m_maxBoost, props.TurboType)); dt.Rows.Add(file, Path.GetFileName(file), props.Enginetype, _stage.ToString(), inj_type.ToString(), mapsensor.ToString(), torque.ToString(), m_E85, T7Valve, props.Partnumber, props.SoftwareID, props.CPUspeed, props.RAMlocked); } catch (Exception E) { Console.WriteLine(E.Message); } } } dt.WriteXml(Application.StartupPath + "\\UserLib.xml"); gridControl1.DataSource = dt; gridView1.BestFitColumns(); this.Text = "User library browser"; }