using Microsoft.Extensions.Options;
|
using WIDESEAWCS_S7Simulator.Core.Interfaces;
|
using WIDESEAWCS_S7Simulator.Core.Protocol;
|
|
namespace WIDESEAWCS_S7Simulator.Application.Protocol;
|
|
/// <summary>
|
/// 化成堆垛机设备协议处理器。
|
/// </summary>
|
public class PlcLinkStackerProtocolHandler : IDeviceProtocolHandler
|
{
|
private readonly MirrorAckProtocolHandler _mirrorAckHandler;
|
private readonly ProtocolMonitoringOptions _options;
|
|
public PlcLinkStackerProtocolHandler(
|
MirrorAckProtocolHandler mirrorAckHandler,
|
IOptions<ProtocolMonitoringOptions> options)
|
{
|
_mirrorAckHandler = mirrorAckHandler;
|
_options = options.Value;
|
}
|
|
public string ProtocolName => "PlcLinkStackerProtocol";
|
|
public bool Process(IMemoryStore memoryStore, ProtocolTemplate template, ProtocolRuntimeState runtimeState)
|
{
|
var ruleIds = _options.PlcLinkStackerRuleIds
|
.Where(x => !string.IsNullOrWhiteSpace(x))
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
.ToArray();
|
if (ruleIds.Length == 0)
|
{
|
return false;
|
}
|
|
bool changed = false;
|
foreach (var ruleId in ruleIds)
|
{
|
var rule = _options.MirrorAckRules
|
.FirstOrDefault(x => string.Equals(x.RuleId, ruleId, StringComparison.OrdinalIgnoreCase));
|
if (rule == null)
|
{
|
continue;
|
}
|
|
changed |= _mirrorAckHandler.Process(memoryStore, template, runtimeState, rule, $"{ProtocolName}:{ruleId}");
|
}
|
|
return changed;
|
}
|
}
|