Skip to content

Commit

Permalink
Fix #23
Browse files Browse the repository at this point in the history
Looks like reserved keywords can be used in enums if you prefix with @

This *may* introduce a regression if any of the old files got saved with the "cons" nasty workaround. Going onwards this is now a thing of the past
  • Loading branch information
robincornelius committed Dec 4, 2016
1 parent ee64f26 commit c649d37
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions EDSTest/Profiles/DS301_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ bit 31: set to 0</description>
<CANopenObject index="1007" name="Synchronous window length" objectType="VAR" memoryType="ROM" dataType="0x07" accessType="rw" PDOmapping="no" defaultValue="0" subNumber="0" disabled="false" TPDOdetectCOS="false">
<description>bit 0-31: window leghth after SYNC when PDOS must be transmited in µs, (0 = not used)</description>
</CANopenObject>
<CANopenObject index="1008" name="Manufacturer device name" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="cons" PDOmapping="no" defaultValue="CANopenNode" subNumber="0" disabled="false" TPDOdetectCOS="false">
<CANopenObject index="1008" name="Manufacturer device name" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="const" PDOmapping="no" defaultValue="CANopenNode" subNumber="0" disabled="false" TPDOdetectCOS="false">
<description>Name of the manufacturer as string</description>
</CANopenObject>
<CANopenObject index="1009" name="Manufacturer hardware version" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="cons" PDOmapping="no" defaultValue="3.00" subNumber="0" disabled="false" TPDOdetectCOS="false">
<CANopenObject index="1009" name="Manufacturer hardware version" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="const" PDOmapping="no" defaultValue="3.00" subNumber="0" disabled="false" TPDOdetectCOS="false">
<description>Name of the hardware version as string</description>
</CANopenObject>
<CANopenObject index="100a" name="Manufacturer software version" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="cons" PDOmapping="no" defaultValue="3.00" subNumber="0" disabled="false" TPDOdetectCOS="false">
<CANopenObject index="100a" name="Manufacturer software version" objectType="VAR" memoryType="ROM" dataType="0x09" accessType="const" PDOmapping="no" defaultValue="3.00" subNumber="0" disabled="false" TPDOdetectCOS="false">
<description>Name of the software version as string.</description>
</CANopenObject>
<CANopenObject index="100c" name="Guard Time" objectType="VAR" memoryType="ROM" dataType="0x06" accessType="ro" PDOmapping="no" defaultValue="" subNumber="0" accessFunctionName="" disabled="false" TPDOdetectCOS="false">
Expand Down
3 changes: 0 additions & 3 deletions libEDSsharp/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ public EDSsharp convert(Device dev)
if (coo.AccessType != null)
{
string at = coo.AccessType;

//Nasty work around so we can use Enum types
at = at.Replace("const", "cons");
entry.accesstype = (EDSsharp.AccessType)Enum.Parse(typeof(EDSsharp.AccessType), at);
}

Expand Down
2 changes: 1 addition & 1 deletion libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ byte getflags(ODentry od)
//fixme rwr and rrw are not supported
if (od.accesstype == EDSsharp.AccessType.ro
|| od.accesstype == EDSsharp.AccessType.rw
|| od.accesstype == EDSsharp.AccessType.cons)
|| od.accesstype == EDSsharp.AccessType.@const)
flags |= 0x04;

if (od.accesstype == EDSsharp.AccessType.wo
Expand Down
6 changes: 2 additions & 4 deletions libEDSsharp/eds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,12 @@ public enum AccessType
wo = 2,
rwr = 3,
rww = 4,
cons = 5,
@const = 5,
UNKNOWN
}

public const AccessType AccessType_Min = AccessType.rw;
public const AccessType AccessType_Max = AccessType.cons;
public const AccessType AccessType_Max = AccessType.@const;


//This is the last file name used for this eds/xml file and is not
Expand Down Expand Up @@ -1124,8 +1124,6 @@ public void parseEDSentry(KeyValuePair<string, Dictionary<string, string>> kvp)

string accesstype = kvp.Value["AccessType"];

// fudging because of enum enumeration and the const keyword
accesstype = accesstype.Replace("const", "cons");
if (Enum.IsDefined(typeof(AccessType), accesstype))
{
od.accesstype = (AccessType)Enum.Parse(typeof(AccessType), accesstype);
Expand Down

0 comments on commit c649d37

Please sign in to comment.