コード例 #1
0
ファイル: MoCapReader.cs プロジェクト: vnmone/vvvv-sdk
        public static MoCapDataList ReadMessage(byte[] b)
        {
            IntPtr pt = Marshal.AllocCoTaskMem(b.Length);

            Marshal.Copy(b, 0, pt, b.Length);

            MoCapDataList res = new MoCapDataList();


            unsafe
            {
                int    total   = 0;
                sbyte *offset  = (sbyte *)pt;
                uint   nbitems = *(uint *)offset;

                //puint = p;
                //GetValue<uint>(b, 0, 4);
                offset += 4;
                total  += 4;

                for (int i = 0; i < nbitems; i++)
                {
                    uint labellen = *(uint *)offset;
                    int  ill      = Convert.ToInt32(labellen);
                    offset += 4;
                    total  += 4;
                    string sname = new string(offset, 0, ill);
                    offset += labellen;
                    total  += ill;

                    uint desclen = *(uint *)offset;
                    ill     = Convert.ToInt32(desclen);
                    offset += 4;
                    total  += 4;
                    string sdesc = new string(offset, 0, ill);
                    offset += ill;
                    total  += ill;



                    MOCAP_ITEM item = *(MOCAP_ITEM *)offset;
                    offset += Marshal.SizeOf(item);
                    total  += Marshal.SizeOf(item);

                    MoCapDataItem di = new MoCapDataItem();
                    di.Description = sdesc;
                    di.Name        = sname;
                    di.Item        = item;

                    res.Add(sname, di);
                }

                return(res);
            }
        }
コード例 #2
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FPinInFilter.PinIsChanged)
            {
                for (int i = 0; i < this.FPinInFilter.SliceCount; i++)
                {
                    string exclude_item;
                    this.FPinInFilter.GetString(i, out exclude_item);
                    this.FExclude.Add(exclude_item);
                }
            }

            if (this.FPinInBang.PinIsChanged)
            {
                string val;
                this.FPinInValue.GetString(0, out val);

                if (val.Length > 0)
                {
                    try
                    {
                        //First 4 characters are packet length
                        string head = val.Substring(0, 4);

                        //Remainder is data
                        string        tail = val.Substring(4);
                        byte[]        msg  = TTypeConverter.GetArray(tail);
                        MoCapDataList data = MoCapReader.ReadMessage(msg);


                        int count = 0;
                        foreach (MoCapDataItem item in data.Values)
                        {
                            if (!this.FExclude.Contains(item.Name))
                            {
                                this.FPinOutName.SliceCount        = count + 1;
                                this.FPinOutDescription.SliceCount = count + 1;
                                this.FPinOutType.SliceCount        = count + 1;
                                this.FPinOutValue1.SliceCount      = count + 1;
                                this.FPinOutValue2.SliceCount      = count + 1;
                                this.FPinOutValue3.SliceCount      = count + 1;
                                this.FPinOutValue4.SliceCount      = count + 1;
                                this.FPinOutValue5.SliceCount      = count + 1;
                                this.FPinOutValue6.SliceCount      = count + 1;
                                this.FPinOutFactor.SliceCount      = count + 1;
                                this.FPinOutReliability.SliceCount = count + 1;

                                this.FPinOutName.SetString(count, item.Name);
                                this.FPinOutDescription.SetString(count, item.Description);
                                this.FPinOutType.SetString(count, item.Item.dwType.ToString());
                                this.FPinOutValue1.SetValue(count, item.Item.dValue1);
                                this.FPinOutValue2.SetValue(count, item.Item.dValue2);
                                this.FPinOutValue3.SetValue(count, item.Item.dValue3);
                                this.FPinOutValue4.SetValue(count, item.Item.dValue4);
                                this.FPinOutValue5.SetValue(count, item.Item.dValue5);
                                this.FPinOutValue6.SetValue(count, item.Item.dValue6);
                                this.FPinOutFactor.SetValue(count, item.Item.dFactor);
                                this.FPinOutReliability.SetValue(count, item.Item.dReliability);

                                count++;
                            }
                        }
                    }
                    catch
                    {
                        SetNAN();
                    }
                }
                else
                {
                    SetNAN();
                }
            }
        }