From 9fed0bfe0e4dfd47b9e4ff84a645f5a44478de94 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Mon, 11 Sep 2017 20:43:32 +0100 Subject: [PATCH] Fix module OD view to at least a view only usable point. Probably as far as im going with modules --- EDSTest/DeviceODView.cs | 126 +++++++++++++++++++++++++++++++++++----- EDSTest/ModuleInfo.cs | 13 ++++- libEDSsharp/eds.cs | 5 ++ 3 files changed, 128 insertions(+), 16 deletions(-) diff --git a/EDSTest/DeviceODView.cs b/EDSTest/DeviceODView.cs index 0c54d38..693ceb9 100644 --- a/EDSTest/DeviceODView.cs +++ b/EDSTest/DeviceODView.cs @@ -186,7 +186,7 @@ private void button_save_changes_Click(object sender, EventArgs e) } - updateselectedindexdisplay(selectedobject.index); + updateselectedindexdisplay(selectedobject.index, currentmodule); validateanddisplaydata(); populateindexlists(); @@ -198,7 +198,7 @@ public void updatedetailslist() if (selectedobject == null) return; - updateselectedindexdisplay(selectedobject.index); + updateselectedindexdisplay(selectedobject.index, currentmodule); } public void validateanddisplaydata() @@ -216,7 +216,15 @@ public void validateanddisplaydata() ODentry od = (ODentry)selectedobject; - label_index.Text = string.Format("0x{0:x4}", od.index); + if (currentmodule == 0) + { + label_index.Text = string.Format("0x{0:x4}", od.index); + } + else + { + label_index.Text = string.Format("0x{0:x4} in module {1} -- {2}", od.index,currentmodule,eds.modules[currentmodule].mi.ProductName); + } + textBox_name.Text = od.parameter_name; textBox_denotation.Text = od.denotation; @@ -360,9 +368,15 @@ public void validateanddisplaydata() ODentry selectedindexod = null; - private void updateselectedindexdisplay(UInt16 index) + UInt16 currentmodule = 0; + + private void updateselectedindexdisplay(UInt16 index,UInt16 mod) { - selectedindexod = eds.ods[index]; + + + selectedindexod = getOD(index,mod); + currentmodule = mod; + updateselectedindexdisplay(); } @@ -469,7 +483,7 @@ private void listView_mandatory_objects_MouseClick(object sender, MouseEventArgs return; UInt16 idx = Convert.ToUInt16(lvi.Text, 16); - updateselectedindexdisplay(idx); + updateselectedindexdisplay(idx, currentmodule); selectedobject = eds.ods[idx]; validateanddisplaydata(); @@ -488,10 +502,30 @@ private void list_mouseclick(ListView listview, MouseEventArgs e) return; ListViewItem lvi = listview.SelectedItems[0]; - UInt16 idx = Convert.ToUInt16(lvi.Text, 16); + + currentmodule = 0; + + UInt16 idx; + if (lvi.Text.Contains('(')) + { + int i = 1+lvi.Text.IndexOf(' '); + string id = lvi.Text.Substring(i, lvi.Text.Length - i); + idx = Convert.ToUInt16(id, 16); + + string mods = lvi.Text.Substring(1, i - 3); + + currentmodule = Convert.ToUInt16(mods, 10); + + } + else + { + idx = Convert.ToUInt16(lvi.Text, 16); + } if (e.Button == MouseButtons.Right) { + if (currentmodule != 0) + return; if (listview.FocusedItem.Bounds.Contains(e.Location) == true) { @@ -513,10 +547,10 @@ private void list_mouseclick(ListView listview, MouseEventArgs e) return; } - updateselectedindexdisplay(idx); + updateselectedindexdisplay(idx, currentmodule); + selectedobject = getOD(idx, currentmodule); - selectedobject = eds.ods[idx]; validateanddisplaydata(); listView_mandatory_objects.HideSelection = true; @@ -701,6 +735,39 @@ public void populateindexlists() } + + + foreach (libEDSsharp.Module m in eds.modules.Values) + { + foreach (KeyValuePair kvp in m.modulesubext) + { + + + UInt16 index = kvp.Value.index; + ListViewItem lvi = new ListViewItem(string.Format("({0}) 0x{1:x4}", m.moduleindex,kvp.Value.index)); + lvi.SubItems.Add(kvp.Value.parameter_name); + lvi.Tag = kvp.Value; + if (selectedobject != null) + if (index == selectedobject.index) + lvi.Selected = true; + + lvi.ForeColor = Color.Blue; + + if (index >= 0x2000 && index < 0x6000) + { + listView_manufacture_objects.Items.Add(lvi); + } + else + { + listView_optional_objects.Items.Add(lvi); + } + + } + } + + + + listView_mandatory_objects.EndUpdate(); listView_manufacture_objects.EndUpdate(); listView_optional_objects.EndUpdate(); @@ -778,7 +845,7 @@ private void addNewObjectToolStripMenuItem_Click(object sender, EventArgs e) //Now switch to it as well Bug #26 - updateselectedindexdisplay(od.index); + updateselectedindexdisplay(od.index, currentmodule); selectedobject = eds.ods[od.index]; validateanddisplaydata(); @@ -834,7 +901,11 @@ private void deleteObjectToolStripMenuItem_Click(object sender, EventArgs e) if (MessageBox.Show(string.Format("Really delete index 0x{0:x4} ?", od.index), "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes) { eds.dirty = true; - eds.ods.Remove(od.index); + if (currentmodule == 0) + { + eds.ods.Remove(od.index); + } + populateindexlists(); } @@ -910,7 +981,7 @@ private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e) } eds.dirty = true; - updateselectedindexdisplay(selectedobject.index); + updateselectedindexdisplay(selectedobject.index, currentmodule); validateanddisplaydata(); } @@ -947,7 +1018,7 @@ private void removeSubItemToolStripMenuItem_Click(object sender, EventArgs e) od.parent.subobjects = newlist; eds.dirty = true; - updateselectedindexdisplay(selectedobject.index); + updateselectedindexdisplay(selectedobject.index, currentmodule); validateanddisplaydata(); } @@ -986,7 +1057,7 @@ private void changeMaxSubIndexToolStripMenuItem_Click(object sender, EventArgs e if(frm.ShowDialog()==DialogResult.OK) { od.defaultvalue = string.Format("0x{0:x2}",frm.maxsubindex); - updateselectedindexdisplay(selectedobject.index); + updateselectedindexdisplay(selectedobject.index, currentmodule); validateanddisplaydata(); } } @@ -1072,6 +1143,31 @@ private void comboBox_memory_SelectedIndexChanged(object sender, EventArgs e) } } } + + private ODentry getOD(UInt16 index, UInt16 selectedmodule) + { + ODentry ret = null; + + if (selectedmodule == 0) + { + if (eds.ods.ContainsKey(index)) + { + return eds.ods[index]; + } + } + else + { + + if (eds.modules.ContainsKey(selectedmodule)) + { + return eds.modules[selectedmodule].modulesubext[index]; + } + + } + + return null; ; + + } } public static class ControlExtensions @@ -1083,4 +1179,6 @@ public static void DoubleBuffering(this Control control, bool enable) } } + + } diff --git a/EDSTest/ModuleInfo.cs b/EDSTest/ModuleInfo.cs index e372f1f..97cccc5 100644 --- a/EDSTest/ModuleInfo.cs +++ b/EDSTest/ModuleInfo.cs @@ -100,8 +100,17 @@ private void listView_modules_MouseClick(object sender, MouseEventArgs e) } else { - lvi = new ListViewItem(string.Format("0x{0:x4}", sindex)); - lvi.SubItems.Add("** FAULT OD NOT FOUND **"); + if (eds.modules[index].modulesubext.ContainsKey(sindex)) + { + lvi = new ListViewItem(string.Format("0x{0:x4}", sindex)); + lvi.SubItems.Add(eds.modules[index].modulesubext[sindex].parameter_name); + + } + else + { + lvi = new ListViewItem(string.Format("0x{0:x4}", sindex)); + lvi.SubItems.Add("** FAULT OD NOT FOUND **"); + } } listView_extends.Items.Add(lvi); diff --git a/libEDSsharp/eds.cs b/libEDSsharp/eds.cs index eafd1b5..0d0c0fd 100644 --- a/libEDSsharp/eds.cs +++ b/libEDSsharp/eds.cs @@ -955,6 +955,11 @@ public bool PDOMapping } } + //FIXME Count "If several modules are gathered to form a new Sub-Index, + //then the number is 0, followed by semicolon and the + //number of bits that are created per module to build a new + //Sub-Index" + [EdsExport] public byte count = 0;