-
Notifications
You must be signed in to change notification settings - Fork 83
Revision number #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Revision number #196
Conversation
1f9af8d to
0e0c08b
Compare
|
I've stumbled on an issue related to EDS<->XDD conversion. CANOpenEditor seems to use an internal representation of the device profile based on the EDS format (EDSsharp class). When trying to add support for the FileRevision field of the EDS file, I noticed that this is not specified in the XDD format. Instead, if my understanding is correct, the XDD format includes just a "fileVersion" string field with "Vendor specific version of the file", i.e. no fixed format/pattern. So oconverting between that and the FilerVersion/FileRevision Unsigned8 fields of the EDS specification is not trivial and may not even be possible. We could try to use a FileVersion.FileRevision format for the XDD fileVersion. However, my first concern is how to store internal the fileVersion read from a XDD file WITHOUT CONVERTING IT so that an arbitary vendor string can be preserved when saving the XDD again. Is it OK to add / remove fields in the EDSsharp class in a way that breaks 1:1 relation with EDS fields? My preference would be to have a fileVersion string in EDSsharp class and only attempts to convert to/from numeric FileVersion / FileRevision fileds when reading or writing a EDS file. Is that OK with the project's style? @CANopenNode |
df81554 to
1bccfda
Compare
c599c9e to
37a3686
Compare
I have implemented my suggestion for now, i.e. the file version is read from XDD and stored internally as string and only attempted to be converted to FileVersion.FileRevision when writing an EDS file |
|
The first 2 goals of the MR are done - pending testing / review from someone else too. For the other 2 goals I have decided to implement them separately, after aligning with the project's core members. |
Review will start as soon as a reviewer is available without needing to do anything no worries (give it a week). |
nimrof
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a partial review, there is a loot to check and a few questions
libEDSsharp/CanOpenXDD.cs
Outdated
| break; | ||
| case "FileRevision": | ||
| eds.fi.FileVersion = keyvalue[1]; | ||
| byte.TryParse(keyvalue[1], out eds.fi.FileVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silently ignoring failed parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I thought about this but saw that TryParse() is already used in many places without checking the return value. I agree handling the error is better, I have updated the code to do that.
libEDSsharp/CanOpenXDD.cs
Outdated
| byte.TryParse(keyvalue[1], out eds.fi.FileVersion); | ||
| break; | ||
| case "RevisionNumber": | ||
| byte.TryParse(keyvalue[1], out eds.fi.FileRevision); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silently ignoring failed parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the code to handle parsing failure.
| case "RevisionNumber": | ||
| byte.TryParse(keyvalue[1], out eds.fi.FileRevision); | ||
| break; | ||
| case "RevisionNum": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was replaced with "RevisionNumber" by mistake, at the time I did not realise that the vendorTextDescription is a separate way to set the device identity fields.
| file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber.ToHexString())); | ||
| file.WriteLine(string.Format(" ProductName: {0}", eds.di.ProductName)); | ||
| file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber)); | ||
| file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber.ToHexString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change to hex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vendor ID & Product ID are usually written in Hex form
libEDSsharp/CanOpenEDS.cs
Outdated
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using System.Security.Cryptography; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I think I added when testing something but forgot to remove it afterwards.
| eds.di.VendorName = textBox_vendorname.Text; | ||
| eds.di.VendorNumber = textBox_vendornumber.Text; | ||
| eds.di.VendorNumber = EDSsharp.U32Parse(textBox_vendornumber.Text); | ||
| eds.di.RevisionNumber = EDSsharp.U32Parse(textBox_revisionnumber.Text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, what is the reason that some are hex and some are not?
For instance i would imagine revision would be non-hex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is so that we don't have to use one format and potentially make the code incompatible with some files. I have not found clear info about the format of each field so I opted to make the code more flexible.
The revision number actually consists of 2 16-bit values, see definition of 0x1018.3 in CiA 301. So having it in Hex is more natural to easily split the 2 values.
| } | ||
| else | ||
| { | ||
| return System.Convert.ToUInt32(str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, though I think octal is not supported in general in the project. In any case, I've updated the function to also support Octal format.
|
There is quite a lot of changes. I didn't go into the details. However, changing CanOpen.proto is always very delicate. Vendor ID and others are already in object 1018, which is mandatory anyway. Core database should not become inconsistent. |
|
In the current state of the program it is hard to add "simple things". My current goal is more ambitious, as described here: #190 (comment) |
Indeed I needed to update quite a few different parts of the code for this to work, but I believe it's in good shape now. We have already been using the updated version in our project. |
The code may not be perfect but it works and this updates also seems to work, i.e. the new feature is operational and nothing seems broken. |
I don't agree changing CanOpen.proto file at this time. Methods can be used to extract information from 1018 object. Standards should be complied by the exporters, but core database must not be messy. Information must not duplicate. I didn't check other parts of this PR. |
Although I don't think it's really messy, I can revert the CanOpen.proto changes, as they are not really needed for the feature to work - I had not mapped the new fields until my latest update a few minutes before. Still, It makes more sense to me to use the DeviceInfo / DeviceIdentity structure as the ground truth for the 0x1018 fields and not vice versa. |
Better to handle imported messy eds file than to export it by default. |
OK, but this was an existing problem for other fields (ProductID, VendorID), I did not introduce it here. I only added the revision number in the same way. I have noted in the description of this PR that linking the DeviceInfo / DeviceIdentity fields with the respective object values is the next step, which will resolve the mess you refer to. But it seems too much to do everything in a single PR, you already said the changes here are a lot. |
|
It seems, we have a different taste for some, according to my opinion, minor thing. It is just a taste. As I said, I have serious plans to work on CANopenEditor. First step will be a core, which will handle a protobuffer based database. Probably there will be a method, which will get/set device information data. And that method will be responsible, how it will access specific field. At this point details doesn't really matter. I'm just very conservative about CanOpen.proto file. |
Maybe I don't have the same view of the project's current state. I find it a very useful tool but at the same time it has some limitations which I am interested to work on. As a first step I want to add the "small" (from the user's PoV) feature of including the RevisionNumber, and I think I have achieved that without making the code quality worse, it's just that the overall organisation and "quality" of the project could be improved from before I started working on it - and that's OK for a non-profit open-source project. Yesterday I reverted the changes in CanOpen.proto without affecting the feature's operation, so there's no reason to worry about that now. |

This addresses the following issues:
The following topics will be implemented in a separate MR:
Initial work done by @temi54c1l8 in #113
Resolves #154 and #155 (partially)