Example #1
0
        public void NewTlvInput(int methodID, ITLVable value)
        {
            switch (methodID)
            {
                case 2: // a change of joystick-achses/button

                    Purpose p = value as Purpose;
                    JoystickVal v = p.Value as JoystickVal;
                    bool wasButton = false;

                    if (v.Buttons != 0x00)
                    {
                        Log.DebugFormat("Detected button-press: {0}", v.Buttons);
                        wasButton = true;
                        if (OnButtonChanged != null)
                        {
                            OnButtonChanged(p.MethodID, GetButtonValues(v));
                        }
                    }

                    if (v.Value != 0x00 || !wasButton)
                    {
                        Log.DebugFormat("Detected achsis changed: {0}", v.Value);
                        if (OnAchsisChanged != null)
                        {
                            OnAchsisChanged(p.MethodID, v);
                        }
                    }

                    break;
                default:
                    break;
            }
        }
Example #2
0
 public void Transmit(ITLVable value)
 {
     try
     {
         byte[] data = Conv.Encode(value);
         Connect(data);
     }
     catch (Exception e)
     {
         Log.Fatal(e);
     }
 }
Example #3
0
 public void NewTlvInput(int methodID, ITLVable value)
 {
     Purpose p = value as Purpose;
     switch (methodID)
     {
         case 1:
             NewResultReceived(p);
             break;
         case 5:
             SetupReceived(p);
             break;
         default:
             break;
     }
 }
Example #4
0
        internal byte[] Encode(ITLVable obj)
        {
            InitEncode();

            List<byte> ret = new List<byte>();
            if (!TransMap.ContainsKey(obj.TlvStructId))
            {
                throw new ApplicationException("There is no metadata registered to convert " + obj.GetType().FullName);
            }

            TLVCompositeConv conv = TransMap[obj.TlvStructId];

            Func(conv, ret, obj, 0);

            ret.Reverse();

            //List<byte> ret = EncodeRek(obj);
            return ret.ToArray();
        }
Example #5
0
 public void TransmitAsync(ITLVable value)
 {
     Task.Factory.StartNew(() => Transmit(value));
 }
Example #6
0
 public byte[] Encode(ITLVable obj)
 {
     return Encoder.Encode(obj);
 }
Example #7
0
        private int Func(TLVListConv conv, List<byte> arr, ITLVable obj, int level)
        {
            int len = 0;

            //obj = (ITLVable)conv.PropInfo.GetValue(obj);
            System.Collections.IList listData = (System.Collections.IList)conv.PropInfo.GetValue(obj);

            // Iterate backwards because stream is created backwards
            for (int i = listData.Count - 1; i >= 0; i--)
            {
                // Set (V)
                len += Func((dynamic)conv.Contains, arr, (dynamic)listData[i], ++level);
            }
            //foreach (dynamic o in listData)
            //{
            //    // Set (V)
            //    len += Func((dynamic)conv.Contains, arr, o, ++level);
            //}

            if (len > 0)
            {
                // Set (L)
                len = SetL(arr, len, true);

                // Set (T)
                len = SetT(conv, arr, len, true);
            }

            return len;
        }
Example #8
0
        private int Func(TLVCompositeConv conv, List<byte> arr, ITLVable obj, int level)
        {
            int len = 0;

            // When coming from Func(TLVListConv c, ... ), PropInfo is null and object already set
            if (level > 0 && conv.PropInfo != null) obj = (ITLVable)conv.PropInfo.GetValue(obj);

            // When generic - now get the real underlying Conv
            if (conv.IsGeneric)
            {
                conv = TransMap[obj.TlvStructId];
            }

            foreach (dynamic c in conv.Children)
            {
                // Set (V)
                len += Func(c, arr, obj, ++level);
            }

            if (len > 0)
            {
                // Set (L)
                len = SetL(arr, len, true);

                // Set (T)
                len = SetT(conv, arr, len, true);

            }

            return len;
        }
Example #9
0
        private int Func(TLVPrimitiveConv conv, List<byte> arr, ITLVable obj, int level)
        {
            int len = 0;

            // Add (V)
            byte[] v = V(conv, obj);
            Add(arr, false, v);
            len += v.Length;

            // Add (L)
            len = SetL(arr, len, true);

            // Add (T)
            len = SetT(conv, arr, len, true);

            return len;
        }
Example #10
0
        /// Returns the V (Value) of obj
        /// </summary>
        /// <param name="conv"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected byte[] V(TLVPrimitiveConv conv, ITLVable obj)
        {
            var value = conv.PropInfo.GetValue(obj);

            return ConvertPrimAsByte(conv, obj);
        }
Example #11
0
        /// <summary>
        /// This callback is invoked by TlvProcessor when a status changes
        /// </summary>
        /// <param name="methodID"></param>
        /// <param name="value"></param>
        public void NewTlvInput(int methodID, ITLVable value)
        {
            Purpose p = value as Purpose;
            JoystickVal v = p.Value as JoystickVal;

            switch (methodID)
            {
                case 3: // change the step of dmx-values (how many values are calculated per timeslice to the current value)
                    TurnSingleStep(v.Value, v.Nr);
                    break;
                case 4: // change the mode of Moving-Head
                    if (v.Nr < movingHeads.Count)
                    {
                        movingHeads[v.Nr].VelocityChanged(MHVelocities[v.Value]);
                    }
                    else
                    {
                        LogMhIdxErr("Mode", v.Nr);
                    }
                    break;
                default:
                    Log.ErrorFormat("Not implemented method id from TLV-input: {0}", methodID);
                    break;
            }
        }