Skip to content

Commit

Permalink
More xml comments (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrof authored Apr 1, 2024
1 parent 01b5180 commit 1d123ec
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 49 deletions.
51 changes: 40 additions & 11 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class CanOpenNodeExporter : IExporter

private string folderpath;
private string gitVersion;
/// <summary>
/// The eds file set when calling export
/// </summary>
protected EDSsharp eds;

private int enabledcount = 0;
Expand All @@ -55,7 +58,9 @@ public class CanOpenNodeExporter : IExporter
ODentry maxRXmappingsOD=null;
ODentry maxTXmappingsOD=null;


/// <summary>
/// Register names of index and subindex that need to have standard names to be able to work with CanOpenNode
/// </summary>
public void prepareCanOpenNames()
{
acceptable_canopen_names.Add(0x101800, "identity");
Expand Down Expand Up @@ -86,7 +91,14 @@ public void prepareCanOpenNames()

}


/// <summary>
/// Export eds into CanOpenNode v1-3 source files (.h and .c)
/// </summary>
/// <param name="folderpath">folder path to save the files into</param>
/// <param name="filename">base filename, .c and .h will be added to this</param>
/// <param name="gitVersion">git version of this software</param>
/// <param name="eds">the eds data to be exported</param>
/// <param name="odname">object dictionary name</param>
public void export(string folderpath, string filename, string gitVersion, EDSsharp eds,string odname)
{
this.folderpath = folderpath;
Expand All @@ -110,13 +122,14 @@ public void export(string folderpath, string filename, string gitVersion, EDSsha

}

/// <summary>
/// Fixes TPDO compatibility subindex
/// </summary>
/// Handle the TPDO communication parameters in a special way, because of
/// sizeof(OD_TPDOCommunicationParameter_t) != sizeof(CO_TPDOCommPar_t) in CANopen.c
/// the existing CO_TPDOCommPar_t has a compatibility entry so we must export one regardless of if its in the OD or not
private void fixcompatentry()
{
// Handle the TPDO communication parameters in a special way, because of
// sizeof(OD_TPDOCommunicationParameter_t) != sizeof(CO_TPDOCommPar_t) in CANopen.c
// the existing CO_TPDOCommPar_t has a compatibility entry so we must export one regardless
// of if its in the OD or not

for (UInt16 idx = 0x1800; idx < 0x1900; idx++)
{
if (ObjectActive(idx))
Expand All @@ -132,7 +145,11 @@ private void fixcompatentry()
}

}

/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
private void specialarraysearch(UInt16 start, UInt16 end)
{
UInt16 lowest = 0xffff;
Expand Down Expand Up @@ -162,7 +179,11 @@ private void specialarraysearch(UInt16 start, UInt16 end)
Console.WriteLine(string.Format("New special array detected start 0x{0:X4} end 0x{1:X4}", lowest, highest));
}
}

/// <summary>
/// Returns true of object is not disabled
/// </summary>
/// <param name="index">index to check</param>
/// <returns>true if index object is not disabled</returns>
public bool ObjectActive(UInt16 index)
{
if (eds.ods.ContainsKey(index))
Expand Down Expand Up @@ -300,7 +321,11 @@ private string print_h_bylocation(string location)
return sb.ToString();
}


/// <summary>
/// Return the header part of one object dictionary entry
/// </summary>
/// <param name="od">the OD entry</param>
/// <returns>part of the C header file that impliments the od entry</returns>
protected string print_h_entry(ODentry od)
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -959,7 +984,11 @@ string write_od()

return returndata.ToString();
}

/// <summary>
/// Returns the c code related to a single object dictionary entry
/// </summary>
/// <param name="od">the OD entry</param>
/// <returns>string containing c code for the OD entry</returns>
protected string write_od_line(ODentry od)
{
StringBuilder sb = new StringBuilder();
Expand Down
7 changes: 7 additions & 0 deletions libEDSsharp/CanOpenXDD_1_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ You should have received a copy of the GNU General Public License

namespace libEDSsharp
{
/// <summary>
/// Convert to/from EDSsharp and CanOpenXDD v1.1, it uses the generated source file CanOpenXSD_1_1
/// </summary>
/// <seealso cref="CanOpenXSD_1_1"/>
public class CanOpenXDD_1_1
{
/// <summary>
Expand Down Expand Up @@ -1203,6 +1207,9 @@ public class CanOpenProject_1_1
{
[XmlElement(ElementName = "ISO15745ProfileContainer", Namespace = "http://www.canopen.org/xml/1.1")]
public List<ISO15745ProfileContainer> ISO15745ProfileContainer { get; set; }
/// <summary>
/// XDD version
/// </summary>
[XmlAttribute(AttributeName = "version")]
public string Version { get; set; }
}
111 changes: 92 additions & 19 deletions libEDSsharp/PDOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

namespace libEDSsharp
{

/// <summary>
/// Represent a PDO slot (mapping + communication index)
/// </summary>
public class PDOSlot
{

private UInt16 _MappingIndex;
private UInt16 _ConfigurationIndex;
/// <summary>
/// Indicate that $NODEID is present and the COB-ID should added to the node id when deployed
/// </summary>
public bool nodeidpresent;
/// <summary>
/// The OD index of the PDO configuration (aka. communication parameter)
/// </summary>
public ushort ConfigurationIndex
{
get { return _ConfigurationIndex; }
Expand All @@ -37,30 +45,52 @@ public ushort ConfigurationIndex

}
}

/// <summary>
/// The OD index of the PDO mapping
/// </summary>
public ushort MappingIndex
{
get { return _MappingIndex; }
}

/// <summary>
/// PDO Mapping access
/// </summary>
public EDSsharp.AccessType mappingAccessType;
/// <summary>
/// PDO Configuration (aka. communication parameter) access
/// </summary>
public EDSsharp.AccessType configAccessType;
/// <summary>
/// PDO mapping CanOpenNode storage group
/// </summary>
public string mappingloc;
/// <summary>
/// PDO config CanOpenNode storage group
/// </summary>
public string configloc;


/// <summary>
/// PDO COB-ID
/// </summary>
public uint COB;

/// <summary>
/// Returns if true the PDO is a TxPDO (aka TPDO)
/// </summary>
/// <returns>true if TXPDO</returns>
public bool isTXPDO()
{
return ConfigurationIndex >= 0x1800;
}

/// <summary>
/// Returns if true the PDO is a RxPDO (aka RPDO)
/// </summary>
/// <returns>true if RxPDO</returns>
public bool isRXPDO()
{
return ConfigurationIndex < 0x1800;
}

/// <summary>
/// PDO invalid bit value
/// </summary>
public bool invalid
{
get
Expand All @@ -69,22 +99,44 @@ public bool invalid
}
set
{

if (value == true)
COB = COB | 0x80000000;
else
COB = COB & 0x7FFFFFFF;
}
}

/// <summary>
/// PDO mapping
/// </summary>
public List<ODentry> Mapping = new List<ODentry>();

/// <summary>
/// PDO inhibit time,multiple of 100us
/// </summary>
public UInt16 inhibit;
/// <summary>
/// PDO event time,multiple of 1ms
/// </summary>
public UInt16 eventtimer;
/// <summary>
/// PDO sync start value
/// </summary>
public byte syncstart;
/// <summary>
/// PDO transmission type
/// </summary>
public byte transmissiontype;
/// <summary>
/// Description of PDO communication index (aka configuration)
/// </summary>
public string DescriptionComm;
/// <summary>
/// Description of PDO mapping index
/// </summary>
public string DescriptionMap;

/// <summary>
/// default constructor
/// </summary>
public PDOSlot()
{
configloc = "PERSIST_COMM";
Expand All @@ -94,7 +146,11 @@ public PDOSlot()
DescriptionComm = "";
DescriptionMap = "";
}

/// <summary>
/// Returns name of a OD entry (including dummy)
/// </summary>
/// <param name="od">object dictionary entry</param>
/// <returns>name of entry with index and subindex prefixed, or blank string if not found</returns>
public string getTargetName(ODentry od)
{
string target = "";
Expand Down Expand Up @@ -133,7 +189,11 @@ public string getTargetName(ODentry od)
return target;

}

/// <summary>
/// Insert a OD entry into the mapping table
/// </summary>
/// <param name="ordinal">The zero-based index at which item should be inserted</param>
/// <param name="entry">OD entry to be mapped</param>
public void insertMapping(int ordinal, ODentry entry)
{
int size = 0;
Expand All @@ -150,28 +210,41 @@ public void insertMapping(int ordinal, ODentry entry)

}


/// <summary>
/// PDO helper class, control all TPDO and RPDO in a node
/// </summary>
public class PDOHelper
{

EDSsharp eds;

/// <summary>
/// Constructor
/// </summary>
/// <param name="eds">eds data to interact with</param>
public PDOHelper(EDSsharp eds)
{
this.eds = eds;
}

/// <summary>
/// List of all T/R PDO
/// </summary>
public List<PDOSlot> pdoslots = new List<PDOSlot>();

/// <summary>
/// Why is this not called from constructor?
/// </summary>
public void build_PDOlists()
{
//List<ODentry> odl = new List<ODentry>();
build_PDOlist(0x1800,pdoslots);
build_PDOlist(0x1400,pdoslots);

}

public void build_PDOlist(UInt16 startcob, List<PDOSlot> slots)
/// <summary>
/// Look through the OD and register PDO
/// </summary>
/// <param name="startcob">OD index to to start looking from, it will stop after 0x1ff indexes</param>
/// <param name="slots">list to add found pdo into</param>
void build_PDOlist(UInt16 startcob, List<PDOSlot> slots)
{
for (UInt16 idx = startcob; idx < startcob + 0x01ff; idx++)
{
Expand Down
8 changes: 8 additions & 0 deletions libEDSsharp/StringUnescape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

namespace libEDSsharp
{
/// <summary>
/// Provides string escape and unescape functions
/// </summary>
public static class StringUnescape
{
/// <summary>
/// Convert litteral special characters like null and tab etc. into there escape sequence '\0' '\t'
/// </summary>
/// <param name="c">the spesial character to convert into escape sequence</param>
/// <returns>a string containing the escape sequence or c if noe escape sequence was found</returns>
public static string Escape(char c)
{
switch (c)
Expand Down
Loading

0 comments on commit 1d123ec

Please sign in to comment.