protected override void _UpdateState(Command[] outputStates)
        {
            Stopwatch stopWatch     = Stopwatch.StartNew();
            var       channelValues = outputStates.ToChannelValuesAsBytes();

            this._eventCnt++;

            foreach (var uE in this._universeTable)
            {
                if (uE.Active)
                {
                    if (this._eventRepeatCount > 0)
                    {
                        if (uE.EventRepeatCount-- > 0)
                        {
                            if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, uE.Size))
                            {
                                continue;
                            }
                        }
                    }

                    E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, uE.Size, this._seqNum++);
                    uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint);
                    uE.EventRepeatCount = this._eventRepeatCount;

                    uE.PktCount++;
                    uE.SlotCount += uE.Size;
                }
            }

            stopWatch.Stop();

            this._totalTicks += stopWatch.ElapsedTicks;
        }
Exemple #2
0
        // -------------------------------------------------------------
        //
        // 	Startup() - called when the plugin is loaded
        //
        //
        // 	todo:
        //
        // 		1) probably add error checking on all 'new' operations
        // 		and system calls
        //
        // 		2) better error reporting and logging
        //
        //      3) Sequence # should be per universe
        //
        // -------------------------------------------------------------
        public override void Start()
        {
            bool cleanStart = true;

            base.Start();

            if(!PluginInstances.Contains(this))
                PluginInstances.Add(this);

            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList<string, Socket>();

            // load all of our xml into working objects
            this.LoadSetupNodeInfo();

            // initialize plugin wide stats
            this._eventCnt = 0;
            this._totalTicks = 0;

            if (_data.Unicast == null && _data.Multicast == null)
                if (_data.Universes[0] != null && (_data.Universes[0].Multicast != null || _data.Universes[0].Unicast != null))
                {
                    _data.Unicast = _data.Universes[0].Unicast;
                    _data.Multicast = _data.Universes[0].Multicast;
                    if(!_updateWarn){
                        //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                        MessageBoxForm.msgIcon = SystemIcons.Information; //this is used if you want to add a system icon to the message form.
                        var messageBox = new MessageBoxForm("The E1.31 plugin is importing data from an older version of the plugin. Please verify the new Streaming ACN (E1.31) configuration.", "Vixen 3 Streaming ACN (E1.31) plugin", false, false);
                        messageBox.ShowDialog();
                        _updateWarn = true;
                    }
                }

            // find all of the network interfaces & build a sorted list indexed by Id
            this._nicTable = new SortedList<string, NetworkInterface>();

            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var nic in nics)
            {
                if (nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                    this._nicTable.Add(nic.Id, nic);
                }
            }

            if (_data.Unicast != null)
            {
                if (!unicasts.ContainsKey(_data.Unicast))
                {
                    unicasts.Add(_data.Unicast, 0);
                }
            }

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();

            // now we need to scan the universeTable
            foreach (var uE in _data.Universes)
            {
                // if it's still active we'll look into making a socket for it
                if (cleanStart && uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (_data.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        IPAddress[] ips = null;

                        try
                        {
                            ips = Dns.GetHostAddresses(_data.Unicast);
                        }
                        catch
                        {
                            //Probably couldn't find the host name
                            NLog.LogManager.GetCurrentClassLogger().Warn("Couldn't connect to host "+_data.Unicast+".");
                            cleanStart = false;
                        }

                        if (ips != null)
                        {
                            IPAddress ip = null;
                            foreach (IPAddress i in ips)
                                if (i.AddressFamily == AddressFamily.InterNetwork)
                                    ip = i;

                            // try to parse our ip address
                            if (ip == null)
                            {
                                // oops - bad ip, fuss and deactivate
                                NLog.LogManager.GetCurrentClassLogger().Warn("Couldn't connect to host " + _data.Unicast + ".");
                                cleanStart = false;
                                uE.Socket = null;
                            }
                            else
                            {
                                // if good, make our destination endpoint
                                uE.DestIpEndPoint = new IPEndPoint(ip, 5568);
                            }
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    else if (_data.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(_data.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            NLog.LogManager.GetCurrentClassLogger().Warn("Couldn't connect to use nic " + _data.Multicast + " for multicasting.");
                            if (!_missingInterfaceWarning)
                            {
                                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                                MessageBoxForm.msgIcon = SystemIcons.Warning; //this is used if you want to add a system icon to the message form.
                                var messageBox = new MessageBoxForm("The Streaming ACN (E1.31) plugin could not find one or more of the multicast interfaces specified. Please verify your network and plugin configuration.", "Vixen 3 Streaming ACN (E1.31) plugin", false, false);
                                messageBox.ShowDialog();
                                _missingInterfaceWarning = true;
                            }
                            cleanStart = false;
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[_data.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(_data.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[_data.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }
                            // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                NLog.LogManager.GetCurrentClassLogger().Warn("Nic " + _data.Multicast + " is available for multicasting bur currently down.");
                                cleanStart = false;
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;

                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(string.Format("No IP On Multicast Interface: {0} - {1}" , networkInterface.Name , uE.InfoToText));
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 64);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(_data.Multicast, uE.Socket);
                                }
                            }
                        }
                    }
                    else
                    {
                        NLog.LogManager.GetCurrentClassLogger().Warn("E1.31 plugin failed to start due to unassigned destinations. This can happen with newly created plugin instances that have yet to be configured.");
                        cleanStart = false;
                    }

                    // if still active we need to create an empty packet
                    if (cleanStart)
                    {
                        var zeroBfr = new byte[uE.Size];
                        var e131Packet = new E131Packet(_data.ModuleInstanceId, "Vixen 3", 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size, _data.Priority, _data.Blind);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
                if(cleanStart)
                    running = true;
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (_data.Warnings)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }

            #if VIXEN21
            return new List<Form> {};
            #endif
        }
        // -------------------------------------------------------------
        //
        // 	Startup() - called when a sequence is executed
        //
        //
        // 	todo:
        //
        // 		1) probably add error checking on all 'new' operations
        // 		and system calls
        //
        // 		2) better error reporting and logging
        //
        // -------------------------------------------------------------
        public void Startup()
        {
            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList<string, Socket>();

            // reload all of our xml into working objects
            this.LoadSetupNodeInfo();

            // initialize plugin wide stats
            this._eventCnt = 0;
            this._totalTicks = 0;

            // initialize sequence # for E1.31 packet (should it be per universe?)
            this._seqNum = 0;

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();

            // check for configured from/to
            if (this._pluginChannelsFrom == 0 && this._pluginChannelsTo == 0)
            {
                foreach (var uE in this._universeTable)
                {
                    uE.Active = false;
                }

                this._messageTexts.AppendLine("Plugin Channels From/To Configuration Error!!");
            }

            // now we need to scan the universeTable
            foreach (var uE in this._universeTable)
            {
                // active? - check universeentry start and size
                if (uE.Active)
                {
                    // is start out of range?
                    if (this._pluginChannelsFrom + uE.Start > this._pluginChannelsTo)
                    {
                        this._messageTexts.AppendLine("Start Error - " + uE.InfoToText);
                        uE.Active = false;
                    }

                    // is size (end) out of range?
                    if (this._pluginChannelsFrom + uE.Start + uE.Size - 1 > this._pluginChannelsTo)
                    {
                        this._messageTexts.AppendLine("Start/Size Error - " + uE.InfoToText);
                        uE.Active = false;
                    }
                }

                // if it's still active we'll look into making a socket for it
                if (uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (uE.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        // try to parse our ip address
                        if (!IPAddress.TryParse(uE.Unicast, out ipAddress))
                        {
                            // oops - bad ip, fuss and deactivate
                            uE.Active = false;
                            uE.Socket = null;
                            this._messageTexts.AppendLine(
                                "Invalid Unicast IP: " + uE.Unicast + " - " + uE.RowUnivToText);
                        }
                        else
                        {
                            // if good, make our destination endpoint
                            uE.DestIpEndPoint = new IPEndPoint(ipAddress, 5568);
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    if (uE.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(uE.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            uE.Active = false;
                            this._messageTexts.AppendLine(
                                "Invalid Multicast NIC ID: " + uE.Multicast + " - " + uE.RowUnivToText);
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[uE.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(uE.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[uE.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }

                                // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                uE.Active = false;
                                this._messageTexts.AppendLine(
                                    "Multicast Interface Down: " + networkInterface.Name + " - " + uE.RowUnivToText);
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;

                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(
                                        "No IP On Multicast Interface: " + networkInterface.Name + " - " + uE.InfoToText);
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, uE.Ttl);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(uE.Multicast, uE.Socket);
                                }
                            }
                        }
                    }

                    // if still active we need to create an empty packet
                    if (uE.Active)
                    {
                        var zeroBfr = new byte[uE.Size];
                        var e131Packet = new E131Packet(this._guid, string.Empty, 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (this._warningsOption)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }

            // MessageBox.Show("Startup");
            #if VIXEN21
            return new List<Form> {};
            #endif
        }
        // -------------------------------------------------------------
        //
        //  Startup() - called when a sequence is executed
        //
        //
        //  todo:
        //
        //      1) probably add error checking on all 'new' operations
        //      and system calls
        //
        //      2) better error reporting and logging
        //
        // -------------------------------------------------------------
        public void Startup()
        {
            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList <string, Socket>();

            // reload all of our xml into working objects
            this.LoadSetupNodeInfo();

            // initialize plugin wide stats
            this._eventCnt   = 0;
            this._totalTicks = 0;

            // initialize sequence # for E1.31 packet (should it be per universe?)
            this._seqNum = 0;

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();

            // check for configured from/to
            if (this._pluginChannelsFrom == 0 && this._pluginChannelsTo == 0)
            {
                foreach (var uE in this._universeTable)
                {
                    uE.Active = false;
                }

                this._messageTexts.AppendLine("Plugin Channels From/To Configuration Error!!");
            }

            // now we need to scan the universeTable
            foreach (var uE in this._universeTable)
            {
                // active? - check universeentry start and size
                if (uE.Active)
                {
                    // is start out of range?
                    if (this._pluginChannelsFrom + uE.Start > this._pluginChannelsTo)
                    {
                        this._messageTexts.AppendLine("Start Error - " + uE.InfoToText);
                        uE.Active = false;
                    }

                    // is size (end) out of range?
                    if (this._pluginChannelsFrom + uE.Start + uE.Size - 1 > this._pluginChannelsTo)
                    {
                        this._messageTexts.AppendLine("Start/Size Error - " + uE.InfoToText);
                        uE.Active = false;
                    }
                }

                // if it's still active we'll look into making a socket for it
                if (uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (uE.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        // try to parse our ip address
                        if (!IPAddress.TryParse(uE.Unicast, out ipAddress))
                        {
                            // oops - bad ip, fuss and deactivate
                            uE.Active = false;
                            uE.Socket = null;
                            this._messageTexts.AppendLine(
                                "Invalid Unicast IP: " + uE.Unicast + " - " + uE.RowUnivToText);
                        }
                        else
                        {
                            // if good, make our destination endpoint
                            uE.DestIpEndPoint = new IPEndPoint(ipAddress, 5568);
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    if (uE.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(uE.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            uE.Active = false;
                            this._messageTexts.AppendLine(
                                "Invalid Multicast NIC ID: " + uE.Multicast + " - " + uE.RowUnivToText);
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[uE.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(uE.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[uE.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }

                            // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                uE.Active = false;
                                this._messageTexts.AppendLine(
                                    "Multicast Interface Down: " + networkInterface.Name + " - " + uE.RowUnivToText);
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;

                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(
                                        "No IP On Multicast Interface: " + networkInterface.Name + " - " + uE.InfoToText);
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, uE.Ttl);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(uE.Multicast, uE.Socket);
                                }
                            }
                        }
                    }

                    // if still active we need to create an empty packet
                    if (uE.Active)
                    {
                        var zeroBfr    = new byte[uE.Size];
                        var e131Packet = new E131Packet(this._guid, string.Empty, 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (this._warningsOption)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }

            // MessageBox.Show("Startup");
#if VIXEN21
            return(new List <Form> {
            });
#endif
        }
        // -------------------------------------------------------------
        //
        //  Startup() - called when the plugin is loaded
        //
        //
        //  todo:
        //
        //      1) probably add error checking on all 'new' operations
        //      and system calls
        //
        //      2) better error reporting and logging
        //
        //      3) Sequence # should be per universe
        //
        // -------------------------------------------------------------
        public override void Start()
        {
            bool cleanStart = true;

            base.Start();

            if (!PluginInstances.Contains(this))
            {
                PluginInstances.Add(this);
            }

            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList <string, Socket>();

            // load all of our xml into working objects
            this.LoadSetupNodeInfo();


            // initialize plugin wide stats
            this._eventCnt   = 0;
            this._totalTicks = 0;

            if (_data.Unicast == null && _data.Multicast == null)
            {
                if (_data.Universes[0] != null && (_data.Universes[0].Multicast != null || _data.Universes[0].Unicast != null))
                {
                    _data.Unicast   = _data.Universes[0].Unicast;
                    _data.Multicast = _data.Universes[0].Multicast;
                    if (!_updateWarn)
                    {
                        //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                        MessageBoxForm.msgIcon = SystemIcons.Information;
                        //this is used if you want to add a system icon to the message form.
                        var messageBox =
                            new MessageBoxForm(
                                "The E1.31 plugin is importing data from an older version of the plugin. Please verify the new Streaming ACN (E1.31) configuration.",
                                "Vixen 3 Streaming ACN (E1.31) plugin", false, false);
                        messageBox.ShowDialog();
                        _updateWarn = true;
                    }
                }
            }

            // find all of the network interfaces & build a sorted list indexed by Id
            this._nicTable = new SortedList <string, NetworkInterface>();

            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var nic in nics)
            {
                if (nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel &&
                    nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                    this._nicTable.Add(nic.Id, nic);
                }
            }

            if (_data.Unicast != null)
            {
                if (!unicasts.ContainsKey(_data.Unicast))
                {
                    unicasts.Add(_data.Unicast, 0);
                }
            }

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();

            // now we need to scan the universeTable
            foreach (var uE in _data.Universes)
            {
                // if it's still active we'll look into making a socket for it
                if (cleanStart && uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (_data.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        IPAddress[] ips = null;

                        try
                        {
                            ips = Dns.GetHostAddresses(_data.Unicast);
                        }
                        catch
                        {
                            //Probably couldn't find the host name
                            NLog.LogManager.GetCurrentClassLogger().Warn("Couldn't connect to host " + _data.Unicast + ".");
                            cleanStart = false;
                        }

                        if (ips != null)
                        {
                            IPAddress ip = null;
                            foreach (IPAddress i in ips)
                            {
                                if (i.AddressFamily == AddressFamily.InterNetwork)
                                {
                                    ip = i;
                                }
                            }

                            // try to parse our ip address
                            if (ip == null)
                            {
                                // oops - bad ip, fuss and deactivate
                                NLog.LogManager.GetCurrentClassLogger().Warn("Couldn't connect to host " + _data.Unicast + ".");
                                cleanStart = false;
                                uE.Socket  = null;
                            }
                            else
                            {
                                // if good, make our destination endpoint
                                uE.DestIpEndPoint = new IPEndPoint(ip, 5568);
                            }
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    else if (_data.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(_data.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            NLog.LogManager.GetCurrentClassLogger()
                            .Warn("Couldn't connect to use nic " + _data.Multicast + " for multicasting.");
                            if (!_missingInterfaceWarning)
                            {
                                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                                MessageBoxForm.msgIcon = SystemIcons.Warning;
                                //this is used if you want to add a system icon to the message form.
                                var messageBox =
                                    new MessageBoxForm(
                                        "The Streaming ACN (E1.31) plugin could not find one or more of the multicast interfaces specified. Please verify your network and plugin configuration.",
                                        "Vixen 3 Streaming ACN (E1.31) plugin", false, false);
                                messageBox.ShowDialog();
                                _missingInterfaceWarning = true;
                            }
                            cleanStart = false;
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[_data.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(_data.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[_data.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }
                            // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                NLog.LogManager.GetCurrentClassLogger()
                                .Warn("Nic " + _data.Multicast + " is available for multicasting bur currently down.");
                                cleanStart = false;
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;


                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(string.Format("No IP On Multicast Interface: {0} - {1}", networkInterface.Name,
                                                                                uE.InfoToText));
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 64);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(_data.Multicast, uE.Socket);
                                }
                            }
                        }
                    }
                    else
                    {
                        NLog.LogManager.GetCurrentClassLogger()
                        .Warn(
                            "E1.31 plugin failed to start due to unassigned destinations. This can happen with newly created plugin instances that have yet to be configured.");
                        cleanStart = false;
                    }

                    // if still active we need to create an empty packet
                    if (cleanStart)
                    {
                        var zeroBfr    = new byte[uE.Size];
                        var e131Packet = new E131Packet(_data.ModuleInstanceId, "Vixen 3", 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size,
                                                        _data.Priority, _data.Blind);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
                if (cleanStart)
                {
                    running = true;
                }
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (_data.Warnings)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }


#if VIXEN21
            return(new List <Form> {
            });
#endif
        }
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            _updateStateStopWatch.Start();

            //Make sure the setup form is closed & the plugin has started
            if (isSetupOpen || !running)
            {
                return;
            }

            if (_data.Universes == null || _data.Universes.Count == 0)
            {
                return;
            }

            if (channelValues == null || channelValues.Length != outputStates.Length)
            {
                channelValues = new byte[outputStates.Length];
            }

            for (int index = 0; index < outputStates.Length; index++)
            {
                if (outputStates[index] is _8BitCommand command)
                {
                    channelValues[index] = command.CommandValue;
                }
                else
                {
                    // State reset
                    channelValues[index] = 0;
                }
            }

            _eventCnt++;

            foreach (var uE in _data.Universes)
            {
                //Not sure why phybuf can be null, but the plugin will crash after being reconfigured otherwise.
                if (uE.PhyBuffer == null)
                {
                    continue;
                }

                //Check if the universe is active and inside a valid channel range
                if (!uE.Active || uE.Start >= OutputCount || !running)
                {
                    continue;
                }

                //Check the universe size boundary.
                int universeSize;
                if ((uE.Start + uE.Size) > OutputCount)
                {
                    universeSize = OutputCount - uE.Start;
                }
                else
                {
                    universeSize = uE.Size;
                }

                // Reduce duplicate packets...
                // -the data. counts are the targets
                // -the uE. counts are how many have happened

                // do we want to suppress this one?  compare to last frame sent
                bool sendit = true;
                bool issame = _data.EventRepeatCount > 0 &&
                              E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize);
                if (issame)
                {
                    // we allow the first event repeat count dups
                    if (_data.EventRepeatCount > 0 && ++uE.EventRepeatCount >= _data.EventRepeatCount)
                    {
                        sendit = false;
                        // we want to suppress, but should we force it anyway?
                        if (_data.EventSuppressCount > 0 && ++uE.EventSuppressCount >= _data.EventSuppressCount)
                        {
                            sendit = true;
                            uE.EventSuppressCount = 0;
                        }
                    }
                }
                else
                {
                    // it's different so will go... clear counters
                    // hopefully this happens within the 7.7 months it will take them to overflow :-)
                    uE.EventRepeatCount   = 0;
                    uE.EventSuppressCount = 0;
                }

                if (sendit)
                {
                    //SeqNumbers are per universe so that they can run independently
                    E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++);
                    uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint);
                    uE.PktCount++;
                    uE.SlotCount += uE.Size;
                }
            }
            _updateStateStopWatch.Stop();

            this._totalTicks += _updateStateStopWatch.ElapsedTicks;
        }
Exemple #7
0
        // -------------------------------------------------------------
        //
        // 	Startup() - called when the plugin is loaded
        //
        //
        // 	todo:
        //
        // 		1) probably add error checking on all 'new' operations
        // 		and system calls
        //
        // 		2) better error reporting and logging
        //
        //      3) Sequence # should be per universe
        //
        // -------------------------------------------------------------
        public override void Start()
        {
            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList<string, Socket>();

            // Load the NICs and XML file
            this.Initialize();

            // initialize plugin wide stats
            this._eventCnt = 0;
            this._totalTicks = 0;

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();

            // now we need to scan the universeTable
            foreach (var uE in _data.Universes)
            {
                // if it's still active we'll look into making a socket for it
                if (uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (uE.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        // try to parse our ip address
                        if (!IPAddress.TryParse(uE.Unicast, out ipAddress))
                        {
                            // oops - bad ip, fuss and deactivate
                            uE.Active = false;
                            uE.Socket = null;
                            this._messageTexts.AppendLine(string.Format("Invalid Unicast IP: {0} - {1}", uE.Unicast, uE.RowUnivToText));
                        }
                        else
                        {
                            // if good, make our destination endpoint
                            uE.DestIpEndPoint = new IPEndPoint(ipAddress, 5568);
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    else if (uE.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(uE.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            uE.Active = false;
                            this._messageTexts.AppendLine(string.Format("Invalid Multicast NIC ID: {0} - {1}", uE.Multicast, uE.RowUnivToText));
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[uE.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(uE.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[uE.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }
                            // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                uE.Active = false;
                                this._messageTexts.AppendLine(string.Format("Multicast Interface Down: {0} - {1}", networkInterface.Name , uE.RowUnivToText));
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;

                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(string.Format("No IP On Multicast Interface: {0} - {1}" , networkInterface.Name , uE.InfoToText));
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, uE.Ttl);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(uE.Multicast, uE.Socket);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new System.Exception("no uni or multi cast");
                    }

                    // if still active we need to create an empty packet
                    if (uE.Active)
                    {
                        var zeroBfr = new byte[uE.Size];
                        for (int i = 0; i < uE.Size; i++)  // init to unlikely value for later compares
                            zeroBfr[i] = (byte)i;
                        var e131Packet = new E131Packet(_data.ModuleInstanceId, string.Empty, 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
                hasStarted = true;
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (_data.Warnings)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }

            #if VIXEN21
            return new List<Form> {};
            #endif
        }
Exemple #8
0
        public void UpdateState(int chainIndex, byte[] channelValues)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            //Make sure the setup form is closed & the plugin has started
            if (isSetupOpen && hasStarted)
            {
                return;
            }
            DateTime lastUpdate;

            // no longer used, but I'm leaving it just in case we need it later...

            /*
             * if (channelValues.Where(w => w == 0).Count() == channelValues.Length)
             * {
             * if (outputStateDictionary.TryGetValue(chainIndex, out lastUpdate))
             * {
             *              if( DateTime.Now - lastUpdate < TimeSpan.FromSeconds(1))
             * return;
             * }
             * outputStateDictionary[chainIndex] = DateTime.Now;
             * }
             * else
             * {
             * outputStateDictionary.TryRemove(chainIndex, out lastUpdate);
             * }
             */

            int universeSize = 0;

            this._eventCnt++;

            if (_data.Universes == null || _data.Universes.Count == 0)
            {
                return;
            }

            foreach (var uE in _data.Universes)
            {
                //Not sure why phybuf can be null, but the plugin will crash after being reconfigured otherwise.
                if (uE.PhyBuffer == null)
                {
                    continue;
                }

                //Check if the universe is active and inside a valid channel range
                if (!uE.Active || uE.Start >= OutputCount)
                {
                    continue;
                }

                //Check the universe size boundary.
                if ((uE.Start + uE.Size) > OutputCount)
                {
                    universeSize = OutputCount - uE.Start;
                }
                else
                {
                    universeSize = uE.Size;
                }

                // Reduce duplicate packets...
                // -the data. counts are the targets
                // -the uE. counts are how many have happened

                // do we want to suppress this one?  compare to last frame sent
                bool sendit = true;
                bool issame = E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize);
                if (issame)
                {
                    // we allow the first event repeat count dups
                    if (_data.EventRepeatCount > 0 && ++uE.EventRepeatCount >= _data.EventRepeatCount)
                    {
                        sendit = false;
                        // we want to suppress, but should we force it anyway?
                        if (_data.EventSuppressCount > 0 && ++uE.EventSuppressCount >= _data.EventSuppressCount)
                        {
                            sendit = true;
                            uE.EventSuppressCount = 0;
                        }
                    }
                }
                else
                {
                    // it's different so will go... clear counters
                    // hopefully this happens within the 7.7 months it will take them to overflow :-)
                    uE.EventRepeatCount   = 0;
                    uE.EventSuppressCount = 0;
                }

                if (sendit)
                {
                    //SeqNumbers are per universe so that they can run independently
                    E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++);
                    uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint);
                    uE.PktCount++;
                    uE.SlotCount += uE.Size;
                }
            }
            stopWatch.Stop();

            this._totalTicks += stopWatch.ElapsedTicks;
        }
Exemple #9
0
        // -------------------------------------------------------------
        //
        //  Startup() - called when the plugin is loaded
        //
        //
        //  todo:
        //
        //      1) probably add error checking on all 'new' operations
        //      and system calls
        //
        //      2) better error reporting and logging
        //
        //      3) Sequence # should be per universe
        //
        // -------------------------------------------------------------
        public override void Start()
        {
            // working copy of networkinterface object
            NetworkInterface networkInterface;

            // a single socket to use for unicast (if needed)
            Socket unicastSocket = null;

            // working ipaddress object
            IPAddress ipAddress = null;

            // a sortedlist containing the multicast sockets we've already done
            var nicSockets = new SortedList <string, Socket>();

            // Load the NICs and XML file
            this.Initialize();

            // initialize plugin wide stats
            this._eventCnt   = 0;
            this._totalTicks = 0;

            // initialize messageTexts stringbuilder to hold all warnings/errors
            this._messageTexts = new StringBuilder();


            // now we need to scan the universeTable
            foreach (var uE in _data.Universes)
            {
                // if it's still active we'll look into making a socket for it
                if (uE.Active)
                {
                    // if it's unicast it's fairly easy to do
                    if (uE.Unicast != null)
                    {
                        // is this the first unicast universe?
                        if (unicastSocket == null)
                        {
                            // yes - make a new socket to use for ALL unicasts
                            unicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                        }

                        // use the common unicastsocket
                        uE.Socket = unicastSocket;

                        // try to parse our ip address
                        if (!IPAddress.TryParse(uE.Unicast, out ipAddress))
                        {
                            // oops - bad ip, fuss and deactivate
                            uE.Active = false;
                            uE.Socket = null;
                            this._messageTexts.AppendLine(string.Format("Invalid Unicast IP: {0} - {1}", uE.Unicast, uE.RowUnivToText));
                        }
                        else
                        {
                            // if good, make our destination endpoint
                            uE.DestIpEndPoint = new IPEndPoint(ipAddress, 5568);
                        }
                    }

                    // if it's multicast roll up your sleeves we've got work to do
                    else if (uE.Multicast != null)
                    {
                        // create an ipaddress object based on multicast universe ip rules
                        var multicastIpAddress =
                            new IPAddress(new byte[] { 239, 255, (byte)(uE.Universe >> 8), (byte)(uE.Universe & 0xff) });

                        // create an ipendpoint object based on multicast universe ip/port rules
                        var multicastIpEndPoint = new IPEndPoint(multicastIpAddress, 5568);

                        // first check for multicast id in nictable
                        if (!this._nicTable.ContainsKey(uE.Multicast))
                        {
                            // no - deactivate and scream & yell!!
                            uE.Active = false;
                            this._messageTexts.AppendLine(string.Format("Invalid Multicast NIC ID: {0} - {1}", uE.Multicast, uE.RowUnivToText));
                        }
                        else
                        {
                            // yes - let's get a working networkinterface object
                            networkInterface = this._nicTable[uE.Multicast];

                            // have we done this multicast id before?
                            if (nicSockets.ContainsKey(uE.Multicast))
                            {
                                // yes - easy to do - use existing socket
                                uE.Socket = nicSockets[uE.Multicast];

                                // setup destipendpoint based on multicast universe ip rules
                                uE.DestIpEndPoint = multicastIpEndPoint;
                            }
                            // is the interface up?
                            else if (networkInterface.OperationalStatus != OperationalStatus.Up)
                            {
                                // no - deactivate and scream & yell!!
                                uE.Active = false;
                                this._messageTexts.AppendLine(string.Format("Multicast Interface Down: {0} - {1}", networkInterface.Name, uE.RowUnivToText));
                            }
                            else
                            {
                                // new interface in 'up' status - let's make a new udp socket
                                uE.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                                // get a working copy of ipproperties
                                IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();

                                // get a working copy of all unicasts
                                UnicastIPAddressInformationCollection unicasts = ipProperties.UnicastAddresses;


                                ipAddress = null;

                                foreach (var unicast in unicasts)
                                {
                                    if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                                    {
                                        ipAddress = unicast.Address;
                                    }
                                }

                                if (ipAddress == null)
                                {
                                    this._messageTexts.AppendLine(string.Format("No IP On Multicast Interface: {0} - {1}", networkInterface.Name, uE.InfoToText));
                                }
                                else
                                {
                                    // set the multicastinterface option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP,
                                        SocketOptionName.MulticastInterface,
                                        ipAddress.GetAddressBytes());

                                    // set the multicasttimetolive option
                                    uE.Socket.SetSocketOption(
                                        SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, uE.Ttl);

                                    // setup destipendpoint based on multicast universe ip rules
                                    uE.DestIpEndPoint = multicastIpEndPoint;

                                    // add this socket to the socket table for reuse
                                    nicSockets.Add(uE.Multicast, uE.Socket);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new System.Exception("no uni or multi cast");
                    }

                    // if still active we need to create an empty packet
                    if (uE.Active)
                    {
                        var zeroBfr = new byte[uE.Size];
                        for (int i = 0; i < uE.Size; i++)                          // init to unlikely value for later compares
                        {
                            zeroBfr[i] = (byte)i;
                        }
                        var e131Packet = new E131Packet(_data.ModuleInstanceId, string.Empty, 0, (ushort)uE.Universe, zeroBfr, 0, uE.Size);
                        uE.PhyBuffer = e131Packet.PhyBuffer;
                    }
                }
                hasStarted = true;
            }

            // any warnings/errors recorded?
            if (this._messageTexts.Length > 0)
            {
                // should we display them
                if (_data.Warnings)
                {
                    // show our warnings/errors
                    J1MsgBox.ShowMsg(
                        "The following warnings and errors were detected during startup:",
                        this._messageTexts.ToString(),
                        "Startup Warnings/Errors",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    // discard warning/errors after reporting them
                    this._messageTexts = new StringBuilder();
                }
            }


#if VIXEN21
            return(new List <Form> {
            });
#endif
        }
        public void UpdateState(int chainIndex, byte[] channelValues)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            //Make sure the setup form is closed & the plugin has started
            if (isSetupOpen && hasStarted)
            {
                return;
            }
            DateTime lastUpdate;

            if (channelValues.Where(w => w == 0).Count() == channelValues.Length)
            {
                if (outputStateDictionary.TryGetValue(chainIndex, out lastUpdate))
                {
                    return;
                }
                else
                {
                    outputStateDictionary[chainIndex] = DateTime.Now;
                }
            }
            else
            {
                outputStateDictionary.TryRemove(chainIndex, out lastUpdate);
            }
            int universeSize = 0;

            this._eventCnt++;

            if (_data.Universes == null || _data.Universes.Count == 0)
            {
                return;
            }

            foreach (var uE in _data.Universes)
            {
                //Check if the universe is active and inside a valid channel range
                if (uE.Active && (uE.Start + 1) <= OutputCount)
                {
                    //Check the universe size boundary.
                    if ((uE.Start + 1 + uE.Size) > OutputCount)
                    {
                        universeSize = OutputCount - uE.Start - 1;
                    }
                    else
                    {
                        universeSize = uE.Size;
                    }


                    //Reduce duplicate packets
                    //SeqNumbers are per universe so that they can run independently
                    if (_data.EventRepeatCount > 0)
                    {
                        if (uE.EventRepeatCount-- > 0)
                        {
                            if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize))
                            {
                                continue;
                            }
                        }
                    }


                    //Not sure why this is needed, but the plugin will crash after being reconfigured otherwise.
                    if (uE.PhyBuffer != null)
                    {
                        E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++);
                        uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint);
                        uE.EventRepeatCount = _data.EventRepeatCount;

                        uE.PktCount++;
                        uE.SlotCount += uE.Size;
                    }
                }
            }

            stopWatch.Stop();

            this._totalTicks += stopWatch.ElapsedTicks;
        }
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            //Make sure the setup form is closed & the plugin has started
            if (isSetupOpen && hasStarted)
            {
                return;
            }


            var channelValues = outputStates.ToChannelValuesAsBytes();

            int universeSize = 0;

            this._eventCnt++;

            if (_universeTable == null)
            {
                return;
            }

            foreach (var uE in this._universeTable)
            {
                //Check if the universe is active and inside a valid channel range
                if (uE.Active && (uE.Start + 1) <= OutputCount)
                {
                    //Check the universe size boundary.
                    if ((uE.Start + 1 + uE.Size) > OutputCount)
                    {
                        universeSize = OutputCount - uE.Start - 1;
                    }
                    else
                    {
                        universeSize = uE.Size;
                    }



                    //Reduce duplicate packets
                    //SeqNumbers are per universe so that they can run independently
                    if (this._eventRepeatCount > 0)
                    {
                        if (uE.EventRepeatCount-- > 0)
                        {
                            if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize))
                            {
                                continue;
                            }
                        }
                    }


                    //Not sure why this is needed, but the plugin will crash after being reconfigured otherwise.
                    if (uE.PhyBuffer != null)
                    {
                        E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++);
                        uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint);
                        uE.EventRepeatCount = this._eventRepeatCount;

                        uE.PktCount++;
                        uE.SlotCount += uE.Size;
                    }
                }
            }

            stopWatch.Stop();

            this._totalTicks += stopWatch.ElapsedTicks;
        }