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; }