-
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
Changes from all commits
e4bf2ff
6f93f4e
ec3b63a
b4f6e3c
0e0c08b
586e2a1
1bccfda
1680130
0ee3492
37a3686
d583899
4fa871f
a8d9ec9
ab69d07
3e69fe1
bf1a956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,10 @@ public void Write(StreamWriter writer, Filetype ft) | |
| { | ||
| writer.WriteLine(string.Format("{2}{0}={1}", f.Name, ((bool)f.GetValue(this)) == true ? 1 : 0, comment == true ? ";" : "")); | ||
| } | ||
| else if (f.FieldType.Name == "UInt32") | ||
| { | ||
| writer.WriteLine(string.Format("{2}{0}={1}", f.Name, string.Format("0x{0:x8}", f.GetValue(this)), comment == true ? ";" : "")); | ||
| } | ||
| else | ||
| { | ||
| writer.WriteLine(string.Format("{2}{0}={1}", f.Name, f.GetValue(this).ToString(), comment == true ? ";" : "")); | ||
|
|
@@ -1020,6 +1024,27 @@ void ApplycompactPDO(UInt16 index) | |
| } | ||
| } | ||
| } | ||
| public static UInt32 U32Parse(string str) | ||
| { | ||
| if (str[0] == '0') | ||
| { | ||
| if (str[1] == 'x' || str[1] == 'X') | ||
| { | ||
| // Hex format | ||
| return System.Convert.ToUInt32(str, 16); | ||
| } | ||
| else | ||
| { | ||
| // Octal format | ||
| return System.Convert.ToUInt32(str, 8); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // Decimal format | ||
| return System.Convert.ToUInt32(str); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This function scans the PDO list and compares it to NrOfRXPDO and NrOfTXPDO | ||
|
|
@@ -1059,7 +1084,38 @@ protected void ApplyimplicitPDO() | |
| } | ||
| UpdatePDOcount(); | ||
| } | ||
|
|
||
| private void GetEDSFileInfo() | ||
| { | ||
| string[] nums = fi.fileVersionString.Split('.'); | ||
| if (nums.Length == 2) | ||
| { | ||
| if (byte.TryParse(nums[0], out fi.FileVersion) == false) | ||
| { | ||
| fi.FileVersion = 1; | ||
| Warnings.warning_list.Add("EDS FileVersion cannot be extracted from string \"" + nums[0] +"\", set to 1"); | ||
| } | ||
| if (byte.TryParse(nums[1], out fi.FileRevision) == false) | ||
| { | ||
| fi.FileRevision = 0; | ||
| Warnings.warning_list.Add("EDS FileRevision cannot be extracted from string \"" + nums[1] + "\", set to 0"); | ||
| } | ||
| } | ||
| else if (nums.Length == 1) | ||
| { | ||
| if (byte.TryParse(nums[0], out fi.FileVersion) == false) | ||
| { | ||
| fi.FileVersion = 1; | ||
| Warnings.warning_list.Add("EDS FileVersion cannot be extracted from string \"" + nums[0] + "\", set to 1"); | ||
| } | ||
| fi.FileRevision = 0; | ||
| } | ||
| else | ||
| { | ||
| fi.FileVersion = 1; | ||
| fi.FileRevision = 0; | ||
| Warnings.warning_list.Add("EDS FileVersion and FileRevision cannot be extracted from string \"" + fi.fileVersionString + "\", set to 1.0"); | ||
| } | ||
| } | ||
| public void Savefile(string filename, InfoSection.Filetype ft) | ||
| { | ||
| if (ft == InfoSection.Filetype.File_EDS) | ||
|
|
@@ -1087,6 +1143,8 @@ public void Savefile(string filename, InfoSection.Filetype ft) | |
| fi.EDSVersionMajor = 4; | ||
| fi.EDSVersionMinor = 0; | ||
|
|
||
| GetEDSFileInfo(); | ||
|
|
||
| StreamWriter writer = System.IO.File.CreateText(filename); | ||
| writer.NewLine = "\n"; | ||
| fi.Write(writer, ft); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,7 +506,7 @@ CANopen DATA TYPES | |
| file.WriteLine("/*******************************************************************************"); | ||
| file.WriteLine(" FILE INFO:"); | ||
| file.WriteLine(string.Format(" FileName: {0}", Path.GetFileName(eds.projectFilename))); | ||
| file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.FileVersion)); | ||
| file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.fileVersionString)); | ||
| file.WriteLine(string.Format(" CreationTime: {0}", eds.fi.CreationTime)); | ||
| file.WriteLine(string.Format(" CreationDate: {0}", eds.fi.CreationDate)); | ||
| file.WriteLine(string.Format(" CreatedBy: {0}", eds.fi.CreatedBy)); | ||
|
|
@@ -517,9 +517,9 @@ CANopen DATA TYPES | |
| file.WriteLine("/*******************************************************************************"); | ||
| file.WriteLine(" DEVICE INFO:"); | ||
| file.WriteLine(string.Format(" VendorName: {0}", eds.di.VendorName)); | ||
| file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber)); | ||
| 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())); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why change to hex?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vendor ID & Product ID are usually written in Hex form |
||
| file.WriteLine("*******************************************************************************/"); | ||
| file.WriteLine(""); | ||
| file.WriteLine(""); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,7 +240,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds) | |
| device.DeviceIdentity.vendorName.readOnly = true; | ||
|
|
||
| device.DeviceIdentity.vendorID = new vendorID(); | ||
| device.DeviceIdentity.vendorID.Value = eds.di.VendorNumber; | ||
| device.DeviceIdentity.vendorID.Value = eds.di.VendorNumber.ToHexString(); | ||
| device.DeviceIdentity.vendorID.readOnly = true; | ||
|
|
||
| device.DeviceIdentity.deviceFamily = new deviceFamily(); | ||
|
|
@@ -263,7 +263,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds) | |
|
|
||
| device.supportedLanguages = "en"; | ||
|
|
||
| device.fileVersion = eds.fi.FileVersion; | ||
| device.fileVersion = eds.fi.FileVersion.ToString(); | ||
|
|
||
| device.fileName = Path.GetFileName(eds.projectFilename); | ||
|
|
||
|
|
@@ -277,7 +277,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds) | |
| device.DeviceIdentity.productName.readOnly = true; | ||
|
|
||
| device.DeviceIdentity.productID = new productID(); | ||
| device.DeviceIdentity.productID.Value = eds.di.ProductNumber; | ||
| device.DeviceIdentity.productID.Value = eds.di.ProductNumber.ToHexString(); | ||
| device.DeviceIdentity.productID.readOnly = true; | ||
|
|
||
| device.DeviceIdentity.productText = new productText(); | ||
|
|
@@ -401,7 +401,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds) | |
| comnet.fileModificationTime = eds.fi.ModificationDateTime; | ||
| comnet.fileModificationDateSpecified = true; | ||
|
|
||
| comnet.fileVersion = eds.fi.FileVersion; | ||
| comnet.fileVersion = eds.fi.FileVersion.ToString(); | ||
|
|
||
| comnet.supportedLanguages = "en"; | ||
|
|
||
|
|
@@ -1157,9 +1157,10 @@ public EDSsharp convert(ISO15745ProfileContainer container) | |
| if (obj.DeviceIdentity != null) | ||
| { | ||
| eds.di.ProductName = obj.DeviceIdentity.productName.Value; | ||
| eds.di.ProductNumber = obj.DeviceIdentity.productID.Value; | ||
| eds.di.ProductNumber = UInt32.Parse(obj.DeviceIdentity.productID.Value); | ||
| eds.di.VendorName = obj.DeviceIdentity.vendorName.Value; | ||
| eds.di.VendorNumber = obj.DeviceIdentity.vendorID.Value; | ||
| eds.di.VendorNumber = UInt32.Parse(obj.DeviceIdentity.vendorID.Value); | ||
|
|
||
|
|
||
| foreach (object o in obj.DeviceIdentity.productText.Items) | ||
| { | ||
|
|
@@ -1184,12 +1185,19 @@ public EDSsharp convert(ISO15745ProfileContainer container) | |
| eds.fi.EDSVersion = keyvalue[1]; | ||
| break; | ||
| case "FileRevision": | ||
| eds.fi.FileVersion = keyvalue[1]; | ||
| if (byte.TryParse(keyvalue[1], out eds.fi.FileVersion) == false) | ||
| { | ||
| eds.fi.FileVersion = 0; | ||
| Warnings.warning_list.Add("XDD FileRevision value \"" + keyvalue[1] + "\" cannot be parsed!"); | ||
| } | ||
| break; | ||
| case "RevisionNum": | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| byte.TryParse(keyvalue[1], out eds.fi.FileRevision); break; | ||
|
|
||
|
|
||
| if (byte.TryParse(keyvalue[1], out eds.fi.FileRevision) == false) | ||
| { | ||
| eds.fi.FileRevision = 0; | ||
| Warnings.warning_list.Add("XDD RevisionNum value \"" + keyvalue[1] + "\" cannot be parsed!"); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||

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.