public void ValidateUadpPubSubConnectionCreateNetworkMessage()
        {
            Assert.IsNotNull(m_uadpPublisherConnection, "The UADP connection from standard configuration is invalid.");

            //Arrange
            WriterGroupDataType            writerGroup0    = m_uadpPublisherConnection.PubSubConnectionConfiguration.WriterGroups[0];
            UadpWriterGroupMessageDataType messageSettings = ExtensionObject.ToEncodeable(writerGroup0.MessageSettings)
                                                             as UadpWriterGroupMessageDataType;

            //Act
            m_uadpPublisherConnection.ResetSequenceNumber();
            UadpNetworkMessage networkMessage0 = m_uadpPublisherConnection.CreateNetworkMessage(writerGroup0) as UadpNetworkMessage;

            //Assert
            Assert.IsNotNull(networkMessage0, "CreateNetworkMessage did not return an UadpNetworkMessage.");

            Assert.AreEqual(networkMessage0.DataSetClassId, Guid.Empty, "UadpNetworkMessage.DataSetClassId is invalid.");
            Assert.AreEqual(networkMessage0.WriterGroupId, writerGroup0.WriterGroupId, "UadpNetworkMessage.WriterGroupId is invalid.");
            Assert.AreEqual(networkMessage0.UADPVersion, 1, "UadpNetworkMessage.UADPVersion is invalid.");
            Assert.AreEqual(networkMessage0.SequenceNumber, 1, "UadpNetworkMessage.SequenceNumber is not 1.");
            Assert.AreEqual(networkMessage0.GroupVersion, messageSettings.GroupVersion, "UadpNetworkMessage.GroupVersion is not valid.");
            Assert.AreEqual(networkMessage0.PublisherId, m_uadpPublisherConnection.PubSubConnectionConfiguration.PublisherId.Value,
                            "UadpNetworkMessage.PublisherId is not valid.");
            Assert.IsNotNull(networkMessage0.UadpDataSetMessages, "UadpNetworkMessage.UadpDataSetMessages is null.");
            Assert.AreEqual(networkMessage0.UadpDataSetMessages.Count, 3, "UadpNetworkMessage.UadpDataSetMessages.Count is not 3.");
            //validate flags
            Assert.AreEqual((uint)networkMessage0.NetworkMessageContentMask, messageSettings.NetworkMessageContentMask,
                            "UadpNetworkMessage.messageSettings.NetworkMessageContentMask is not valid.");
        }
        public void ValidateUdpPubSubConnectionCreateNetworkMessage()
        {
            Assert.IsNotNull(m_udpPublisherConnection, "The UADP connection from standard configuration is invalid.");

            //Arrange
            WriterGroupDataType            writerGroup0    = m_udpPublisherConnection.PubSubConnectionConfiguration.WriterGroups.First();
            UadpWriterGroupMessageDataType messageSettings = ExtensionObject.ToEncodeable(writerGroup0.MessageSettings)
                                                             as UadpWriterGroupMessageDataType;

            //Act
            m_udpPublisherConnection.ResetSequenceNumber();

            var networkMessages = m_udpPublisherConnection.CreateNetworkMessages(writerGroup0, new WriterGroupPublishState());

            Assert.IsNotNull(networkMessages, "connection.CreateNetworkMessages shall not return null");
            var networkMessagesNetworkType = networkMessages.FirstOrDefault(net => net.IsMetaDataMessage == false);

            Assert.IsNotNull(networkMessagesNetworkType, "connection.CreateNetworkMessages shall return only one network message");

            UadpNetworkMessage networkMessage0 = networkMessagesNetworkType as UadpNetworkMessage;

            Assert.IsNotNull(networkMessage0, "networkMessageEncode should not be null");

            //Assert
            Assert.IsNotNull(networkMessage0, "CreateNetworkMessage did not return an UadpNetworkMessage.");

            Assert.AreEqual(networkMessage0.DataSetClassId, Guid.Empty, "UadpNetworkMessage.DataSetClassId is invalid.");
            Assert.AreEqual(networkMessage0.WriterGroupId, writerGroup0.WriterGroupId, "UadpNetworkMessage.WriterGroupId is invalid.");
            Assert.AreEqual(networkMessage0.UADPVersion, 1, "UadpNetworkMessage.UADPVersion is invalid.");
            Assert.AreEqual(networkMessage0.SequenceNumber, 1, "UadpNetworkMessage.SequenceNumber is not 1.");
            Assert.AreEqual(networkMessage0.GroupVersion, messageSettings.GroupVersion, "UadpNetworkMessage.GroupVersion is not valid.");
            Assert.AreEqual(networkMessage0.PublisherId, m_udpPublisherConnection.PubSubConnectionConfiguration.PublisherId.Value,
                            "UadpNetworkMessage.PublisherId is not valid.");
            Assert.IsNotNull(networkMessage0.DataSetMessages, "UadpNetworkMessage.UadpDataSetMessages is null.");
            Assert.AreEqual(networkMessage0.DataSetMessages.Count, 3, "UadpNetworkMessage.UadpDataSetMessages.Count is not 3.");
            //validate flags
            Assert.AreEqual((uint)networkMessage0.NetworkMessageContentMask, messageSettings.NetworkMessageContentMask,
                            "UadpNetworkMessage.messageSettings.NetworkMessageContentMask is not valid.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the network message built from the provided writerGroupConfiguration
        /// </summary>
        /// <param name="writerGroupConfiguration"></param>
        /// <returns></returns>
        public override UaNetworkMessage CreateNetworkMessage(WriterGroupDataType writerGroupConfiguration)
        {
            UadpWriterGroupMessageDataType messageSettings = ExtensionObject.ToEncodeable(writerGroupConfiguration.MessageSettings)
                                                             as UadpWriterGroupMessageDataType;

            if (messageSettings == null)
            {
                //Wrong configuration of writer group MessageSettings
                return(null);
            }

            //Create list of dataSet messages to be sent
            List <UadpDataSetMessage> dataSetMessages = new List <UadpDataSetMessage>();

            foreach (DataSetWriterDataType dataSetWriter in writerGroupConfiguration.DataSetWriters)
            {
                //check if dataSetWriter enabled
                if (dataSetWriter.Enabled)
                {
                    DataSet dataSet = Application.DataCollector.CollectData(dataSetWriter.DataSetName);
                    if (dataSet != null)
                    {
                        UadpDataSetWriterMessageDataType dataSetMessageSettings =
                            ExtensionObject.ToEncodeable(dataSetWriter.MessageSettings) as
                            UadpDataSetWriterMessageDataType;
                        // check MessageSettings to see how to encode DataSet
                        if (dataSetMessageSettings != null)
                        {
                            UadpDataSetMessage uadpDataSetMessage = new UadpDataSetMessage(dataSet);
                            uadpDataSetMessage.DataSetWriterId = dataSetWriter.DataSetWriterId;
                            uadpDataSetMessage.SetMessageContentMask((UadpDataSetMessageContentMask)dataSetMessageSettings.DataSetMessageContentMask);
                            uadpDataSetMessage.SetFieldContentMask((DataSetFieldContentMask)dataSetWriter.DataSetFieldContentMask);
                            uadpDataSetMessage.SequenceNumber = (ushort)(Utils.IncrementIdentifier(ref m_dataSetSequenceNumber) % UInt16.MaxValue);
                            uadpDataSetMessage.ConfiguredSize = dataSetMessageSettings.ConfiguredSize;
                            uadpDataSetMessage.DataSetOffset  = dataSetMessageSettings.DataSetOffset;
                            uadpDataSetMessage.TimeStamp      = DateTime.UtcNow;
                            uadpDataSetMessage.Status         = (ushort)StatusCodes.Good;
                            dataSetMessages.Add(uadpDataSetMessage);
                        }
                    }
                }
            }

            //cancel send if no dataset message
            if (dataSetMessages.Count == 0)
            {
                return(null);
            }

            UadpNetworkMessage uadpNetworkMessage = new UadpNetworkMessage(dataSetMessages);

            uadpNetworkMessage.SetNetworkMessageContentMask((UadpNetworkMessageContentMask)messageSettings.NetworkMessageContentMask);
            uadpNetworkMessage.WriterGroupId = writerGroupConfiguration.WriterGroupId;
            // Network message header
            uadpNetworkMessage.PublisherId    = PubSubConnectionConfiguration.PublisherId.Value;
            uadpNetworkMessage.SequenceNumber = (ushort)(Utils.IncrementIdentifier(ref m_sequenceNumber) % UInt16.MaxValue);

            // Writer group header
            uadpNetworkMessage.GroupVersion         = messageSettings.GroupVersion;
            uadpNetworkMessage.NetworkMessageNumber = 1; //only one network message per publish

            return(uadpNetworkMessage);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create the list of network messages built from the provided writerGroupConfiguration
        /// </summary>
        public override IList <UaNetworkMessage> CreateNetworkMessages(WriterGroupDataType writerGroupConfiguration, WriterGroupPublishState state)
        {
            UadpWriterGroupMessageDataType messageSettings = ExtensionObject.ToEncodeable(writerGroupConfiguration.MessageSettings)
                                                             as UadpWriterGroupMessageDataType;

            if (messageSettings == null)
            {
                //Wrong configuration of writer group MessageSettings
                return(null);
            }
            DatagramWriterGroupTransportDataType transportSettings = ExtensionObject.ToEncodeable(writerGroupConfiguration.TransportSettings)
                                                                     as DatagramWriterGroupTransportDataType;

            if (transportSettings == null)
            {
                //Wrong configuration of writer group TransportSettings
                return(null);
            }
            List <UaNetworkMessage> networkMessages = new List <UaNetworkMessage>();

            //Create list of dataSet messages to be sent
            List <UadpDataSetMessage> dataSetMessages = new List <UadpDataSetMessage>();

            foreach (DataSetWriterDataType dataSetWriter in writerGroupConfiguration.DataSetWriters)
            {
                //check if dataSetWriter enabled
                if (dataSetWriter.Enabled)
                {
                    DataSet dataSet = CreateDataSet(dataSetWriter, state);

                    if (dataSet != null)
                    {
                        bool hasMetaDataChanged = state.HasMetaDataChanged(dataSetWriter, dataSet.DataSetMetaData);

                        if (hasMetaDataChanged)
                        {
                            // add metadata network message
                            networkMessages.Add(new UadpNetworkMessage(writerGroupConfiguration, dataSet.DataSetMetaData)
                            {
                                PublisherId     = PubSubConnectionConfiguration.PublisherId.Value,
                                DataSetWriterId = dataSetWriter.DataSetWriterId
                            });
                        }

                        UadpDataSetWriterMessageDataType dataSetMessageSettings = ExtensionObject.ToEncodeable(dataSetWriter.MessageSettings) as
                                                                                  UadpDataSetWriterMessageDataType;
                        // check MessageSettings to see how to encode DataSet
                        if (dataSetMessageSettings != null)
                        {
                            UadpDataSetMessage uadpDataSetMessage = new UadpDataSetMessage(dataSet);
                            uadpDataSetMessage.DataSetWriterId = dataSetWriter.DataSetWriterId;
                            uadpDataSetMessage.SetMessageContentMask((UadpDataSetMessageContentMask)dataSetMessageSettings.DataSetMessageContentMask);
                            uadpDataSetMessage.SetFieldContentMask((DataSetFieldContentMask)dataSetWriter.DataSetFieldContentMask);
                            uadpDataSetMessage.SequenceNumber = (ushort)(Utils.IncrementIdentifier(ref m_dataSetSequenceNumber) % UInt16.MaxValue);
                            uadpDataSetMessage.ConfiguredSize = dataSetMessageSettings.ConfiguredSize;
                            uadpDataSetMessage.DataSetOffset  = dataSetMessageSettings.DataSetOffset;
                            uadpDataSetMessage.Timestamp      = DateTime.UtcNow;
                            uadpDataSetMessage.Status         = StatusCodes.Good;
                            dataSetMessages.Add(uadpDataSetMessage);

                            state.OnMessagePublished(dataSetWriter, dataSet);
                        }
                    }
                }
            }

            //cancel send if no dataset message
            if (dataSetMessages.Count == 0)
            {
                return(networkMessages);
            }

            UadpNetworkMessage uadpNetworkMessage = new UadpNetworkMessage(writerGroupConfiguration, dataSetMessages);

            uadpNetworkMessage.SetNetworkMessageContentMask((UadpNetworkMessageContentMask)messageSettings.NetworkMessageContentMask);
            uadpNetworkMessage.WriterGroupId = writerGroupConfiguration.WriterGroupId;
            // Network message header
            uadpNetworkMessage.PublisherId    = PubSubConnectionConfiguration.PublisherId.Value;
            uadpNetworkMessage.SequenceNumber = (ushort)(Utils.IncrementIdentifier(ref m_sequenceNumber) % UInt16.MaxValue);

            // Writer group header
            uadpNetworkMessage.GroupVersion         = messageSettings.GroupVersion;
            uadpNetworkMessage.NetworkMessageNumber = 1; //only one network message per publish

            networkMessages.Add(uadpNetworkMessage);


            return(networkMessages);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a PubSubConfiguration object programmatically.
        /// </summary>
        /// <returns></returns>
        public static PubSubConfigurationDataType CreatePublisherConfiguration()
        {
            // Define a PubSub connection with PublisherId 100
            PubSubConnectionDataType pubSubConnection1 = new PubSubConnectionDataType();

            pubSubConnection1.Name                = "UADPConnection1";
            pubSubConnection1.Enabled             = true;
            pubSubConnection1.PublisherId         = (UInt16)100;
            pubSubConnection1.TransportProfileUri = Profiles.UadpTransport;
            NetworkAddressUrlDataType address = new NetworkAddressUrlDataType();

            // Specify the local Network interface name to be used
            // e.g. address.NetworkInterface = "Ethernet";
            // Leave empty to publish on all available local interfaces.
            address.NetworkInterface = String.Empty;
            address.Url = "opc.udp://239.0.0.1:4840";
            pubSubConnection1.Address = new ExtensionObject(address);

            #region Define WriterGroup1
            WriterGroupDataType writerGroup1 = new WriterGroupDataType();
            writerGroup1.Name                  = "WriterGroup 1";
            writerGroup1.Enabled               = true;
            writerGroup1.WriterGroupId         = 1;
            writerGroup1.PublishingInterval    = 5000;
            writerGroup1.KeepAliveTime         = 5000;
            writerGroup1.MaxNetworkMessageSize = 1500;
            writerGroup1.HeaderLayoutUri       = "UADP-Cyclic-Fixed";
            UadpWriterGroupMessageDataType messageSettings = new UadpWriterGroupMessageDataType()
            {
                DataSetOrdering           = DataSetOrderingType.AscendingWriterId,
                GroupVersion              = 0,
                NetworkMessageContentMask = (uint)(UadpNetworkMessageContentMask.PublisherId | UadpNetworkMessageContentMask.GroupHeader
                                                   | UadpNetworkMessageContentMask.WriterGroupId | UadpNetworkMessageContentMask.GroupVersion
                                                   | UadpNetworkMessageContentMask.NetworkMessageNumber | UadpNetworkMessageContentMask.SequenceNumber)
            };

            writerGroup1.MessageSettings   = new ExtensionObject(messageSettings);
            writerGroup1.TransportSettings = new ExtensionObject(new DatagramWriterGroupTransportDataType());

            // Define DataSetWriter 'Simple'
            DataSetWriterDataType dataSetWriter1 = new DataSetWriterDataType();
            dataSetWriter1.Name                    = "Writer 1";
            dataSetWriter1.DataSetWriterId         = 1;
            dataSetWriter1.Enabled                 = true;
            dataSetWriter1.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter1.DataSetName             = "Simple";
            dataSetWriter1.KeyFrameCount           = 1;
            UadpDataSetWriterMessageDataType uadpDataSetWriterMessage = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 15,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };
            dataSetWriter1.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            writerGroup1.DataSetWriters.Add(dataSetWriter1);

            // Define DataSetWriter 'AllTypes'
            DataSetWriterDataType dataSetWriter2 = new DataSetWriterDataType();
            dataSetWriter2.Name                    = "Writer 2";
            dataSetWriter2.DataSetWriterId         = 2;
            dataSetWriter2.Enabled                 = true;
            dataSetWriter2.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter2.DataSetName             = "AllTypes";
            dataSetWriter2.KeyFrameCount           = 1;
            uadpDataSetWriterMessage               = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 47,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };
            dataSetWriter2.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            writerGroup1.DataSetWriters.Add(dataSetWriter2);

            pubSubConnection1.WriterGroups.Add(writerGroup1);
            #endregion

            #region  Define PublishedDataSet Simple
            PublishedDataSetDataType publishedDataSetSimple = new PublishedDataSetDataType();
            publishedDataSetSimple.Name = "Simple"; //name shall be unique in a configuration
            // Define  publishedDataSetSimple.DataSetMetaData
            publishedDataSetSimple.DataSetMetaData = new DataSetMetaDataType();
            publishedDataSetSimple.DataSetMetaData.DataSetClassId = Uuid.Empty;
            publishedDataSetSimple.DataSetMetaData.Name           = publishedDataSetSimple.Name;
            publishedDataSetSimple.DataSetMetaData.Fields         = new FieldMetaDataCollection()
            {
                new FieldMetaData()
                {
                    Name           = "BoolToggle",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Boolean,
                    DataType       = DataTypeIds.Boolean,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Int32,
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32Fast",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Int32,
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "DateTime",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.DateTime,
                    DataType       = DataTypeIds.DateTime,
                    ValueRank      = ValueRanks.Scalar
                },
            };
            publishedDataSetSimple.DataSetMetaData.ConfigurationVersion = new ConfigurationVersionDataType()
            {
                MinorVersion = 1,
                MajorVersion = 1
            };

            PublishedDataItemsDataType publishedDataSetSimpleSource = new PublishedDataItemsDataType();
            publishedDataSetSimpleSource.PublishedData = new PublishedVariableDataTypeCollection();
            //create PublishedData based on metadata names
            foreach (var field in publishedDataSetSimple.DataSetMetaData.Fields)
            {
                publishedDataSetSimpleSource.PublishedData.Add(
                    new PublishedVariableDataType()
                {
                    PublishedVariable = new NodeId(field.Name, PublishedValuesWrites.NamespaceIndexSimple),
                    AttributeId       = Attributes.Value,
                });
            }

            publishedDataSetSimple.DataSetSource = new ExtensionObject(publishedDataSetSimpleSource);
            #endregion

            #region  Define PublishedDataSet AllTypes
            PublishedDataSetDataType publishedDataSetAllTypes = new PublishedDataSetDataType();
            publishedDataSetAllTypes.Name = "AllTypes"; //name shall be unique in a configuration
            // Define  publishedDataSetAllTypes.DataSetMetaData
            publishedDataSetAllTypes.DataSetMetaData = new DataSetMetaDataType();
            publishedDataSetAllTypes.DataSetMetaData.DataSetClassId = Uuid.Empty;
            publishedDataSetAllTypes.DataSetMetaData.Name           = publishedDataSetAllTypes.Name;
            publishedDataSetAllTypes.DataSetMetaData.Fields         = new FieldMetaDataCollection()
            {
                new FieldMetaData()
                {
                    Name           = "BoolToggle",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Boolean,
                    DataType       = DataTypeIds.Boolean,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Byte",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Byte,
                    DataType       = DataTypeIds.Byte,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int16",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Int16,
                    DataType       = DataTypeIds.Int16,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Int32,
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "SByte",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.SByte,
                    DataType       = DataTypeIds.SByte,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "UInt16",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.UInt16,
                    DataType       = DataTypeIds.UInt16,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "UInt32",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.UInt32,
                    DataType       = DataTypeIds.UInt32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Float",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Float,
                    DataType       = DataTypeIds.Float,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Double",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    BuiltInType    = (byte)DataTypes.Double,
                    DataType       = DataTypeIds.Double,
                    ValueRank      = ValueRanks.Scalar
                },
            };
            publishedDataSetAllTypes.DataSetMetaData.ConfigurationVersion = new ConfigurationVersionDataType()
            {
                MinorVersion = 1,
                MajorVersion = 1
            };
            PublishedDataItemsDataType publishedDataSetAllTypesSource = new PublishedDataItemsDataType();
            //create PublishedData based on metadata names
            foreach (var field in publishedDataSetAllTypes.DataSetMetaData.Fields)
            {
                publishedDataSetAllTypesSource.PublishedData.Add(
                    new PublishedVariableDataType()
                {
                    PublishedVariable = new NodeId(field.Name, PublishedValuesWrites.NamespaceIndexAllTypes),
                    AttributeId       = Attributes.Value,
                });
            }
            publishedDataSetAllTypes.DataSetSource = new ExtensionObject(publishedDataSetAllTypesSource);
            #endregion

            //create  the PubSub configuration root object
            PubSubConfigurationDataType pubSubConfiguration = new PubSubConfigurationDataType();
            pubSubConfiguration.Connections = new PubSubConnectionDataTypeCollection()
            {
                pubSubConnection1
            };
            pubSubConfiguration.PublishedDataSets = new PublishedDataSetDataTypeCollection()
            {
                publishedDataSetSimple, publishedDataSetAllTypes
            };

            return(pubSubConfiguration);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a PubSubConfiguration object for UDP & UADP programmatically.
        /// </summary>
        /// <returns></returns>
        private static PubSubConfigurationDataType CreatePublisherConfiguration_UdpUadp(string urlAddress)
        {
            // Define a PubSub connection with PublisherId 1
            PubSubConnectionDataType pubSubConnection1 = new PubSubConnectionDataType();

            pubSubConnection1.Name                = "Publisher Connection1 UDP UADP";
            pubSubConnection1.Enabled             = true;
            pubSubConnection1.PublisherId         = (UInt16)1;
            pubSubConnection1.TransportProfileUri = Profiles.PubSubUdpUadpTransport;
            NetworkAddressUrlDataType address = new NetworkAddressUrlDataType();

            // Specify the local Network interface name to be used
            // e.g. address.NetworkInterface = "Ethernet";
            // Leave empty to publish on all available local interfaces.
            address.NetworkInterface = String.Empty;
            address.Url = urlAddress;
            pubSubConnection1.Address = new ExtensionObject(address);

            #region Define WriterGroup1
            WriterGroupDataType writerGroup1 = new WriterGroupDataType();
            writerGroup1.Name                  = "WriterGroup 1";
            writerGroup1.Enabled               = true;
            writerGroup1.WriterGroupId         = 1;
            writerGroup1.PublishingInterval    = 5000;
            writerGroup1.KeepAliveTime         = 5000;
            writerGroup1.MaxNetworkMessageSize = 1500;
            writerGroup1.HeaderLayoutUri       = "UADP-Cyclic-Fixed";
            UadpWriterGroupMessageDataType uadpMessageSettings = new UadpWriterGroupMessageDataType()
            {
                DataSetOrdering           = DataSetOrderingType.AscendingWriterId,
                GroupVersion              = 0,
                NetworkMessageContentMask = (uint)(UadpNetworkMessageContentMask.PublisherId
                                                   | UadpNetworkMessageContentMask.GroupHeader
                                                   | UadpNetworkMessageContentMask.WriterGroupId
                                                   | UadpNetworkMessageContentMask.GroupVersion
                                                   | UadpNetworkMessageContentMask.NetworkMessageNumber
                                                   | UadpNetworkMessageContentMask.SequenceNumber)
            };

            writerGroup1.MessageSettings = new ExtensionObject(uadpMessageSettings);
            // initialize Datagram (UDP) Transport Settings
            writerGroup1.TransportSettings = new ExtensionObject(new DatagramWriterGroupTransportDataType());

            // Define DataSetWriter 'Simple'
            DataSetWriterDataType dataSetWriter1 = new DataSetWriterDataType();
            dataSetWriter1.Name                    = "Writer 1";
            dataSetWriter1.DataSetWriterId         = 1;
            dataSetWriter1.Enabled                 = true;
            dataSetWriter1.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter1.DataSetName             = "Simple";
            dataSetWriter1.KeyFrameCount           = 1;
            UadpDataSetWriterMessageDataType uadpDataSetWriterMessage = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 15,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter1.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            writerGroup1.DataSetWriters.Add(dataSetWriter1);

            // Define DataSetWriter 'AllTypes'
            DataSetWriterDataType dataSetWriter2 = new DataSetWriterDataType();
            dataSetWriter2.Name                    = "Writer 2";
            dataSetWriter2.DataSetWriterId         = 2;
            dataSetWriter2.Enabled                 = true;
            dataSetWriter2.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter2.DataSetName             = "AllTypes";
            dataSetWriter2.KeyFrameCount           = 1;
            uadpDataSetWriterMessage               = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 47,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter2.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            writerGroup1.DataSetWriters.Add(dataSetWriter2);

            pubSubConnection1.WriterGroups.Add(writerGroup1);
            #endregion

            //  Define PublishedDataSet Simple
            PublishedDataSetDataType publishedDataSetSimple = CreatePublishedDataSetSimple();

            // Define PublishedDataSet AllTypes
            PublishedDataSetDataType publishedDataSetAllTypes = CreatePublishedDataSetAllTypes();

            //create  the PubSub configuration root object
            PubSubConfigurationDataType pubSubConfiguration = new PubSubConfigurationDataType();
            pubSubConfiguration.Connections = new PubSubConnectionDataTypeCollection()
            {
                pubSubConnection1
            };
            pubSubConfiguration.PublishedDataSets = new PublishedDataSetDataTypeCollection()
            {
                publishedDataSetSimple, publishedDataSetAllTypes
            };

            return(pubSubConfiguration);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a PubSubConfiguration object for MQTT & UADP programmatically.
        /// </summary>
        /// <returns></returns>
        private static PubSubConfigurationDataType CreatePublisherConfiguration_MqttUadp(string urlAddress)
        {
            // Define a PubSub connection with PublisherId 3
            PubSubConnectionDataType pubSubConnection1 = new PubSubConnectionDataType();

            pubSubConnection1.Name                = "Publisher Connection MQTT UADP";
            pubSubConnection1.Enabled             = true;
            pubSubConnection1.PublisherId         = (UInt16)3;
            pubSubConnection1.TransportProfileUri = Profiles.PubSubMqttUadpTransport;
            NetworkAddressUrlDataType address = new NetworkAddressUrlDataType();

            // Specify the local Network interface name to be used
            // e.g. address.NetworkInterface = "Ethernet";
            // Leave empty to publish on all available local interfaces.
            address.NetworkInterface = String.Empty;
            address.Url = urlAddress;
            pubSubConnection1.Address = new ExtensionObject(address);

            // Configure the mqtt specific configuration with the MQTTbroker
            ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500);

            pubSubConnection1.ConnectionProperties = mqttConfiguration.ConnectionProperties;

            string brokerQueueName = "Uadp_WriterGroup_1";
            string brokerMetaData  = "$Metadata";

            #region Define WriterGroup1
            WriterGroupDataType writerGroup1 = new WriterGroupDataType();
            writerGroup1.Name                  = "WriterGroup 1";
            writerGroup1.Enabled               = true;
            writerGroup1.WriterGroupId         = 1;
            writerGroup1.PublishingInterval    = 5000;
            writerGroup1.KeepAliveTime         = 5000;
            writerGroup1.MaxNetworkMessageSize = 1500;
            writerGroup1.HeaderLayoutUri       = "UADP-Cyclic-Fixed";
            UadpWriterGroupMessageDataType uadpMessageSettings = new UadpWriterGroupMessageDataType()
            {
                DataSetOrdering           = DataSetOrderingType.AscendingWriterId,
                GroupVersion              = 0,
                NetworkMessageContentMask = (uint)(UadpNetworkMessageContentMask.PublisherId
                                                   | UadpNetworkMessageContentMask.GroupHeader
                                                   | UadpNetworkMessageContentMask.WriterGroupId
                                                   | UadpNetworkMessageContentMask.PayloadHeader
                                                   | UadpNetworkMessageContentMask.GroupVersion
                                                   | UadpNetworkMessageContentMask.NetworkMessageNumber
                                                   | UadpNetworkMessageContentMask.SequenceNumber)
            };

            writerGroup1.MessageSettings = new ExtensionObject(uadpMessageSettings);
            // initialize Broker transport settings
            writerGroup1.TransportSettings = new ExtensionObject(new BrokerWriterGroupTransportDataType()
            {
                QueueName = brokerQueueName,
            });

            // Define DataSetWriter 'Simple'
            DataSetWriterDataType dataSetWriter1 = new DataSetWriterDataType();
            dataSetWriter1.Name                    = "Writer 1";
            dataSetWriter1.DataSetWriterId         = 1;
            dataSetWriter1.Enabled                 = true;
            dataSetWriter1.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter1.DataSetName             = "Simple";
            dataSetWriter1.KeyFrameCount           = 1;
            UadpDataSetWriterMessageDataType uadpDataSetWriterMessage = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 15,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter1.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            BrokerDataSetWriterTransportDataType uadpDataSetWriterTransport = new BrokerDataSetWriterTransportDataType()
            {
                QueueName          = brokerQueueName,
                MetaDataQueueName  = $"{brokerQueueName}/{brokerMetaData}",
                MetaDataUpdateTime = 60000
            };
            dataSetWriter1.TransportSettings = new ExtensionObject(uadpDataSetWriterTransport);


            writerGroup1.DataSetWriters.Add(dataSetWriter1);

            // Define DataSetWriter 'AllTypes'
            DataSetWriterDataType dataSetWriter2 = new DataSetWriterDataType();
            dataSetWriter2.Name                    = "Writer 2";
            dataSetWriter2.DataSetWriterId         = 2;
            dataSetWriter2.Enabled                 = true;
            dataSetWriter2.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter2.DataSetName             = "AllTypes";
            dataSetWriter2.KeyFrameCount           = 1;
            uadpDataSetWriterMessage               = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 47,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter2.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);

            dataSetWriter2.TransportSettings = new ExtensionObject(uadpDataSetWriterTransport);
            writerGroup1.DataSetWriters.Add(dataSetWriter2);

            pubSubConnection1.WriterGroups.Add(writerGroup1);
            #endregion

            //  Define PublishedDataSet Simple
            PublishedDataSetDataType publishedDataSetSimple = CreatePublishedDataSetSimple();

            // Define PublishedDataSet AllTypes
            PublishedDataSetDataType publishedDataSetAllTypes = CreatePublishedDataSetAllTypes();

            //create  the PubSub configuration root object
            PubSubConfigurationDataType pubSubConfiguration = new PubSubConfigurationDataType();
            pubSubConfiguration.Connections = new PubSubConnectionDataTypeCollection()
            {
                pubSubConnection1
            };
            pubSubConfiguration.PublishedDataSets = new PublishedDataSetDataTypeCollection()
            {
                publishedDataSetSimple, publishedDataSetAllTypes
            };

            return(pubSubConfiguration);
        }