Skip to content

Commit

Permalink
Set the mapping typedefs to set the max number in the group they are in
Browse files Browse the repository at this point in the history
fixes #220
  • Loading branch information
robincornelius committed Aug 12, 2020
1 parent 7c49b15 commit 108c058
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
52 changes: 52 additions & 0 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class CanOpenNodeExporter : IExporter
List<UInt16> openings = new List<UInt16>();
List<UInt16> closings = new List<UInt16>();

private byte maxRXmappingsize = 0;
private byte maxTXmappingsize = 0;
ODentry maxRXmappingsOD=null;
ODentry maxTXmappingsOD=null;


public void export(string folderpath, string filename, string gitVersion, EDSsharp eds)
{
Expand Down Expand Up @@ -191,6 +196,38 @@ protected void prewalkArrays()
}

}

//Find maximum no entries in a mapping config to define an appropriate array
maxRXmappingsize = 0;
maxTXmappingsize = 0;

for (ushort x=0x1600;x<0x1800;x++)
{
if(eds.ods.ContainsKey(x))
{
byte maxcount = EDSsharp.ConvertToByte(eds.ods[x].subobjects[0].defaultvalue);

if(maxcount > maxRXmappingsize)
{
maxRXmappingsize = maxcount;
maxRXmappingsOD = eds.ods[x];
}
}
}

for (ushort x = 0x1a00; x < 0x1c00; x++)
{
if (eds.ods.ContainsKey(x))
{
byte maxcount = EDSsharp.ConvertToByte(eds.ods[x].subobjects[0].defaultvalue);

if (maxcount > maxTXmappingsize)
{
maxTXmappingsize = maxcount;
maxTXmappingsOD = eds.ods[x];
}
}
}
}

string lastname = "";
Expand Down Expand Up @@ -485,6 +522,21 @@ OBJECT DICTIONARY

structnamelist.Add(structname);

// we need to search the mappings to find the largest or this will not generate correctly
// as can opennode only has 1 structure defined for all mappings see #220

if (kvp.Key>0x1600 || kvp.Key<0x1800)
{
//switch the OD entry to the largest
od = maxRXmappingsOD;
}

if (kvp.Key > 0x1A00 || kvp.Key < 0x1C00)
{
//switch the OD entry to the largest
od = maxTXmappingsOD;
}

file.WriteLine(string.Format("/*{0:X4} */ typedef struct {{", kvp.Key));
foreach (KeyValuePair<UInt16, ODentry> kvp2 in kvp.Value.subobjects)
{
Expand Down
53 changes: 53 additions & 0 deletions libEDSsharp/LegacyCanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class LegacyCanOpenNodeExporter : IExporter
List<UInt16> openings = new List<UInt16>();
List<UInt16> closings = new List<UInt16>();

private byte maxRXmappingsize = 0;
private byte maxTXmappingsize = 0;
ODentry maxRXmappingsOD = null;
ODentry maxTXmappingsOD = null;

public void export(string folderpath, string filename, string gitVersion, EDSsharp eds)
{
Expand Down Expand Up @@ -191,6 +195,39 @@ protected void prewalkArrays()
}

}

//Find maximum no entries in a mapping config to define an appropriate array
maxRXmappingsize = 0;
maxTXmappingsize = 0;

for (ushort x = 0x1600; x < 0x1800; x++)
{
if (eds.ods.ContainsKey(x))
{
byte maxcount = EDSsharp.ConvertToByte(eds.ods[x].subobjects[0].defaultvalue);

if (maxcount > maxRXmappingsize)
{
maxRXmappingsize = maxcount;
maxRXmappingsOD = eds.ods[x];
}
}
}

for (ushort x = 0x1a00; x < 0x1c00; x++)
{
if (eds.ods.ContainsKey(x))
{
byte maxcount = EDSsharp.ConvertToByte(eds.ods[x].subobjects[0].defaultvalue);

if (maxcount > maxTXmappingsize)
{
maxTXmappingsize = maxcount;
maxTXmappingsOD = eds.ods[x];
}
}
}

}

string lastname = "";
Expand Down Expand Up @@ -485,6 +522,22 @@ OBJECT DICTIONARY

structnamelist.Add(structname);


// we need to search the mappings to find the largest or this will not generate correctly
// as can opennode only has 1 structure defined for all mappings see #220

if (kvp.Key > 0x1600 || kvp.Key < 0x1800)
{
//switch the OD entry to the largest
od = maxRXmappingsOD;
}

if (kvp.Key > 0x1A00 || kvp.Key < 0x1C00)
{
//switch the OD entry to the largest
od = maxTXmappingsOD;
}

file.WriteLine(string.Format("/*{0:X4} */ typedef struct {{", kvp.Key));
foreach (KeyValuePair<UInt16, ODentry> kvp2 in kvp.Value.subobjects)
{
Expand Down

1 comment on commit 108c058

@trojanobelix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Robin, this does not work, I think

It should be

                if (kvp.Key>=0x1600 && kvp.Key<0x1800)
                {
                    //change the OD entry to the largest one
                    od = maxRXmappingsOD;
                }

                if (kvp.Key >= 0x1A00 && kvp.Key < 0x1C00)
                {
                    //set the OD entry to the largest one
                    od = maxTXmappingsOD;
                }

instead of

                if (kvp.Key > 0x1600 || kvp.Key < 0x1800)   // why OR? This takes all numbers 0...0xFFFF 
                {
                    //change the OD entry to the largest one
                    od = maxRXmappingsOD;
                }

                if (kvp.Key > 0x1A00 || kvp.Key < 0x1C00)
                {
                    //change the OD entry to the largest one
                    od = maxTXmappingsOD;
                }

And it's good to search the mappings to find the largest one, but setting the "od" variable to maxXXmappingsOD, e.g.
od = maxRXmappingsOD;
doesn't work because the member list creation still uses kvp.Value.subobjects, which is not the maximum number of members.

so instead using
foreach (KeyValuePair<UInt16, ODentry> kvp2 in kvp.Value.subobjects)

it should be something like

foreach (KeyValuePair<UInt16, ODentry> kvp2 in od.subobjects)

Because "od" is set to the max[TX/RX]mappingsOD

Please sign in to comment.