Skip to content

Commit

Permalink
Add in dummy object support and allow PDO configuration tabs to be ab…
Browse files Browse the repository at this point in the history
…le to select dummy entries
  • Loading branch information
robincornelius committed Dec 2, 2016
1 parent 3d8cb8a commit eaf0b5e
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 32 deletions.
134 changes: 110 additions & 24 deletions EDSTest/DevicePDOView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public void updatePDOinfo()

TXchoices.Add(String.Format("empty"));

//TXchoices.Add(string.Format("Dummy Bool")); //not sure how this works at all for a bit???

TXchoices.Add(string.Format("0x002/00/Dummy Int8"));
TXchoices.Add(string.Format("0x003/00/Dummy Int16"));
TXchoices.Add(string.Format("0x004/00/Dummy Int32"));
TXchoices.Add(string.Format("0x005/00/Dummy UInt8"));
TXchoices.Add(string.Format("0x006/00/Dummy UInt16"));
TXchoices.Add(string.Format("0x007/00/Dummy UInt32"));


listView_TXPDO.BeginUpdate();

Expand Down Expand Up @@ -209,7 +218,7 @@ void updatePDOTXslot(ODentry od , int row)
if (sub.defaultvalue != "")
data = Convert.ToUInt32(sub.defaultvalue, EDSsharp.getbase(sub.defaultvalue));

if (data == 0) //FIX ME also include dummy usage here
if (data == 0)
{
listView_TXCOBmap.AddComboBoxCell(row, byteoff + 2, TXchoices);
listView_TXCOBmap.Items[row].SubItems[byteoff + 2].Text = "empty";
Expand All @@ -222,34 +231,77 @@ void updatePDOTXslot(ODentry od , int row)
UInt16 pdoindex = (UInt16)((data >> 16) & 0x0000FFFF);
byte pdosub = (byte)((data >> 8) & 0x000000FF);

//fixme sanity checking here please
if (!eds.ods.ContainsKey(pdoindex))
continue;
String target = "";
int PDOdatasize = 0;

ODentry targetod = eds.ods[pdoindex];
//dummy objects
if (pdoindex>=0x0002 && pdoindex<=0x007)
{
//the dummy objects
switch (pdoindex)
{
case 0x002:
target = "0x0002/00/Dummy Int8";
PDOdatasize = 1;
break;
case 0x003:
target = "0x0002/00/Dummy Int16";
PDOdatasize = 2;
break;
case 0x004:
target = "0x0002/00/Dummy Int32";
PDOdatasize = 4;
break;
case 0x005:
target = "0x0002/00/Dummy UInt8";
PDOdatasize = 1;
break;
case 0x006:
target = "0x0002/00/Dummy UInt16";
PDOdatasize = 2;
break;
case 0x007:
target = "0x0002/00/Dummy UInt32";
PDOdatasize = 4;
break;
}

if(pdosub!=0)
if (PDOdatasize == 0)
continue;

}
else
{
targetod = targetod.subobjects[pdosub];
//fixme sanity checking here please
if (!eds.ods.ContainsKey(pdoindex))
continue;

ODentry targetod = eds.ods[pdoindex];

if (pdosub != 0)
{
//FIXME direct sub array access, unprotected and will fault with holes in range
targetod = targetod.subobjects[pdosub];
}

target = String.Format("0x{0:x4}/{1:x2}/", targetod.index, targetod.subindex) + targetod.parameter_name;
PDOdatasize = targetod.sizeofdatatype();
}


listView_TXCOBmap.AddComboBoxCell(row, byteoff+2, TXchoices);

String target = String.Format("0x{0:x4}/{1:x2}/", targetod.index, targetod.subindex) + targetod.parameter_name;
listView_TXCOBmap.Items[row].SubItems[byteoff+2].Text = target;

int PDOdatasize = targetod.sizeofdatatype();
while (PDOdatasize != 1)
int oldPDOdatasize = PDOdatasize;

while (oldPDOdatasize != 1)
{
listView_TXCOBmap.Items[row].SubItems[byteoff + PDOdatasize+1].Text = " - ";
PDOdatasize--;
listView_TXCOBmap.Items[row].SubItems[byteoff + oldPDOdatasize + 1].Text = " - ";
oldPDOdatasize--;

}

byteoff += targetod.sizeofdatatype();


byteoff += PDOdatasize;

}
}
Expand Down Expand Up @@ -286,14 +338,48 @@ void listView_TXCOBmap_onComboBoxIndexChanged(int row, int col, string Text)
UInt16 index = Convert.ToUInt16(bits[0], 16);
Byte sub = Convert.ToByte(bits[1], 16);

ODentry od = eds.ods[index];
if(sub!=0)
od = od.subobjects[sub];

//fixme for non basic types will this work?? i think
//its not even allowed for PDO but need trap in code to
//prevent this and throw error here
int datalength = 8* od.sizeofdatatype();
int datalength = 0;

if (index >= 0x002 && index <= 0x007)
{
//the dummy objects
switch(index)
{
case 0x002:
datalength = 8;
break;
case 0x003:
datalength = 16;
break;
case 0x004:
datalength = 32;
break;
case 0x005:
datalength = 8;
break;
case 0x006:
datalength = 16;
break;
case 0x007:
datalength = 32;
break;

}

}
else
{

ODentry od = eds.ods[index];
if (sub != 0)
od = od.subobjects[sub];

//fixme for non basic types will this work?? i think
//its not even allowed for PDO but need trap in code to
//prevent this and throw error here
datalength = 8 * od.sizeofdatatype();
}

totaldatalength += datalength;

Expand Down
2 changes: 1 addition & 1 deletion EDSTest/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions libEDSsharp/NetworkPDOreport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ public void gennetpdodoc(string filepath, List<EDSsharp> network)

if (subindex2 == 0)
{
name2 = eds2.ods[index2].parameter_name;
//fixme getobject could return null
name2 = eds2.getobject(index2).parameter_name;

}
else
{
name2 = eds2.ods[index2].getsubobject(subindex2).parameter_name;
//fixme getobject could return null
name2 = eds2.getobject(index2).getsubobject(subindex2).parameter_name;
}

string sizemsg = "";
Expand Down
30 changes: 25 additions & 5 deletions libEDSsharp/eds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ public enum AccessType

Dictionary<string, Dictionary<string, string>> eds;
public SortedDictionary<UInt16, ODentry> ods;
public SortedDictionary<UInt16, ODentry> dummy_ods;

public FileInfo fi;
public DeviceInfo di;
public MandatoryObjects md;
Expand All @@ -977,6 +979,7 @@ public EDSsharp()

eds = new Dictionary<string, Dictionary<string, string>>();
ods = new SortedDictionary<UInt16, ODentry>();
dummy_ods = new SortedDictionary<UInt16, ODentry>();

fi = new FileInfo();
di = new DeviceInfo();
Expand Down Expand Up @@ -1008,10 +1011,12 @@ public EDSsharp()

ODentry od = new ODentry();





dummy_ods.Add(2, new ODentry("Dummy Int8", 0x002, 0x00, DataType.INTEGER8, "0", AccessType.ro, PDOMappingType.optional));
dummy_ods.Add(3, new ODentry("Dummy Int16", 0x002, 0x00, DataType.INTEGER16, "0", AccessType.ro, PDOMappingType.optional));
dummy_ods.Add(4, new ODentry("Dummy Int32", 0x002, 0x00, DataType.INTEGER32, "0", AccessType.ro, PDOMappingType.optional));
dummy_ods.Add(5, new ODentry("Dummy UInt8", 0x002, 0x00, DataType.UNSIGNED8, "0", AccessType.ro, PDOMappingType.optional));
dummy_ods.Add(6, new ODentry("Dummy UInt16", 0x002, 0x00, DataType.UNSIGNED16, "0", AccessType.ro, PDOMappingType.optional));
dummy_ods.Add(7, new ODentry("Dummy UInt32", 0x002, 0x00, DataType.UNSIGNED32, "0", AccessType.ro, PDOMappingType.optional));

}

Expand Down Expand Up @@ -1558,8 +1563,23 @@ public bool createRXPDO(UInt16 index)
{
return createPDO(true, index);
}


public ODentry getobject(UInt16 no)
{

if(no>=0x002 && no<=0x007)
{
return dummy_ods[no];
}

if (ods.ContainsKey(no))
{
return ods[no];
}

return null;

}
}

public class ParameterException : Exception
Expand Down

0 comments on commit eaf0b5e

Please sign in to comment.