private void SubscribeToComponents() { foreach (var control in Dialers.Select(dialer => dialer.Value)) { SubscribeToComponent(control); } foreach (var control in Switchers.Select(switcher => switcher.Value)) { SubscribeToComponent(control); } foreach (var control in States.Select(state => state.Value)) { SubscribeToComponent(control); } foreach (var control in Faders.Select(level => level.Value)) { SubscribeToComponent(control); } foreach (var control in RoomCombiners.Select(roomCombiner => roomCombiner.Value)) { SubscribeToComponent(control); } }
private void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args) { if (Debug.Level == 2) { Debug.Console(2, this, "RX: '{0}'", ShowHexResponse ? ComTextHelper.GetEscapedText(args.Text) : args.Text); } //Debug.Console(1, this, "RX: '{0}'", args.Text); try { DeviceRx = args.Text; CommandPassthruFeedback.FireUpdate(); if (args.Text.IndexOf("Welcome to the Tesira Text Protocol Server...", StringComparison.Ordinal) > -1) { // Indicates a new TTP session // moved to CustomActivate() method CommunicationMonitor.Start(); CrestronInvoke.BeginInvoke((o) => HandleAttributeSubscriptions()); } else if (args.Text.IndexOf("! ", StringComparison.Ordinal) > -1) { // response is from a subscribed attribute //(if(args.Text const string pattern = "! [\\\"](.*?[^\\\\])[\\\"] (.*)"; var match = Regex.Match(args.Text, pattern); if (!match.Success) { return; } var customName = match.Groups[1].Value; var value = match.Groups[2].Value; AdvanceQueue(args.Text); foreach (var controlPoint in Faders.Where(controlPoint => customName == controlPoint.Value.LevelCustomName || customName == controlPoint.Value.MuteCustomName)) { controlPoint.Value.ParseSubscriptionMessage(customName, value); return; } foreach (var controlPoint in Dialers.Where(controlPoint => customName == controlPoint.Value.AutoAnswerCustomName || customName == controlPoint.Value.ControlStatusCustomName || customName == controlPoint.Value.DialerCustomName)) { controlPoint.Value.ParseSubscriptionMessage(customName, value); return; } foreach (var controlPoint in States.Where(controlPoint => customName == controlPoint.Value.StateCustomName)) { controlPoint.Value.ParseSubscriptionMessage(customName, value); return; } foreach (var controlPoint in Switchers.Where(controlPoint => customName == controlPoint.Value.SelectorCustomName)) { controlPoint.Value.ParseSubscriptionMessage(customName, value); return; } foreach (var controlPoint in Meters.Where(controlPoint => customName == controlPoint.Value.MeterCustomName)) { controlPoint.Value.ParseSubscriptionMessage(customName, value); return; } // same for dialers // same for switchers } else if (args.Text.IndexOf("+OK", StringComparison.Ordinal) > -1) { if (args.Text == "+OK") // Check for a simple "+OK" only 'ack' repsonse or a list response and ignore { return; } // response is not from a subscribed attribute. From a get/set/toggle/increment/decrement command //string pattern = "(?<=\" )(.*?)(?=\\+)"; //string data = Regex.Replace(args.Text, pattern, ""); AdvanceQueue(args.Text); } else if (args.Text.IndexOf("-ERR", StringComparison.Ordinal) > -1) { // Error response Debug.Console(2, this, "Error From DSP: '{0}'", args.Text); switch (args.Text) { case "-ERR ALREADY_SUBSCRIBED": { WatchDogSniffer = false; AdvanceQueue(args.Text); break; } default: { WatchDogSniffer = false; AdvanceQueue(args.Text); break; } } } } catch (Exception e) { if (Debug.Level == 2) { Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e); } } }
private void CreateDspObjects() { Debug.Console(2, "Creating DSP Objects"); var props = JsonConvert.DeserializeObject <TesiraDspPropertiesConfig>(_dc.Properties.ToString()); if (props == null) { return; } Debug.Console(2, this, "Props Exists"); Debug.Console(2, this, "Here's the props string\n {0}", _dc.Properties.ToString()); Faders.Clear(); Presets.Clear(); Dialers.Clear(); States.Clear(); Switchers.Clear(); ControlPointList.Clear(); Meters.Clear(); RoomCombiners.Clear(); if (props.FaderControlBlocks != null) { Debug.Console(2, this, "levelControlBlocks is not null - There are {0} of them", props.FaderControlBlocks.Count()); foreach (var block in props.FaderControlBlocks) { var key = block.Key; Debug.Console(2, this, "LevelControlBlock Key - {0}", key); var value = block.Value; Faders.Add(key, new TesiraDspFaderControl(key, value, this)); Debug.Console(2, this, "Added LevelControlPoint {0} LevelTag: {1} MuteTag: {2}", key, value.LevelInstanceTag, value.MuteInstanceTag); if (block.Value.Enabled) { //Add ControlPoint to the list for the watchdog ControlPointList.Add(Faders[key]); } } } if (props.SwitcherControlBlocks != null) { Debug.Console(2, this, "switcherControlBlocks is not null - There are {0} of them", props.FaderControlBlocks.Count()); foreach (var block in props.SwitcherControlBlocks) { var key = block.Key; Debug.Console(2, this, "SwitcherControlBlock Key - {0}", key); var value = block.Value; Switchers.Add(key, new TesiraDspSwitcher(key, value, this)); Debug.Console(2, this, "Added TesiraSwitcher {0} InstanceTag {1}", key, value.SwitcherInstanceTag); if (block.Value.Enabled) { //Add ControlPoint to the list for the watchdog ControlPointList.Add(Switchers[key]); } } } if (props.DialerControlBlocks != null) { Debug.Console(2, this, "DialerControlBlocks is not null - There are {0} of them", props.DialerControlBlocks.Count()); foreach (var block in props.DialerControlBlocks) { var key = block.Key; Debug.Console(2, this, "LevelControlBlock Key - {0}", key); var value = block.Value; Dialers.Add(key, new TesiraDspDialer(key, value, this)); Debug.Console(2, this, "Added DspDialer {0} ControlStatusTag: {1} DialerTag: {2}", key, value.ControlStatusInstanceTag, value.DialerInstanceTag); if (block.Value.Enabled) { ControlPointList.Add(Dialers[key]); } } } if (props.StateControlBlocks != null) { Debug.Console(2, this, "stateControlBlocks is not null - There are {0} of them", props.StateControlBlocks.Count()); foreach (var block in props.StateControlBlocks) { var key = block.Key; var value = block.Value; States.Add(key, new TesiraDspStateControl(key, value, this)); Debug.Console(2, this, "Added DspState {0} InstanceTag: {1}", key, value.StateInstanceTag); if (block.Value.Enabled) { ControlPointList.Add(States[key]); } } } if (props.Presets != null) { foreach (var preset in props.Presets) { var value = preset.Value; var key = preset.Key; Presets.Add(key, value); Debug.Console(2, this, "Added Preset {0} {1}", value.Label, value.PresetName); } } if (props.MeterControlBlocks != null) { foreach (var meter in props.MeterControlBlocks) { var key = meter.Key; var value = meter.Value; Meters.Add(key, new TesiraDspMeter(key, value, this)); Debug.Console(2, this, "Adding Meter {0} InstanceTag: {1}", key, value.MeterInstanceTag); if (value.Enabled) { ControlPointList.Add(Meters[key]); } } } if (props.CrosspointStateControlBlocks != null) { foreach (var mixer in props.CrosspointStateControlBlocks) { var key = mixer.Key; var value = mixer.Value; CrosspointStates.Add(key, new TesiraDspCrosspointState(key, value, this)); Debug.Console(2, this, "Adding Mixer {0} InstanceTag: {1}", key, value.MatrixInstanceTag); if (value.Enabled) { ControlPointList.Add(CrosspointStates[key]); } } } if (props.RoomCombinerControlBlocks == null) { return; } foreach (var roomCombiner in props.RoomCombinerControlBlocks) { var key = roomCombiner.Key; var value = roomCombiner.Value; RoomCombiners.Add(key, new TesiraDspRoomCombiner(key, value, this)); Debug.Console(2, this, "Adding Mixer {0} InstanceTag: {1}", key, value.RoomCombinerInstanceTag); if (value.Enabled) { ControlPointList.Add(RoomCombiners[key]); } } //Keep me at the end of this method! DeviceManager.AddDevice(new TesiraDspDeviceInfo(String.Format("{0}--DeviceInfo", Key), String.Format("{0}--DeviceInfo", Name, Presets), this, Presets)); }