Give the telnet window the rest of what N1MM's has
The packet window showed traffic and took a command line, and everything else
about the cluster lived in a dialog under Config. It is now the window N1MM has,
with the same five tabs.
Telnet shows the traffic with spot lines in green, what went out in blue and
lines from a preferred spotter in bold. Double clicking a spot line, or "Jump to
this spot", puts the radio there with the call in the entry window. Scrolling
stops while the pointer is over the traffic. The client keeps the last two
hundred lines, so a window opened mid-contest is not blank.
Clusters keeps the operator's nodes with their ports, passwords and after-login
commands, connects and disconnects, and holds the logon settings. Download
fetches the published list of telnet nodes from NG3K — around fifty, with the
sysop's call and a note about each — and clicking one fills the boxes in. N1MM
downloads its list from its own web service, which asks the operator to opt in
to data collection and is N1MM's to run, so this reads a public page instead.
ClusterList takes any page with telnet:// links in a table; a page it cannot
read leaves the stored list alone.
Filters decide which spots reach the bandmap: bands, modes, beacons, busted
calls, stations outside the call history file, blacklisted spotters and calls,
spots from outside your country, continent or a list of prefixes, and how long a
spot stays on the map. A busted spot is a call the callsign database has never
heard that is one character away from one it knows; a call nothing resembles is
kept, because that is what a new station looks like. Nothing is filtered out of
the traffic itself — the operator sees everything the node sends.
Buttons edits the twelve command buttons. A button takes what N1MM's takes: the
message macros, several commands separated by semicolons, or {CONN} and the name
of a favourite, which connects to that node instead of sending anything. The
label takes the macros too. Right-clicking a button opens the editor.
Config ▸ Cluster now opens this window on the Clusters tab rather than a dialog
of its own, which is where N1MM keeps those settings.
Three things that could take the program down while a cluster was connected:
Settings.Load read a null where the property is not nullable. A file that names
a key with a null value — one written before the property existed and then
edited — put that null straight through, because the property's own default only
runs when the key is missing. Opening the telnet window then threw on the first
list it touched. Every null is now put back to the default the property
declares, walking into the stored records and the lists of them.
Bandmap was written from the cluster's thread and read from the window's, so a
dictionary could be modified while a window enumerated it. Every method locks
now.
ClusterClient disposed its token source while its own loop still used it, and
the retry delay sat outside the catch, so a disconnect faulted the loop task.
Along the way the message macros were checked against N1MM's function-key
documentation, and several were wrong. {LOGGEDCALL} is N1MM's {LASTCALL}, the
serial is #, and there is no {MYZONE}; {NAME} and {GRIDSQUARE} stand for the
other station's name and grid, not ours; {OTHERMHZ} is the radio the operator is
not on. The single-character macros * and ! were missing. Added from the same
table: {LASTCALL}, {PREVNR}, {NAMEANDSPACE}, {CHNAME}, {GRID}, the two grid
bearings and the grid distance, {FREQ}, {FREQROUND}, the other-radio
frequencies, {TIMESTAMP} and {TIME2}. Frequencies are formatted the way N1MM
formats them, with R for the decimal point on CW. The macros that pass a station
to the other band take the second radio as a new argument, and stand for nothing
at a one-radio station.
Left out, and written down: saving spots to a database, which N1MM keeps in its
admin database rather than in the log file the two programs share; the
special-calls list; the two-character busted check, which is a few hundred
thousand lookups per spot against a few hundred for one character; and N1MM's
action macros, which need a different shape than an expander that returns a
string.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,29 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Nonemm.Contests;
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Core.Calls;
|
||||
|
||||
namespace Nonemm.Session;
|
||||
|
||||
/// Fills in a function key message. The macro names are N1MM's, so a message
|
||||
/// file written for either program says the same thing.
|
||||
/// Fills in a function key message. The macro names and what they stand for are
|
||||
/// N1MM's, from its published function-key documentation, so a message file
|
||||
/// written for either program says the same thing.
|
||||
///
|
||||
/// Only the text macros are here. N1MM also has action macros — `{WIPE}`,
|
||||
/// `{LOG}`, `{RUN}`, the CAT and SO2R families — which run a program command
|
||||
/// rather than standing for text; they expand to nothing, so a message that
|
||||
/// holds one still sends the right characters.
|
||||
public static class MessageExpander
|
||||
{
|
||||
/// Cut numbers: a contest operator sends T for zero and N for nine because
|
||||
/// they are shorter.
|
||||
private const string CutDigits = "T12345678N";
|
||||
|
||||
public static string Expand(string template, RadioPosition session)
|
||||
/// `other` is the radio the operator is not on, for the macros that pass a
|
||||
/// station to the other band. Null when the station has one radio, and then
|
||||
/// those macros stand for nothing.
|
||||
public static string Expand(string template, RadioPosition session, RadioPosition? other = null)
|
||||
{
|
||||
StringBuilder text = new();
|
||||
int at = 0;
|
||||
@@ -25,13 +38,14 @@ public static class MessageExpander
|
||||
text.Append(template[at..]);
|
||||
break;
|
||||
}
|
||||
text.Append(Macro(template[(at + 1)..close], session));
|
||||
text.Append(Macro(template[(at + 1)..close], session, other));
|
||||
at = close + 1;
|
||||
continue;
|
||||
}
|
||||
if (c == '#')
|
||||
// the single-character macros, which take no braces
|
||||
if (c is '*' or '!' or '#')
|
||||
{
|
||||
text.Append(session.SentNumber);
|
||||
text.Append(Single(c, session));
|
||||
at++;
|
||||
continue;
|
||||
}
|
||||
@@ -41,23 +55,129 @@ public static class MessageExpander
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
private static string Macro(string name, RadioPosition session) => name.ToUpperInvariant() switch
|
||||
private static string Single(char macro, RadioPosition session) => macro switch
|
||||
{
|
||||
"MYCALL" => session.Me.Callsign,
|
||||
"CALL" => session.Entry.Call.Trim(),
|
||||
"LOGGEDCALL" => session.Log.Qsos.Count > 0 ? session.Log.Qsos[^1].Call.Text : "",
|
||||
"EXCH" => session.Instance.SentExchange,
|
||||
"SENTRST" => session.DefaultReport(),
|
||||
"SENTRSTCUT" => Cut(session.DefaultReport()),
|
||||
"SENTNR" => session.SentNumber.ToString(),
|
||||
"SENTNRCUT" => Cut(session.SentNumber.ToString()),
|
||||
"NAME" => session.Me.Name,
|
||||
"GRIDSQUARE" => session.Me.GridSquare,
|
||||
"MYZONE" => session.Me.CqZone.ToString(),
|
||||
"OTHERMHZ" => (session.Frequency.Megahertz).ToString("0.###"),
|
||||
_ => "",
|
||||
'*' => session.Me.Callsign,
|
||||
'!' => TheirCall(session),
|
||||
_ => SerialNumber(session),
|
||||
};
|
||||
|
||||
/// The number for this contact, or the one just logged when nothing is
|
||||
/// typed in the callsign box, so a repeat after logging sends the same
|
||||
/// number again.
|
||||
private static string SerialNumber(RadioPosition session) =>
|
||||
session.Entry.Call.Trim().Length == 0 && LastLogged(session) is { } last
|
||||
? last.SentNumber.ToString(CultureInfo.InvariantCulture)
|
||||
: session.SentNumber.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
private static string Macro(string name, RadioPosition session, RadioPosition? other) =>
|
||||
name.ToUpperInvariant() switch
|
||||
{
|
||||
"MYCALL" => session.Me.Callsign,
|
||||
"CALL" => TheirCall(session),
|
||||
"LASTCALL" => LastLogged(session)?.Call.Text ?? "",
|
||||
"PREVNR" => LastLogged(session) is { } last
|
||||
? last.SentNumber.ToString("000", CultureInfo.InvariantCulture)
|
||||
: "",
|
||||
"EXCH" => session.Instance.SentExchange,
|
||||
"SENTRST" => session.DefaultReport(),
|
||||
"SENTRSTCUT" => Cut(session.DefaultReport()),
|
||||
"GRID" => session.Me.GridSquare,
|
||||
"GRIDSQUARE" => Theirs(session, ExchangeSlot.GridSquare, known => known.GridSquare),
|
||||
"GRIDBEARING" => Bearing(session, reverse: false),
|
||||
"REVGRIDBEARING" => Bearing(session, reverse: true),
|
||||
// N1MM's own documentation spells this one KMGRIGDISTANCE; the
|
||||
// program answers to KMGRIDDISTANCE, so that is what is read here
|
||||
"KMGRIDDISTANCE" => Distance(session),
|
||||
"NAME" => Name(session),
|
||||
"NAMEANDSPACE" => Name(session) is { Length: > 0 } theirName ? theirName + " " : "",
|
||||
"CHNAME" => session.Session.History.Find(session.Entry.Call)?.Name ?? "",
|
||||
"FREQ" => FrequencyText(session, session.Frequency, round: false),
|
||||
"FREQROUND" => FrequencyText(session, session.Frequency, round: true),
|
||||
"OTHERFREQ" => other is null ? "" : FrequencyText(session, other.Frequency, round: false),
|
||||
"OTHERFREQROUND" => other is null ? "" : FrequencyText(session, other.Frequency, round: true),
|
||||
"OTHERMHZ" => other is null ? "" : Megahertz(session, other.Frequency),
|
||||
"OTHERBAND" => other is null ? "" : Bands.ForFrequency(other.Frequency)?.Name ?? "",
|
||||
"LRMHZ" => Megahertz(session, Radio(session, other, 1)),
|
||||
"RRMHZ" => Megahertz(session, Radio(session, other, 2)),
|
||||
"TIMESTAMP" => DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture),
|
||||
"TIME2" => DateTime.UtcNow.ToString("HHmm", CultureInfo.InvariantCulture),
|
||||
_ => "",
|
||||
};
|
||||
|
||||
/// The call being worked, or the last one logged when the box is empty,
|
||||
/// which is what N1MM sends for both `{CALL}` and `!`.
|
||||
private static string TheirCall(RadioPosition session) =>
|
||||
session.Entry.Call.Trim() is { Length: > 0 } typed ? typed : LastLogged(session)?.Call.Text ?? "";
|
||||
|
||||
private static Qso? LastLogged(RadioPosition session) =>
|
||||
session.Log.Qsos.Count > 0 ? session.Log.Qsos[^1] : null;
|
||||
|
||||
private static string Name(RadioPosition session) =>
|
||||
Theirs(session, ExchangeSlot.Name, known => known.Name);
|
||||
|
||||
/// What the operator has typed in that exchange box, or what the call
|
||||
/// history file says when the contest has no such box or it is empty.
|
||||
private static string Theirs(
|
||||
RadioPosition session,
|
||||
ExchangeSlot slot,
|
||||
Func<CallHistoryEntry, string> fromHistory)
|
||||
{
|
||||
string typed = session.Entry.ValueOf(slot).Trim();
|
||||
if (typed.Length > 0)
|
||||
{
|
||||
return typed;
|
||||
}
|
||||
CallHistoryEntry? known = session.Session.History.Find(session.Entry.Call);
|
||||
return known is null ? "" : fromHistory(known);
|
||||
}
|
||||
|
||||
/// Kilohertz to one decimal, and on CW the decimal point is sent as R.
|
||||
private static string FrequencyText(RadioPosition session, Frequency frequency, bool round)
|
||||
{
|
||||
if (round)
|
||||
{
|
||||
return Math.Round(frequency.Kilohertz).ToString("0", CultureInfo.InvariantCulture);
|
||||
}
|
||||
return CwDecimal(session, frequency.Kilohertz.ToString("0.0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// The band in megahertz, as N1MM sends it: 14, or 3R5 on CW.
|
||||
private static string Megahertz(RadioPosition session, Frequency frequency) =>
|
||||
Bands.ForFrequency(frequency) is { } band
|
||||
? CwDecimal(session, band.MegahertzLabel.ToString("0.###", CultureInfo.InvariantCulture))
|
||||
: "";
|
||||
|
||||
private static Frequency Radio(RadioPosition session, RadioPosition? other, int number) =>
|
||||
session.RadioNumber == number ? session.Frequency
|
||||
: other?.RadioNumber == number ? other.Frequency
|
||||
: Frequency.Zero;
|
||||
|
||||
private static string CwDecimal(RadioPosition session, string text) =>
|
||||
session.Mode.Category == ModeCategory.Cw ? text.Replace('.', 'R') : text;
|
||||
|
||||
private static string Bearing(RadioPosition session, bool reverse)
|
||||
{
|
||||
if (!Grids(session, out GridSquare mine, out GridSquare theirs))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
double bearing = reverse ? theirs.BearingTo(mine) : mine.BearingTo(theirs);
|
||||
return Math.Round(bearing).ToString("0", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static string Distance(RadioPosition session) =>
|
||||
Grids(session, out GridSquare mine, out GridSquare theirs)
|
||||
? Math.Round(mine.DistanceTo(theirs)).ToString("0", CultureInfo.InvariantCulture)
|
||||
: "";
|
||||
|
||||
private static bool Grids(RadioPosition session, out GridSquare mine, out GridSquare theirs)
|
||||
{
|
||||
theirs = default;
|
||||
return GridSquare.TryParse(session.Me.GridSquare, out mine)
|
||||
&& GridSquare.TryParse(Theirs(session, ExchangeSlot.GridSquare, known => known.GridSquare), out theirs);
|
||||
}
|
||||
|
||||
private static string Cut(string digits) =>
|
||||
new(digits.Select(d => char.IsAsciiDigit(d) ? CutDigits[d - '0'] : d).ToArray());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user