コード例 #1
0
        protected virtual void OnVoipInfoReceived(string command, string info)
        {
#if DEBUG
            CrestronConsole.PrintLine("{0}, {1} = {2}", Name, command, info);
            CrestronConsole.Print("  elements =");
            foreach (var element in SoundstructureSocket.ElementsFromString(info))
            {
                CrestronConsole.Print(" {0}", element);
            }
            CrestronConsole.PrintLine("");
#endif
            _initialised = true;
        }
コード例 #2
0
        private void SocketOnReceivedData(string data)
        {
#if DEBUG
            CrestronConsole.PrintLine("Soundstructure Rx: {0}", data);
#endif
            if (!DeviceCommunicating)
            {
                DeviceCommunicating = true;
            }

            if (data.Contains(' '))
            {
                List <string> elements = SoundstructureSocket.ElementsFromString(data);

                switch (elements[0])
                {
                case "error":
                {
                    ErrorLog.Error("Soundtructure received Error: {0}", elements[1]);
                }
                break;

                case "ran":
                    if (PresetRan != null)
                    {
                        PresetRan(this, elements[1]);
                    }
                    break;

                case "vcitem":
                    // this should be a response from the vclist command which sends back all virtual channels defined
                    try
                    {
                        List <uint> values = new List <uint>();

                        for (int element = 4; element < elements.Count(); element++)
                        {
                            values.Add(Convert.ToUInt32(elements[element]));
                        }

                        SoundstructurePhysicalChannelType type = (SoundstructurePhysicalChannelType)Enum.Parse(typeof(SoundstructurePhysicalChannelType), elements[3], true);

                        if (type == SoundstructurePhysicalChannelType.VOIP_OUT)
                        {
                            _listedItems.Add(new VoipOutChannel(this, elements[1], values.ToArray()));
                        }
                        else if (type == SoundstructurePhysicalChannelType.VOIP_IN)
                        {
                            _listedItems.Add(new VoipInChannel(this, elements[1], values.ToArray()));
                        }
                        else if (type == SoundstructurePhysicalChannelType.PSTN_OUT)
                        {
                            _listedItems.Add(new AnalogPhoneOutChannel(this, elements[1], values.ToArray()));
                        }
                        else if (type == SoundstructurePhysicalChannelType.PSTN_IN)
                        {
                            _listedItems.Add(new AnalogPhoneInChannel(this, elements[1], values.ToArray()));
                        }
                        else
                        {
                            _listedItems.Add(new VirtualChannel(this, elements[1],
                                                                (SoundstructureVirtualChannelType)Enum.Parse(typeof(SoundstructureVirtualChannelType), elements[2], true),
                                                                type, values.ToArray()));
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("Error parsing Soundstructure vcitem: {0}", e.Message);
                    }
                    break;

                case "vcgitem":
                {
                    List <ISoundstructureItem> channels = new List <ISoundstructureItem>();
                    if (elements.Count() > 2)
                    {
                        for (int e = 2; e < elements.Count(); e++)
                        {
                            if (VirtualChannels.Contains(elements[e]))
                            {
                                channels.Add(VirtualChannels[elements[e]]);
                            }
                        }
                        VirtualChannelGroup group = new VirtualChannelGroup(this, elements[1], channels);
                        _listedItems.Add(group);
                    }
                    else
                    {
                        ErrorLog.Warn("Ignoring Soundstructure group item {0} as it has no members", elements[1]);
                    }
                }
                break;

                case "vcrename":
                {
                    List <ISoundstructureItem> channels = new List <ISoundstructureItem>();
                    foreach (VirtualChannel channel in VirtualChannels)
                    {
                        if (channel.Name == elements[1])
                        {
                            VirtualChannel newChannel = new VirtualChannel(this, elements[2],
                                                                           channel.VirtualChannelType, channel.PhysicalChannelType, channel.PhysicalChannelIndex.ToArray());
                            channels.Add(newChannel);
                        }
                        else
                        {
                            channels.Add(channel);
                        }
                    }
                    VirtualChannels = new SoundstructureItemCollection(channels);
                }
                break;

                case "vcgrename":
                {
                    List <ISoundstructureItem> groups = new List <ISoundstructureItem>();
                    foreach (VirtualChannelGroup group in VirtualChannelGroups)
                    {
                        if (group.Name == elements[1])
                        {
                            List <ISoundstructureItem> channels = new List <ISoundstructureItem>();
                            foreach (VirtualChannel channel in group)
                            {
                                channels.Add(channel);
                            }
                            VirtualChannelGroup newGroup = new VirtualChannelGroup(this, elements[2], channels);
                            groups.Add(newGroup);
                        }
                        else
                        {
                            groups.Add(group);
                        }
                    }
                    VirtualChannelGroups = new SoundstructureItemCollection(groups);
                }
                break;

                case "val":
                    // this should be a value response from a set or get
                {
                    try
                    {
                        if (elements[1] == "eth_settings" && elements[2] == "1")
                        {
                            LanAdapter = new SoundstructureEthernetSettings(elements[3]);
                            break;
                        }

                        bool commandOK = false;
                        SoundstructureCommandType commandType = SoundstructureCommandType.FADER;

                        try
                        {
                            commandType = (SoundstructureCommandType)Enum.Parse(typeof(SoundstructureCommandType), elements[1], true);
                            commandOK   = true;
                        }
                        catch
                        {
                            if (elements[1].StartsWith("voip_") && VirtualChannels.Contains(elements[2]))
                            {
                                VirtualChannel channel = VirtualChannels[elements[2]] as VirtualChannel;
                                if (channel.IsVoip && VoipInfoReceived != null)
                                {
                                    string info = data.Substring(data.IndexOf(channel.Name) + channel.Name.Length + 2,
                                                                 data.Length - data.IndexOf(channel.Name) - channel.Name.Length - 2);
                                    VoipInfoReceived(channel, new SoundstructureVoipInfoReceivedEventArgs(elements[1], info));
                                }
                            }
                        }

                        if (commandOK)
                        {
                            switch (commandType)
                            {
                            case SoundstructureCommandType.MATRIX_MUTE:
#if DEBUG
                                CrestronConsole.PrintLine("Matrix Mute Input: \x22{0}\x22 Output: \x22{1}\x22 Value: {2}", elements[2], elements[3], elements[4]);
#endif
                                break;

                            case SoundstructureCommandType.FADER:
                                if (elements[2] == "min" || elements[2] == "max")
                                {
                                    OnValueChange(elements[3], commandType, elements[2], Convert.ToDouble(elements[4]));
                                }
                                else
                                {
                                    OnValueChange(elements[2], commandType, Convert.ToDouble(elements[3]));
                                }
                                break;

                            case SoundstructureCommandType.PHONE_DIAL:
                                // Cannot parse reply for string values and we don't currently need to track this.
                                break;

                            default:
                                if (elements.Count > 3)
                                {
                                    OnValueChange(elements[2], commandType, Convert.ToDouble(elements[3]));
                                }
                                break;
                            }

                            if (!Initialized && CheckAllItemsHaveInitialised())
                            {
                                Initialized = true;

                                ErrorLog.Notice("Soundstructure Initialised");
                                CrestronConsole.PrintLine("Soundstructure Initialised!");

                                if (HasInitialised != null)
                                {
                                    HasInitialised(this);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("Soundstructure Rx: {0}, Error: {1}", data, e.Message);
                    }
                }
                break;

                default:
                    break;
                }
            }
            else
            {
                if (data == "vclist")
                {
                    VirtualChannels = new SoundstructureItemCollection(_listedItems);
                    _listedItems.Clear();

                    _socket.Send("vcglist");
                }
                else if (data == "vcglist")
                {
                    VirtualChannelGroups = new SoundstructureItemCollection(_listedItems);
                    _listedItems.Clear();

                    foreach (ISoundstructureItem item in VirtualChannelGroups)
                    {
                        item.Init();
                    }

                    foreach (ISoundstructureItem item in VirtualChannels)
                    {
                        if (!ChannelIsGrouped(item))
                        {
                            item.Init();
                        }
                    }
                }
            }
        }
コード例 #3
0
        void VoipInfoReceived(ISoundstructureItem item, SoundstructureVoipInfoReceivedEventArgs args)
        {
            if (item != VoipOutChannel)
            {
                return;
            }
            var elements = SoundstructureSocket.ElementsFromString(args.Info);

            if (elements.Count <= 1)
            {
                return;
            }
            var lineNumber = uint.Parse(elements[0]);

            if (lineNumber != Number)
            {
                return;
            }
            try
            {
                switch (args.Command)
                {
                case "voip_line_state":
                    try
                    {
                        State = (VoipLineState)Enum.Parse(typeof(VoipLineState), elements[1], true);
                        if (StateChanged != null)
                        {
                            StateChanged(this, State);
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("Could not parse VoipLineState \"{2}\" for Line {0}, {1}",
                                       lineNumber, e.Message, elements[1]);
                    }
                    break;

                case "voip_line_label":
                    Label = elements[1];
                    break;

                case "voip_call_appearance_line":
                    CallAppearance = uint.Parse(elements[1]);
                    break;

                case "voip_call_appearance_state":
                    try
                    {
                        var state = (VoipCallAppearanceState)Enum.Parse(typeof(VoipCallAppearanceState), elements[1], true);
                        if (CallAppearanceState != state)
                        {
                            CallAppearanceState = state;
                            if (CallAppearanceState == VoipCallAppearanceState.Connected)
                            {
                                _callConnectedTime = DateTime.Now;
                            }
                        }
                        try
                        {
                            if (CallAppearanceStateChanged != null)
                            {
                                CallAppearanceStateChanged(this, new VoipLineCallAppearanceStateEventArgs(CallAppearance, CallAppearanceState));
                            }
                        }
                        catch (Exception e)
                        {
                            ErrorLog.Exception(string.Format("Error calling event {0}.CallAppearanceStateChanged", GetType().Name), e);
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("Could not parse VoipCallAppearanceState \"{0}\" for Line {1}, {2}", elements[1], lineNumber, e.Message);
                    }
                    break;

                case "voip_call_appearance_info":
                    // Not sure why this was > 3 instead of >= 3 !?!
                    if (elements.Count >= 3)
                    {
                        var lineIndex = uint.Parse(elements[1]);
                        _callInfoLine[lineIndex] = elements[2];
                        if (CallInfoLineChanged != null)
                        {
                            CallInfoLineChanged(this, new VoipLineCallInfoLineEventArgs(lineIndex, elements[2]));
                        }
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error parsing Voip feedback info in VoipLine[{0}], {1}", Number, e.Message);
                ErrorLog.Error("VoipInfoReceived() args.Command = \"{0}\" args.Info = \"{1}\"", args.Command, args.Info);
            }
        }
コード例 #4
0
 public Soundstructure(string hostAddress)
 {
     _socket = new SoundstructureSocket(hostAddress);
     _socket.ReceivedData  += SocketOnReceivedData;
     _socket.StatusChanged += SocketOnStatusChanged;
 }