예제 #1
0
        protected virtual void OnVoipInfoReceived(string command, string info)
        {
#if DEBUG
            CrestronConsole.PrintLine("{0}, {1} = {2}", this.Name, command, info);
            CrestronConsole.Print("  elements =");
            foreach (string element in SoundstructureSocket.ElementsFromString(info))
            {
                CrestronConsole.Print(" {0}", element);
            }
            CrestronConsole.PrintLine("");
#endif
        }
예제 #2
0
        void VoipInfoReceived(ISoundstructureItem item, SoundstructureVoipInfoReceivedEventArgs args)
        {
            if (item == this.VoipOutChannel)
            {
                List <string> elements = SoundstructureSocket.ElementsFromString(args.Info);
                if (elements.Count > 1)
                {
                    uint lineNumber = uint.Parse(elements[0]);
                    if (lineNumber == this.Number)
                    {
                        try
                        {
                            switch (args.Command)
                            {
                            case "voip_line_state":
                                try
                                {
                                    this.State = (VoipLineState)Enum.Parse(typeof(VoipLineState), elements[1], true);
                                    if (StateChanged != null)
                                    {
                                        StateChanged(this, 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":
                                this.Label = elements[1];
                                break;

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

                            case "voip_call_appearance_state":
                                try
                                {
                                    VoipCallAppearanceState state = (VoipCallAppearanceState)Enum.Parse(typeof(VoipCallAppearanceState), elements[1], true);
                                    if (this.CallAppearanceState != state)
                                    {
                                        this.CallAppearanceState = state;
                                        if (CallAppearanceState == VoipCallAppearanceState.Connected)
                                        {
                                            _CallConnectedTime = DateTime.Now;
                                        }
                                    }
                                    try
                                    {
                                        if (CallAppearanceStateChanged != null)
                                        {
                                            CallAppearanceStateChanged(this, new VoipLineCallAppearanceStateEventArgs(this.CallAppearance, this.CallAppearanceState));
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        ErrorLog.Exception(string.Format("Error calling event {0}.CallAppearanceStateChanged", this.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":
                                if (elements.Count > 3)
                                {
                                    uint 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}", this.Number, e.Message);
                            ErrorLog.Error("VoipInfoReceived() args.Command = \"{0}\" args.Info = \"{1}\"", args.Command, args.Info);
                        }
                    }
                }
            }
        }
예제 #3
0
        public void OnReceive(string receivedString)
        {
#if DEBUG
            CrestronConsole.PrintLine("Soundstructure Rx: {0}", receivedString);
#endif
            if (!this.DeviceCommunicating)
            {
                this.DeviceCommunicating = true;
                this.FusionUpdate();
                if (this.DeviceCommunicatingChanged != null)
                {
                    this.DeviceCommunicatingChanged(this, true);
                }
            }

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

                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 (this.VirtualChannels.Contains(elements[e]))
                            {
                                channels.Add(this.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 this.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);
                        }
                    }
                    this.VirtualChannels = new SoundstructureItemCollection(channels);
                }
                break;

                case "vcgrename":
                {
                    List <ISoundstructureItem> groups = new List <ISoundstructureItem>();
                    foreach (VirtualChannelGroup group in this.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);
                        }
                    }
                    this.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")
                        {
                            this.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_") && this.VirtualChannels.Contains(elements[2]))
                            {
                                VirtualChannel channel = this.VirtualChannels[elements[2]] as VirtualChannel;
                                if (channel.IsVoip && VoipInfoReceived != null)
                                {
                                    string info = receivedString.Substring(receivedString.IndexOf(channel.Name) + channel.Name.Length + 2,
                                                                           receivedString.Length - receivedString.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}", receivedString, e.Message);
                    }
                }
                break;

                default:
                    break;
                }
            }
            else
            {
                if (receivedString == "vclist")
                {
                    this.VirtualChannels = new SoundstructureItemCollection(listedItems);
                    listedItems.Clear();

                    Socket.Send("vcglist");
                }
                else if (receivedString == "vcglist")
                {
                    this.VirtualChannelGroups = new SoundstructureItemCollection(listedItems);
                    listedItems.Clear();

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

                    foreach (ISoundstructureItem item in VirtualChannels)
                    {
                        if (!ChannelIsGrouped(item))
                        {
                            item.Init();
                        }
                    }
                }
            }
        }
예제 #4
0
 public Soundstructure(string hostAddress)
 {
     Socket = new SoundstructureSocket(this, hostAddress);
     Socket.ReceivedData  += new TCPSocketReceivedDataEventHandler(Socket_ReceivedData);
     Socket.StatusChanged += new TCPSocketStatusChangeEventHandler(Socket_StatusChanged);
 }