private void PrintPdo(ushort start, ushort end, string caption, EDSsharp eds)
        {
            file.WriteLine("## {0}", caption);
            file.WriteLine();
            foreach (var kvp in eds.ods)
            {
                ODentry od    = kvp.Value;
                int     index = kvp.Key;

                if (od.Disabled)
                {
                    continue;
                }

                if (od.Index >= start && od.Index < end)
                {
                    file.WriteLine(string.Format("### {0} {1:x4}", caption, od.Index));
                    file.WriteLine();
                    byte current_bit = 0;
                    foreach (var kvp2 in od.subobjects)
                    {
                        ODentry odsub    = kvp2.Value;
                        ushort  subindex = kvp2.Key;

                        if (subindex == 0)
                        {
                            continue;
                        }

                        var data = Convert.ToUInt32(odsub.defaultvalue, EDSsharp.Getbase(odsub.defaultvalue));

                        if (data != 0)
                        {
                            byte   datasize = (byte)(data & 0x000000FF);
                            ushort pdoindex = (ushort)((data >> 16) & 0x0000FFFF);
                            byte   pdosub   = (byte)((data >> 8) & 0x000000FF);

                            file.Write($"* Byte{current_bit / 8}: ");

                            if (eds.ods.ContainsKey(pdoindex) && (pdosub == 0 || eds.ods[pdoindex].Containssubindex(pdosub)))
                            {
                                ODentry maptarget;
                                if (pdosub == 0)
                                {
                                    maptarget = eds.ods[pdoindex];
                                }
                                else
                                {
                                    maptarget = eds.ods[pdoindex].Getsubobject(pdosub);
                                }

                                if (!maptarget.Disabled && datasize == (8 * maptarget.Sizeofdatatype()))
                                {
                                    if (maptarget.parent == null)
                                    {
                                        file.Write(string.Format("[0x{0:x4} - {1}]", maptarget.Index, maptarget.parameter_name));
                                    }
                                    else
                                    {
                                        file.Write(string.Format("[0x{0:x4} sub 0x{1:x2} - {2}]", maptarget.Index, maptarget.Subindex, maptarget.parameter_name));
                                    }
                                }
                            }
                            file.WriteLine();
                            var by = (datasize / 8);
                            for (int i = 1; i < by; ++i)
                            {
                                file.WriteLine($"* Byte{current_bit / 8 + i}: -\"-");
                            }
                            current_bit += datasize;
                        }
                    }
                    for (int i = (current_bit / 8); i < 8; ++i)
                    {
                        file.WriteLine($"* Byte{i}: empty");
                    }
                    file.WriteLine();
                }
            }
        }
Example #2
0
        void UpdatePDOTXslot(ODentry od, int row)
        {
            UInt16 idx = (UInt16)(od.Index + 0x200);

            if (!eds.ods.ContainsKey(idx))
            {
                return;
            }

            ODentry oddef = eds.ods[idx];

            int byteoff = 0;

            foreach (KeyValuePair <UInt16, ODentry> kvp in oddef.subobjects)
            {
                if (byteoff >= 8)
                {
                    continue;
                }

                ODentry sub = kvp.Value;
                if (sub.Subindex == 0)
                {
                    continue;
                }

                UInt32 data = 0;
                if (sub.defaultvalue != "")
                {
                    data = Convert.ToUInt32(sub.defaultvalue, EDSsharp.Getbase(sub.defaultvalue));
                }

                if (data == 0)
                {
                    listView_TXCOBmap.AddComboBoxCell(row, byteoff + 3, TXchoices);
                    listView_TXCOBmap.Items[row].SubItems[byteoff + 3].Text = "empty";
                    byteoff++;
                    continue;
                }

                //format is 0x6000 01 08
                byte   datasize = (byte)(data & 0x000000FF);
                UInt16 pdoindex = (UInt16)((data >> 16) & 0x0000FFFF);
                byte   pdosub   = (byte)((data >> 8) & 0x000000FF);

                //sanity check the real OD against the mapping parameters section

                bool mappingfail = true;
                if (eds.ods.ContainsKey(pdoindex) && (pdosub == 0 || eds.ods[pdoindex].Containssubindex(pdosub)))
                {
                    ODentry maptarget;
                    if (pdosub == 0)
                    {
                        maptarget = eds.ods[pdoindex];
                    }
                    else
                    {
                        maptarget = eds.ods[pdoindex].Getsubobject(pdosub);
                    }

                    if (maptarget.Disabled == false && datasize == (8 * maptarget.Sizeofdatatype()))
                    {
                        mappingfail = false;
                    }

                    if (mappingfail == true)
                    {
                        MessageBox.Show(String.Format("PDO mapping failed for object 0x{0:x4}/{1:x2}\nplease manually check the PDO mapping in the TX and RX PDO tabs\n as it does not agree with the mapping parameter 0x{2:x4}/{3:x2}\nThis can occur if you edit objects that are already mapped", pdoindex, pdosub, idx, sub.Subindex));
                    }
                }

                String target      = "";
                int    PDOdatasize = 0;

                //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      = "0x0003/00/Dummy Int16";
                        PDOdatasize = 2;
                        break;

                    case 0x004:
                        target      = "0x0004/00/Dummy Int32";
                        PDOdatasize = 4;
                        break;

                    case 0x005:
                        target      = "0x0005/00/Dummy UInt8";
                        PDOdatasize = 1;
                        break;

                    case 0x006:
                        target      = "0x0006/00/Dummy UInt16";
                        PDOdatasize = 2;
                        break;

                    case 0x007:
                        target      = "0x0007/00/Dummy UInt32";
                        PDOdatasize = 4;
                        break;
                    }

                    if (PDOdatasize == 0)
                    {
                        continue;
                    }
                }
                else
                {
                    //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, pdosub) + targetod.parameter_name;
                    PDOdatasize = targetod.Sizeofdatatype();
                }


                listView_TXCOBmap.AddComboBoxCell(row, byteoff + 3, TXchoices);
                listView_TXCOBmap.Items[row].SubItems[byteoff + 3].Text = target;

                int oldPDOdatasize = PDOdatasize;

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

                byteoff += PDOdatasize;
            }
        }