Read split from the radio, and read two of them
Split. RadioState carries a transmit frequency, zero meaning the radio transmits where it listens, so split is not a second flag that can disagree with it. The contact stores it in N1MM's QSX column, the entry window shows 14008.00 followed by the transmit frequency, and the bandmap draws a red bar there. SetSplitAsync sets the frequency before turning split on, or a radio last split somewhere else transmits there. Every command now goes out with a + in front, asking rigctld for its extended answer: named fields ended by an RPRT line. The raw answer is bare values with no terminator, so the client had to know how many lines each command returns — there was a `command == "m"` special case for the one that returns two. Add a third such command and get the count wrong once, and every later answer is read against the wrong command for the rest of the session. RigctldReply parses the extended form and is tested on its own. A radio that cannot do split answers RPRT -11. That is an answer, not a broken connection, so the frequency and mode it did report still count. Two radios. Settings hold a list rather than one host and port, with the single radio an older settings file holds carried into it. Both radios are read and both show on the bandmap, the active one green and the other orange, but only the active one drives the entry window: the second radio moving must not drag the operator off the station being worked. Ctrl+Tab swaps, and a contact records which radio made it. This is not a full two-radio operating position — no second entry window, no alternating CQ, no audio switching. It is two radios read and logged correctly. Tested against a stand-in for rigctld over a real socket, and looked at under Xvfb with two fake radios, one of them split. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
89
tests/Nonemm.Rig.Tests/FakeRigctld.cs
Normal file
89
tests/Nonemm.Rig.Tests/FakeRigctld.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Nonemm.Rig.Tests;
|
||||
|
||||
/// A stand-in for hamlib's `rigctld`, answering in the extended form the client
|
||||
/// asks for. It records what it was told so a test can check the commands that
|
||||
/// went out, not only what came back.
|
||||
public sealed class FakeRigctld : IDisposable
|
||||
{
|
||||
private readonly TcpListener listener;
|
||||
private readonly CancellationTokenSource stopping = new();
|
||||
private readonly List<string> received = [];
|
||||
private readonly Lock guard = new();
|
||||
|
||||
public FakeRigctld()
|
||||
{
|
||||
listener = new TcpListener(IPAddress.Loopback, 0);
|
||||
listener.Start();
|
||||
_ = Task.Run(() => ServeAsync(stopping.Token));
|
||||
}
|
||||
|
||||
public int Port => ((IPEndPoint)listener.LocalEndpoint).Port;
|
||||
|
||||
public long FrequencyHertz { get; set; } = 14_025_000;
|
||||
|
||||
public string Mode { get; set; } = "CW";
|
||||
|
||||
public bool IsSplit { get; set; }
|
||||
|
||||
public long TransmitFrequencyHertz { get; set; }
|
||||
|
||||
/// -11 is what hamlib returns for something the radio cannot do.
|
||||
public bool SupportsSplit { get; set; } = true;
|
||||
|
||||
public IReadOnlyList<string> Received
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (guard)
|
||||
{
|
||||
return [.. received];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
stopping.Cancel();
|
||||
listener.Stop();
|
||||
stopping.Dispose();
|
||||
}
|
||||
|
||||
private async Task ServeAsync(CancellationToken cancellation)
|
||||
{
|
||||
try
|
||||
{
|
||||
using TcpClient client = await listener.AcceptTcpClientAsync(cancellation);
|
||||
using StreamReader reader = new(client.GetStream(), Encoding.ASCII);
|
||||
using StreamWriter writer = new(client.GetStream(), Encoding.ASCII) { AutoFlush = true };
|
||||
while (await reader.ReadLineAsync(cancellation) is { } line)
|
||||
{
|
||||
lock (guard)
|
||||
{
|
||||
received.Add(line);
|
||||
}
|
||||
await writer.WriteAsync(Answer(line.TrimStart('+').Trim()));
|
||||
}
|
||||
}
|
||||
catch (Exception e) when (e is OperationCanceledException or IOException or SocketException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private string Answer(string command)
|
||||
{
|
||||
string verb = command.Split(' ')[0];
|
||||
return verb switch
|
||||
{
|
||||
"f" => $"get_freq:\nFrequency: {FrequencyHertz}\nRPRT 0\n",
|
||||
"m" => $"get_mode:\nMode: {Mode}\nPassband: 500\nRPRT 0\n",
|
||||
"s" when !SupportsSplit => "RPRT -11\n",
|
||||
"s" => $"get_split_vfo:\nSplit: {(IsSplit ? 1 : 0)}\nTX VFO: VFOB\nRPRT 0\n",
|
||||
"i" => $"get_split_freq:\nTX Frequency: {TransmitFrequencyHertz}\nRPRT 0\n",
|
||||
_ => $"{verb}: {command}\nRPRT 0\n",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user