예제 #1
0
        void ListView_TXCOBmap_onComboBoxIndexChanged(int row, int col, string Text)
        {
            //row+0x1a00 will be the slot to adjust

            eds.Dirty = true;

            UInt16  slot   = (UInt16)(0x200 + Convert.ToUInt16(listView_TXCOBmap.Items[row].SubItems[2].Text, 16));
            ODentry slotod = eds.ods[slot];

            //Now rebuild the entire slot working out data size as we go

            for (byte p = 1; p < slotod.subobjects.Count; p++)
            {
                //fixme ordinal access
                slotod.subobjects[p].defaultvalue = "0x00000000";
            }

            byte subcount        = 1;
            int  totaldatalength = 0;

            ListViewItem item = listView_TXCOBmap.Items[row];

            foreach (ListViewItem.ListViewSubItem subitem in item.SubItems)
            {
                if (subitem.Text == "" || subitem.Text == " - " || subitem.Text == "   ")
                {
                    continue;
                }

                string[] bits = subitem.Text.Split('/');
                if (bits.Length != 3) //ignore the first column
                {
                    continue;
                }
                UInt16 index = Convert.ToUInt16(bits[0], 16);
                Byte   sub   = Convert.ToByte(bits[1], 16);


                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];

                    //fixme ordinal access
                    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;

                if (totaldatalength > 64)
                {
                    MessageBox.Show(String.Format("Too much data in TX PDO {0}", slotod.Index));
                    break;
                }

                string value = string.Format("0x{0:x4}{1:x2}{2:x2}", index, sub, datalength);

                if (subcount >= slotod.subobjects.Count())
                {
                    MessageBox.Show("PDO Mapping array is too small, please add more elements in OD editor");
                    break;
                }

                //fixme ordinal access
                slotod.subobjects[subcount].defaultvalue = value;

                subcount++;
            }

            //fixme ordinal access
            //write out the number of objects used into the sub object count [0]
            slotod.subobjects[0].defaultvalue = string.Format("{0}", subcount - 1);

            UpdatePDOinfo();
            doUpdateOD();
        }
예제 #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;
            }
        }