-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRigDriverFactory.cs
More file actions
139 lines (127 loc) · 6.45 KB
/
Copy pathRigDriverFactory.cs
File metadata and controls
139 lines (127 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using OscarWatch.Core.Models;
namespace OscarWatch.Rig;
public static class RigDriverFactory
{
public static IRigDriver Create(RigSettings settings)
{
if (settings.DualRadioEnabled)
throw new InvalidOperationException("Use Create(RigEndpointSettings) for dual-radio endpoints.");
if (settings.Type == RigType.FlexSmartSdr)
{
return new FlexRadioDriver(
settings.NetworkHost,
settings.NetworkPort > 0 ? settings.NetworkPort : RigSettings.FlexSmartSdrDefaultPort,
settings.CatDelayMs);
}
return CreateSingle(
settings.Type,
settings.Port,
settings.BaudRate,
settings.Region,
settings.CatDelayMs,
settings.CivAddress,
settings.KenwoodHardwareRtsEnabled,
settings.KenwoodTraceEnabled);
}
public static IRigDriver Create(RigEndpointSettings endpoint) => endpoint.Type switch
{
RigType.SdrRigCtlTcp => new RigCtlTcpDriver(
endpoint.NetworkHost,
endpoint.NetworkPort,
endpoint.CatDelayMs),
RigType.Dummy => new DummyRigDriver(),
RigType.YaesuFt817 => new YaesuFt817Driver(
RigType.YaesuFt817, endpoint.Port, endpoint.BaudRate, endpoint.Region, endpoint.CatDelayMs),
RigType.YaesuFt818 => new YaesuFt818Driver(
endpoint.Port, endpoint.BaudRate, endpoint.Region, endpoint.CatDelayMs),
RigType.YaesuFt991 => new YaesuFt991Driver(
RigType.YaesuFt991, endpoint.Port, endpoint.BaudRate, endpoint.Region, endpoint.CatDelayMs),
RigType.YaesuFt991a => new YaesuFt991aDriver(
endpoint.Port, endpoint.BaudRate, endpoint.Region, endpoint.CatDelayMs),
RigType.YaesuFtx1 => new YaesuFtx1Driver(
endpoint.Port, endpoint.BaudRate, endpoint.Region, endpoint.CatDelayMs),
RigType.IcomIc705 => new IcomIc705Driver(
endpoint.Port, endpoint.BaudRate, ResolveEndpointCivAddress(endpoint), endpoint.CatDelayMs),
RigType.IcomIc7300 => new IcomIc7300Driver(
endpoint.Port, endpoint.BaudRate, ResolveEndpointCivAddress(endpoint), endpoint.CatDelayMs),
RigType.IcomIc905 => new IcomIc905Driver(
endpoint.Port, endpoint.BaudRate, ResolveEndpointCivAddress(endpoint), endpoint.CatDelayMs),
RigType.IcomIc706 or RigType.IcomIc706Mkii or RigType.IcomIc706MkiiG =>
CreateIc706SeriesDriver(endpoint),
_ => CreateSingle(
endpoint.Type,
endpoint.Port,
endpoint.BaudRate,
endpoint.Region,
endpoint.CatDelayMs,
ResolveEndpointCivAddress(endpoint))
};
/// <summary>Dual-radio uplink must be a serial CAT rig or dummy, not SDR rigctl.</summary>
public static void EnsureValidDualEndpoint(RigEndpointSettings endpoint, bool isDownlink)
{
if (endpoint.Type == RigType.SdrRigCtlTcp && !isDownlink)
throw new InvalidOperationException("SDR rigctl TCP is supported on the downlink only.");
if (endpoint.Type == RigType.FlexSmartSdr)
throw new InvalidOperationException("FlexRadio SmartSDR is a single-radio full-duplex driver; disable Dual radio.");
if (endpoint.Type == RigType.Dummy && isDownlink)
throw new InvalidOperationException("Dummy radio is supported on the uplink only.");
}
private static IRigDriver CreateIc706SeriesDriver(RigEndpointSettings endpoint) =>
new IcomIc706SeriesDriver(
endpoint.Type,
endpoint.Port,
endpoint.BaudRate,
ResolveEndpointCivAddress(endpoint),
endpoint.CatDelayMs);
private static string ResolveEndpointCivAddress(RigEndpointSettings endpoint)
{
if (!string.IsNullOrWhiteSpace(endpoint.CivAddress))
return endpoint.CivAddress.Trim();
return RigSettings.DefaultCivAddressFor(endpoint.Type);
}
private static IRigDriver CreateSingle(
RigType type,
string port,
int baudRate,
RigRegion region,
int catDelayMs,
string civAddress,
bool kenwoodHardwareRtsEnabled = true,
bool kenwoodTraceEnabled = true)
{
return type switch
{
RigType.IcomIc910 => new IcomIc910Driver(port, baudRate, civAddress, catDelayMs),
RigType.IcomIc9100 => new IcomIc9100Driver(port, baudRate, civAddress, catDelayMs),
RigType.IcomIc9700 => new IcomIc9700Driver(port, baudRate, civAddress, catDelayMs),
RigType.IcomIc821h => new IcomIc821hDriver(port, baudRate, civAddress, catDelayMs),
RigType.IcomIc705 =>
throw new InvalidOperationException("IC-705 requires Settings → Radio → Dual radio."),
RigType.IcomIc7300 =>
throw new InvalidOperationException("IC-7300 requires Settings → Radio → Dual radio."),
RigType.IcomIc905 =>
throw new InvalidOperationException("IC-905 requires Settings → Radio → Dual radio."),
RigType.IcomIc706 or RigType.IcomIc706Mkii or RigType.IcomIc706MkiiG =>
throw new InvalidOperationException("IC-706 series radios require Settings → Radio → Dual radio."),
RigType.YaesuFt847 => new YaesuFt847Driver(port, baudRate, catDelayMs),
RigType.YaesuFt817 or RigType.YaesuFt818 =>
throw new InvalidOperationException("FT-817/FT-818 require Settings → Radio → Dual radio."),
RigType.YaesuFt991 or RigType.YaesuFt991a =>
throw new InvalidOperationException("FT-991/FT-991A require Settings → Radio → Dual radio."),
RigType.YaesuFtx1 =>
throw new InvalidOperationException("FTX-1 series radios require Settings → Radio → Dual radio."),
RigType.KenwoodTs2000 => new KenwoodTs2000Driver(
port,
baudRate,
catDelayMs,
hardwareRtsEnabled: kenwoodHardwareRtsEnabled,
traceEnabled: kenwoodTraceEnabled),
RigType.FlexSmartSdr =>
throw new InvalidOperationException("FlexRadio SmartSDR requires network host/port via RigSettings."),
RigType.SdrRigCtlTcp =>
throw new InvalidOperationException("SDR rigctl TCP requires Settings → Radio → Dual radio (downlink)."),
RigType.Dummy => new DummyRigDriver(),
_ => new DummyRigDriver()
};
}
}