/// <summary> /// Sends the data described by a data set collection to remote destination. /// </summary> /// <param name="producerBinding">Encapsulates functionality used by the <see cref="IMessageWriter" /> to collect all the data (data set items) required to prepare new message and send it over the network.</param> /// <param name="length">Number of items to be send used to calculate the length of the message.</param> /// <param name="contentMask">The content mask represented as unsigned number <see cref="UInt64" />. The order of the bits starting from the least significant /// bit matches the order of the data items within the data set.</param> /// <param name="encoding">The encoding.</param> /// <param name="dataSelector">The data selector.</param> /// <param name="messageSequenceNumber">The message sequence number. A monotonically increasing sequence number assigned by the publisher to each message sent.</param> /// <param name="timeStamp">The time stamp - the time the Data was collected.</param> /// <param name="configurationVersion">The configuration version.</param> /// <exception cref="System.ArgumentOutOfRangeException">Impossible to convert null value /// or</exception> void IMessageWriter.Send(Func<int, IProducerBinding> producerBinding, ushort length, ulong contentMask, FieldEncodingEnum encoding, DataSelector dataSelector, ushort messageSequenceNumber, DateTime timeStamp, ConfigurationVersionDataType configurationVersion) { lock (this) { if (State.State != HandlerState.Operational) return; ContentMask = contentMask; CreateMessage(encoding, dataSelector.PublisherId, dataSelector.DataSetWriterId, length, messageSequenceNumber, timeStamp, configurationVersion); //UInt64 _mask = 0x1; for (int i = 0; i < length; i++) { //TODO: Implement ContentMask https://github.com/mpostol/OPC-UA-OOI/issues/89 //if ((ContentMask & _mask) > 0) //{ IProducerBinding _pb = producerBinding(i); switch (encoding) { case FieldEncodingEnum.VariantFieldEncoding: WriteValueVariant(_pb); break; case FieldEncodingEnum.CompressedFieldEncoding: WriteValue(_pb); break; case FieldEncodingEnum.DataValueFieldEncoding: WriteDataValue(_pb); break; } //} //_mask = _mask << 1; } SendMessage(); } }
/// <summary> /// Sends the data described by a data set collection to remote destination. /// </summary> /// <param name="producerBinding">Encapsulates functionality used by the <see cref="T:UAOOI.Networking.SemanticData.MessageHandling.IMessageWriter" /> to collect all the data (data set items) required to prepare new message and send it over the network.</param> /// <param name="length">Number of items to be send used to calculate the length of the message.</param> /// <param name="contentMask">The content mask represented as unsigned number <see cref="T:System.UInt64" />. The order of the bits starting from the least significant /// bit matches the order of the data items within the data set.</param> /// <param name="encoding">The encoding.</param> /// <param name="dataSelector">The data selector.</param> /// <param name="messageSequenceNumber">The message sequence number. A monotonically increasing sequence number assigned by the publisher to each message sent.</param> /// <param name="timeStamp">The time stamp - the time the Data was collected.</param> /// <param name="configurationVersion">The configuration version.</param> /// <exception cref="ArgumentOutOfRangeException">length</exception> public void Send(Func<int, IProducerBinding> producerBinding, ushort length, ulong contentMask, FieldEncodingEnum encoding, DataSelector dataSelector, ushort messageSequenceNumber, DateTime timeStamp, ConfigurationVersionDataType configurationVersion) { if (length > 2) throw new ArgumentOutOfRangeException("length"); m_Buffer = new Object[length]; for (int i = 0; i < 2; i++) m_Buffer[i] = producerBinding(i); m_HaveSendData = true; }
/// <summary> /// Sends the data described by a data set collection to remote destination. /// </summary> /// <param name="producerBinding">Encapsulates functionality used by the <see cref="IMessageWriter" /> to collect all the data (data set items) required to prepare new message and send it over the network.</param> /// <param name="length">Number of items to be send used to calculate the length of the message.</param> /// <param name="contentMask">The content mask represented as unsigned number <see cref="ulong" />. The order of the bits starting from the least significant /// bit matches the order of the data items within the data set.</param> /// <param name="encoding">The encoding.</param> /// <param name="dataSelector">The data selector.</param> /// <param name="messageSequenceNumber">The message sequence number. A monotonically increasing sequence number assigned by the publisher to each message sent.</param> /// <param name="timeStamp">The time stamp - the time the Data was collected.</param> /// <param name="configurationVersion">The configuration version.</param> /// <exception cref="System.ArgumentOutOfRangeException">Impossible to convert null value /// or</exception> void IMessageWriter.Send (Func <int, IProducerBinding> producerBinding, ushort length, ulong contentMask, FieldEncodingEnum encoding, DataSelector dataSelector, ushort messageSequenceNumber, DateTime timeStamp, ConfigurationVersionDataType configurationVersion) { lock (this) { if (State.State != HandlerState.Operational) { return; } ContentMask = contentMask; CreateMessage(encoding, dataSelector.PublisherId, dataSelector.DataSetWriterId, length, messageSequenceNumber, timeStamp, configurationVersion); //UInt64 _mask = 0x1; for (int i = 0; i < length; i++) { //TODO: Implement ContentMask https://github.com/mpostol/OPC-UA-OOI/issues/89 //if ((ContentMask & _mask) > 0) //{ IProducerBinding _pb = producerBinding(i); switch (encoding) { case FieldEncodingEnum.VariantFieldEncoding: WriteValueVariant(_pb); break; case FieldEncodingEnum.CompressedFieldEncoding: WriteValue(_pb); break; case FieldEncodingEnum.DataValueFieldEncoding: WriteDataValue(_pb); break; } //} //_mask = _mask << 1; } SendMessage(); } }
public void Send(Func<int, IProducerBinding> producerBinding, ushort length, ulong contentMask, FieldEncodingEnum encoding, DataSelector dataSelector, ushort messageSequenceNumber, DateTime timeStamp, ConfigurationVersionDataType configurationVersion) { IsOk++; Assert.AreEqual<int>(3, length); }
/// <summary> /// Adds the message handler. It must initialize binding between the <see cref="IMessageHandler" /> and the local data resources. /// </summary> /// <param name="messageHandler">The message handler.</param> /// <param name="configuration">The configuration.</param> protected internal virtual void AddMessageHandler(IMessageHandler messageHandler, AssociationConfiguration configuration) { DataSetId = new DataSelector() { DataSetWriterId = configuration.DataSetWriterId, PublisherId = configuration.PublisherId }; }
public void BinaryUDPPackageWriterTestMethod() { int _port = 35678; using (BinaryUDPPackageWriter _writer = new BinaryUDPPackageWriter("localhost", _port, new Helpers.UABinaryEncoderImplementation())) { Assert.AreEqual<int>(0, _writer.m_NumberOfSentBytes); Assert.AreEqual<int>(0, _writer.m_NumberOfAttachToNetwork); Assert.AreEqual<int>(0, _writer.m_NumberOfSentMessages); Assert.AreEqual<HandlerState>(HandlerState.Disabled, _writer.State.State); _writer.AttachToNetwork(); Assert.AreEqual<HandlerState>(HandlerState.Operational, _writer.State.State); Assert.AreEqual<int>(1, _writer.m_NumberOfAttachToNetwork); Assert.AreEqual<int>(0, _writer.m_NumberOfSentBytes); Assert.AreEqual<int>(0, _writer.m_NumberOfSentMessages); ProducerBinding _binding = new ProducerBinding() { Value = String.Empty }; int _sentItems = 0; Guid m_Guid = CommonDefinitions.TestGuid; DataSelector _testDataSelector = new DataSelector() { DataSetWriterId = CommonDefinitions.DataSetId, PublisherId = CommonDefinitions.TestGuid }; ((IMessageWriter)_writer).Send((x) => { _binding.Value = CommonDefinitions.TestValues[x]; _sentItems++; return _binding; }, Convert.ToUInt16(CommonDefinitions.TestValues.Length), UInt64.MaxValue, FieldEncodingEnum.VariantFieldEncoding, _testDataSelector, 0, CommonDefinitions.TestMinimalDateTime, new ConfigurationVersionDataType() { MajorVersion = 0, MinorVersion = 0 } ); Assert.AreEqual(CommonDefinitions.TestValues.Length, _sentItems); Assert.AreEqual<int>(1, _writer.m_NumberOfAttachToNetwork); Assert.AreEqual<int>(115, _writer.m_NumberOfSentBytes); Assert.AreEqual<int>(1, _writer.m_NumberOfSentMessages); byte[] _shouldBeInBuffer = CommonDefinitions.GetTestBinaryArrayVariant4Consumer(); byte[] _outputBuffer = _writer.DoUDPRead(); CollectionAssert.AreEqual(_outputBuffer, _shouldBeInBuffer); } }