diff --git a/EDSEditorGUI/ChangeMappingWidth.Designer.cs b/EDSEditorGUI/ChangeMappingWidth.Designer.cs new file mode 100644 index 00000000..101033b6 --- /dev/null +++ b/EDSEditorGUI/ChangeMappingWidth.Designer.cs @@ -0,0 +1,119 @@ +namespace ODEditor +{ + partial class ChangeMappingWidth + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChangeMappingWidth)); + this.label_enterwidth = new System.Windows.Forms.Label(); + this.updown_newwidth = new System.Windows.Forms.NumericUpDown(); + this.button_ok = new System.Windows.Forms.Button(); + this.button_cancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.updown_newwidth)).BeginInit(); + this.SuspendLayout(); + // + // label_enterwidth + // + this.label_enterwidth.AutoSize = true; + this.label_enterwidth.Location = new System.Drawing.Point(33, 24); + this.label_enterwidth.Name = "label_enterwidth"; + this.label_enterwidth.Size = new System.Drawing.Size(126, 13); + this.label_enterwidth.TabIndex = 0; + this.label_enterwidth.Text = "Enter the new width (bits)"; + // + // updown_newwidth + // + this.updown_newwidth.Location = new System.Drawing.Point(165, 22); + this.updown_newwidth.Maximum = new decimal(new int[] { + 64, + 0, + 0, + 0}); + this.updown_newwidth.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.updown_newwidth.Name = "updown_newwidth"; + this.updown_newwidth.Size = new System.Drawing.Size(61, 20); + this.updown_newwidth.TabIndex = 1; + this.updown_newwidth.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + // + // button_ok + // + this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK; + this.button_ok.Location = new System.Drawing.Point(12, 57); + this.button_ok.Name = "button_ok"; + this.button_ok.Size = new System.Drawing.Size(130, 37); + this.button_ok.TabIndex = 2; + this.button_ok.Text = "OK"; + this.button_ok.UseVisualStyleBackColor = true; + this.button_ok.Click += new System.EventHandler(this.button_ok_Click); + // + // button_cancel + // + this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button_cancel.Location = new System.Drawing.Point(183, 57); + this.button_cancel.Name = "button_cancel"; + this.button_cancel.Size = new System.Drawing.Size(130, 37); + this.button_cancel.TabIndex = 3; + this.button_cancel.Text = "Cancel"; + this.button_cancel.UseVisualStyleBackColor = true; + this.button_cancel.Click += new System.EventHandler(this.button_cancel_Click); + // + // ChangeMappingWidth + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(325, 111); + this.Controls.Add(this.button_cancel); + this.Controls.Add(this.button_ok); + this.Controls.Add(this.updown_newwidth); + this.Controls.Add(this.label_enterwidth); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.KeyPreview = true; + this.Name = "ChangeMappingWidth"; + this.Text = "Change mapping width"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ChangeMappingWidth_KeyDown); + ((System.ComponentModel.ISupportInitialize)(this.updown_newwidth)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label_enterwidth; + private System.Windows.Forms.NumericUpDown updown_newwidth; + private System.Windows.Forms.Button button_ok; + private System.Windows.Forms.Button button_cancel; + } +} \ No newline at end of file diff --git a/EDSEditorGUI/ChangeMappingWidth.cs b/EDSEditorGUI/ChangeMappingWidth.cs new file mode 100644 index 00000000..f5256566 --- /dev/null +++ b/EDSEditorGUI/ChangeMappingWidth.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ODEditor +{ + /// + /// A small dialog for PDO mapping width adjustments + /// + public partial class ChangeMappingWidth : Form + { + public int selected_width = 1; + private int default_width = 1; + + public ChangeMappingWidth(int current_width, int max_width) + { + InitializeComponent(); + // Validate params + if (current_width < 1) + current_width = 1; + if (max_width < 1) + max_width = 1; + if (current_width > max_width) + current_width = max_width; + updown_newwidth.Maximum = max_width; + updown_newwidth.Value = current_width; + selected_width = current_width; + default_width = current_width; + } + + private void button_ok_Click(object sender, EventArgs e) + { + selected_width = (int)updown_newwidth.Value; + if (selected_width != default_width) + { + this.DialogResult = DialogResult.OK; + } + else + { + this.DialogResult = DialogResult.Cancel; + } + this.Close(); + } + + private void button_cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void ChangeMappingWidth_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + this.button_ok_Click(null, null); + } + else if (e.KeyCode == Keys.Escape) + { + this.button_cancel_Click(null, null); + } + } + } +} diff --git a/EDSEditorGUI/ChangeMappingWidth.resx b/EDSEditorGUI/ChangeMappingWidth.resx new file mode 100644 index 00000000..a903c780 --- /dev/null +++ b/EDSEditorGUI/ChangeMappingWidth.resx @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + AAABAAEAEBAAAAAAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAA + AAD///8B////Af///wH///8B////Af///wH///8B////Af///wH///8B////Af///wH///8B////Af// + /wH///8B////Afb29v/29vb/9vb2//b29v/29vb/9vb2//b29v/29vb/9vb2//b29v/29vb/9vb2//b2 + 9v/29vb/9vb2/////wH29vb/QkJC/0JCQv9CQkL/9vb2//b29v9CQkL/QkJC/0JCQv/29vb/9vb2/0JC + Qv9CQkL/QkJC//b29v////8B9vb2/0JCQv/x7/D/QkJC//b29v/29vb/QkJC//Hv8P9CQkL/9vb2//b2 + 9v9CQkL/8e/w/0JCQv/29vb/////Afb29v9CQkL/QkJC/0JCQv/29vb/9vb2/0JCQv9CQkL/QkJC//b2 + 9v/29vb/QkJC/0JCQv9CQkL/9vb2/////wH29vb/9vb2/0JCQv/29vb/9vb2//b29v/29vb/QkJC//b2 + 9v/29vb/9vb2//b29v9CQkL/9vb2//b29v////8B////Afb29v9CQkL/9vb2//b29v/29vb/9vb2/0JC + Qv/29vb/9vb2//b29v/29vb/QkJC//b29v////8B////Af///wH29vb/QkJC/0JCQv9CQkL/QkJC/0JC + Qv9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv/29vb/////Af///wH///8B9vb2//b29v/29vb/9vb2//b2 + 9v/29vb/QkJC//b29v/29vb/9vb2//b29v/29vb/9vb2/////wH///8B////Af///wH///8B////Af// + /wH///8B9vb2/0JCQv/29vb/////Af///wH///8B////Af///wH///8B////Af///wH///8B////Af// + /wH29vb/9vb2//b29v9CQkL/9vb2//b29v/29vb/////Af///wH///8B////Af///wH///8B////Af// + /wH///8B9vb2/0JCQv9CQkL/QkJC/0JCQv9CQkL/9vb2/////wH///8B////Af///wH///8B////Af// + /wH///8B////Afb29v9CQkL/8e/w//Hv8P/x7/D/QkJC//b29v////8B////Af///wH///8B////Af// + /wH///8B////Af///wH29vb/QkJC//Hv8P/x7/D/8e/w/0JCQv/29vb/////Af///wH///8B////Af// + /wH///8B////Af///wH///8B9vb2/0JCQv9CQkL/QkJC/0JCQv9CQkL/9vb2/////wH///8B////Af// + /wH///8B////Af///wH///8B////Afb29v/29vb/9vb2//b29v/29vb/9vb2//b29v////8B////Af// + /wH///8BAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA + //8AAP//AAD//w== + + + \ No newline at end of file diff --git a/EDSEditorGUI/DevicePDOView2.Designer.cs b/EDSEditorGUI/DevicePDOView2.Designer.cs index b94639a0..847b9aa7 100644 --- a/EDSEditorGUI/DevicePDOView2.Designer.cs +++ b/EDSEditorGUI/DevicePDOView2.Designer.cs @@ -58,6 +58,7 @@ private void InitializeComponent() this.contextMenuStrip_removeitem = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItem_removeitem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem_insert = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem_changewidth = new System.Windows.Forms.ToolStripMenuItem(); this.grid1 = new SourceGrid.Grid(); this.button_down = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); @@ -313,25 +314,33 @@ private void InitializeComponent() this.contextMenuStrip_removeitem.ImageScalingSize = new System.Drawing.Size(20, 20); this.contextMenuStrip_removeitem.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem_removeitem, - this.toolStripMenuItem_insert}); + this.toolStripMenuItem_insert, + this.toolStripMenuItem_changewidth}); this.contextMenuStrip_removeitem.Name = "contextMenuStrip_removeitem"; - this.contextMenuStrip_removeitem.Size = new System.Drawing.Size(145, 48); + this.contextMenuStrip_removeitem.Size = new System.Drawing.Size(200, 70); this.contextMenuStrip_removeitem.Text = "Remove Item"; // // toolStripMenuItem_removeitem // this.toolStripMenuItem_removeitem.Name = "toolStripMenuItem_removeitem"; - this.toolStripMenuItem_removeitem.Size = new System.Drawing.Size(144, 22); + this.toolStripMenuItem_removeitem.Size = new System.Drawing.Size(199, 22); this.toolStripMenuItem_removeitem.Tag = "remove"; this.toolStripMenuItem_removeitem.Text = "Remove Item"; // // toolStripMenuItem_insert // this.toolStripMenuItem_insert.Name = "toolStripMenuItem_insert"; - this.toolStripMenuItem_insert.Size = new System.Drawing.Size(144, 22); + this.toolStripMenuItem_insert.Size = new System.Drawing.Size(199, 22); this.toolStripMenuItem_insert.Tag = "insert"; this.toolStripMenuItem_insert.Text = "Insert Item"; // + // toolStripMenuItem_changewidth + // + this.toolStripMenuItem_changewidth.Name = "toolStripMenuItem_changewidth"; + this.toolStripMenuItem_changewidth.Size = new System.Drawing.Size(199, 22); + this.toolStripMenuItem_changewidth.Tag = "changewidth"; + this.toolStripMenuItem_changewidth.Text = "Change mapping width"; + // // grid1 // this.grid1.AllowDrop = true; @@ -395,7 +404,7 @@ private void InitializeComponent() this.AutoSize = true; this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); - this.Controls.Add(this.button_addPDO); + this.Controls.Add(this.button_addPDO); this.Controls.Add(this.button_savepdochanges); this.Controls.Add(this.button_deletePDO); this.Controls.Add(this.groupBox2); @@ -449,5 +458,6 @@ private void InitializeComponent() private System.Windows.Forms.Button button_down; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem_changewidth; } } diff --git a/EDSEditorGUI/DevicePDOView2.cs b/EDSEditorGUI/DevicePDOView2.cs index 025c0b20..d3c21a4a 100644 --- a/EDSEditorGUI/DevicePDOView2.cs +++ b/EDSEditorGUI/DevicePDOView2.cs @@ -30,6 +30,9 @@ public partial class DevicePDOView2 : MyTabUserControl Point RightClickPoint = new Point(0, 0); + // Info columns: ID, COB, Index + const int INFO_COLS_COUNT = 3; + public DevicePDOView2() { InitializeComponent(); @@ -54,15 +57,15 @@ public DevicePDOView2() for (int x = 0; x < 64; x++) { - grid1[0, 3 + x] = new MyHeader(string.Format("{0}", x)); + grid1[0, INFO_COLS_COUNT + x] = new MyHeader(string.Format("{0}", x)); } for (int x = 0; x < 8; x++) { - grid1[1, 3 + x * 8] = new MyHeader(string.Format("Byte {0}", x)); - grid1[1, 3 + x * 8].ColumnSpan = 8; + grid1[1, INFO_COLS_COUNT + x * 8] = new MyHeader(string.Format("Byte {0}", x)); + grid1[1, INFO_COLS_COUNT + x * 8].ColumnSpan = 8; - grid1[1, 3 + x * 8].View.BackColor = Color.Tomato; + grid1[1, INFO_COLS_COUNT + x * 8].View.BackColor = Color.Tomato; } @@ -85,6 +88,7 @@ private void ContextMenuStrip_removeitem_ItemClicked(object sender, ToolStripIte int foundrow, foundcol; SourceGrid.Cells.ICellVirtual v = getItemAtGridPoint(RightClickPoint, out foundrow, out foundcol); SourceGrid.Cells.Cell c = (SourceGrid.Cells.Cell)v; + var width_limit = 64 + INFO_COLS_COUNT - foundcol; if (c == null) return; @@ -98,15 +102,29 @@ private void ContextMenuStrip_removeitem_ItemClicked(object sender, ToolStripIte switch (e.ClickedItem.Tag) { case "remove": - location.slot.Mapping.Remove(location.entry); + location.slot.Mapping.Remove(location.mappingentry); break; case "insert": - ODentry od = new ODentry(); - location.slot.Mapping.Insert(location.ordinal, eds.dummy_ods[0x002]); + PDOMappingEntry od = new PDOMappingEntry(); + od.entry = eds.dummy_ods[0x002]; + od.width = Math.Min(od.entry.Sizeofdatatype(), width_limit); + location.slot.Mapping.Insert(location.ordinal, od); break; + case "changewidth": + var mapping = location.slot.Mapping[location.ordinal]; + width_limit = Math.Min(mapping.entry.Sizeofdatatype(), width_limit); + if (mapping.width > width_limit) + mapping.width = width_limit; + var temp = new ChangeMappingWidth(mapping.width, width_limit); + if (temp.ShowDialog() == DialogResult.OK) + { + mapping.width = temp.selected_width; + location.slot.Mapping[location.ordinal] = mapping; + } + break; } helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4); @@ -133,25 +151,39 @@ private void Vcc_ValueChangedEvent(object sender, EventArgs e) PDOlocator location = (PDOlocator)((SourceGrid.Cells.Cell)cell.Cell).Tag; PDOSlot slot = location.slot; - ODentry newentry = null; + var newmapping = new PDOMappingEntry(); - if (eds.tryGetODEntry(newindex, out newentry)) + if (eds.tryGetODEntry(newindex, out newmapping.entry)) { if (newsubindex != 0) - newentry = newentry.subobjects[newsubindex]; + { + newmapping.entry = newmapping.entry.subobjects[newsubindex]; + newmapping.width = newmapping.entry.Sizeofdatatype(); + } } else { return; } - if (location.entry == null) + int current_width = newmapping.entry.Sizeofdatatype(); + int width_limit = 64 + INFO_COLS_COUNT - cell.Position.Column; + width_limit = Math.Min(width_limit, newmapping.entry.Sizeofdatatype()); + current_width = Math.Min(width_limit, current_width); + newmapping.width = current_width; + var change_pdo_entry_width = new ChangeMappingWidth(current_width, width_limit); + if (change_pdo_entry_width.ShowDialog() == DialogResult.OK) { - slot.Mapping.Add(newentry); + newmapping.width = change_pdo_entry_width.selected_width; + } + + if (location.mappingentry.entry == null) + { + slot.Mapping.Add(newmapping); } else { - slot.Mapping[location.ordinal] = newentry; + slot.Mapping[location.ordinal] = newmapping; } helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4); @@ -427,7 +459,6 @@ public void UpdatePDOinfo(bool updatechoices = true) #if !NETCOREAPP comboStandard.Control.DropDownWidth = 0x100; #endif - comboStandard.Changed += ComboStandard_Changed; //tableLayoutPanel1.SuspendLayout(); @@ -444,8 +475,8 @@ public void UpdatePDOinfo(bool updatechoices = true) { if (isTXPDO != slot.isTXPDO()) continue; - if (grid1.ColumnsCount > 64+3) - grid1.ColumnsCount = 64+3; + if (grid1.ColumnsCount > 64+INFO_COLS_COUNT) + grid1.ColumnsCount = 64+INFO_COLS_COUNT; grid1.Redim(grid1.RowsCount + 1, grid1.ColumnsCount); grid1.Rows[grid1.RowsCount - 1].Tag = slot; grid1.Rows[row + 2].Height = 30; @@ -460,33 +491,34 @@ public void UpdatePDOinfo(bool updatechoices = true) int bitoff = 0; int ordinal = 0; - foreach (ODentry entry in slot.Mapping) + foreach (PDOMappingEntry mappingentry in slot.Mapping) { - if ((bitoff + entry.Sizeofdatatype()) > 64) + if ((bitoff + mappingentry.width) > 64) { string toDisplay = string.Join(Environment.NewLine, slot.Mapping); MessageBox.Show(string.Format("Invalid TXPDO mapping parameters in 0x{0:X}!\r\nTrying to map more than the maximum lenght of a CAN message (8 bytes).\r\n\r\nMembers are:\r\n{1}", slot.ConfigurationIndex,toDisplay)); break; } - string target = slot.getTargetName(entry); - grid1[row + 2, bitoff + 3] = new SourceGrid.Cells.Cell(target, comboStandard); - grid1[row + 2, bitoff + 3].ColumnSpan = entry.Sizeofdatatype(); - grid1[row + 2, bitoff + 3].View = viewNormal; + string target = slot.getTargetName(mappingentry.entry); + grid1[row + 2, bitoff + INFO_COLS_COUNT] = new SourceGrid.Cells.Cell(target, comboStandard); + grid1[row + 2, bitoff + INFO_COLS_COUNT].ColumnSpan = mappingentry.width; + grid1[row + 2, bitoff + INFO_COLS_COUNT].View = viewNormal; + grid1[row + 2, bitoff + INFO_COLS_COUNT].ToolTipText = grid1[row + 2, bitoff + INFO_COLS_COUNT].DisplayText; - PDOlocator location = new PDOlocator(); - location.slot = slot; - location.ordinal = ordinal; - location.entry = entry; + PDOlocator location = new PDOlocator(); + location.slot = slot; + location.ordinal = ordinal; + location.mappingentry = mappingentry; - Console.WriteLine(string.Format("New location at Row {0} Col {1} Loc {2}", row, bitoff, location.ToString())); - grid1[row + 2, bitoff + 3].Tag = location; + Console.WriteLine(string.Format("New location at Row {0} Col {1} Loc {2}", row, bitoff, location.ToString())); + grid1[row + 2, bitoff + INFO_COLS_COUNT].Tag = location; - ValueChangedController vcc = new ValueChangedController(); - vcc.ValueChangedEvent += Vcc_ValueChangedEvent; + ValueChangedController vcc = new ValueChangedController(); + vcc.ValueChangedEvent += Vcc_ValueChangedEvent; - grid1[row + 2, bitoff + 3].AddController(vcc); - bitoff += entry.Sizeofdatatype(); + grid1[row + 2, bitoff + INFO_COLS_COUNT].AddController(vcc); + bitoff += mappingentry.width; ordinal++; @@ -496,23 +528,24 @@ public void UpdatePDOinfo(bool updatechoices = true) //Pad out with an empty combo if (bitoff < 64) { - grid1[row + 2, bitoff + 3] = new SourceGrid.Cells.Cell("Empty", comboStandard); - int colspan = 64 - bitoff; - if (colspan > 8) + grid1[row + 2, bitoff + INFO_COLS_COUNT] = new SourceGrid.Cells.Cell("Empty", comboStandard); + // Align "Empty" cell to byte end + int colspan = (64 - bitoff) % 8; + if ((colspan == 0) && ((64 - bitoff) > 8)) colspan = 8; - grid1[row + 2, bitoff + 3].ColumnSpan = colspan; - grid1[row + 2, bitoff + 3].View = viewEmpty; + grid1[row + 2, bitoff + INFO_COLS_COUNT].ColumnSpan = colspan; + grid1[row + 2, bitoff + INFO_COLS_COUNT].View = viewEmpty; ValueChangedController vcc = new ValueChangedController(); vcc.ValueChangedEvent += Vcc_ValueChangedEvent; - grid1[row + 2, bitoff + 3].AddController(vcc); + grid1[row + 2, bitoff + INFO_COLS_COUNT].AddController(vcc); PDOlocator location = new PDOlocator(); location.slot = slot; location.ordinal = ordinal; - location.entry = null; + location.mappingentry.entry = null; Console.WriteLine(string.Format("New location at Row {0} Col {1} Loc {2}", row, bitoff, location.ToString())); - grid1[row + 2, bitoff + 3].Tag = location; + grid1[row + 2, bitoff + INFO_COLS_COUNT].Tag = location; } @@ -523,12 +556,6 @@ public void UpdatePDOinfo(bool updatechoices = true) grid1.VScrollBar.Value = savVScrollValue; } - private void ComboStandard_Changed(object sender, EventArgs e) - { - - - } - public void redrawtable() { @@ -561,12 +588,12 @@ private class PDOlocator { public PDOSlot slot; public int ordinal; - public ODentry entry; + public PDOMappingEntry mappingentry; public override string ToString() { string msg; - msg = String.Format("Ordinal {0} , slot {1} entry {2}", ordinal, slot.ToString(), entry == null ? "NULL" : entry.ToString()); + msg = String.Format("Ordinal {0} , slot {1} entry {2}", ordinal, slot.ToString(), mappingentry.entry == null ? "NULL" : mappingentry.ToString()); return msg; } @@ -581,7 +608,7 @@ private void clickEvent_Click(object sender, EventArgs e) private void button_down_Click(object sender, EventArgs e) { - int newwidth = grid1.Columns[3].Width - 10; + int newwidth = grid1.Columns[INFO_COLS_COUNT].Width - 10; if (newwidth < 18) newwidth = 18; @@ -589,19 +616,19 @@ private void button_down_Click(object sender, EventArgs e) for (int x = 0; x < 64; x++) { - grid1.Columns[x + 3].Width = newwidth; + grid1.Columns[x + INFO_COLS_COUNT].Width = newwidth; } } private void button_up_Click(object sender, EventArgs e) { - int newwidth = grid1.Columns[3].Width + 10; + int newwidth = grid1.Columns[INFO_COLS_COUNT].Width + 10; Console.WriteLine("New Width " + newwidth.ToString()); for (int x = 0; x < 64; x++) { - grid1.Columns[x + 3].Width = newwidth; + grid1.Columns[x + INFO_COLS_COUNT].Width = newwidth; } } @@ -696,7 +723,7 @@ private void grid1_DragDrop(object sender, DragEventArgs e) foreach (ODentry entry in entries) { - location.slot.insertMapping(location.ordinal, entry); + location.slot.insertMapping(location.ordinal, new PDOMappingEntry(entry, entry.Sizeofdatatype())); } helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4); diff --git a/Tests/PDOHelperTests.cs b/Tests/PDOHelperTests.cs index df940964..01e869ba 100644 --- a/Tests/PDOHelperTests.cs +++ b/Tests/PDOHelperTests.cs @@ -26,14 +26,14 @@ public void Test_TPDO() //fill it with some dummy entries - ODentry od; - tryGetODEntry(0x0002, out od); + var od = new PDOMappingEntry(); + tryGetODEntry(0x0002, out od.entry); slot.Mapping.Add(od); - tryGetODEntry(0x0003, out od); + tryGetODEntry(0x0003, out od.entry); slot.Mapping.Add(od); - tryGetODEntry(0x0004, out od); + tryGetODEntry(0x0004, out od.entry); slot.Mapping.Add(od); pdo.buildmappingsfromlists(true); @@ -103,14 +103,14 @@ public void Test_RPDO() //fill it with some dummy entries - ODentry od; - tryGetODEntry(0x0002, out od); + var od = new PDOMappingEntry(); + tryGetODEntry(0x0002, out od.entry); slot.Mapping.Add(od); - tryGetODEntry(0x0003, out od); + tryGetODEntry(0x0003, out od.entry); slot.Mapping.Add(od); - tryGetODEntry(0x0004, out od); + tryGetODEntry(0x0004, out od.entry); slot.Mapping.Add(od); pdo.buildmappingsfromlists(true); diff --git a/libEDSsharp/PDOHelper.cs b/libEDSsharp/PDOHelper.cs index 332b0bf3..1b71d0db 100644 --- a/libEDSsharp/PDOHelper.cs +++ b/libEDSsharp/PDOHelper.cs @@ -6,6 +6,27 @@ namespace libEDSsharp { + + /// + /// Represents a single PDO mapping entry + /// Holds a reference to ODentry and a mapped width + /// + public struct PDOMappingEntry + { + public ODentry entry; + public int width; + + public PDOMappingEntry(ODentry entry = null, int width = 0) + { + if ((entry != null) && (width == 0)) + this.width = entry.Sizeofdatatype(); + else + this.width = width; + + this.entry = entry; + } + } + /// /// Represent a PDO slot (mapping + communication index) /// @@ -109,7 +130,7 @@ public bool invalid /// /// PDO mapping /// - public List Mapping = new List(); + public List Mapping = new List(); /// /// PDO inhibit time,multiple of 100us /// @@ -142,7 +163,7 @@ public PDOSlot() configloc = "PERSIST_COMM"; mappingloc = "PERSIST_COMM"; transmissiontype = 254; - Mapping = new List(); + Mapping = new List(); DescriptionComm = ""; DescriptionMap = ""; } @@ -194,15 +215,15 @@ public string getTargetName(ODentry od) /// /// The zero-based index at which item should be inserted /// OD entry to be mapped - public void insertMapping(int ordinal, ODentry entry) + public void insertMapping(int ordinal, PDOMappingEntry entry) { int size = 0; - foreach(ODentry e in Mapping) + foreach(PDOMappingEntry e in Mapping) { - size += e.Sizeofdatatype(); + size += e.width; } - if (size + entry.Sizeofdatatype() > 64) + if (size + entry.width > 64) return; Mapping.Insert(ordinal,entry); @@ -333,10 +354,10 @@ void build_PDOlist(UInt16 startIdx, List slots) //validate this against what is in the actual object mapped try { - ODentry maptarget; + var maptarget = new PDOMappingEntry(null, datasize); if (pdosub == 0) { - if (eds.tryGetODEntry(pdoindex, out maptarget) == false) + if (eds.tryGetODEntry(pdoindex, out maptarget.entry) == false) { Console.WriteLine("MAPPING FAILED"); //Critical PDO error @@ -344,15 +365,17 @@ void build_PDOlist(UInt16 startIdx, List slots) } } else - maptarget = eds.ods[pdoindex].Getsubobject(pdosub); + maptarget.entry = eds.ods[pdoindex].Getsubobject(pdosub); - if (maptarget.prop.CO_disabled == false && datasize == (maptarget.Sizeofdatatype())) + if ((maptarget.entry.prop.CO_disabled == false) && + (datasize <= maptarget.entry.Sizeofdatatype()) && + (datasize > 0)) { //mappingfail = false; } else { - Console.WriteLine(String.Format("MAPPING FAILED {0} != {1}", datasize, maptarget.Sizeofdatatype())); + Console.WriteLine(String.Format("MAPPING FAILED {0} != {1}", datasize, maptarget.entry.Sizeofdatatype())); } slot.Mapping.Add(maptarget); @@ -504,11 +527,11 @@ public void buildmappingsfromlists(bool isCANopenNode_V4) mapping.addsubobject(0x00, sub); byte mappingcount = 1; - foreach (ODentry mapslot in slot.Mapping) + foreach (PDOMappingEntry mapslot in slot.Mapping) { sub = new ODentry(String.Format("Application object {0:X}", mappingcount), (ushort)slot.MappingIndex, mappingcount); sub.datatype = DataType.UNSIGNED32; - sub.defaultvalue = string.Format("0x{0:X4}{1:X2}{2:X2}", mapslot.Index, mapslot.Subindex, mapslot.Sizeofdatatype()); + sub.defaultvalue = string.Format("0x{0:X4}{1:X2}{2:X2}", mapslot.entry.Index, mapslot.entry.Subindex, mapslot.width); sub.accesstype = EDSsharp.AccessType.rw; mapping.addsubobject(mappingcount, sub);