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:
@@ -24,6 +24,7 @@ public sealed class AppSession : IDisposable
|
||||
private ClusterClient? cluster;
|
||||
private StationNetwork? network;
|
||||
private MessageSender? keyer;
|
||||
private AlternatingCq? alternating;
|
||||
private So2rBox? box;
|
||||
|
||||
public AppSession(UserPaths paths, Settings settings)
|
||||
@@ -91,6 +92,10 @@ public sealed class AppSession : IDisposable
|
||||
|
||||
public MessageSender? Keyer => keyer;
|
||||
|
||||
/// Alternating CQ, or null while there is no keyer. It needs two radios to
|
||||
/// do anything, and a keyer that reports when a message has gone out.
|
||||
public AlternatingCq? Alternating => alternating;
|
||||
|
||||
/// The SO2R box, or null when there is none and the operator switches the
|
||||
/// transmitter and the headphones by hand.
|
||||
public So2rBox? Box => box;
|
||||
@@ -245,6 +250,8 @@ public sealed class AppSession : IDisposable
|
||||
/// without one.
|
||||
public void ApplyKeyerSettings()
|
||||
{
|
||||
alternating?.Dispose();
|
||||
alternating = null;
|
||||
keyer?.Dispose();
|
||||
keyer = null;
|
||||
switch (Settings.KeyerKind.ToLowerInvariant())
|
||||
@@ -261,6 +268,10 @@ public sealed class AppSession : IDisposable
|
||||
if (keyer is not null)
|
||||
{
|
||||
_ = keyer.SetSpeedAsync(Settings.KeyerSpeed);
|
||||
alternating = new AlternatingCq(
|
||||
keyer,
|
||||
CallCqOnAsync,
|
||||
TimeSpan.FromMilliseconds(Settings.AlternatingCqGapMs));
|
||||
}
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
@@ -303,12 +314,47 @@ public sealed class AppSession : IDisposable
|
||||
{
|
||||
return;
|
||||
}
|
||||
activeRadio = (activeRadio + 1) % positions.Count;
|
||||
MoveToRadio(positions[(activeRadio + 1) % positions.Count].RadioNumber);
|
||||
}
|
||||
|
||||
/// Moves the operator to a radio by number. Alternating CQ calls this from
|
||||
/// the keyer's thread, so everything it raises is posted by the windows.
|
||||
public void MoveToRadio(int radioNumber)
|
||||
{
|
||||
int at = positions.FindIndex(p => p.RadioNumber == radioNumber);
|
||||
if (at < 0 || at == activeRadio)
|
||||
{
|
||||
return;
|
||||
}
|
||||
activeRadio = at;
|
||||
_ = FollowActiveRadioAsync();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
ActiveRadioChanged?.Invoke(this, ActiveRadioNumber);
|
||||
}
|
||||
|
||||
/// Moves to the radio and sends its CQ message, which is F1. Used by
|
||||
/// alternating CQ; the operator's own F1 goes through the entry window.
|
||||
private async Task CallCqOnAsync(int radioNumber)
|
||||
{
|
||||
RadioPosition position = positions.FirstOrDefault(p => p.RadioNumber == radioNumber)
|
||||
?? throw new InvalidOperationException($"there is no radio {radioNumber}");
|
||||
if (keyer is null)
|
||||
{
|
||||
throw new InvalidOperationException("there is no keyer");
|
||||
}
|
||||
string template = Messages.For(
|
||||
position.Mode.Category,
|
||||
Settings.CwMessages,
|
||||
Settings.PhoneMessages)[0];
|
||||
if (template.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("F1 has no message — Config ▸ Keyer and messages");
|
||||
}
|
||||
MoveToRadio(radioNumber);
|
||||
await PointTransmitAtAsync(radioNumber).ConfigureAwait(false);
|
||||
await keyer.SendAsync(MessageExpander.Expand(template, position)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// Puts both radios in the headphones, or goes back to one. An operator
|
||||
/// listens to the second radio while the first is sending.
|
||||
public void ToggleListenToBoth()
|
||||
@@ -414,6 +460,7 @@ public sealed class AppSession : IDisposable
|
||||
DisposeRadios();
|
||||
cluster?.Dispose();
|
||||
network?.Dispose();
|
||||
alternating?.Dispose();
|
||||
keyer?.Dispose();
|
||||
box?.Dispose();
|
||||
store?.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user