Alternate CQ between the two radios
Ctrl+B calls CQ on one radio, and when that message has gone out, moves to the other and calls there. The keyboard, the entry window and the SO2R box follow each turn. N1MM calls this dueling CQs and puts it on the same key. The turn is taken when the keyer says the message has ended, not when a timer guesses it has. So MessageSender grew a Finished event and a ReportsCompletion flag, and both keyers fill them in: cwdaemon answers the <ESC>h reply request that now goes out in front of every message, and a WinKeyer clears the busy bit in the status bytes it sends of its own accord. The status-byte reading is in WinkeyerStatus, away from the serial port, because that is the half that can be tested without a keyer on the desk. A keyer that reports nothing refuses to start alternating CQ rather than keying the second radio over the first. AlternatingCq itself takes the keyer, a callback that calls CQ on a radio, the gap and a wait function, so the alternation is tested without sleeping. The gap is in Config ▸ Keyer and messages and will not go below 100 ms, which is N1MM's floor too: an SO2R box works relays. docs/keying.md writes down why cwdaemon does the timing and we do not. N1MM keys DTR itself with a coarse sleep, a busy-wait and a margin that grows every time the sleep overshoots, and it raises the thread to TIME_CRITICAL for the length of the message. The busy-wait ports to Linux; the priority does not, without CAP_SYS_NICE, and a garbage collection mid-element is audible. A direct serial keyer stays a reasonable third option, to be taken knowingly. Running it against a fake daemon that takes 1.5 seconds to play a message: six CQs went out back to back and the keyboard moved between the two entry windows each time. Escape stopped it, let the message in flight finish, and started nothing further. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,11 +27,49 @@ public class CwDaemonSenderTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TextGoesOutInUpperCase()
|
||||
public async Task TextGoesOutInUpperCaseBehindAReplyRequest()
|
||||
{
|
||||
using CwDaemonSender sender = new("127.0.0.1", Port);
|
||||
byte[] sent = await NextDatagram(() => sender.SendAsync("cq test de dl1abc"));
|
||||
Assert.Equal("CQ TEST DE DL1ABC", Encoding.ASCII.GetString(sent));
|
||||
await sender.SendAsync("cq test de dl1abc");
|
||||
|
||||
// one receive at a time: two at once can take the datagrams in either order
|
||||
UdpReceiveResult request = await daemon.ReceiveAsync().WaitAsync(TimeSpan.FromSeconds(5));
|
||||
UdpReceiveResult text = await daemon.ReceiveAsync().WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal("\u001bhnonemm", Encoding.ASCII.GetString(request.Buffer));
|
||||
Assert.Equal("CQ TEST DE DL1ABC", Encoding.ASCII.GetString(text.Buffer));
|
||||
}
|
||||
|
||||
/// cwdaemon answers with `h` and the text of the reply request once the
|
||||
/// message has been played.
|
||||
[Fact]
|
||||
public async Task TheReplySaysTheMessageHasGoneOut()
|
||||
{
|
||||
using CwDaemonSender sender = new("127.0.0.1", Port);
|
||||
TaskCompletionSource finished = new();
|
||||
sender.Finished += (_, _) => finished.TrySetResult();
|
||||
|
||||
Task<UdpReceiveResult> request = daemon.ReceiveAsync();
|
||||
await sender.SendAsync("test");
|
||||
UdpReceiveResult from = await request.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
await daemon.SendAsync(Encoding.ASCII.GetBytes("hnonemm\r\n"), from.RemoteEndPoint);
|
||||
|
||||
await finished.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AReplyForSomebodyElseIsPassedOver()
|
||||
{
|
||||
using CwDaemonSender sender = new("127.0.0.1", Port);
|
||||
TaskCompletionSource finished = new();
|
||||
sender.Finished += (_, _) => finished.TrySetResult();
|
||||
|
||||
Task<UdpReceiveResult> request = daemon.ReceiveAsync();
|
||||
await sender.SendAsync("test");
|
||||
UdpReceiveResult from = await request.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
await daemon.SendAsync(Encoding.ASCII.GetBytes("hsomebodyelse\r\n"), from.RemoteEndPoint);
|
||||
|
||||
await Assert.ThrowsAsync<TimeoutException>(
|
||||
() => finished.Task.WaitAsync(TimeSpan.FromMilliseconds(300)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
49
tests/Nonemm.Keying.Tests/WinkeyerStatusTests.cs
Normal file
49
tests/Nonemm.Keying.Tests/WinkeyerStatusTests.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace Nonemm.Keying.Tests;
|
||||
|
||||
public class WinkeyerStatusTests
|
||||
{
|
||||
[Fact]
|
||||
public void SendingEndsWhenTheBusyFlagClears()
|
||||
{
|
||||
WinkeyerStatus status = new();
|
||||
|
||||
Assert.False(status.Read(0xC4));
|
||||
Assert.True(status.IsSending);
|
||||
Assert.True(status.Read(0xC0));
|
||||
Assert.False(status.IsSending);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AStatusByteThatRepeatsTheLastOneIsNotAnEnding()
|
||||
{
|
||||
WinkeyerStatus status = new();
|
||||
status.Read(0xC4);
|
||||
status.Read(0xC0);
|
||||
|
||||
Assert.False(status.Read(0xC0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearingTheBusyFlagWithTheBreakInFlagSetStillEndsIt()
|
||||
{
|
||||
WinkeyerStatus status = new();
|
||||
status.Read(0xC4);
|
||||
|
||||
Assert.True(status.Read(0xC2));
|
||||
}
|
||||
|
||||
/// The speed pot and the characters the keyer echoes say nothing about the
|
||||
/// buffer.
|
||||
[Theory]
|
||||
[InlineData(0x80)]
|
||||
[InlineData(0xBF)]
|
||||
[InlineData((byte)'K')]
|
||||
public void OtherBytesAreNotStatus(byte value)
|
||||
{
|
||||
WinkeyerStatus status = new();
|
||||
status.Read(0xC4);
|
||||
|
||||
Assert.False(status.Read(value));
|
||||
Assert.True(status.IsSending);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user