Example #1
0
        internal VirtualChannel(Soundstructure device, string name, SoundstructureVirtualChannelType vcType, SoundstructurePhysicalChannelType pcType, uint[] values)
        {
            Device              = device;
            Device.ValueChange += Device_ValueChange;
            Name = name;
            VirtualChannelType    = vcType;
            PhysicalChannelType   = pcType;
            _physicalChannelIndex = new List <uint>(values);

#if DEBUG
            CrestronConsole.Print("Received {0} with name: {1}, Virtual Type: {2}, Physical Type: {3} Values:",
                                  GetType().ToString().Split('.').Last(), Name, VirtualChannelType.ToString(), PhysicalChannelType.ToString());

            foreach (var value in PhysicalChannelIndex)
            {
                CrestronConsole.Print(" {0}", value);
            }

            CrestronConsole.PrintLine("");
#endif
        }
Example #2
0
 public VoipChannel(Soundstructure device, string name, SoundstructurePhysicalChannelType pcType, uint[] values)
     : base(device, name, SoundstructureVirtualChannelType.MONO, pcType, values)
 {
     Device.VoipInfoReceived += Device_VoipInfoReceived;
 }
Example #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();
                        }
                    }
                }
            }
        }