Write the numbered Cabrillo lines a .udc file asks for

CabrilloFormat 2, 3, 4 and 5 name the NAQP, NA Sprint, Sweepstakes and
section-and-serial lines. A file asking for one of those got the default
line; it now gets the layout, ported from CabrilloString2 and
CabrilloString4 in N1MM's Contact.cs, in N1MM's columns.

The exchange the layouts split into columns is built from the boxes the
file defines, in the order it defines them. N1MM builds it from the
section box alone, which writes only half of a two-box exchange such as
NAQP's name and state.

Format 6, the ARRL RTTY Roundup line, is still not read. No published
.udc file asks for it, because the Roundup has a contest class of its
own.

ExchangeSlots.ValueOf moves to Nonemm.Contests as QsoExchange.ValueOf,
so the contest code can read a contact through its exchange boxes
without a second copy of that switch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
2026-08-31 12:27:49 +00:00
parent cf5bdd6082
commit a07b181ee1
7 changed files with 251 additions and 28 deletions

View File

@@ -0,0 +1,30 @@
using Nonemm.Core;
namespace Nonemm.Contests;
/// Reading the exchange back out of a logged contact, one entry box at a time.
/// `ExchangeSlots.Apply` in `Nonemm.Session` puts the values in.
public static class QsoExchange
{
/// What the contact holds for one exchange box, or an empty string for a
/// box it holds nothing for.
public static string ValueOf(Qso qso, ExchangeSlot slot) => slot switch
{
ExchangeSlot.ReceivedReport => qso.ReceivedReport,
ExchangeSlot.SerialNumber => Digits(qso.ReceivedNumber),
ExchangeSlot.Zone => Digits(qso.Zone),
ExchangeSlot.Section => qso.Section,
ExchangeSlot.Check => Digits(qso.Check),
ExchangeSlot.Precedence => qso.Precedence,
ExchangeSlot.Exchange1 => qso.Exchange1,
ExchangeSlot.MiscText => qso.MiscText,
ExchangeSlot.Name => qso.Name,
ExchangeSlot.Qth => qso.Qth,
ExchangeSlot.GridSquare => qso.GridSquare,
ExchangeSlot.Power => qso.Power,
ExchangeSlot.Comment => qso.Comment,
_ => "",
};
private static string Digits(int value) => value > 0 ? value.ToString() : "";
}

View File

@@ -0,0 +1,96 @@
using Nonemm.Core;
namespace Nonemm.Contests.Udc;
/// The numbered `CabrilloFormat` layouts. A `.udc` file that names one of
/// these asks for a QSO line the default layout cannot write:
///
/// | Format | Line | What the exchange looks like |
/// |---|---|---|
/// | 2 | NAQP | two columns: `SAM` and `OH` |
/// | 3 | NA Sprint | the same two columns, taken from the second and third words |
/// | 4 | Sweepstakes | one column: `0034 B 77 OH` |
/// | 5 | section and serial | one column: `OH034` |
///
/// Each width below is N1MM's width less one. N1MM separates two columns by
/// padding the first one; `CabrilloWriter` pads the first one and then adds a
/// space. So a column N1MM writes 14 characters wide is 13 characters here.
public sealed class UdcCabrilloFormat(int format)
{
public bool IsNumbered => format is 2 or 3 or 4 or 5;
public CabrilloExchange Line(Qso qso, StationInfo me, string sent, string received) =>
format is 2 or 3
? ExchangeInTwoColumns(qso, me, sent, received)
: ExchangeInOneColumn(qso, me, sent);
/// Formats 2 and 3. Format 3 starts at the second word of the exchange:
/// the NA Sprint exchange begins with the serial number, and the column
/// before these two already holds it.
///
/// N1MM leaves both columns empty when the exchange is one word long,
/// which looks like a slip. That one word goes in the first column here.
private CabrilloExchange ExchangeInTwoColumns(
Qso qso,
StationInfo me,
string sent,
string received)
{
int firstWord = format == 3 ? 1 : 0;
string[] sentWords = Words(sent);
string[] receivedWords = Words(received);
return new CabrilloExchange(
[
new CabrilloField(me.Callsign, 13),
new CabrilloField($"{qso.SentNumber}".PadLeft(4), 5),
new CabrilloField(Cut(Word(sentWords, firstWord), 10), 11),
new CabrilloField(Word(sentWords, firstWord + 1), 11),
],
[
new CabrilloField(qso.Call.Text, 13),
new CabrilloField($"{qso.ReceivedNumber}".PadLeft(4), 5),
new CabrilloField(Cut(Word(receivedWords, firstWord), 10), 11),
new CabrilloField(Word(receivedWords, firstWord + 1), 11),
]);
}
/// Formats 4 and 5. Neither line ends in a transmitter number.
///
/// The last column is 12 wide rather than 11, because a Sweepstakes
/// exchange is 12 characters long and a value wider than its column is
/// cut. Nothing follows it on the line, so the space the writer adds after
/// it falls at the end of the line.
private CabrilloExchange ExchangeInOneColumn(Qso qso, StationInfo me, string sent) =>
new(
[
new CabrilloField(me.Callsign, 13),
new CabrilloField(
format == 5
? sent + $"{qso.SentNumber:000}"
: $"{qso.SentNumber:0000} {SingleSpaced(sent)}",
13),
],
[
new CabrilloField(qso.Call.Text, 13),
new CabrilloField(
format == 5
? qso.Section + $"{qso.ReceivedNumber:000}"
: $"{qso.ReceivedNumber:0000} {qso.Precedence} {qso.Check:00} {Cut(qso.Section.PadRight(3), 3)}",
12),
])
{
AddsTransmitter = false,
};
private static string[] Words(string exchange) =>
exchange.Split(' ', StringSplitOptions.RemoveEmptyEntries);
private static string Word(string[] words, int at) => words.Length > at ? words[at] : "";
private static string Cut(string value, int width) =>
value.Length > width ? value[..width] : value;
/// One space between words. An operator can line the sent exchange up with
/// extra spaces, and N1MM takes them out before writing this line.
private static string SingleSpaced(string exchange) => string.Join(' ', Words(exchange));
}

View File

@@ -15,6 +15,7 @@ public sealed class UserDefinedContest : Contest
private readonly IReadOnlyList<ExchangeField> exchangeFields;
private readonly IReadOnlyList<string> workableStations;
private readonly UdcCabrillo cabrillo;
private readonly UdcCabrilloFormat cabrilloFormat;
public UserDefinedContest(UdcFile file)
{
@@ -26,6 +27,7 @@ public sealed class UserDefinedContest : Contest
exchangeFields = ReadExchangeFields(file);
workableStations = file.List("IsWorkable");
cabrillo = new UdcCabrillo(file.Text("CabrilloString"));
cabrilloFormat = new UdcCabrilloFormat(file.Number("CabrilloFormat", 1));
}
public static UserDefinedContest Load(string path) =>
@@ -103,6 +105,17 @@ public sealed class UserDefinedContest : Contest
private string SentExchange(QsoContext qso) =>
qso.Entry.SentExchange.Length > 0 ? qso.Entry.SentExchange : SentExchangeFor(qso.Me);
/// The exchange values of one contact, in the order the file lists the
/// entry boxes. The report is left out because no numbered layout has a
/// column for it.
private string ReceivedExchange(Qso qso) =>
string.Join(
' ',
exchangeFields
.Where(field => field.Slot != ExchangeSlot.ReceivedReport)
.Select(field => QsoExchange.ValueOf(qso, field.Slot))
.Where(value => value.Length > 0));
public IReadOnlyList<Multiplier> MultipliersFor(QsoContext qso) =>
IsWorkable(qso)
? multipliers.Select(m => m.For(qso)).OfType<Multiplier>().ToList()
@@ -119,15 +132,22 @@ public sealed class UserDefinedContest : Contest
return (int)Math.Round(total * pointsMultiplier.ForEntry(entry));
}
/// `CabrilloString` lays out the whole line, which is how a contest whose
/// sponsor asks for its own columns is written. Without it the line is the
/// usual one: each station, its report and its exchange.
/// A sponsor who asks for columns of their own gets them two ways:
/// `CabrilloString` names every column, and a numbered `CabrilloFormat`
/// names one of the four layouts N1MM has built in. A file with neither
/// gets the usual line: each station, its report and its exchange.
public CabrilloExchange CabrilloExchange(Qso qso, StationInfo me, ContestEntry entry) =>
cabrillo.IsDefined
? new CabrilloExchange(cabrillo.Fields(qso, me, entry), [])
{
AddsTransmitter = cabrillo.HasTransmitter,
}
: cabrilloFormat.IsNumbered
? cabrilloFormat.Line(
qso,
me,
entry.SentExchange.Length > 0 ? entry.SentExchange : SentExchangeFor(me),
ReceivedExchange(qso))
: new CabrilloExchange(
[
new CabrilloField(me.Callsign, 13),

View File

@@ -26,26 +26,6 @@ public static class ExchangeSlots
_ => qso,
};
/// What a logged contact holds for one exchange box. The inverse of
/// `Apply`, used to load a contact back into the entry boxes.
public static string ValueOf(Qso qso, ExchangeSlot slot) => slot switch
{
ExchangeSlot.ReceivedReport => qso.ReceivedReport,
ExchangeSlot.SerialNumber => Digits(qso.ReceivedNumber),
ExchangeSlot.Zone => Digits(qso.Zone),
ExchangeSlot.Section => qso.Section,
ExchangeSlot.Check => Digits(qso.Check),
ExchangeSlot.Precedence => qso.Precedence,
ExchangeSlot.Exchange1 => qso.Exchange1,
ExchangeSlot.MiscText => qso.MiscText,
ExchangeSlot.Name => qso.Name,
ExchangeSlot.Qth => qso.Qth,
ExchangeSlot.GridSquare => qso.GridSquare,
ExchangeSlot.Power => qso.Power,
ExchangeSlot.Comment => qso.Comment,
_ => "",
};
/// What the call history file says this station sends in one exchange box,
/// or an empty string when the file holds nothing for it.
public static string ValueFrom(CallHistoryEntry known, ExchangeField field) => field.Slot switch

View File

@@ -361,7 +361,7 @@ public sealed class OperatingPosition
Entry.Call = qso.Call.Text;
for (int at = 0; at < Entry.Exchange.Count; at++)
{
Entry[at + 1] = ExchangeSlots.ValueOf(qso, Entry.Exchange[at].Slot);
Entry[at + 1] = QsoExchange.ValueOf(qso, Entry.Exchange[at].Slot);
}
OtherName = Entry.Exchange.Any(f => f.Slot == ExchangeSlot.Name) ? "" : qso.Name;
Comment = qso.Comment;