diff --git a/EDSTest/DeviceODView.cs b/EDSTest/DeviceODView.cs index 5974bca1..8b70fe00 100644 --- a/EDSTest/DeviceODView.cs +++ b/EDSTest/DeviceODView.cs @@ -148,8 +148,9 @@ private void button_save_changes_Click(object sender, EventArgs e) selectedobject.defaultvalue = textBox_defaultvalue.Text; selectedobject.TPDODetectCos = checkBox_COS.Checked; - - + selectedobject.HighLimit = textBox_highvalue.Text; + selectedobject.LowLimit = textBox_lowvalue.Text; + selectedobject.actualvalue = textBox_actualvalue.Text; DataType dt = (DataType)Enum.Parse(typeof(DataType), comboBox_datatype.SelectedItem.ToString()); selectedobject.datatype = dt; diff --git a/EDSTest/Form1.cs b/EDSTest/Form1.cs index 8e4831be..3e7be798 100644 --- a/EDSTest/Form1.cs +++ b/EDSTest/Form1.cs @@ -932,12 +932,14 @@ private void documentationToolStripMenuItem_Click(object sender, EventArgs e) } string temp = dir + Path.DirectorySeparatorChar + "documentation.html"; + string temp2 = dir + Path.DirectorySeparatorChar + "documentation.md"; this.UseWaitCursor = true; DocumentationGen docgen = new DocumentationGen(); docgen.genhtmldoc(temp, dv.eds); - + docgen.genmddoc(temp2, dv.eds); + System.Diagnostics.Process.Start("file://" + temp2); if (IsRunningOnMono()) { System.Diagnostics.Process.Start("file://" + temp); diff --git a/libEDSsharp/Bridge.cs b/libEDSsharp/Bridge.cs index f4558b21..db8a6350 100644 --- a/libEDSsharp/Bridge.cs +++ b/libEDSsharp/Bridge.cs @@ -64,6 +64,8 @@ public Device convert(EDSsharp eds) coo.AccessType = od.accesstype.ToString(); coo.DataType = string.Format("0x{0:x2}", (int)od.datatype); coo.DefaultValue = od.defaultvalue; + coo.HighValue = od.HighLimit; + coo.LowValue = od.LowLimit; coo.PDOmapping = od.PDOtype.ToString(); coo.TPDOdetectCOS = od.TPDODetectCos.ToString().ToLower(); coo.AccessFunctionPreCode = od.AccessFunctionPreCode; @@ -85,10 +87,14 @@ public Device convert(EDSsharp eds) Xml2CSharp.CANopenSubObject sub = new Xml2CSharp.CANopenSubObject(); sub.Name = subod.parameter_name; + sub.Description = new Xml2CSharp.Description(); + sub.Description.Text = subod.Description; sub.ObjectType = subod.objecttype.ToString(); sub.AccessType = subod.accesstype.ToString(); sub.DataType = string.Format("0x{0:x2}", (int)subod.datatype); sub.DefaultValue = subod.defaultvalue; + sub.HighValue = subod.HighLimit; + sub.LowValue = subod.LowLimit; sub.PDOmapping = subod.PDOtype.ToString(); sub.SubIndex = String.Format("{0:x2}", subindex); sub.TPDOdetectCOS = subod.TPDODetectCos.ToString().ToLower(); @@ -317,6 +323,8 @@ public EDSsharp convert(Device dev) entry.objecttype = (ObjectType)Enum.Parse(typeof(ObjectType), coo.ObjectType); entry.defaultvalue = coo.DefaultValue; + entry.HighLimit = coo.HighValue; + entry.LowLimit = coo.LowValue; //entry.nosubindexes = Convert.ToInt16(coo.SubNumber); if (coo.PDOmapping != null) @@ -375,7 +383,12 @@ public EDSsharp convert(Device dev) subentry.datatype = (DataType)datatype; } + if (coosub.Description != null) + subentry.Description = coosub.Description.Text; //FIXME URL/LANG + subentry.defaultvalue = coosub.DefaultValue; + subentry.HighLimit = coosub.HighValue; + subentry.LowLimit = coosub.LowValue; byte subindex = Convert.ToByte(coosub.SubIndex, 16); diff --git a/libEDSsharp/CanOpenNodeExporter.cs b/libEDSsharp/CanOpenNodeExporter.cs index 84aecbe2..0811bc9f 100644 --- a/libEDSsharp/CanOpenNodeExporter.cs +++ b/libEDSsharp/CanOpenNodeExporter.cs @@ -381,10 +381,11 @@ private void export_h() StreamWriter file = new StreamWriter(folderpath + Path.DirectorySeparatorChar + "CO_OD.h"); - + file.WriteLine("// clang-format off"); addGPLheader(file); - file.WriteLine("#pragma once"); + file.WriteLine("#ifndef CO_OD_H_"); + file.WriteLine("#define CO_OD_H_"); file.WriteLine(""); file.WriteLine(@"/******************************************************************************* @@ -527,7 +528,7 @@ TYPE DEFINITIONS FOR RECORDS file.WriteLine(string.Format("/*{0:x4} */ typedef struct {{", kvp.Key)); foreach (KeyValuePair kvp2 in kvp.Value.subobjects) - { + { string paramaterarrlen = ""; ODentry subod = kvp2.Value; @@ -766,7 +767,8 @@ ALIASES FOR OBJECT DICTIONARY VARIABLES break; } } - + file.WriteLine("#endif"); + file.WriteLine("// clang-format on"); file.Close(); } @@ -775,6 +777,7 @@ private void export_c() { StreamWriter file = new StreamWriter(folderpath + Path.DirectorySeparatorChar + "CO_OD.c"); + file.WriteLine("// clang-format off"); addGPLheader(file); file.WriteLine(@"#include ""CO_driver.h"" @@ -840,6 +843,7 @@ OBJECT DICTIONARY file.Write(write_od()); file.WriteLine("};"); + file.WriteLine("// clang-format on"); file.Close(); } diff --git a/libEDSsharp/CanOpenXML.cs b/libEDSsharp/CanOpenXML.cs index 7796a730..454c9e4d 100644 --- a/libEDSsharp/CanOpenXML.cs +++ b/libEDSsharp/CanOpenXML.cs @@ -145,7 +145,11 @@ public class CANopenObject { public string PDOmapping { get; set; } [XmlAttribute(AttributeName="defaultValue")] public string DefaultValue { get; set; } - [XmlElement(ElementName="CANopenSubObject")] + [XmlAttribute(AttributeName = "highValue")] + public string HighValue { get; set; } + [XmlAttribute(AttributeName = "lowValue")] + public string LowValue { get; set; } + [XmlElement(ElementName="CANopenSubObject")] public List CANopenSubObject { get; set; } [XmlAttribute(AttributeName="subNumber")] public string SubNumber { get; set; } @@ -165,7 +169,9 @@ public class CANopenSubObject { public string SubIndex { get; set; } [XmlAttribute(AttributeName="name")] public string Name { get; set; } - [XmlAttribute(AttributeName="objectType")] + [XmlElement(ElementName = "description")] + public Description Description { get; set; } + [XmlAttribute(AttributeName="objectType")] public string ObjectType { get; set; } [XmlAttribute(AttributeName="dataType")] public string DataType { get; set; } @@ -175,6 +181,10 @@ public class CANopenSubObject { public string PDOmapping { get; set; } [XmlAttribute(AttributeName="defaultValue")] public string DefaultValue { get; set; } + [XmlAttribute(AttributeName = "highValue")] + public string HighValue { get; set; } + [XmlAttribute(AttributeName = "lowValue")] + public string LowValue { get; set; } [XmlAttribute(AttributeName = "TPDOdetectCOS")] public string TPDOdetectCOS { get; set; } } diff --git a/libEDSsharp/DocumentationGen.cs b/libEDSsharp/DocumentationGen.cs index c97a6972..d4282d90 100644 --- a/libEDSsharp/DocumentationGen.cs +++ b/libEDSsharp/DocumentationGen.cs @@ -35,7 +35,7 @@ public void genhtmldoc(string filepath, EDSsharp eds) file = new StreamWriter(filepath, false); - file.Write(""); + file.Write(""); file.Write(string.Format("

{0} Documentation

",eds.di.ProductName)); @@ -156,7 +156,234 @@ public void write2linetableheader(string a, object b) file.Write("{0}{1}",a,b.ToString()); } + public void genmddoc(string filepath, EDSsharp eds) + { + + file = new StreamWriter(filepath, false); + + file.WriteLine(); + file.WriteLine("# Device Information"); + file.WriteLine(); + + file.WriteLine("Product name"); + file.WriteLine($" ~ {eds.di.ProductName}"); + file.WriteLine(); + file.WriteLine("Product number"); + file.WriteLine($" ~ {eds.di.ProductNumber}"); + file.WriteLine(); + file.WriteLine("Revision number"); + file.WriteLine($" ~ {eds.di.RevisionNumber}"); + file.WriteLine(); + file.WriteLine("Vendor name"); + file.WriteLine($" ~ {eds.di.VendorName}"); + file.WriteLine(); + + + file.WriteLine($"Granularity: {eds.di.Granularity}"); + file.WriteLine(); + file.WriteLine("Supported Baudrates:"); + file.WriteLine(); + + file.WriteLine($"- [{(eds.di.BaudRate_1000 ? "x" : " ")}] 1000 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_800 ? "x" : " ")}] 800 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_500 ? "x" : " ")}] 500 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_250 ? "x" : " ")}] 250 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_125 ? "x" : " ")}] 125 kBit/s"); + //file.WriteLine($"- [{(true ? "x" : " ")}] 100 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_50 ? "x" : " ")}] 50 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_20 ? "x" : " ")}] 20 kBit/s"); + file.WriteLine($"- [{(eds.di.BaudRate_10 ? "x" : " ")}] 10 kBit/s"); + file.WriteLine(); + + file.WriteLine("# PDO Mapping"); + file.WriteLine(); + + PrintPdo(0x1600, 0x1800, "RPDO", eds); + PrintPdo(0x1a00, 0x1c00, "TPDO", eds); + + file.WriteLine("# Mandatory objects"); + file.WriteLine(); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.Disabled == true) + continue; + + if (od.Index == 0x1000 || od.Index == 0x1001 || od.Index == 0x1018) + { + writeODentrymd(od); + } + } + + file.WriteLine("# Optional objects"); + file.WriteLine(); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.Disabled == true) + continue; + + if ((od.Index > 0x1001 && od.Index != 0x1018 && od.Index < 0x2000) || od.Index >= 0x6000) + { + writeODentrymd(od); + } + } + + file.WriteLine("# Manufacturer specific objects"); + file.WriteLine(); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.Disabled == true) + continue; + if (od.Index >= 0x2000 && od.Index < 0x6000) + { + writeODentrymd(od); + } + } + + file.Close(); + } + + public void writeODentrymd(ODentry od) + { + if (od.parent == null) + { + file.WriteLine(String.Format("## 0x{0:x4} - {1}", od.Index, od.parameter_name)); + } + else + { + file.WriteLine(String.Format("### 0x{0:x4} sub 0x{2:x2} - {1}", od.Index, od.parameter_name, od.Subindex)); + } + file.WriteLine(); + + write2linetableheadermd("Paramater", "Value"); + + ObjectType ot = od.objecttype; + if (ot == ObjectType.UNKNOWN && od.parent != null) + ot = od.parent.objecttype; + + write2linetablerowmd("Object Type", ot.ToString()); + + DataType dt = od.datatype; + if (dt == DataType.UNKNOWN && od.parent != null) + dt = od.parent.datatype; + + write2linetablerowmd("Data Type", dt.ToString()); + write2linetablerowmd("Default Value", od.defaultvalue); + if (!String.IsNullOrEmpty(od.HighLimit)) + write2linetablerowmd("High Value", od.HighLimit); + if (!String.IsNullOrEmpty(od.LowLimit)) + write2linetablerowmd("Low Value", od.LowLimit); + + write2linetablerowmd("Location", od.StorageLocation); + write2linetablerowmd("Access type", od.accesstype.ToString()); + write2linetablerowmd("PDO mapping", od.PDOMapping); + if (od.parent == null) + write2linetablerowmd("No Sub index", od.Nosubindexes); + + + file.WriteLine(); + + string description = od.Description; + file.WriteLine($"{description}"); + + file.WriteLine(); + + foreach (KeyValuePair sub in od.subobjects) + { + ODentry subod = sub.Value; + writeODentrymd(subod); + } + + if (od.parent == null) + { + file.WriteLine("---------------"); + file.WriteLine(); + } + } + + private void PrintPdo(ushort start, ushort end, string caption, EDSsharp eds) + { + file.WriteLine("## {0}", caption); + file.WriteLine(); + foreach (var kvp in eds.ods) + { + ODentry od = kvp.Value; + int index = kvp.Key; + + if (od.Disabled) + continue; + + if (od.Index >= start && od.Index < end) + { + file.WriteLine(string.Format("### {0} {1:x4}", caption, od.Index)); + file.WriteLine(); + byte current_bit = 0; + foreach (var kvp2 in od.subobjects) + { + ODentry odsub = kvp2.Value; + ushort subindex = kvp2.Key; + + if (subindex == 0) + continue; + + var data = Convert.ToUInt32(odsub.defaultvalue, EDSsharp.Getbase(odsub.defaultvalue)); + + if (data != 0) + { + byte datasize = (byte)(data & 0x000000FF); + ushort pdoindex = (ushort)((data >> 16) & 0x0000FFFF); + byte pdosub = (byte)((data >> 8) & 0x000000FF); + + file.Write($"* Byte{current_bit / 8}: "); + + if (eds.ods.ContainsKey(pdoindex) && (pdosub == 0 || eds.ods[pdoindex].Containssubindex(pdosub))) + { + ODentry maptarget; + if (pdosub == 0) + maptarget = eds.ods[pdoindex]; + else + maptarget = eds.ods[pdoindex].Getsubobject(pdosub); + + if (!maptarget.Disabled && datasize == (8 * maptarget.Sizeofdatatype())) + { + if (maptarget.parent == null) + file.Write(string.Format("[0x{0:x4} - {1}]", maptarget.Index, maptarget.parameter_name)); + else + file.Write(string.Format("[0x{0:x4} sub 0x{1:x2} - {2}]", maptarget.Index, maptarget.Subindex, maptarget.parameter_name)); + } + } + file.WriteLine(); + var by = (datasize / 8); + for (int i = 1; i < by; ++i) + file.WriteLine($"* Byte{current_bit / 8 + i}: -\"-"); + current_bit += datasize; + } + } + for (int i = (current_bit / 8); i < 8; ++i) + file.WriteLine($"* Byte{i}: empty"); + file.WriteLine(); + } + } + } + + public void write2linetablerowmd(string a, object b) + { + if (b == null) + b = ""; + file.WriteLine($"| {a} | {b.ToString()} |"); + } + + public void write2linetableheadermd(string a, object b) + { + write2linetablerowmd(a, b); + file.WriteLine("|:------|:-----|"); + } } } diff --git a/libEDSsharp/NetworkPDOreport.cs b/libEDSsharp/NetworkPDOreport.cs index 691e3bc9..e4488cca 100644 --- a/libEDSsharp/NetworkPDOreport.cs +++ b/libEDSsharp/NetworkPDOreport.cs @@ -33,7 +33,7 @@ public void gennetpdodoc(string filepath, List network) file = new StreamWriter(filepath, false); - file.Write(" Network PDO report"); + file.Write(" Network PDO report"); file.Write(string.Format("

PDO Network Documentation

"));