Skip to content

Commit

Permalink
Remove odname parameter from canopennode exporters
Browse files Browse the repository at this point in the history
Path.GetFileNameWithoutExtension([FileName] is used internally instead (this is done externally before)
  • Loading branch information
nimrof committed Jul 22, 2024
1 parent 565a845 commit 7c7f28c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion EDSEditorGUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void exportCanOpenNode(DeviceView dv, string FileName, ExporterFactory.E
string savePath = Path.GetDirectoryName(FileName);
string baseFileName = Path.GetFileNameWithoutExtension(FileName);
var filepath = $"{savePath}/{baseFileName}";
exporter.export(filepath, this.gitVersion, dv.eds, baseFileName);
exporter.export(filepath, this.gitVersion, dv.eds);
}
catch (Exception ex)
{
Expand Down
4 changes: 1 addition & 3 deletions EDSSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ private static void openEDSfile(string infile, string outfile, InfoSection.Filet

private static void exportCOOD(string outpath,ExporterFactory.Exporter type)
{
string odname = outpath;

outpath = Path.GetFullPath(outpath);

string savePath = Path.GetDirectoryName(outpath);
Expand All @@ -105,7 +103,7 @@ private static void exportCOOD(string outpath,ExporterFactory.Exporter type)
IExporter exporter = ExporterFactory.getExporter(type);
var filepath = Path.Combine(savePath, Path.GetFileNameWithoutExtension(outpath));

exporter.export(filepath, gitversion, eds, odname);
exporter.export(filepath, gitversion, eds);

foreach(string warning in Warnings.warning_list)
{
Expand Down
63 changes: 32 additions & 31 deletions Tests/ExporterTestsV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ public ExporterTestsV4()
_eds = new EDSsharp();
}

void GetExportResult(EDSsharp eds, out IEnumerable<String> cfile, out IEnumerable<String> hfile)
void GetExportResult(EDSsharp eds, out IEnumerable<String> cfile, out IEnumerable<String> hfile, out string odname)
{
var fullPath = Path.GetTempFileName();
var tempfile = Path.GetFileName(fullPath);
var path = Path.GetTempPath();

var cfilePath = fullPath + ".c";
var hfilePath = fullPath + ".h";
export(cfilePath, ".", eds, "OD_Test");
export(cfilePath, ".", eds);
cfile = File.ReadLines(cfilePath);
hfile = File.ReadLines(hfilePath);
odname = tempfile;
}

bool FindExpectedLines(IEnumerable<String> lines, List<String> expectedLines)
Expand Down Expand Up @@ -85,12 +86,12 @@ public void TestVariableStringZeroData()

_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
Assert.True(FindExpectedLines(hfile, new List<string> { "#define OD_Test_ENTRY_H2000 &OD_Test->list[0]" }));
Assert.True(FindExpectedLines(hfile, new List<string> { "#define OD_Test_ENTRY_H2000_testString &OD_Test->list[0]" }));
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> { $"#define {odname}_ENTRY_H2000 &{odname}->list[0]" }));
Assert.True(FindExpectedLines(hfile, new List<string> { $"#define {odname}_ENTRY_H2000_testString &{odname}->list[0]" }));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testString = {",
" .dataOrig = NULL,",
" .attribute = ODA_SDO_R | ODA_STR,",
Expand All @@ -99,8 +100,8 @@ public void TestVariableStringZeroData()
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x01, ODT_VAR, &OD_TestObjs.o_2000_testString, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x01, ODT_VAR, &{odname}Objs.o_2000_testString, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -123,25 +124,25 @@ public void TestVariableString(string defaultValue, uint stringLengthMin, int ex

_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var _);
GetExportResult(_eds, out var cfile, out var _, out var odname);

Assert.True(FindExpectedLines(cfile, new List<string> {
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
$" .x2000_testString = {{{expectedInitialValues}}}",
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testString = {",
" .dataOrig = &OD_Test_RAM.x2000_testString[0],",
$" .dataOrig = &{odname}_RAM.x2000_testString[0],",
" .attribute = ODA_SDO_R | ODA_STR,",
$" .dataLength = {expectedLength}",
" }",
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x01, ODT_VAR, &OD_TestObjs.o_2000_testString, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x01, ODT_VAR, &{odname}Objs.o_2000_testString, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -165,18 +166,18 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int
od.subobjects[1].prop.CO_stringLengthMin = stringLengthMin;
_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> {
"typedef struct {",
" struct {",
" uint8_t numElements;",
$" char str[{expectedLength+1}];",
" } x2000_testRec;",
"} OD_Test_RAM_t;"}));
$"}} {odname}_RAM_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
" .x2000_testRec = {",
" .numElements = 0x00,",
$" .str = {{{expectedInitialValues}}}",
Expand All @@ -187,20 +188,20 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int
{
"typedef struct {",
" OD_obj_record_t o_2000_testRec[2];",
"} OD_TestObjs_t;"}));
$"}} {odname}Objs_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testRec = {",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.numElements,",
$" .dataOrig = &{odname}_RAM.x2000_testRec.numElements,",
" .subIndex = 0,",
" .attribute = ODA_SDO_RW | ODA_TRPDO,",
" .dataLength = 1",
" },",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.str[0],",
$" .dataOrig = &{odname}_RAM.x2000_testRec.str[0],",
" .subIndex = 1,",
" .attribute = ODA_SDO_RW | ODA_TRPDO | ODA_STR,",
$" .dataLength = {expectedLength}",
Expand All @@ -210,8 +211,8 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x02, ODT_REC, &OD_TestObjs.o_2000_testRec, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x02, ODT_REC, &{odname}Objs.o_2000_testRec, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -231,17 +232,17 @@ public void TestRecordWithZeroLengthString()
od.addsubobject(1, new ODentry("str", 0x2000, DataType.VISIBLE_STRING, "", EDSsharp.AccessType.rw, PDOMappingType.optional));
_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> {
"typedef struct {",
" struct {",
" uint8_t numElements;",
" } x2000_testRec;",
"} OD_Test_RAM_t;"}));
$"}} {odname}_RAM_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
" .x2000_testRec = {",
" .numElements = 0x00",
" }",
Expand All @@ -251,14 +252,14 @@ public void TestRecordWithZeroLengthString()
{
"typedef struct {",
" OD_obj_record_t o_2000_testRec[2];",
"} OD_TestObjs_t;"}));
$"}} {odname}Objs_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testRec = {",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.numElements,",
$" .dataOrig = &{odname}_RAM.x2000_testRec.numElements,",
" .subIndex = 0,",
" .attribute = ODA_SDO_RW | ODA_TRPDO,",
" .dataLength = 1",
Expand All @@ -274,8 +275,8 @@ public void TestRecordWithZeroLengthString()

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x02, ODT_REC, &OD_TestObjs.o_2000_testRec, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x02, ODT_REC, &{odname}Objs.o_2000_testRec, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand Down
3 changes: 1 addition & 2 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public void prepareCanOpenNames()
/// <param name="filepath">filepath, .c and .h will be added to this to make the mulitiple files</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 filepath, string gitVersion, EDSsharp eds,string odname)
public void export(string filepath, string gitVersion, EDSsharp eds)
{
this.folderpath = Path.GetDirectoryName(filepath);
string filename = Path.GetFileNameWithoutExtension(filepath);
Expand Down
5 changes: 2 additions & 3 deletions libEDSsharp/CanOpenNodeExporter_V4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public class CanOpenNodeExporter_V4 : IExporter
/// <param name="filepath">filepath, .c and .h will be added to this to make the mulitiple files</param>
/// <param name="gitVersion"></param>
/// <param name="eds"></param>
/// <param name="odname"></param>
public void export(string filepath, string gitVersion, EDSsharp eds, string odname)
public void export(string filepath, string gitVersion, EDSsharp eds)
{
string filename = Path.GetFileNameWithoutExtension(filepath);
string folderpath = Path.GetDirectoryName(filepath);
this.odname = odname;
this.odname = filename;

Prepare(eds);

Expand Down
3 changes: 1 addition & 2 deletions libEDSsharp/IExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public interface IExporter
/// <param name="filepath">filepath, .c and .h will be added to this to make the mulitiple 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 filepath, string gitVersion, EDSsharp eds , string odname="OD");
void export(string filepath, string gitVersion, EDSsharp eds);
}
}

0 comments on commit 7c7f28c

Please sign in to comment.