Skip to content

Commit

Permalink
Improve ResendData server support (#1854)
Browse files Browse the repository at this point in the history
* add resend data support to sample node manager
* After WG discussion, ensure after ResendData only a single value per monitored item is sent in the next publish (sync client cache)
* Seperate resend data state from ready to publish with IsResendData property
  • Loading branch information
mregen authored Jun 29, 2022
1 parent c0fc029 commit 10d4dbc
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

using System;
using System.Collections.Generic;
using System.Text;
using Opc.Ua.Server;

namespace Opc.Ua.Sample
Expand Down Expand Up @@ -68,6 +69,7 @@ public DataChangeMonitoredItem(
m_nextSampleTime = DateTime.UtcNow.Ticks;
m_readyToPublish = false;
m_readyToTrigger = false;
m_resendData = false;
m_alwaysReportUpdates = alwaysReportUpdates;
}

Expand Down Expand Up @@ -104,6 +106,7 @@ public DataChangeMonitoredItem(
m_nextSampleTime = DateTime.UtcNow.Ticks;
m_readyToPublish = false;
m_readyToTrigger = false;
m_resendData = false;
m_queue = null;
m_filter = filter;
m_range = 0;
Expand Down Expand Up @@ -465,11 +468,18 @@ public bool IsReadyToTrigger
}
}

public void SetupResendDataTrigger()
/// <inheritdoc/>
public bool IsResendData
{
// Does nothing since this type of Monitored Item does not support Resend data functionality
get
{
lock (m_lock)
{
return m_resendData;
}
}
}

/// <summary>
/// Returns the results for the create request.
/// </summary>
Expand Down Expand Up @@ -516,28 +526,36 @@ public ServiceResult GetModifyResult(out MonitoredItemModifyResult result)
return ServiceResult.Good;
}
}

/// <inheritdoc/>
public void SetupResendDataTrigger()
{
lock (m_lock)
{
if (m_monitoringMode == MonitoringMode.Reporting)
{
m_resendData = true;
}
}
}
#endregion

#region IDataChangeMonitoredItem Members
/// <summary>
/// Queues a new data change.
/// </summary>
/// <inheritdoc/>
public void QueueValue(DataValue value, ServiceResult error)
{
QueueValue(value, error, false);
}
#endregion

#region IDataChangeMonitoredItem2 Members
/// <summary>
/// Queues a new data change.
/// </summary>
/// <inheritdoc/>
public void QueueValue(DataValue value, ServiceResult error, bool ignoreFilters)
{
lock (m_lock)
{
// check if value has changed.
if (!m_alwaysReportUpdates)
if (!m_alwaysReportUpdates && !ignoreFilters)
{
if (!Opc.Ua.Server.MonitoredItem.ValueChanged(value, error, m_lastValue, m_lastError, m_filter, m_range))
{
Expand Down Expand Up @@ -686,31 +704,45 @@ public bool Publish(OperationContext context, Queue<MonitoredItemNotification> n
// check if not ready to publish.
if (!IsReadyToPublish)
{
return false;
if (!m_resendData)
{
return false;
}
}
else
{
// update sample time.
IncrementSampleTime();
}

// update sample time.
IncrementSampleTime();

// update publish flag.
m_readyToPublish = false;
m_readyToTrigger = false;

// check if queuing is enabled.
if (m_queue == null)
{
Publish(context, m_lastValue, m_lastError, notifications, diagnostics);
}
else
if (m_queue != null && (!m_resendData || m_queue.ItemsInQueue != 0))
{
DataValue value = null;
ServiceResult error = null;

while (m_queue.Publish(out value, out error))
{
Publish(context, value, error, notifications, diagnostics);

if (m_resendData)
{
m_readyToPublish = m_queue.ItemsInQueue > 0;
break;
}
}
}
else
{
Publish(context, m_lastValue, m_lastError, notifications, diagnostics);
}

// update flags
m_resendData = false;

return true;
}
Expand Down Expand Up @@ -828,6 +860,7 @@ private void Publish(
private bool m_alwaysReportUpdates;
private bool m_semanticsChanged;
private bool m_structureChanged;
private bool m_resendData;
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2970,7 +2970,6 @@ public virtual void TransferMonitoredItems(
{
monitoredItems[ii].SetupResendDataTrigger();
}

errors[ii] = StatusCodes.Good;
}
}
Expand All @@ -2989,10 +2988,9 @@ protected virtual void OnMonitoredItemsTransferred(
IList<IMonitoredItem> monitoredItems
)
{
// does nothing.
// overridden by the sub-class.
}


/// <summary>
/// Changes the monitoring mode for a set of monitored items.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Applications/ServerControls.Net4/ServerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ServerForm()
/// <summary>
/// Creates a form which displays the status for a UA server.
/// </summary>
public ServerForm(StandardServer server, ApplicationConfiguration configuration, bool showCertificateValidationDialog = false)
public ServerForm(StandardServer server, ApplicationConfiguration configuration, bool showCertificateValidationDialog = true)
{
InitializeComponent();

Expand Down
8 changes: 1 addition & 7 deletions Applications/ServerControls.Net4/UA Server Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,12 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion Libraries/Opc.Ua.Server/Subscription/IMonitoredItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public interface IMonitoredItem
bool IsReadyToTrigger { get; set; }

/// <summary>
/// Setup the resend data trigger by setting the monitor item in ResendData state
/// Gets a value indicating whether the monitored item is resending data.
/// </summary>
bool IsResendData { get; }

/// <summary>
/// Set the resend data trigger flag.
/// </summary>
void SetupResendDataTrigger();

Expand Down
Loading

0 comments on commit 10d4dbc

Please sign in to comment.