Skip to content

Commit

Permalink
Adding some missing comments (CANopenNode#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrof authored Mar 30, 2024
1 parent 10c759a commit 0c3f6ae
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 60 deletions.
15 changes: 13 additions & 2 deletions libEDSsharp/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ You should have received a copy of the GNU General Public License

namespace libEDSsharp
{
/// <summary>
/// Converts between CanOpenXML and EDSsharp
/// </summary>
public class Bridge
{


/// <summary>
/// Convert from EDSsharp to CanOpenXML
/// </summary>
/// <param name="eds">the eds data</param>
/// <returns>CanOpenXML device containing data from eds</returns>
public Device convert(EDSsharp eds)
{
eds.UpdatePDOcount();
Expand Down Expand Up @@ -269,6 +275,11 @@ public Xml2CSharp.Characteristic makecharcteristic(string name, string content)
return cl;
}

/// <summary>
/// Convert from CanOpenXML to EDSsharp
/// </summary>
/// <param name="dev">CanOpenXML device</param>
/// <returns>EDSsharp object containing data from dev</returns>
public EDSsharp convert(Device dev)
{
EDSsharp eds = new EDSsharp();
Expand Down
11 changes: 9 additions & 2 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ based heavily on the files CO_OD.h and CO_OD.c from CANopenNode which are

namespace libEDSsharp
{

/// <summary>
/// Export .c and .h files for CanOpenNode v1-3
/// </summary>
public class CanOpenNodeExporter : IExporter
{

Expand Down Expand Up @@ -1347,7 +1349,12 @@ public static string GetValue()

return method.Invoke(null, null) as string;
}

/// <summary>
/// Generates a valid C language variable name using input
/// </summary>
/// <param name="name">base name that will be used to make a variable name</param>
/// <param name="entry">the OD entry for the variable</param>
/// <returns></returns>
protected string make_cname(string name,ODentry entry)
{
if (name == null)
Expand Down
18 changes: 9 additions & 9 deletions libEDSsharp/CanOpenNodeExporter_V4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void export(string folderpath, string filename, string gitVersion, EDSsha
/// <summary>
/// Generate ODStorage, ODObjs, ODList, ODDefines and ODCnt entries
/// </summary>
/// <param name="ods"></param>
/// <param name="eds">EDS object</param>
private void Prepare(EDSsharp eds)
{
ODStorageGroups = new List<string>();
Expand Down Expand Up @@ -380,11 +380,10 @@ private int Prepare_rec(ODentry od, string indexH, string varName, string group)
/// <summary>
/// Export the header file
/// </summary>
/// <param name="folderpath"></param>
/// <param name="filename"></param>
/// <param name="gitVersion"></param>
/// <param name="fi"></param>
/// <param name="di"></param>
/// <param name="folderpath">path to folder that will contain the file</param>
/// <param name="filename">filename</param>
/// <param name="gitVersion">git version that will be added to file comment</param>
/// <param name="eds">data that contain the data that will be exported</param>
private void Export_h(string folderpath, string filename, string gitVersion, EDSsharp eds)
{

Expand Down Expand Up @@ -558,9 +557,10 @@ OD config structure
/// <summary>
/// Export the c file
/// </summary>
/// <param name="folderpath"></param>
/// <param name="filename"></param>
/// <param name="gitVersion"></param>
/// <param name="folderpath">path to folder that will contain the file</param>
/// <param name="filename">filename</param>
/// <param name="gitVersion">git version that will be added to file comment</param>
/// <param name="eds">data that contain the data that will be exported</param>
private void Export_c(string folderpath, string filename, string gitVersion, EDSsharp eds)
{

Expand Down
61 changes: 48 additions & 13 deletions libEDSsharp/DocumentationGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ You should have received a copy of the GNU General Public License

namespace libEDSsharp
{
/// <summary>
/// Documentation generator
/// </summary>
public class DocumentationGen
{
StreamWriter file = null;

/// <summary>
/// Generate html documentation
/// </summary>
/// <param name="filepath">where the documentation should be saved</param>
/// <param name="eds">data to generate the documentation from</param>
public void genhtmldoc(string filepath, EDSsharp eds)
{

Expand Down Expand Up @@ -96,8 +104,11 @@ public void genhtmldoc(string filepath, EDSsharp eds)


}

public void writeODentryhtml(ODentry od)
/// <summary>
/// Write a object dictionary html entry to file
/// </summary>
/// <param name="od">Object dictionary entry</param>
void writeODentryhtml(ODentry od)
{
if (od.parent == null)
{
Expand Down Expand Up @@ -142,19 +153,32 @@ public void writeODentryhtml(ODentry od)
}

}

public void write2linetablerow(string a,object b)
/// <summary>
/// Write a html table row with 2 elements to file
/// </summary>
/// <param name="a">element a</param>
/// <param name="b">element b</param>
void write2linetablerow(string a,object b)
{
if (b == null)
b = "";
file.Write("<tr><td>{0}</td><td>{1}</td></tr>", a, b.ToString());
}

public void write2linetableheader(string a, object b)
/// <summary>
/// Write a html table header with 2 elements to file
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
void write2linetableheader(string a, object b)
{
file.Write("<tr><th>{0}</th><th>{1}</th></tr>",a,b.ToString());
}

/// <summary>
/// Generate markup documentation
/// </summary>
/// <param name="filepath">where the documentation should be created</param>
/// <param name="eds">data to generate the documentation from</param>
/// <param name="gitVersion">git version of this software</param>
public void genmddoc(string filepath, EDSsharp eds, string gitVersion)
{
file = new StreamWriter(filepath, false);
Expand Down Expand Up @@ -253,8 +277,12 @@ Device Information

file.Close();
}

private void PrintPdoMd(EDSsharp eds, bool skipDisabled = false)
/// <summary>
/// Write a all PDO information in markup
/// </summary>
/// <param name="eds">data containing the information</param>
/// <param name="skipDisabled">skip disabled PDOs</param>
void PrintPdoMd(EDSsharp eds, bool skipDisabled = false)
{
var parameters = new SortedDictionary<UInt16, ODentry>();
var mappings = new SortedDictionary<UInt16, ODentry>();
Expand Down Expand Up @@ -361,8 +389,11 @@ private void PrintPdoMd(EDSsharp eds, bool skipDisabled = false)
file.WriteLine();
}
}

private void PrintODentryMd(ODentry od)
/// <summary>
/// Write a object dictionary markup entry to file
/// </summary>
/// <param name="od">Object dictionary entry</param>
void PrintODentryMd(ODentry od)
{
var descriptions = new List<string>();

Expand Down Expand Up @@ -410,8 +441,12 @@ private void PrintODentryMd(ODentry od)
file.WriteLine(string.Join("\n", descriptions));
}
}

private string PrintDataType(ODentry od)
/// <summary>
/// Returns the datatype of a object dictionary
/// </summary>
/// <param name="od">the object dictionary entry</param>
/// <returns>datatype of the OD entry</returns>
string PrintDataType(ODentry od)
{
string dt = od.datatype.ToString();
if ((od.datatype == DataType.VISIBLE_STRING || od.datatype == DataType.UNICODE_STRING)
Expand Down
17 changes: 17 additions & 0 deletions libEDSsharp/ExporterFactory.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@

namespace libEDSsharp
{
/// <summary>
/// Factory for making different canopennode exporter
/// </summary>
public static class ExporterFactory
{
/// <summary>
/// CanOpenNode exporter types
/// </summary>
public enum Exporter
{
/// <summary>
/// CanOpenNode exporter v4 (latest)
/// </summary>
CANOPENNODE_V4 = 0,
/// <summary>
/// CanOpenNode exporter for v1-3 (legacy)
/// </summary>
CANOPENNODE_LEGACY = 1
}

/// <summary>
/// Returns exporter based on ex parameter
/// </summary>
/// <param name="ex">what exporter version you want. Default is CANOPENNODE_LEGACY</param>
/// <returns>A exporter</returns>
public static IExporter getExporter(Exporter ex = Exporter.CANOPENNODE_LEGACY)
{
IExporter exporter;
Expand Down
11 changes: 11 additions & 0 deletions libEDSsharp/IExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@

namespace libEDSsharp
{
/// <summary>
/// Interface for exporting CanOpenNode OD files
/// </summary>
public interface IExporter
{
/// <summary>
/// Export file(s)
/// </summary>
/// <param name="folderpath">Path to the folder that will contain the new files</param>
/// <param name="filename">base filename for the new files</param>
/// <param name="gitVersion">version that will be saved to the file</param>
/// <param name="eds">The eds that will be exported</param>
/// <param name="odname">The object dictionary name</param>
void export(string folderpath, string filename, string gitVersion, EDSsharp eds , string odname="OD");
}
}
23 changes: 19 additions & 4 deletions libEDSsharp/NetworkPDOreport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ You should have received a copy of the GNU General Public License

namespace libEDSsharp
{
/// <summary>
/// Generate a PDO network report
/// </summary>
public class NetworkPDOreport
{

StreamWriter file = null;

/// <summary>
/// Generate a PDO network report
/// </summary>
/// <param name="filepath">where the doc should be saved</param>
/// <param name="network">Data from the different nodes in the network</param>
public void gennetpdodoc(string filepath, List<EDSsharp> network)
{

Expand Down Expand Up @@ -320,15 +327,23 @@ public void gennetpdodoc(string filepath, List<EDSsharp> network)

}


/// <summary>
/// Write a html table row with 2 elements to file
/// </summary>
/// <param name="a">element a</param>
/// <param name="b">element b</param>
public void write2linetablerow(string a, object b)
{
if (b == null)
b = "";
file.Write("<tr><td>{0}</td><td>{1}</td></tr>", a, b.ToString());
}

public void write2linetableheader(string a, object b)
/// <summary>
/// Write a html table header with 2 elements to file
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
void write2linetableheader(string a, object b)
{
file.Write("<tr><th>{0}</th><th>{1}</th></tr>", a, b.ToString());
}
Expand Down
Loading

0 comments on commit 0c3f6ae

Please sign in to comment.