public void savedatatobinary(int address, int length, byte[] data, string filename, bool DoTransActionEntry) { FileInfo fi = new FileInfo(filename); if (m_currentFiletype == FileType.MOTRONICME7 || m_currentFiletype == FileType.MOTRONICME96) { // little endian, reverse bytes data = reverseEndian(data); } if (address > 0 && address < fi.Length) { try { byte[] beforedata = readdatafromfile(filename, address, length, false); FileStream fsi1 = File.OpenWrite(filename); BinaryWriter bw1 = new BinaryWriter(fsi1); fsi1.Position = address; for (int i = 0; i < length; i++) { bw1.Write((byte)data.GetValue(i)); } fsi1.Flush(); bw1.Close(); fsi1.Close(); fsi1.Dispose(); if (m_ProjectTransactionLog != null && DoTransActionEntry) { TransactionEntry tentry = new TransactionEntry(DateTime.Now, address, length, beforedata, data, 0, 0, ""); m_ProjectTransactionLog.AddToTransactionLog(tentry); SignalTransactionLogChanged(tentry.SymbolAddress, tentry.Note); } } catch (Exception E) { frmInfoBox info = new frmInfoBox("Failed to write to binary. Is it read-only? Details: " + E.Message); } } }
private void LoadMotronic18File(string filename, out SymbolCollection symbols, out AxisCollection axis) { // Get axis table from the binary // $E328 // find sequence 00 02 05 07 int readstate = 0; int lookuptablestartaddress = 0x00; int axisaddress = 0; readstate = 0; axis = new AxisCollection(); m_tempaxis = new AxisCollection(); SymbolCollection m_tempSymbols = new SymbolCollection(); symbols = new SymbolCollection(); byte[] _fileParameters = new byte[256]; int _fileParameterIndex = 0; byte[] datacheck = FileTools.Instance.readdatafromfile(filename, 0, 16, false); bool _fileValid = false; foreach (byte b in datacheck) { if (b != 0xFF) _fileValid = true; } if (!_fileValid) { frmInfoBox info = new frmInfoBox("This is not a M1.8 binary. These file types are not supported."); return; } int _fuelAndIgnitionAddress = 0; FileStream fs = new FileStream(filename, FileMode.Open); fs.Position = 0x7900; using (BinaryReader br = new BinaryReader(fs)) { for (int t = 0x7900; t < fs.Length; t++) { byte b = br.ReadByte(); //00 02 05 07 switch (readstate) { case 0: // we're reading addresses now if (b == 0xFF) { // end of table... stop reading readstate = 2; } else { axisaddress = (int)b * 256; readstate = 1; } break; case 1: axisaddress += (int)b; if (axisaddress > 0x2000) { AxisHelper ah = new AxisHelper(); ah.IsM18 = true; Console.WriteLine("Axis address: " + axisaddress.ToString("X4")); if (m_tempaxis.Count == 0) _fuelAndIgnitionAddress = axisaddress; ah.Addressinfile = axisaddress; m_tempaxis.Add(ah); } axisaddress = 0; readstate = 0; break; case 2: break; default: break; } } } fs.Close(); fs.Dispose(); SetProgressPercentage("Analyzing structure", 30); // from here, read 3 times 0F and find the limiters from there //Console.WriteLine("Speed limiter: " + _fileParameters[118].ToString() + " km/h"); // now read all axis addresses upto the end marker foreach (AxisHelper ah in m_tempaxis) { // get the address information for this axus Console.WriteLine("Filling information for axis at address: " + ah.Addressinfile.ToString("X4")); if (FillAxisInformation(filename, ah)) { if (!Helpers.Instance.AxisPresentInCollection(ah.Addressinfile, axis)) { axis.Add(ah); Console.WriteLine("Added axis: " + ah.Addressinfile.ToString("X4")); } } else { Console.WriteLine("What to do with : " + ah.Addressinfile.ToString("X4")); SymbolHelper sh = new SymbolHelper(); sh.Flash_start_address = ah.Addressinfile; m_tempSymbols.Add(sh); } } SetProgressPercentage("Adding axis", 40); // add secondary (Y) axis stuff that may not be in the lookup table m_tempaxis = new AxisCollection(); foreach (AxisHelper ah in axis) { int newaxisstart = ah.Addressinfile + ah.Length + 2; Console.WriteLine("Axis: " + ah.Addressinfile.ToString("X4") + " " + ah.Length.ToString()); if (CheckForAxisPresent(filename, newaxisstart, m_tempaxis, ah.Length)) { Console.WriteLine("Possible Y axis at address : " + newaxisstart.ToString("X4")); AxisHelper ahnew = new AxisHelper(); ahnew.IsM18 = true; ahnew.Addressinfile = newaxisstart; m_tempaxis.Add(ahnew); } } SetProgressPercentage("Adding axis, 2nd run", 60); // alsnog toevoegen aan collectie foreach (AxisHelper ahnew in m_tempaxis) { if (FillAxisInformation(filename, ahnew)) { if (!Helpers.Instance.AxisPresentInCollection(ahnew.Addressinfile, axis)) { Console.WriteLine("Add to axis (3rd): " + ahnew.Addressinfile.ToString("X4")); axis.Add(ahnew); } } } // first pointer in the stack points to fuel and ignition maps! if (_fuelAndIgnitionAddress > 0) { SymbolHelper shfuel = new SymbolHelper(); shfuel.Flash_start_address = _fuelAndIgnitionAddress; shfuel.Length = 256; shfuel.Varname = "Ignition map"; shfuel.Cols = 16; shfuel.Rows = 16; shfuel.Category = "Ignition"; symbols.Add(shfuel); // we need to manually add some axis to it as well. SymbolHelper shignition = new SymbolHelper(); shignition.Flash_start_address = _fuelAndIgnitionAddress + 256; shignition.Length = 256; shignition.Cols = 16; shignition.Rows = 16; shignition.Varname = "VE map"; shignition.Category = "Fuel"; // we need to manually add some axis to it as well. symbols.Add(shignition); } // now determine the gaps in the axis structure axis.SortColumn = "Addressinfile"; axis.SortingOrder = GenericComparer.SortOrder.Ascending; axis.Sort(); //<GS-01032011> to correctly determine the LAST map in the sequence with this algoritm // we need to insert a dummy axis at the first address AFTER the data // check whether the two last axis in the collection join up to form a 3D map // otherwise its just a 2D map if (axis.Count > 2) { AxisHelper ah = new AxisHelper(); ah.IsM18 = true; ah.Length = 0; ah.Descr = "Dummy"; if (axis[axis.Count - 2].Addressinfile + axis[axis.Count - 2].Length + 2 == axis[axis.Count - 1].Addressinfile) { // 3D map ah.Addressinfile = axis[axis.Count - 2].Addressinfile + 4 + axis[axis.Count - 2].Length + axis[axis.Count - 1].Length + (axis[axis.Count - 2].Length * axis[axis.Count - 1].Length); } else { // 2D map ah.Addressinfile = axis[axis.Count - 1].Addressinfile + 2 + axis[axis.Count - 1].Length; } Console.WriteLine("Added dummy axis: " + ah.Addressinfile.ToString("X4")); axis.Add(ah); } int address = 0; int length = 0; AxisHelper previousAxisHelper = new AxisHelper(); int symbolnumber = 0; SetProgressPercentage("Determing maps", 80); m_tempSymbols.SortColumn = "Flash_start_address"; m_tempSymbols.SortingOrder = GenericComparer.SortOrder.Ascending; m_tempSymbols.Sort(); int tempLen = 8; // assume first maplength = 8; int _previousAddress = 0; foreach (SymbolHelper shtest in m_tempSymbols) { SymbolHelper sh = new SymbolHelper(); sh.Varname = shtest.Flash_start_address.ToString("X4"); if (_previousAddress != 0) { tempLen = sh.Flash_start_address - _previousAddress; } else { _previousAddress = sh.Flash_start_address; } sh.Flash_start_address = shtest.Flash_start_address; sh.Length = tempLen; sh.Symbol_number = symbolnumber++; symbols.Add(sh); } int _mapLengthDiff = 0; bool _issueMapFound = false; AxisHelper _lastRPMSupportPointAxis = new AxisHelper(); foreach (AxisHelper ah in axis) { if (address != 0) { // is there a gap? //Console.WriteLine("Handling axis: " + ah.Addressinfile.ToString("X4")); int endofpreviousaxis = address + length + 2; if (endofpreviousaxis < ah.Addressinfile) { int gaplen = ah.Addressinfile - endofpreviousaxis; // check whether there are symbol address in between bool _symbolfound = false; foreach (SymbolHelper shtemp in symbols) { if (shtemp.Flash_start_address >= endofpreviousaxis && shtemp.Flash_start_address + shtemp.Length <= endofpreviousaxis + gaplen) { _symbolfound = true; //Console.WriteLine("GAP OVERRULED: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString() + " by " + shtemp.Flash_start_address.ToString("X4") + " " + shtemp.Length.ToString("X4")); // add the axis as a symbol in that case SymbolHelper shnew = new SymbolHelper(); shnew.Flash_start_address = ah.Addressinfile; shnew.Length = 8;// gaplen;// ah.Length; shnew.Varname = /*"NEW: " +*/ shnew.Flash_start_address.ToString("X4"); symbols.Add(shnew); if (gaplen > shnew.Length) { Console.WriteLine("might be more symbols after " + shtemp.Flash_start_address.ToString("X4")); } break; } } //Console.WriteLine("AXIS: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); /*if (endofpreviousaxis == 0xFCC5) { Console.WriteLine("PREV AXIS ADDRESS: "+ previousAxisHelper.Addressinfile.ToString("X4")); Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); }*/ Console.WriteLine("GAP: " + endofpreviousaxis.ToString("X4") + " - " + ah.Addressinfile.ToString("X4") + " length: " + gaplen.ToString()); SymbolHelper sh = new SymbolHelper(); sh.Varname = endofpreviousaxis.ToString("X4"); sh.Length = gaplen; if (_mapLengthDiff > 0) { sh.Length = _mapLengthDiff; _mapLengthDiff = 0; } sh.Symbol_number = symbolnumber++; sh.Flash_start_address = endofpreviousaxis; /*if (sh.Length == 256) { sh.Cols = 16; sh.Rows = 16; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { // there are 4 maps with this size in Motronic 4.3 // the one that had lots of 127 values in it is the VE map // and has a correction factor of 1/127 (lambda = 1) // the others are ignition maps and have a correction factor of 0.75 ?? if (FileTools.Instance.MapContainsMostly(filename, sh, 127, 4, 10)) { sh.Varname = "VE map"; sh.Category = "Fuel"; } else { sh.Varname = "Ignition map"; sh.Category = "Ignition"; } } } else if (sh.Length == 144) { sh.Cols = 12; sh.Rows = 12; sh.Varname = "Warmup fuel correction"; //sh.Category = "Examining"; sh.Category = "Fuel"; } else if (sh.Length == 128) { sh.Cols = 16; sh.Rows = 8; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { sh.Varname = "Boost map"; sh.Category = "Boost"; } } else if (sh.Length == 84) { sh.Cols = 7; sh.Rows = 12; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { sh.Varname = "Dwell angle characteristic map"; //sh.Category = "Examining"; sh.Category = "Ignition"; } } else if (sh.Length == 80) { sh.Cols = 5; sh.Rows = 16; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { sh.Varname = "Cylinder compensation"; sh.Category = "Correction"; } } else if (sh.Length == 70) { sh.Cols = 7; sh.Rows = 10; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { sh.Varname = "Cranking fuel enrichment"; sh.Category = "Cranking"; } } else if (sh.Length == 64) { sh.Cols = 8; sh.Rows = 8; // there's one map with this length that has 0x30 ID for axis and this is the MAF to Load conversion map SymbolHelper shxaxis = Helpers.Instance.GetXaxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address); SymbolHelper shyaxis = Helpers.Instance.GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address); if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x30) { if (FileTools.Instance.FirstColumnForTableAveragesLessThan(filename, sh, 50, 8)) { sh.Varname = "MAF to Load conversion map"; sh.Category = "MAF"; } } //<GS-28022011> this needs more work.. some bins don't have overboost //these bins have no boost map either and have a different amount of 64 byte length maps else if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x3B ) { sh.Varname = "Overboost map"; sh.Category = "Boost"; } else if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x40 && FileTools.Instance.readdatafromfile(filename, shyaxis.Y_axis_address, 1)[0] == 0x3B) { if (!FileTools.Instance.MapContainsMostly(filename, sh, 0, 0, 90) && FileTools.Instance.FirstColumnForTableAveragesLessThan(filename, sh, 50, 8)) { sh.Varname = "Acceleration correction"; sh.Category = "Fuel"; } } } else if (sh.Length == 50) { sh.Cols = 10; sh.Rows = 5; } else if (sh.Length == 48) { sh.Cols = 8; sh.Rows = 6; } else if (sh.Length == 42) { sh.Cols = 6; sh.Rows = 7; } else if (sh.Length == 40) { sh.Cols = 8; sh.Rows = 5; if (FileTools.Instance.CurrentFiletype == FileType.MOTRONIC18) { sh.Varname = "Idle fuel map"; sh.Category = "Fuel"; } } else if (sh.Length == 24) { sh.Cols = sh.Length; sh.Rows = 0; //SymbolHelper tsh = GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address); float[] xaxis; float[] yaxis; string xdescr; string ydescr; Helpers.Instance.GetAxisValues(filename, symbols, axis, sh.Varname, sh.Flash_start_address, sh.Rows, sh.Cols, out xaxis, out yaxis, out xdescr, out ydescr); //Console.WriteLine(sh.Varname + " " + xaxis.Length.ToString() + " " + yaxis.Length.ToString()); if (sh.Length != xaxis.Length * yaxis.Length) { // in that case we're at the point where maps are not longer in sync with axis Console.WriteLine("Offset found for sync problem: " + sh.Flash_start_address.ToString("X6")); _mapLengthDiff = sh.Length - (xaxis.Length); _issueMapFound = true; _symbolfound = false; } } else if (sh.Length == 16) { sh.Cols = sh.Length; sh.Rows = 1; //SymbolHelper tsh = GetYAxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address); float[] xaxis; float[] yaxis; string xdescr; string ydescr; Helpers.Instance.GetAxisValues(filename, symbols, axis, sh.Varname, sh.Flash_start_address, sh.Rows, sh.Cols, out xaxis, out yaxis, out xdescr, out ydescr); //Console.WriteLine(sh.Varname + " " + xaxis.Length.ToString() + " " + yaxis.Length.ToString()); if (FileTools.Instance.MapContainsMostly(filename, sh, 127, 20, 50) && xaxis.Length == 16) { sh.Varname = "WOT enrichment"; sh.Category = "Fuel"; } else if (xaxis.Length == 16 && FileTools.Instance.MapContainsMostly(filename, sh, 55, 4, 30)) { sh.Varname = "WOT ignition"; sh.Category = "Examining"; } } else if (sh.Length == 8) { if (_issueMapFound) { sh.Cols = sh.Length; sh.Rows = 1; // one of these maps should be the MAF limit map... which one though } } else { SymbolHelper shxaxis = Helpers.Instance.GetXaxisSymbol(filename, symbols, axis, sh.Varname, sh.Flash_start_address); if (FileTools.Instance.readdatafromfile(filename, shxaxis.X_axis_address, 1)[0] == 0x38 && shxaxis.X_axis_length == sh.Length) { sh.Category = "Temperature compensation"; } else { //Console.WriteLine(sh.Varname + " len: " + sh.Length.ToString("X2") + " axis len: " + shxaxis.X_axis_length.ToString("X2")); } sh.Cols = sh.Length; sh.Rows = 1; }*/ if (!_symbolfound) { symbols.Add(sh); } } } length = ah.Length; address = ah.Addressinfile; previousAxisHelper = ah; } // try to determine ignition maps probablility /* SymbolCollection ignition_maps = new SymbolCollection(); foreach (SymbolHelper sh in symbols) { if (sh.Varname == "Ignition map") { sh.Average_value = DetermineAverageMapValue(filename, sh); ignition_maps.Add(sh); } } //ignition_maps.SortColumn = "Average_value"; ignition_maps.SortColumn = "Flash_start_address"; //ignition_maps.SortingOrder = GenericComparer.SortOrder.Descending; ignition_maps.SortingOrder = GenericComparer.SortOrder.Ascending; ignition_maps.Sort(); if (ignition_maps.Count == 3) { ignition_maps[0].Varname = "Ignition map: wide open throttle"; ignition_maps[1].Varname = "Ignition map: part throttle"; ignition_maps[2].Varname = "Ignition map: knock/limp home"; } foreach (SymbolHelper sh in ignition_maps) { foreach (SymbolHelper shorg in symbols) { if (sh.Flash_start_address == shorg.Flash_start_address) { shorg.Varname = sh.Varname; break; } } } SymbolCollection cylinderCompensationMaps = new SymbolCollection(); foreach (SymbolHelper sh in symbols) { if (sh.Varname == "Cylinder compensation") { cylinderCompensationMaps.Add(sh); } } cylinderCompensationMaps.SortColumn = "Flash_start_address"; cylinderCompensationMaps.SortingOrder = GenericComparer.SortOrder.Ascending; cylinderCompensationMaps.Sort(); if (cylinderCompensationMaps.Count == 5) { cylinderCompensationMaps[0].Varname = "Cylinder compensation #1"; cylinderCompensationMaps[1].Varname = "Cylinder compensation #2"; cylinderCompensationMaps[2].Varname = "Cylinder compensation #3"; cylinderCompensationMaps[3].Varname = "Cylinder compensation #4"; cylinderCompensationMaps[4].Varname = "Cylinder compensation #5"; } foreach (SymbolHelper sh in cylinderCompensationMaps) { foreach (SymbolHelper shorg in symbols) { if (sh.Flash_start_address == shorg.Flash_start_address) { shorg.Varname = sh.Varname; break; } } } int _8lengthmapcount = 0; foreach (SymbolHelper sh in symbols) { if (sh.Length == 8) _8lengthmapcount++; } int idx = 7; if (_8lengthmapcount < 25) idx = 5; //else idx = 7; if (_8lengthmapcount > 10) { symbols.SortColumn = "Flash_start_address"; symbols.SortingOrder = GenericComparer.SortOrder.Descending; symbols.Sort(); int tidx = 0; foreach (SymbolHelper sh in symbols) { if (sh.Length == 8) tidx++; if (tidx == idx) { sh.Varname = "MAF limit"; sh.Category = "MAF"; } if (tidx == idx + 3) { sh.Varname = "Internal load limiter"; sh.Category = "Examining"; } } } LoadMotronic18Limiters();*/ //TestSymbolListIntegrety(symbols, axis); SetProgressPercentage("Sorting data", 90); // sort the symbol on length, biggest on top symbols.SortColumn = "Length"; symbols.SortingOrder = GenericComparer.SortOrder.Descending; symbols.Sort(); }
private void ConvertPartNumber() { PartNumberConverter pnc = new PartNumberConverter(); ECUInformation ecuinfo = pnc.GetECUInfo(buttonEdit1.Text, ""); lblCarModel.Text = "---"; lblEngineType.Text = "---"; lblPower.Text = "---"; lblTorque.Text = "---"; lblDescription.Text = "---"; checkEdit1.Checked = false; checkEdit2.Checked = false; checkEdit4.Checked = false; if (ecuinfo.Valid) { lblCarModel.Text = ecuinfo.Carmodel.ToString(); lblEngineType.Text = ecuinfo.Enginetype.ToString(); lblDescription.Text = ecuinfo.SoftwareID; lblPower.Text = ecuinfo.Bhp.ToString() + " bhp"; if (ecuinfo.Is2point3liter) { checkEdit1.Checked = false; checkEdit2.Checked = true; } else { checkEdit1.Checked = true; checkEdit2.Checked = false; } if (ecuinfo.Isturbo) checkEdit4.Checked = true; if (ecuinfo.Isfpt) { checkEdit4.Checked = true; } lblTorque.Text = ecuinfo.Torque.ToString() + " Nm"; if (comboBoxEdit1.EditValue == null) comboBoxEdit1.EditValue = ""; try { if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + ".BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + ".BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + "_1.BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + "_0.BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else { simpleButton2.Enabled = false; simpleButton3.Enabled = false; simpleButton4.Enabled = false; } } catch (Exception E) { Console.WriteLine("Failed to check for library availability: " + E.Message); } } else { frmInfoBox info = new frmInfoBox("The entered partnumber was not recognized by MotronicSuite"); } }
private void simpleButton2_Click(object sender, EventArgs e) { // show the details for this transaction (including data, meaning 2 mapviewers showing the details) frmInfoBox info = new frmInfoBox("Still needs to be implemented"); }
private void smoothSelectionToolStripMenuItem_Click(object sender, EventArgs e) { if (m_viewtype == ViewType.Hexadecimal) { frmInfoBox info = new frmInfoBox("Smoothing cannot be done in Hex view!"); return; } DevExpress.XtraGrid.Views.Base.GridCell[] cellcollection = gridView1.GetSelectedCells(); if (cellcollection.Length > 2) { // get boundaries for this selection // we need 4 corners int max_column = 0; int min_column = 0xFFFF; int max_row = 0; int min_row = 0xFFFF; foreach (DevExpress.XtraGrid.Views.Base.GridCell cell in cellcollection) { if (cell.Column.AbsoluteIndex > max_column) max_column = cell.Column.AbsoluteIndex; if (cell.Column.AbsoluteIndex < min_column) min_column = cell.Column.AbsoluteIndex; if (cell.RowHandle > max_row) max_row = cell.RowHandle; if (cell.RowHandle < min_row) min_row = cell.RowHandle; } if (max_column == min_column) { // one column selected only int top_value = Convert.ToInt32(gridView1.GetRowCellValue(max_row, gridView1.Columns[max_column])); int bottom_value = Convert.ToInt32(gridView1.GetRowCellValue(min_row, gridView1.Columns[max_column])); double diffvalue = (top_value - bottom_value) / (cellcollection.Length - 1); for (int t = 1; t < cellcollection.Length - 1; t++) { double newvalue = bottom_value + (t * diffvalue); gridView1.SetRowCellValue(min_row + t, gridView1.Columns[max_column], newvalue); } } else if (max_row == min_row) { // one row selected only int top_value = Convert.ToInt32(gridView1.GetRowCellValue(max_row, gridView1.Columns[max_column])); int bottom_value = Convert.ToInt32(gridView1.GetRowCellValue(max_row, gridView1.Columns[min_column])); double diffvalue = (top_value - bottom_value) / (cellcollection.Length - 1); for (int t = 1; t < cellcollection.Length - 1; t++) { double newvalue = bottom_value + (t * diffvalue); gridView1.SetRowCellValue(min_row, gridView1.Columns[min_column + t], newvalue); } } else { // block selected // interpolation on 4 points!!! int top_leftvalue = Convert.ToInt32(gridView1.GetRowCellValue(min_row, gridView1.Columns[min_column])); int top_rightvalue = Convert.ToInt32(gridView1.GetRowCellValue(min_row, gridView1.Columns[max_column])); int bottom_leftvalue = Convert.ToInt32(gridView1.GetRowCellValue(max_row, gridView1.Columns[min_column])); int bottom_rightvalue = Convert.ToInt32(gridView1.GetRowCellValue(max_row, gridView1.Columns[max_column])); for (int tely = 1; tely < max_row - min_row; tely++) { for (int telx = 1; telx < max_column - min_column; telx++) { // get values double valx1 = 0; double valx2 = 0; double valy1 = 0; double valy2 = 0; if (telx + min_column > 0) { valx1 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row, gridView1.Columns[telx + min_column - 1])); } else { valx1 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row, gridView1.Columns[min_column])); } if ((telx + min_column) < gridView1.Columns.Count - 1) { valx2 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row, gridView1.Columns[telx + min_column + 1])); } else { valx2 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row, gridView1.Columns[telx + min_column])); } if (tely + min_row > 0) { valy1 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row - 1, gridView1.Columns[telx + min_column])); } else { valy1 = Convert.ToDouble(gridView1.GetRowCellValue(min_row, gridView1.Columns[telx + min_column])); } if ((tely + min_row) < gridView1.RowCount - 1) { valy2 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row + 1, gridView1.Columns[telx + min_column])); } else { valy2 = Convert.ToDouble(gridView1.GetRowCellValue(tely + min_row, gridView1.Columns[telx + min_column])); } //Console.WriteLine("valx1 = " + valx1.ToString() + " valx2 = " + valx2.ToString() + " valy1 = " + valy1.ToString() + " valy2 = " + valy2.ToString()); // x as double valuex = (valx2 + valx1) / 2; double valuey = (valy2 + valy1) / 2; float newvalue = (float)((valuex + valuey) / 2); gridView1.SetRowCellValue(min_row + tely, gridView1.Columns[min_column + telx], newvalue.ToString("F0")); m_map_content = GetDataFromGridView(m_isUpsideDown); //double diffvaluex = (top_rightvalue - top_leftvalue) / (max_column - min_column - 1); //double diffvaluey = (top_rightvalue - top_leftvalue) / (max_column - min_column - 1); } } } // simpleButton3.Enabled = false; } }
private void ConvertPartNumber() { PartNumberConverter pnc = new PartNumberConverter(); ECUInformation ecuinfo = pnc.GetECUInfo(buttonEdit1.Text, ""); lblCarModel.Text = "---"; lblEngineType.Text = "---"; lblPower.Text = "---"; lblTorque.Text = "---"; lblDescription.Text = "---"; checkEdit1.Checked = false; checkEdit2.Checked = false; checkEdit4.Checked = false; if (ecuinfo.Valid) { lblCarModel.Text = ecuinfo.Carmodel.ToString(); lblEngineType.Text = ecuinfo.Enginetype.ToString(); lblDescription.Text = ecuinfo.SoftwareID; lblPower.Text = ecuinfo.Bhp.ToString() + " bhp"; if (ecuinfo.Is2point3liter) { checkEdit1.Checked = false; checkEdit2.Checked = true; } else { checkEdit1.Checked = true; checkEdit2.Checked = false; } if (ecuinfo.Isturbo) { checkEdit4.Checked = true; } if (ecuinfo.Isfpt) { checkEdit4.Checked = true; } lblTorque.Text = ecuinfo.Torque.ToString() + " Nm"; if (comboBoxEdit1.EditValue == null) { comboBoxEdit1.EditValue = ""; } try { if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + ".BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + ".BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + "_1.BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "Binaries\\" + buttonEdit1.Text + "_" + comboBoxEdit1.EditValue.ToString() + "_0.BIN"))) { simpleButton2.Enabled = true; simpleButton3.Enabled = true; simpleButton4.Enabled = true; } else { simpleButton2.Enabled = false; simpleButton3.Enabled = false; simpleButton4.Enabled = false; } } catch (Exception E) { Console.WriteLine("Failed to check for library availability: " + E.Message); } } else { frmInfoBox info = new frmInfoBox("The entered partnumber was not recognized by MotronicSuite"); } }
public void savedatatobinary(int address, int length, byte[] data, string filename, bool DoTransActionEntry, string note) { FileInfo fi = new FileInfo(filename); if (m_currentFiletype == FileType.MOTRONICME7) { // little endian, reverse bytes data = reverseEndian(data); } if (address > 0 && address < fi.Length) { try { byte[] beforedata = readdatafromfile(filename, address, length, false); FileStream fsi1 = File.OpenWrite(filename); BinaryWriter bw1 = new BinaryWriter(fsi1); fsi1.Position = address; for (int i = 0; i < length; i++) { bw1.Write((byte)data.GetValue(i)); } fsi1.Flush(); bw1.Close(); fsi1.Close(); fsi1.Dispose(); if (m_ProjectTransactionLog != null && DoTransActionEntry) { TransactionEntry tentry = new TransactionEntry(DateTime.Now, address, length, beforedata, data, 0, 0, note); m_ProjectTransactionLog.AddToTransactionLog(tentry); SignalTransactionLogChanged(tentry.SymbolAddress, tentry.Note); } } catch (Exception E) { frmInfoBox info = new frmInfoBox("Failed to write to binary. Is it read-only? Details: " + E.Message); } } }