Export WAE QTC traffic to ADIF, and read it back

ADIF has no record for QTC traffic, which is why N1MM leaves it out and why
a WAE log cannot be moved between databases as ADIF. The plain export now
writes the contacts alone, as N1MM does: it used to write the QTC rows as
contacts, with the time of the traffic in RST_SENT and the reported callsign
in RST_RCVD.

File > Export > Export ADIF with QTC traffic writes the whole log instead.
A QTC row goes out with the station, time, band and mode, and the traffic in
application-defined fields — APP_NONEMM_QTC and friends, the prefix the ADIF
specification keeps for a program's own data — with the line in the comment
as well so the file can be read without this program. The report columns are
left off that record, because on a QTC row they hold the time and callsign
of the contact being reported. Reading such a file back rebuilds the rows,
so a WAE log survives the round trip whole. The item is only in the menu for
a contest with traffic.

Another program reading that file sees each QTC row as an ordinary contact
with the station the traffic was exchanged with and ignores the extra
fields. There is no way around that in ADIF, which is why the plain export
is still the one to hand over.

Contacts now also carry their row kind in APP_NONEMM_EXCHANGE1. Without it
a WAE log read back holds contacts with no kind at all, which N1MM's own
queries do not find.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0157i7PiZyqBkquxS9A6FTdQ
This commit is contained in:
2026-09-10 19:31:04 +00:00
co-authored by Claude Opus 5
parent c686a86dcc
commit 0d9b4a713e
8 changed files with 247 additions and 12 deletions
+48 -1
View File
@@ -1,10 +1,16 @@
using System.Globalization;
using Nonemm.Contests.Rules;
using Nonemm.Core;
namespace Nonemm.Formats.Adif;
/// Reads ADIF into contacts. Fields the log has no room for are dropped rather
/// than crammed into a comment.
///
/// A record carrying the `APP_NONEMM_QTC_*` fields this program writes is WAE
/// QTC traffic rather than a contact, and it goes back into the log the way
/// N1MM keeps traffic: see `WaeQtc`. A record from another program never has
/// those fields, so it reads as a contact.
public static class AdifReader
{
public static IReadOnlyList<Qso> Read(string text, string contestName = "DX", int contestNumber = 1)
@@ -74,7 +80,7 @@ public static class AdifReader
return null;
}
DateTime when = ParseTimestamp(record);
return new Qso
Qso qso = new()
{
Id = Qso.NewId(),
TimestampUtc = when,
@@ -94,7 +100,48 @@ public static class AdifReader
GridSquare = Value(record, "GRIDSQUARE"),
Comment = Value(record, "COMMENT"),
Operator = Value(record, "OPERATOR"),
Exchange1 = Value(record, "APP_NONEMM_EXCHANGE1"),
};
return Traffic(record) is { } qtc ? qtc.ApplyTo(qso) with { Comment = "" } : qso;
}
/// The QTC line a record carries, or null when it is an ordinary contact.
/// A record with the direction field but nothing readable in the rest is
/// taken as a contact rather than as traffic with empty fields.
private static WaeQtc? Traffic(Dictionary<string, string> record)
{
string direction = Value(record, "APP_NONEMM_QTC").ToUpperInvariant();
if (direction is not ("SENT" or "RCVD"))
{
return null;
}
string call = Value(record, "APP_NONEMM_QTC_CALL");
string time = Value(record, "APP_NONEMM_QTC_TIME");
if (call.Length == 0 || time.Length == 0)
{
return null;
}
(int series, int count) = ParseSeries(Value(record, "APP_NONEMM_QTC_SERIES"));
return new WaeQtc(
Callsign.Parse(Value(record, "CALL")),
direction == "SENT",
series,
count,
time,
Callsign.Parse(call),
Integer(record, "APP_NONEMM_QTC_NR"),
Integer(record, "APP_NONEMM_QTC_OWNNR"));
}
/// `3/10` is the third series, ten lines in it.
private static (int Series, int Count) ParseSeries(string text)
{
string[] parts = text.Split('/', StringSplitOptions.TrimEntries);
return parts.Length == 2
&& int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out int series)
&& int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out int count)
? (series, count)
: (0, 0);
}
private static Frequency ParseFrequency(Dictionary<string, string> record)
+77 -6
View File
@@ -1,17 +1,35 @@
using System.Globalization;
using System.Text;
using Nonemm.Contests.Rules;
using Nonemm.Core;
namespace Nonemm.Formats.Adif;
/// Writes ADIF 3.1.4, which is what logbook and award programs read.
///
/// ADIF has no record for WAE QTC traffic, which is why N1MM leaves it out of
/// its export and why a WAE log cannot be moved between N1MM databases as
/// ADIF. A QTC row here is written as a record of its own, with the traffic in
/// application-defined fields — `APP_NONEMM_QTC_*`, the prefix the ADIF
/// specification reserves for a program's own data. Another program reads the
/// record as an ordinary contact with the station the traffic was exchanged
/// with and ignores the extra fields, so the caller says whether to write the
/// traffic at all: `Write(qsos)` leaves it out, as N1MM does.
public sealed class AdifWriter
{
/// The name the application-defined fields carry, which is the PROGRAMID.
private const string Program = "NONEMM";
private readonly StationInfo me;
public AdifWriter(StationInfo me) => this.me = me;
public string Write(IEnumerable<Qso> qsos)
/// The contacts alone, which is the file to hand to another program.
public string Write(IEnumerable<Qso> qsos) => Write(qsos, withQtcTraffic: false);
/// `withQtcTraffic` keeps the WAE QTC rows, so the file holds the whole log
/// and reading it back rebuilds it.
public string Write(IEnumerable<Qso> qsos, bool withQtcTraffic)
{
StringBuilder text = new();
text.Append("Nonemm ADIF export\r\n");
@@ -20,6 +38,10 @@ public sealed class AdifWriter
text.Append("<EOH>\r\n");
foreach (Qso qso in qsos.OrderBy(q => q.TimestampUtc))
{
if (WaeQtc.IsQtc(qso) && !withQtcTraffic)
{
continue;
}
text.Append(Record(qso)).Append("\r\n");
}
return text.ToString();
@@ -28,16 +50,23 @@ public sealed class AdifWriter
public string Record(Qso qso)
{
StringBuilder line = new();
bool isTraffic = WaeQtc.IsQtc(qso);
Field(line, "CALL", qso.Call.Text);
Field(line, "QSO_DATE", qso.TimestampUtc.ToString("yyyyMMdd", CultureInfo.InvariantCulture));
Field(line, "TIME_ON", qso.TimestampUtc.ToString("HHmmss", CultureInfo.InvariantCulture));
Field(line, "BAND", qso.Band?.Name.ToLowerInvariant() ?? "");
Field(line, "FREQ", (qso.Frequency.Megahertz).ToString("0.000000", CultureInfo.InvariantCulture));
Field(line, "MODE", qso.Mode.AdifName);
Field(line, "RST_SENT", qso.SentReport);
Field(line, "RST_RCVD", qso.ReceivedReport);
Field(line, "STX", qso.SentNumber > 0 ? qso.SentNumber.ToString(CultureInfo.InvariantCulture) : "");
Field(line, "SRX", qso.ReceivedNumber > 0 ? qso.ReceivedNumber.ToString(CultureInfo.InvariantCulture) : "");
// the report columns of a QTC row hold the time and callsign of the
// contact being reported, not a report and not a serial number, so
// they are left out here and written under their own names below
if (!isTraffic)
{
Field(line, "RST_SENT", qso.SentReport);
Field(line, "RST_RCVD", qso.ReceivedReport);
Field(line, "STX", qso.SentNumber > 0 ? qso.SentNumber.ToString(CultureInfo.InvariantCulture) : "");
Field(line, "SRX", qso.ReceivedNumber > 0 ? qso.ReceivedNumber.ToString(CultureInfo.InvariantCulture) : "");
}
Field(line, "CONTEST_ID", qso.ContestName);
Field(line, "OPERATOR", qso.Operator.Length > 0 ? qso.Operator : me.Callsign);
Field(line, "STATION_CALLSIGN", me.Callsign);
@@ -46,11 +75,53 @@ public sealed class AdifWriter
Field(line, "GRIDSQUARE", qso.GridSquare);
Field(line, "CQZ", qso.Zone > 0 ? qso.Zone.ToString(CultureInfo.InvariantCulture) : "");
Field(line, "ARRL_SECT", qso.Section);
Field(line, "COMMENT", qso.Comment);
Field(line, "COMMENT", Comment(qso));
// which kind of row this is: `QSO` for a contact in WAE, `SQTC` or
// `RQTC` for traffic. ADIF has no field for it, and without it a WAE
// log read back holds contacts that N1MM's own queries do not find
Field(line, $"APP_{Program}_EXCHANGE1", qso.Exchange1);
Traffic(line, qso);
line.Append("<EOR>");
return line.ToString();
}
/// The QTC line this row carries, in fields of our own: which way it went,
/// the series it belongs to, and the contact it reports. The reported time,
/// callsign and serial number are in the report columns of the row as well,
/// because that is where N1MM keeps them, but they are written again here
/// under their own names so the file says what they are.
private static void Traffic(StringBuilder line, Qso qso)
{
if (WaeQtc.From(qso) is not { } qtc)
{
return;
}
Field(line, $"APP_{Program}_QTC", qtc.IsSent ? "SENT" : "RCVD");
Field(line, $"APP_{Program}_QTC_SERIES", qtc.SeriesText);
Field(line, $"APP_{Program}_QTC_TIME", qtc.TimeUtc);
Field(line, $"APP_{Program}_QTC_CALL", qtc.Call.Text);
Field(line, $"APP_{Program}_QTC_NR", qtc.Number.ToString(CultureInfo.InvariantCulture));
if (qtc.OwnNumber > 0)
{
Field(
line,
$"APP_{Program}_QTC_OWNNR",
qtc.OwnNumber.ToString(CultureInfo.InvariantCulture));
}
}
/// A QTC row says so in the comment as well, so the traffic can be read by
/// somebody looking at the file rather than only by this program.
private static string Comment(Qso qso)
{
if (WaeQtc.From(qso) is not { } qtc)
{
return qso.Comment;
}
string what = qtc.IsSent ? "sent" : "rcvd";
return $"WAE QTC {what} {qtc.SeriesText}: {qtc.TimeUtc} {qtc.Call.Text} {qtc.Number:000}";
}
private static void Field(StringBuilder text, string name, string value)
{
if (value.Length > 0)