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; } }
public void Transmit(ITLVable value) { try { byte[] data = Conv.Encode(value); Connect(data); } catch (Exception e) { Log.Fatal(e); } }
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; } }
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(); }
public void TransmitAsync(ITLVable value) { Task.Factory.StartNew(() => Transmit(value)); }
public byte[] Encode(ITLVable obj) { return Encoder.Encode(obj); }
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; }
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; }
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; }
/// 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); }
/// <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; } }