Skip to content

Commit

Permalink
Issue #47 fixed: Saving after editing PDO Mappings is now correct.
Browse files Browse the repository at this point in the history
  • Loading branch information
CANopenNode committed Mar 16, 2023
1 parent a2f6414 commit 32ef9eb
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 71 deletions.
53 changes: 27 additions & 26 deletions EDSEditorGUI/DevicePDOView2.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions EDSEditorGUI/DevicePDOView2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void ContextMenuStrip_removeitem_ItemClicked(object sender, ToolStripIte

}

helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);
UpdatePDOinfo();


Expand Down Expand Up @@ -154,7 +154,7 @@ private void Vcc_ValueChangedEvent(object sender, EventArgs e)
slot.Mapping[location.ordinal] = newentry;
}

helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);

doUpdateOD();
UpdatePDOinfo();
Expand Down Expand Up @@ -688,7 +688,7 @@ private void grid1_DragDrop(object sender, DragEventArgs e)
location.slot.insertMapping(location.ordinal, entry);
}

helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);
UpdatePDOinfo(false); //dont cause the list to refresh

}
Expand Down Expand Up @@ -723,7 +723,7 @@ private void button_deletePDO_Click(object sender, EventArgs e)

helper.pdoslots.Remove(selectedslot);

helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);
doUpdateOD();
UpdatePDOinfo();

Expand All @@ -744,7 +744,7 @@ private void addnewPDO()
UInt16 slot = helper.findPDOslotgap(isTXPDO);
helper.addPDOslot(slot);

helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);
doUpdateOD();
UpdatePDOinfo();
}
Expand Down Expand Up @@ -801,7 +801,7 @@ private void button_savepdochanges_Click_1(object sender, EventArgs e)

try
{
helper.buildmappingsfromlists();
helper.buildmappingsfromlists((ExporterFactory.Exporter)Properties.Settings.Default.ExporterType == ExporterFactory.Exporter.CANOPENNODE_V4);
}
catch (Exception ex)
{
Expand All @@ -810,8 +810,12 @@ private void button_savepdochanges_Click_1(object sender, EventArgs e)

doUpdateOD();
UpdatePDOinfo();
}

private void listView_TXPDO_SelectedIndexChanged(object sender, EventArgs e)
{

}

}
}

4 changes: 2 additions & 2 deletions Tests/PDOHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Test_TPDO()
tryGetODEntry(0x0004, out od);
slot.Mapping.Add(od);

pdo.buildmappingsfromlists();
pdo.buildmappingsfromlists(true);

//check configuration object exists
ODentry comparamOD;
Expand Down Expand Up @@ -115,7 +115,7 @@ public void Test_RPDO()
tryGetODEntry(0x0004, out od);
slot.Mapping.Add(od);

pdo.buildmappingsfromlists();
pdo.buildmappingsfromlists(true);

//check configuration object exists
ODentry comparamOD;
Expand Down
94 changes: 59 additions & 35 deletions libEDSsharp/PDOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ public bool invalid
public UInt16 eventtimer;
public byte syncstart;
public byte transmissiontype;
public string Description;
public string DescriptionComm;
public string DescriptionMap;

public PDOSlot()
{
configloc = "PERSIST_COMM";
mappingloc = "PERSIST_COMM";
transmissiontype = 254;
Mapping = new List<ODentry>();
Description = "";
}
DescriptionComm = "";
DescriptionMap = "";
}

public string getTargetName(ODentry od)
{
Expand Down Expand Up @@ -206,14 +208,15 @@ public void build_PDOlist(UInt16 startcob, List<PDOSlot> slots)

slot.configAccessType = od.accesstype;
slot.configloc = od.prop.CO_storageGroup;
slot.Description = od.Description;
slot.DescriptionComm = od.Description;


Console.WriteLine(String.Format("Found PDO Entry {0:x4} {1:x3}", idx, slot.COB));

//Look at mappings

ODentry mapping = eds.Getobject((ushort)(idx + 0x200));
slot.DescriptionMap = mapping.Description;
if(mapping==null)
{
Console.WriteLine(string.Format("No mapping for index 0x{0:x4} should be at 0x{1:x4}", idx, idx + 0x200));
Expand Down Expand Up @@ -294,7 +297,7 @@ public void build_PDOlist(UInt16 startcob, List<PDOSlot> slots)
/// Rebuild the communication and mapping paramaters from the
/// lists the PDOhelper currently has. These live in the list pdoslots
/// </summary>
public void buildmappingsfromlists()
public void buildmappingsfromlists(bool isCANopenNode_V4)
{
for(ushort x=0x1400;x<0x1c00;x++)
{
Expand All @@ -309,51 +312,53 @@ public void buildmappingsfromlists()
config.Index = slot.ConfigurationIndex;
config.datatype = DataType.PDO_COMMUNICATION_PARAMETER;
config.objecttype = ObjectType.RECORD;

ODentry sub = new ODentry("max sub-index", (ushort)slot.ConfigurationIndex, 0);
sub.defaultvalue = slot.isTXPDO()? "6" : "5";// max supported sub index TPDO=6, RPDO=5 according DS301
sub.datatype = DataType.UNSIGNED8;
sub.accesstype = EDSsharp.AccessType.ro;
config.addsubobject(0x00,sub);

config.accesstype = slot.configAccessType;
config.prop.CO_storageGroup = slot.configloc;
config.Description = slot.Description;
config.Description = slot.DescriptionComm;

ODentry sub;

if (slot.isTXPDO())
{

config.parameter_name = "TPDO communication parameter";
config.prop.CO_countLabel = "TPDO";
config.prop.CO_countLabel = "TPDO";

sub = new ODentry("Highest sub-index supported", (ushort)slot.ConfigurationIndex, 0);
sub.defaultvalue = "0x06";
sub.datatype = DataType.UNSIGNED8;
sub.accesstype = EDSsharp.AccessType.ro;
config.addsubobject(0x00, sub);

sub = new ODentry("COB-ID used by TPDO", (ushort)slot.ConfigurationIndex, 1);
sub.datatype = DataType.UNSIGNED32;
if (slot.nodeidpresent)
sub.defaultvalue = "$NODEID + "; // DSP306: "The $NODEID must appear at the beginning of the expression. Otherwise the line is interpreted as without a formula.
sub.defaultvalue = "$NODEID+"; // DSP306: "The $NODEID must appear at the beginning of the expression. Otherwise the line is interpreted as without a formula.
sub.defaultvalue += slot.COB.ToHexString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x01, sub);

sub = new ODentry("transmission type", (ushort)slot.ConfigurationIndex, 2);
sub = new ODentry("Transmission type", (ushort)slot.ConfigurationIndex, 2);
sub.datatype = DataType.UNSIGNED8;
sub.defaultvalue = slot.transmissiontype.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x02, sub);

sub = new ODentry("inhibit time", (ushort)slot.ConfigurationIndex, 3);
sub = new ODentry("Inhibit time", (ushort)slot.ConfigurationIndex, 3);
sub.datatype = DataType.UNSIGNED16;
sub.defaultvalue = slot.inhibit.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x03, sub);

sub = new ODentry("compatibility entry", (ushort)slot.ConfigurationIndex, 4);
sub.datatype = DataType.UNSIGNED8;
sub.defaultvalue = "0";
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x04, sub);

sub = new ODentry("event timer", (ushort)slot.ConfigurationIndex, 5);
if (!isCANopenNode_V4)
{
sub = new ODentry("compatibility entry", (ushort)slot.ConfigurationIndex, 4);
sub.datatype = DataType.UNSIGNED8;
sub.defaultvalue = "0";
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x04, sub);
}

sub = new ODentry("Event timer", (ushort)slot.ConfigurationIndex, 5);
sub.datatype = DataType.UNSIGNED16;
sub.defaultvalue = slot.eventtimer.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
Expand All @@ -369,27 +374,36 @@ public void buildmappingsfromlists()
else
{
config.parameter_name = "RPDO communication parameter";
config.prop.CO_countLabel = "RPDO";
config.prop.CO_countLabel = "RPDO";

sub = new ODentry("Highest sub-index supported", (ushort)slot.ConfigurationIndex, 0);
sub.defaultvalue = isCANopenNode_V4 ? "0x05" : "0x02";
sub.datatype = DataType.UNSIGNED8;
sub.accesstype = EDSsharp.AccessType.ro;
config.addsubobject(0x00, sub);

sub = new ODentry("COB-ID used by RPDO", (ushort)slot.ConfigurationIndex, 1);
sub.datatype = DataType.UNSIGNED32;
if (slot.nodeidpresent)
sub.defaultvalue = "$NODEID + "; // DSP306: "The $NODEID must appear at the beginning of the expression. Otherwise the line is interpreted as without a formula.
sub.defaultvalue = "$NODEID+"; // DSP306: "The $NODEID must appear at the beginning of the expression. Otherwise the line is interpreted as without a formula.
sub.defaultvalue += slot.COB.ToHexString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x01, sub);

sub = new ODentry("transmission type", (ushort)slot.ConfigurationIndex, 2);
sub = new ODentry("Transmission type", (ushort)slot.ConfigurationIndex, 2);
sub.datatype = DataType.UNSIGNED8;
sub.defaultvalue = slot.transmissiontype.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x02, sub);

sub = new ODentry("event timer", (ushort)slot.ConfigurationIndex, 5);
sub.datatype = DataType.UNSIGNED16;
sub.defaultvalue = slot.eventtimer.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x05, sub);
if (isCANopenNode_V4)
{
sub = new ODentry("Event timer", (ushort)slot.ConfigurationIndex, 5);
sub.datatype = DataType.UNSIGNED16;
sub.defaultvalue = slot.eventtimer.ToString();
sub.accesstype = EDSsharp.AccessType.rw;
config.addsubobject(0x05, sub);
}
}

eds.ods.Add(slot.ConfigurationIndex,config);
Expand All @@ -406,8 +420,9 @@ public void buildmappingsfromlists()

mapping.prop.CO_storageGroup = slot.mappingloc;
mapping.accesstype = slot.mappingAccessType;
mapping.Description = slot.DescriptionMap;

sub = new ODentry("Number of mapped objects", (ushort)slot.MappingIndex, 0);
sub = new ODentry("Number of mapped application objects in PDO", (ushort)slot.MappingIndex, 0);
sub.datatype = DataType.UNSIGNED8;
sub.defaultvalue = slot.Mapping.Count().ToString();
sub.accesstype = EDSsharp.AccessType.rw;
Expand All @@ -416,7 +431,7 @@ public void buildmappingsfromlists()
byte mappingcount = 1;
foreach (ODentry mapslot in slot.Mapping)
{
sub = new ODentry(String.Format("Mapped object {0:x}",mappingcount), (ushort)slot.MappingIndex, mappingcount);
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.accesstype = EDSsharp.AccessType.rw;
Expand All @@ -425,6 +440,15 @@ public void buildmappingsfromlists()
mappingcount++;

}

for (; mappingcount <= 8; mappingcount++)
{
sub = new ODentry(String.Format("Application object {0:x}", mappingcount), (ushort)slot.MappingIndex, mappingcount);
sub.datatype = DataType.UNSIGNED32;
sub.defaultvalue = "0x00000000";
sub.accesstype = EDSsharp.AccessType.rw;
mapping.addsubobject(mappingcount, sub);
}
eds.ods.Add(slot.MappingIndex,mapping);

}
Expand Down
2 changes: 1 addition & 1 deletion libEDSsharp/docs/libEDSsharp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32ef9eb

Please sign in to comment.