Exemplo n.º 1
0
        public void SendRdm(List <RdmPacket> packets, RdmEndPoint targetAddress, UId targetId)
        {
            if (packets.Count < 1)
            {
                throw new ArgumentException("Rdm packets list is empty.");
            }

            RdmPacket primaryPacket = packets[0];

            //Create sACN Packet
            ArtRdmSubPacket rdmPacket = new ArtRdmSubPacket();

            rdmPacket.DeviceId    = targetId;
            rdmPacket.RdmVersion  = (byte)RdmVersions.SubMessage;
            rdmPacket.Command     = primaryPacket.Header.Command;
            rdmPacket.ParameterId = primaryPacket.Header.ParameterId;
            rdmPacket.SubDevice   = (short)primaryPacket.Header.SubDevice;
            rdmPacket.SubCount    = (short)packets.Count;

            MemoryStream    rdmData    = new MemoryStream();
            RdmBinaryWriter dataWriter = new RdmBinaryWriter(rdmData);

            foreach (RdmPacket item in packets)
            {
                RdmPacket.WritePacket(item, dataWriter, true);
            }

            rdmPacket.RdmData = rdmData.ToArray();

            Send(rdmPacket, targetAddress);
        }
Exemplo n.º 2
0
        public void SendBackgroundRdm(RdmPacket packet)
        {
            if (!IsTcpConnectionAlive())
            {
                throw new InvalidOperationException("No healthy TCP connection exists for RDMNet broadcast.");
            }

            //Fill in addition details
            packet.Header.SourceId      = RdmSourceId;
            packet.Header.DestinationId = UId.Broadcast;

            //Create Rdm Packet
            MemoryStream    rdmData   = new MemoryStream();
            RdmBinaryWriter rdmWriter = new RdmBinaryWriter(rdmData);

            //Write the RDM sub-start code.
            rdmWriter.Write((byte)RdmVersions.SubMessage);

            //Write the RDM packet
            RdmPacket.WritePacket(packet, rdmWriter);

            //Write the checksum
            rdmWriter.WriteNetwork((short)RdmPacket.CalculateChecksum(rdmData.GetBuffer()));

            //Create sACN Packet
            RdmNetPacket dmxPacket = new RdmNetPacket();

            dmxPacket.Framing.SourceName = SourceName;
            dmxPacket.Framing.EndpointID = (short)0;
            dmxPacket.RdmNet.RdmData     = rdmData.GetBuffer();

            AliveTcpSocket.SendPacket(dmxPacket);

            RaiseRdmPacketSent(new NewPacketEventArgs <RdmPacket>(null, packet));
        }
Exemplo n.º 3
0
        public void SendRdm(RdmPacket packet, RdmEndPoint targetAddress, UId targetId, UId sourceId)
        {
            //Fill in addition details
            packet.Header.SourceId      = sourceId;
            packet.Header.DestinationId = targetId;

            //Sub Devices
            if (targetId is SubDeviceUId)
            {
                packet.Header.SubDevice = ((SubDeviceUId)targetId).SubDeviceId;
            }

            //Create Rdm Packet
            using (var rdmData = new MemoryStream())
            {
                var rdmWriter = new RdmBinaryWriter(rdmData);

                //Write the RDM packet
                RdmPacket.WritePacket(packet, rdmWriter);

                //Write the checksum
                rdmWriter.WriteNetwork((short)(RdmPacket.CalculateChecksum(rdmData.GetBuffer()) + (int)RdmVersions.SubMessage + (int)DmxStartCodes.RDM));

                //Create sACN Packet
                var rdmPacket = new ArtRdmPacket();
                rdmPacket.Address      = (byte)targetAddress.Universe;
                rdmPacket.SubStartCode = (byte)RdmVersions.SubMessage;
                rdmPacket.RdmData      = rdmData.GetBuffer();

                Send(rdmPacket, targetAddress);

                RdmPacketSent?.Invoke(this, new NewPacketEventArgs <RdmPacket>(new IPEndPoint(targetAddress.IpAddress, Port), packet));
            }
        }
Exemplo n.º 4
0
        public void SendRdm(RdmPacket packet, RdmEndPoint targetAddress, UId targetId, UId sourceId)
        {
            if (BlockRDM)
            {
                return;
            }

            //Fill in addition details
            packet.Header.SourceId      = sourceId;
            packet.Header.DestinationId = targetId;

            SubDeviceUId id = targetId as SubDeviceUId;

            if (id != null)
            {
                packet.Header.SubDevice = id.SubDeviceId;
            }

            //Create Rdm Packet
            MemoryStream    rdmData   = new MemoryStream();
            RdmBinaryWriter rdmWriter = new RdmBinaryWriter(rdmData);

            //Write the RDM sub-start code.
            rdmWriter.Write((byte)RdmVersions.SubMessage);

            //Write the RDM packet
            RdmPacket.WritePacket(packet, rdmWriter);

            //Write the checksum
            rdmWriter.WriteNetwork((short)RdmPacket.CalculateChecksum(rdmData.GetBuffer()) + (byte)DmxStartCodes.RDM);

            //Create sACN Packet
            RdmNetPacket dmxPacket = new RdmNetPacket();

            dmxPacket.Framing.SourceName = SourceName;
            dmxPacket.Framing.EndpointID = (short)targetAddress.Universe;
            dmxPacket.RdmNet.RdmData     = rdmData.GetBuffer();

            SendPacket(dmxPacket, targetAddress);

            RaiseRdmPacketSent(new NewPacketEventArgs <RdmPacket>(targetAddress, packet));
        }