Skip to content

Commit 01ce96a

Browse files
committed
Fixes for CANOPENNODE_LEGACY (old version)
1 parent b3f85db commit 01ce96a

File tree

4 files changed

+101
-42
lines changed

4 files changed

+101
-42
lines changed

EDSEditorGUI/DeviceODView.cs

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,16 @@ public void PopulateObject()
303303
? od.parent.datatype.ToString()
304304
: od.datatype.ToString();
305305
ComboBoxSet(comboBox_dataType, dataType);
306-
comboBox_accessSDO.SelectedItem = od.AccessSDO().ToString();
307-
comboBox_accessPDO.SelectedItem = od.AccessPDO().ToString();
306+
if (CANopenNodeV4)
307+
{
308+
comboBox_accessSDO.SelectedItem = od.AccessSDO().ToString();
309+
comboBox_accessPDO.SelectedItem = od.AccessPDO().ToString();
310+
}
311+
else
312+
{
313+
comboBox_accessSDO.SelectedItem = od.accesstype.ToString();
314+
comboBox_accessPDO.SelectedItem = od.PDOtype.ToString();
315+
}
308316
comboBox_accessSRDO.SelectedItem = od.prop.CO_accessSRDO.ToString();
309317

310318
textBox_defaultValue.Text = od.defaultvalue;
@@ -401,28 +409,52 @@ private void Button_saveChanges_Click(object sender, EventArgs e)
401409
od.datatype = DataType.UNKNOWN;
402410
}
403411

404-
AccessSDO accessSDO;
405-
try
406-
{
407-
accessSDO = (AccessSDO)Enum.Parse(typeof(AccessSDO), comboBox_accessSDO.SelectedItem.ToString());
412+
if (CANopenNodeV4)
413+
{
414+
AccessSDO accessSDO;
415+
try
416+
{
417+
accessSDO = (AccessSDO)Enum.Parse(typeof(AccessSDO), comboBox_accessSDO.SelectedItem.ToString());
418+
}
419+
catch (Exception)
420+
{
421+
accessSDO = AccessSDO.ro;
422+
}
423+
424+
AccessPDO accessPDO;
425+
try
426+
{
427+
accessPDO = (AccessPDO)Enum.Parse(typeof(AccessPDO), comboBox_accessPDO.SelectedItem.ToString());
428+
}
429+
catch (Exception)
430+
{
431+
accessPDO = AccessPDO.no;
432+
}
433+
434+
od.AccessSDO(accessSDO, accessPDO);
435+
od.AccessPDO(accessPDO);
408436
}
409-
catch (Exception) {
410-
accessSDO = AccessSDO.ro;
437+
else
438+
{
439+
try
440+
{
441+
od.accesstype = (EDSsharp.AccessType)Enum.Parse(typeof(EDSsharp.AccessType), comboBox_accessSDO.SelectedItem.ToString());
442+
}
443+
catch (Exception)
444+
{
445+
od.accesstype = EDSsharp.AccessType.ro;
446+
}
447+
448+
try
449+
{
450+
od.PDOtype = (PDOMappingType)Enum.Parse(typeof(PDOMappingType), comboBox_accessPDO.SelectedItem.ToString());
451+
}
452+
catch (Exception)
453+
{
454+
od.PDOtype = PDOMappingType.no;
455+
}
411456
}
412457

413-
AccessPDO accessPDO;
414-
try
415-
{
416-
accessPDO = (AccessPDO)Enum.Parse(typeof(AccessPDO), comboBox_accessPDO.SelectedItem.ToString());
417-
}
418-
catch (Exception)
419-
{
420-
accessPDO = AccessPDO.no;
421-
}
422-
423-
od.AccessSDO(accessSDO, accessPDO);
424-
od.AccessPDO(accessPDO);
425-
426458
// CO_accessSRDO
427459
try
428460
{

libEDSsharp/Bridge.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ public Device convert(EDSsharp eds)
5353

5454
// if(od.subindex==-1)
5555
{
56+
if (od.objecttype == ObjectType.ARRAY && od.datatype == DataType.UNKNOWN)
57+
{
58+
//add the datatype field to parent objects if they don't have it already
59+
//if the 2nd subobject does not exist then we do nothing.
60+
ODentry sub = od.Getsubobject(1);
61+
if (sub != null)
62+
{
63+
od.datatype = sub.datatype;
64+
}
65+
}
66+
67+
if (od.objecttype == ObjectType.REC && od.accesstype == EDSsharp.AccessType.UNKNOWN)
68+
{
69+
ODentry sub = od.Getsubobject(1);
70+
if (sub != null)
71+
{
72+
od.accesstype = sub.accesstype;
73+
}
74+
}
75+
5676
Xml2CSharp.CANopenObject coo = new Xml2CSharp.CANopenObject();
5777
coo.Index = string.Format("{0:x4}", od.Index);
5878
coo.Name = od.parameter_name;
@@ -87,32 +107,19 @@ public Device convert(EDSsharp eds)
87107
sub.Description = new Xml2CSharp.Description();
88108
sub.Description.Text = subod.Description;
89109
sub.ObjectType = subod.objecttype.ToString();
90-
sub.AccessType = subod.accesstype.ToString();
91-
sub.DataType = string.Format("0x{0:x2}", (int)subod.datatype);
110+
sub.AccessType = subod.accesstype == EDSsharp.AccessType.UNKNOWN ? od.accesstype.ToString() : subod.accesstype.ToString();
111+
sub.DataType = string.Format("0x{0:x2}", (int)(subod.datatype == DataType.UNKNOWN ? od.datatype : subod.datatype));
92112
sub.DefaultValue = subod.defaultvalue;
93113
sub.HighValue = subod.HighLimit;
94114
sub.LowValue = subod.LowLimit;
95115
sub.PDOmapping = subod.PDOtype.ToString();
96116
sub.SubIndex = String.Format("{0:x2}", subindex);
97-
sub.TPDOdetectCOS = subod.prop.CO_flagsPDO.ToString().ToLower();
117+
sub.TPDOdetectCOS = (subod.prop.CO_flagsPDO ? subod.prop.CO_flagsPDO : od.prop.CO_flagsPDO).ToString().ToLower();
98118
coo.CANopenSubObject.Add(sub);
99119

100120
}
101121
}
102122

103-
if (od.objecttype == ObjectType.ARRAY && od.datatype == DataType.UNKNOWN)
104-
{
105-
//add the datatype field to parent objects if they don't have it already
106-
//if the 2nd subobject does not exist then we do nothing.
107-
ODentry sub = od.Getsubobject(1);
108-
if (sub != null)
109-
{
110-
od.datatype = sub.datatype;
111-
}
112-
113-
114-
}
115-
116123
dev.CANopenObjectList.CANopenObject.Add(coo);
117124
}
118125

libEDSsharp/CanOpenNodeExporter.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,19 @@ TYPE DEFINITIONS FOR RECORDS
531531
//We need to identify all the record types used and generate a struct for each one
532532
//FIXME the original CANopenNode exporter said how many items used this struct in the comments
533533

534-
List<string> structnamelist = new List<string>();
534+
List<string> structnamelist = new List<string>();
535+
536+
/* make sure, we have all storage groups */
537+
eds.CO_storageGroups.Add("ROM");
538+
eds.CO_storageGroups.Add("EEPROM");
535539

536540
foreach (KeyValuePair<UInt16, ODentry> kvp in eds.ods)
537541
{
538542
ODentry od = kvp.Value;
539543

544+
/* make sure, we have all storage groups */
545+
eds.CO_storageGroups.Add(od.prop.CO_storageGroup);
546+
540547
if (od.objecttype != ObjectType.REC)
541548
continue;
542549

@@ -831,7 +838,7 @@ private void export_c(string filename)
831838
file.WriteLine("// clang-format off");
832839
addHeader(file);
833840
file.WriteLine(@"// For CANopenNode V2 users, C macro `CO_VERSION_MAJOR=2` has to be added to project options
834-
#ifndef CO_VERSION_MAJOR
841+
#ifndef CO_VERSION_MAJOR
835842
#include ""CO_driver.h""
836843
#include """ + filename + @".h""
837844
#include ""CO_SDO.h""
@@ -933,8 +940,7 @@ protected string write_od_line(ODentry od)
933940

934941
byte flags = getflags(od);
935942

936-
DataType t = eds.Getdatatype(od);
937-
int datasize = (int)Math.Ceiling((double)od.Sizeofdatatype() / (double)8.0);
943+
int datasize = od.objecttype == ObjectType.REC ? 0 : (int)Math.Ceiling((double)od.Sizeofdatatype() / (double)8.0);
938944

939945
string array = "";
940946

@@ -1027,7 +1033,7 @@ public byte getflags(ODentry od)
10271033
if (od.objecttype == ObjectType.REC)
10281034
return 0;
10291035

1030-
switch(od.prop.CO_storageGroup.ToUpper())
1036+
switch((od.parent == null ? od : od.parent).prop.CO_storageGroup.ToUpper())
10311037
{
10321038
case "ROM":
10331039
flags = 0x01;
@@ -1075,6 +1081,19 @@ public byte getflags(ODentry od)
10751081
}
10761082
}
10771083

1084+
if (od.Index == 0x1003)
1085+
{
1086+
/* SDO server may write to the variable */
1087+
flags |= 0x08;
1088+
}
1089+
1090+
switch (od.PDOtype)
1091+
{
1092+
case libEDSsharp.PDOMappingType.RPDO: mapping |= 0x10; break;
1093+
case libEDSsharp.PDOMappingType.TPDO: mapping |= 0x20; break;
1094+
case libEDSsharp.PDOMappingType.optional: mapping |= 0x30; break;
1095+
}
1096+
10781097
if (od.PDOMapping)
10791098
{
10801099
flags |= mapping;

libEDSsharp/eds.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ public void ObjectTypeString(string objectType)
12741274
default:
12751275
case "VAR": this.objecttype = ObjectType.VAR; break;
12761276
case "ARRAY": this.objecttype = ObjectType.ARRAY; break;
1277+
case "REC":
12771278
case "RECORD": this.objecttype = ObjectType.REC; break;
12781279
}
12791280
}

0 commit comments

Comments
 (0)