You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

2 months ago
namespace Housing.Services;
public static class StartSignalWatcher
{
public static Task WaitForStartAsync(StartSignalSettings settings, CancellationToken cancellationToken = default)
{
if (!settings.Enabled)
{
return Task.CompletedTask;
}
var connection = GetConnection(settings);
return connection switch
{
"NI6501" or "NI-6501" or "NIDAQ" or "DAQ" => new Ni6501StartSignalWatcher(settings).WaitForStartAsync(cancellationToken),
"TCP" or "LAN" or "ETHERNET" => new TcpStartSignalWatcher(settings).WaitForStartAsync(cancellationToken),
_ => throw new InvalidOperationException("Hardware.ini [StartSignal] Connection은 Ni6501 또는 Tcp로 설정하세요.")
};
}
public static string Describe(StartSignalSettings settings)
{
var connection = GetConnection(settings);
return connection switch
{
"NI6501" or "NI-6501" or "NIDAQ" or "DAQ" => $"NI-6501 {settings.PhysicalChannel}",
"TCP" or "LAN" or "ETHERNET" => string.IsNullOrWhiteSpace(settings.ReadCommand)
? $"LAN {settings.Host}:{settings.Port} 수신 대기"
: $"LAN {settings.Host}:{settings.Port} 명령: {settings.ReadCommand}",
_ => connection
};
}
private static string GetConnection(StartSignalSettings settings)
{
return string.IsNullOrWhiteSpace(settings.Connection)
? "NI6501"
: settings.Connection.Trim().ToUpperInvariant();
}
}