Check the signal report before it goes in the log
The log window took any text in the two report columns. It now checks the report the same way it checks the zone or the section: RST on most modes, and a signal-to-noise ratio in decibels on FT8, FT4, JT65, Q65 and MSK144. A WAE QTC row is skipped, because it keeps the time sent and the other station's call in those two columns. The grid column is checked on every contest now, not only when the contest asks for a locator, and the value is stored as JN88dd. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015NZkFxHde1iifAQemFTHxf
This commit is contained in:
@@ -3,5 +3,9 @@ namespace Nonemm.Core;
|
||||
/// One operating mode. `Name` is what goes in the log and must round-trip.
|
||||
public sealed record Mode(string Name, ModeCategory Category, string CabrilloCode, string AdifName)
|
||||
{
|
||||
/// True for the weak-signal modes, which exchange a signal-to-noise ratio
|
||||
/// in decibels rather than RST.
|
||||
public bool ReportsDecibels { get; init; }
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
@@ -11,12 +11,17 @@ public static class Modes
|
||||
public static readonly Mode Rtty = new("RTTY", ModeCategory.Digital, "RY", "RTTY");
|
||||
public static readonly Mode Psk31 = new("PSK31", ModeCategory.Digital, "DG", "PSK31");
|
||||
public static readonly Mode Psk63 = new("PSK63", ModeCategory.Digital, "DG", "PSK63");
|
||||
public static readonly Mode Ft8 = new("FT8", ModeCategory.Digital, "DG", "FT8");
|
||||
public static readonly Mode Ft4 = new("FT4", ModeCategory.Digital, "DG", "FT4");
|
||||
public static readonly Mode Ft8 =
|
||||
new("FT8", ModeCategory.Digital, "DG", "FT8") { ReportsDecibels = true };
|
||||
public static readonly Mode Ft4 =
|
||||
new("FT4", ModeCategory.Digital, "DG", "FT4") { ReportsDecibels = true };
|
||||
public static readonly Mode Mfsk = new("MFSK", ModeCategory.Digital, "DG", "MFSK");
|
||||
public static readonly Mode Jt65 = new("JT65", ModeCategory.Digital, "DG", "JT65");
|
||||
public static readonly Mode Msk144 = new("MSK144", ModeCategory.Digital, "DG", "MSK144");
|
||||
public static readonly Mode Q65 = new("Q65", ModeCategory.Digital, "DG", "Q65");
|
||||
public static readonly Mode Jt65 =
|
||||
new("JT65", ModeCategory.Digital, "DG", "JT65") { ReportsDecibels = true };
|
||||
public static readonly Mode Msk144 =
|
||||
new("MSK144", ModeCategory.Digital, "DG", "MSK144") { ReportsDecibels = true };
|
||||
public static readonly Mode Q65 =
|
||||
new("Q65", ModeCategory.Digital, "DG", "Q65") { ReportsDecibels = true };
|
||||
public static readonly Mode Digital = new("DIGI", ModeCategory.Digital, "DG", "DATA");
|
||||
|
||||
public static readonly IReadOnlyList<Mode> All =
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Nonemm.Core;
|
||||
|
||||
/// Checks a signal report before it goes in the log. Most modes exchange RST;
|
||||
/// the weak-signal modes exchange a signal-to-noise ratio in decibels instead.
|
||||
public static class SignalReport
|
||||
{
|
||||
private const int Weakest = -50;
|
||||
private const int Strongest = 50;
|
||||
|
||||
public static bool IsPlausible(string text, Mode mode)
|
||||
{
|
||||
string report = text.Trim();
|
||||
return mode.ReportsDecibels ? IsDecibels(report) : IsRst(report);
|
||||
}
|
||||
|
||||
/// What to type, for an error message.
|
||||
public static string Example(Mode mode) => mode.ReportsDecibels
|
||||
? "-12"
|
||||
: mode.Category == ModeCategory.Phone ? "59" : "599";
|
||||
|
||||
/// Readability 1 to 5, strength 1 to 9 and, on CW and the digital modes,
|
||||
/// tone 1 to 9. Two figures pass on every mode: phone sends two, and an
|
||||
/// operator on CW may drop the tone.
|
||||
private static bool IsRst(string report) =>
|
||||
report.Length is 2 or 3
|
||||
&& report[0] is >= '1' and <= '5'
|
||||
&& report[1] is >= '1' and <= '9'
|
||||
&& (report.Length == 2 || report[2] is >= '1' and <= '9');
|
||||
|
||||
private static bool IsDecibels(string report) =>
|
||||
int.TryParse(report, NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture, out int decibels)
|
||||
&& decibels >= Weakest
|
||||
&& decibels <= Strongest;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Nonemm.Session;
|
||||
|
||||
/// One editable column of the log window.
|
||||
/// `Width` is in characters.
|
||||
public sealed record QsoColumn(string Label, QsoField Field, int Width);
|
||||
/// One column of the log window.
|
||||
/// `Width` is in characters. A column that is not editable is worked out from
|
||||
/// the contact rather than typed in, such as the points it scored.
|
||||
public sealed record QsoColumn(string Label, QsoField Field, int Width, bool IsEditable = true);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Globalization;
|
||||
using Nonemm.Contests;
|
||||
using Nonemm.Contests.Multipliers;
|
||||
using Nonemm.Contests.Rules;
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Core.Country;
|
||||
|
||||
@@ -22,7 +23,8 @@ public sealed class QsoEditor
|
||||
Columns = BuildColumns(contest, me, exchangeKinds);
|
||||
}
|
||||
|
||||
/// Log columns, left to right.
|
||||
/// The log columns this contest opens with, left to right. The operator can
|
||||
/// pick a different set; see `LogColumns`.
|
||||
public IReadOnlyList<QsoColumn> Columns { get; }
|
||||
|
||||
public static string Read(Qso qso, QsoField field) => field switch
|
||||
@@ -52,6 +54,11 @@ public sealed class QsoEditor
|
||||
QsoField.WpxPrefix => qso.WpxPrefix,
|
||||
QsoField.RadioNumber => Digits(qso.RadioNumber),
|
||||
QsoField.RunPosition => Digits(qso.RunPosition),
|
||||
QsoField.Points => qso.Points.ToString(CultureInfo.InvariantCulture),
|
||||
QsoField.Multipliers => string.Concat(
|
||||
qso.IsMultiplier1 ? "1" : "",
|
||||
qso.IsMultiplier2 ? "2" : "",
|
||||
qso.IsMultiplier3 ? "3" : ""),
|
||||
_ => "",
|
||||
};
|
||||
|
||||
@@ -94,9 +101,9 @@ public sealed class QsoEditor
|
||||
QsoField.QsxFrequency => WithFrequency(value, f => qso with { QsxFrequency = f }, allowEmpty: true),
|
||||
QsoField.Mode => WithMode(qso, value),
|
||||
QsoField.Call => WithCall(qso, value),
|
||||
QsoField.SentReport => QsoEdit.Accept(qso with { SentReport = value }),
|
||||
QsoField.SentReport => WithReport(qso, value, r => qso with { SentReport = r }),
|
||||
QsoField.SentNumber => Count(value, n => qso with { SentNumber = n }),
|
||||
QsoField.ReceivedReport => QsoEdit.Accept(qso with { ReceivedReport = value }),
|
||||
QsoField.ReceivedReport => WithReport(qso, value, r => qso with { ReceivedReport = r }),
|
||||
QsoField.ReceivedNumber => Count(value, n => qso with { ReceivedNumber = n }),
|
||||
QsoField.Zone => Count(value, n => qso with { Zone = n }),
|
||||
QsoField.Section => QsoEdit.Accept(qso with { Section = value }),
|
||||
@@ -106,7 +113,7 @@ public sealed class QsoEditor
|
||||
QsoField.MiscText => QsoEdit.Accept(qso with { MiscText = value }),
|
||||
QsoField.Name => QsoEdit.Accept(qso with { Name = value }),
|
||||
QsoField.Qth => QsoEdit.Accept(qso with { Qth = value }),
|
||||
QsoField.GridSquare => QsoEdit.Accept(qso with { GridSquare = value }),
|
||||
QsoField.GridSquare => WithGrid(qso, value),
|
||||
QsoField.Power => QsoEdit.Accept(qso with { Power = value }),
|
||||
QsoField.Comment => QsoEdit.Accept(qso with { Comment = value }),
|
||||
QsoField.Operator => QsoEdit.Accept(qso with { Operator = value }),
|
||||
@@ -165,6 +172,31 @@ public sealed class QsoEditor
|
||||
return QsoEdit.Accept(set(Frequency.FromKilohertz(kilohertz)));
|
||||
}
|
||||
|
||||
/// A WAE QTC row keeps the time sent and the other station's call in the
|
||||
/// two report columns, so there is no report there to check.
|
||||
private static QsoEdit WithReport(Qso qso, string value, Func<string, Qso> set)
|
||||
{
|
||||
if (value.Length == 0 || WaeQtc.IsQtc(qso) || SignalReport.IsPlausible(value, qso.Mode))
|
||||
{
|
||||
return QsoEdit.Accept(set(value));
|
||||
}
|
||||
return QsoEdit.Refuse(
|
||||
$"{value} is not a signal report on {qso.Mode.Name}; write it as {SignalReport.Example(qso.Mode)}");
|
||||
}
|
||||
|
||||
/// The locator is stored the way it is written: upper case field and
|
||||
/// square, lower case subsquare.
|
||||
private static QsoEdit WithGrid(Qso qso, string value)
|
||||
{
|
||||
if (value.Length == 0)
|
||||
{
|
||||
return QsoEdit.Accept(qso with { GridSquare = "" });
|
||||
}
|
||||
return GridSquare.TryParse(value, out GridSquare grid)
|
||||
? QsoEdit.Accept(qso with { GridSquare = grid.Text })
|
||||
: QsoEdit.Refuse($"{value} is not a grid square");
|
||||
}
|
||||
|
||||
private static QsoEdit WithMode(Qso qso, string value)
|
||||
{
|
||||
Mode? mode = Modes.Parse(value);
|
||||
@@ -237,11 +269,14 @@ public sealed class QsoEditor
|
||||
{
|
||||
columns.Add(new QsoColumn("SntNr", QsoField.SentNumber, 5));
|
||||
}
|
||||
foreach (ExchangeField field in contest.LogFieldsFor(me).Where(f => !f.IsSent))
|
||||
foreach (ExchangeField field in contest.LogFieldsFor(me))
|
||||
{
|
||||
QsoField mapped = FieldFor(field.Slot);
|
||||
kinds[mapped] = field.Kind;
|
||||
columns.Add(new QsoColumn(field.Label, mapped, Math.Max(field.Width, field.Label.Length + 1)));
|
||||
if (!field.IsSent)
|
||||
{
|
||||
columns.Add(new QsoColumn(field.Label, mapped, Math.Max(field.Width, field.Label.Length + 1)));
|
||||
}
|
||||
}
|
||||
if (contest.HasQtcTraffic)
|
||||
{
|
||||
@@ -253,11 +288,16 @@ public sealed class QsoEditor
|
||||
columns.Add(new QsoColumn("QTC?", QsoField.MiscText, 6));
|
||||
}
|
||||
columns.Add(new QsoColumn("Op", QsoField.Operator, 8));
|
||||
columns.Add(new QsoColumn("Cty", QsoField.CountryPrefix, 6));
|
||||
columns.Add(new QsoColumn("Pts", QsoField.Points, 4, IsEditable: false));
|
||||
columns.Add(new QsoColumn("Mult", QsoField.Multipliers, 5, IsEditable: false));
|
||||
return columns;
|
||||
}
|
||||
|
||||
private static QsoField FieldFor(ExchangeSlot slot) => slot switch
|
||||
{
|
||||
ExchangeSlot.SentReport => QsoField.SentReport,
|
||||
ExchangeSlot.SentNumber => QsoField.SentNumber,
|
||||
ExchangeSlot.ReceivedReport => QsoField.ReceivedReport,
|
||||
ExchangeSlot.SerialNumber => QsoField.ReceivedNumber,
|
||||
ExchangeSlot.Zone => QsoField.Zone,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace Nonemm.Session;
|
||||
|
||||
/// A field of a logged contact that can be edited in the log window. The names
|
||||
/// match the log columns.
|
||||
/// A field of a logged contact the log window can show. Most can be edited;
|
||||
/// `Points` and `Multipliers` are worked out from the rules and are read only.
|
||||
/// The names match the log columns.
|
||||
public enum QsoField
|
||||
{
|
||||
Time,
|
||||
@@ -29,4 +30,6 @@ public enum QsoField
|
||||
WpxPrefix,
|
||||
RadioNumber,
|
||||
RunPosition,
|
||||
Points,
|
||||
Multipliers,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user