From 67d005105d022d1e40b4670dfbe237cdc4c57643 Mon Sep 17 00:00:00 2001 From: Claus Niesen Date: Tue, 21 Sep 2021 23:46:17 -0500 Subject: [PATCH 1/3] Draft: Added rig type detection. Fixes #10. --- IcomClockOmniRig/OmniRigBase.cs | 2 +- IcomClockOmniRig/OmniRigV1.cs | 2 + IcomClockOmniRig/OmniRigV2.cs | 1 + IcomClockOmniRig/ProgramOptions.cs | 69 ++++++++++++++------ IcomClockOmniRig/Properties/AssemblyInfo.cs | 4 +- IcomClockOmniRigTests/ProgramOptionsTests.cs | 6 +- 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/IcomClockOmniRig/OmniRigBase.cs b/IcomClockOmniRig/OmniRigBase.cs index 281cf8e..3787246 100644 --- a/IcomClockOmniRig/OmniRigBase.cs +++ b/IcomClockOmniRig/OmniRigBase.cs @@ -59,7 +59,7 @@ public void CheckTransceiverModel() { } (string rigType, string rigStatus) rigInfo = RigInfo(programOptions.RigNumber); - if (programOptions.TransceiverModel != rigInfo.rigType) { + if (programOptions.TransceiverModel != programOptions.LookupTransceiverModel(rigInfo.rigType)) { throw new ExitException(ExitCode.OPTION_TRANSCEIVER_MODEL, "Error: Transceiver model doesn't match transceiver in OmniRig. This check can be overwritten via the '-f' flag but be careful."); } } diff --git a/IcomClockOmniRig/OmniRigV1.cs b/IcomClockOmniRig/OmniRigV1.cs index 6f9b469..efd9dd9 100644 --- a/IcomClockOmniRig/OmniRigV1.cs +++ b/IcomClockOmniRig/OmniRigV1.cs @@ -34,6 +34,8 @@ public OmniRigV1(ProgramOptions programOptions) : base(programOptions) { } OmniRig = new OmniRigX(); OmniRig.CustomReply += OmniRig_CustomReply; + programOptions.InitRigBasedDefaults(OmniRig.Rig1.RigType); + } protected override string SoftwareVersion() { diff --git a/IcomClockOmniRig/OmniRigV2.cs b/IcomClockOmniRig/OmniRigV2.cs index 0f6762b..83d9939 100644 --- a/IcomClockOmniRig/OmniRigV2.cs +++ b/IcomClockOmniRig/OmniRigV2.cs @@ -36,6 +36,7 @@ public OmniRigV2(ProgramOptions programOptions) : base(programOptions) { // OmniRig 2 does some file copying while starting - we need to wait Sleep(3000); OmniRig.CustomReply += OmniRig_CustomReply; + programOptions.InitRigBasedDefaults(OmniRig.Rig1.RigType); } protected override string SoftwareVersion() { diff --git a/IcomClockOmniRig/ProgramOptions.cs b/IcomClockOmniRig/ProgramOptions.cs index d5380cc..e59dd50 100644 --- a/IcomClockOmniRig/ProgramOptions.cs +++ b/IcomClockOmniRig/ProgramOptions.cs @@ -28,9 +28,9 @@ public enum OmniRigVersion { public class ProgramOptions { public bool ReversedTimeZone { get; } = false; public int RigNumber { get; } = 1; - public string TransceiverAddress { get; } = "94"; + public string TransceiverAddress { get; private set; } = null; public string ControllerAddress { get; } = "E0"; - public string TransceiverModel { get; } = "IC-7300"; + public string TransceiverModel { get; private set; } = null; public OmniRigVersion OmnirigVersion { get; } = OmniRigVersion.OmniRigVersion1; public bool Quiet { get; } = false; public bool ForceTranceiverModel { get; } = false; @@ -39,21 +39,36 @@ public class ProgramOptions { private const string Postamble = "FD"; private readonly IDictionary> Transceivers = new Dictionary>() { - {"IC-7100", new Dictionary {{"setDateCommand", "1A050120"}, {"setTimeCommand", "1A050121"}, {"setUtcOffsetCommand", "1A050123"}, {"transceiverAddress", "88"}}}, - {"IC-7300", new Dictionary {{"setDateCommand", "1A050094"}, {"setTimeCommand", "1A050095"}, {"setUtcOffsetCommand", "1A050096"}, {"transceiverAddress", "94"}}}, + {"IC-7100", new Dictionary {{"setDateCommand", "1A050120"}, {"setTimeCommand", "1A050121"}, {"setUtcOffsetCommand", "1A050123"}, {"transceiverAddress", "88"}}}, + {"IC-7300", new Dictionary {{"setDateCommand", "1A050094"}, {"setTimeCommand", "1A050095"}, {"setUtcOffsetCommand", "1A050096"}, {"transceiverAddress", "94"}}}, {"IC-7600", new Dictionary {{"setDateCommand", "1A050053"}, {"setTimeCommand", "1A050054"}, {"setUtcOffsetCommand", "1A050056"}, {"transceiverAddress", "7A"}}}, {"IC-7610", new Dictionary {{"setDateCommand", "1A050158"}, {"setTimeCommand", "1A050159"}, {"setUtcOffsetCommand", "1A050162"}, {"transceiverAddress", "98"}}}, {"IC-7700", new Dictionary {{"setDateCommand", "1A050058"}, {"setTimeCommand", "1A050059"}, {"setUtcOffsetCommand", "1A050061"}, {"transceiverAddress", "74"}}}, {"IC-7850", new Dictionary {{"setDateCommand", "1A050095"}, {"setTimeCommand", "1A050096"}, {"setUtcOffsetCommand", "1A050099"}, {"transceiverAddress", "8E"}}}, {"IC-7851", new Dictionary {{"setDateCommand", "1A050095"}, {"setTimeCommand", "1A050096"}, {"setUtcOffsetCommand", "1A050099"}, {"transceiverAddress", "8E"}}}, - {"IC-9700", new Dictionary {{"setDateCommand", "1A050179"}, {"setTimeCommand", "1A050180"}, {"setUtcOffsetCommand", "1A050184"}, {"transceiverAddress", "A2"}}}, + {"IC-9700", new Dictionary {{"setDateCommand", "1A050179"}, {"setTimeCommand", "1A050180"}, {"setUtcOffsetCommand", "1A050184"}, {"transceiverAddress", "A2"}}}, {"IC-R8600", new Dictionary {{"setDateCommand", "1A050131"}, {"setTimeCommand", "1A050132"}, {"setUtcOffsetCommand", "1A050135"}, {"transceiverAddress", "96"}}}, {"IC-R9500", new Dictionary {{"setDateCommand", "1A050048"}, {"setTimeCommand", "1A050049"}, {"setUtcOffsetCommand", "1A050051"}, {"transceiverAddress", "72"}}} }; + private readonly IDictionary RigTypes = new Dictionary() { + {"IC-7100", "IC-7100"}, {"IC-7100-DATA-FIL1", "IC-7100"}, {"IC-7100e4", "IC-7100"}, {"IC-7100e4-DATA", "IC-7100"}, + {"IC-7300", "IC-7300"}, {"IC-7300-DATA", "IC-7300"}, + {"IC-7600", "IC-7600"}, {"IC-7600v2", "IC-7600"}, {"IC-7600v2-DATA", "IC-7600"}, + {"IC-7610", "IC-7610"}, {"IC-7610-DATA", "IC-7610"}, {"IC-7610-DATA-FIL1", "IC-7610"}, + {"IC-7700", "IC-7700"}, {"IC-7700v2", "IC-7700"}, {"IC-7700v2-DATA", "IC-7700"}, + {"IC-7850", "IC-7850"}, {"IC-7850-DATA", ""}, {"IC-7850-DATA-FIL1", ""}, + {"IC-7851", "IC-7851"}, {"IC-7851-DATA", "IC-7851"}, {"IC-7851-DATA-FIL1", "IC-7851"}, + {"IC-9700", "IC-9700"}, {"IC-9700-DATA", "IC-9700"}, {"IC-9700-SAT", "IC-9700"}, + {"IC-R8600", "IC-R8600"}, + {"IC-R9500", "IC-R9500"} + }; + public ProgramOptions(string[] args) { - string TransceiverAddressOverride = null; - + if (!Quiet) { + PrintProgramInfo(); + } + for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if(arg == "-u") { @@ -91,7 +106,7 @@ public ProgramOptions(string[] args) { throw new ExitException(ExitCode.OPTION_TRANSCEIVER_ADDRESS); } if (Utilities.IsHex(args[i])) { - TransceiverAddressOverride = args[i]; + TransceiverAddress = args[i]; } else { Console.WriteLine("ERROR: Invalid transceiver address specified: " + args[i] + "\n\n"); PrintHelp(); @@ -158,20 +173,13 @@ public ProgramOptions(string[] args) { default: throw new ArgumentException("Invalid OmniRigVersion: " + OmnirigVersion); } - - TransceiverAddress = (TransceiverAddressOverride == null) ? LookupTransceiverAddress() : TransceiverAddressOverride; - - if (!Quiet) { - PrintProgramInfo(); - PrintOptions(); - } } private void PrintProgramInfo() { Console.Write( " ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n" + " :: ::\n" + - " :: IcomClockOmniRig 2.0 - https://github.com/cniesen/IcomClockOmniRig ::\n" + + " :: IcomClockOmniRig 2.1 - https://github.com/cniesen/IcomClockOmniRig ::\n" + " :: ::\n" + " :: A program to set the Icom tranceiver clock to your computer's time ::\n" + " :: ::\n" + @@ -186,9 +194,9 @@ private void PrintHelp() { "Options:\n" + "\t-u\t\tReverse local and UTC time (show UTC as clock and local time as on UTC display)\n\n" + "\t-r \tThe selected rig in OmniRig (default: 1)\n\n" + - "\t-m \tThe Icom transceiver model (default: IC-7300)\n" + + "\t-m \tThe Icom transceiver model (default: auto detect from OmniRig)\n" + "\t\t\tValid models: " + ListValidTransceiverModels() + "\n\n" + - "\t-a \tThe Icom transceiver address (default: 94)\n\n" + + "\t-a \tThe Icom transceiver address (default: rig default address)\n\n" + "\t-c \tThe controller address (default: E0)\n\n" + "\t-o \tOmniRig version number (default: 1)\n" + "\t\t\t1 = original OmniRig by VE3NEA\n" + @@ -210,10 +218,33 @@ private void PrintOptions() { } + public void InitRigBasedDefaults(string rigType) { + if (TransceiverModel == null) { + TransceiverModel = LookupTransceiverModel(rigType); + } + + if (TransceiverAddress == null) { + TransceiverAddress = LookupTransceiverAddress(); + } + + if (!Quiet) { + PrintOptions(); + } + } + private bool IsValidTransceiverModel(string transceiverModel) { return Transceivers.ContainsKey(transceiverModel); } + public string LookupTransceiverModel(string rigType) { + try { + return RigTypes[rigType]; + } catch (KeyNotFoundException e) { + throw new KeyNotFoundException("OmniRig's rig type '" + rigType + "' not found", e); + + } + } + public string LookupTransceiverAddress() { try { return Transceivers[TransceiverModel]["transceiverAddress"]; @@ -227,7 +258,7 @@ public string LookupCommand(string command, string data) { try { return Preamble + TransceiverAddress + ControllerAddress + Transceivers[TransceiverModel][command] + data + Postamble; } catch (KeyNotFoundException e) { - throw new KeyNotFoundException("Command " + command + " not found for tranceiver " + TransceiverModel, e); + throw new KeyNotFoundException("Command '" + command + "' not found for tranceiver " + TransceiverModel, e); } } diff --git a/IcomClockOmniRig/Properties/AssemblyInfo.cs b/IcomClockOmniRig/Properties/AssemblyInfo.cs index 4baac1c..ef7474f 100644 --- a/IcomClockOmniRig/Properties/AssemblyInfo.cs +++ b/IcomClockOmniRig/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] \ No newline at end of file diff --git a/IcomClockOmniRigTests/ProgramOptionsTests.cs b/IcomClockOmniRigTests/ProgramOptionsTests.cs index 637cfa8..108e3bc 100644 --- a/IcomClockOmniRigTests/ProgramOptionsTests.cs +++ b/IcomClockOmniRigTests/ProgramOptionsTests.cs @@ -9,7 +9,7 @@ public class ProgramOptionsTests { readonly string help_beginning = " ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n" + " :: ::\n" + - " :: IcomClockOmniRig 2.0 - https://github.com/cniesen/IcomClockOmniRig ::\n" + + " :: IcomClockOmniRig 2.1 - https://github.com/cniesen/IcomClockOmniRig ::\n" + " :: ::\n" + " :: A program to set the Icom tranceiver clock to your computer's time ::\n" + " :: ::\n" + @@ -20,9 +20,9 @@ public class ProgramOptionsTests { "Options:\n" + "\t-u\t\tReverse local and UTC time (show UTC as clock and local time as on UTC display)\n\n" + "\t-r \tThe selected rig in OmniRig (default: 1)\n\n" + - "\t-m \tThe Icom transceiver model (default: IC-7300)\n" + + "\t-m \tThe Icom transceiver model (default: auto detect from OmniRig)\n" + "\t\t\tValid models: IC-7100, IC-7300, IC-7600, IC-7610, IC-7700, IC-7850, IC-7851, IC-9700, IC-R8600, IC-R9500\n\n" + - "\t-a \tThe Icom transceiver address (default: 94)\n\n" + + "\t-a \tThe Icom transceiver address (default: rig default address)\n\n" + "\t-c \tThe controller address (default: E0)\n\n" + "\t-o \tOmniRig version number (default: 1)\n" + "\t\t\t1 = original OmniRig by VE3NEA\n" + From 9cda19e0f756d0a0d22348d19bc13e45797610cf Mon Sep 17 00:00:00 2001 From: Claus Niesen Date: Sun, 24 Oct 2021 05:16:26 -0500 Subject: [PATCH 2/3] Automatic rig type detection with support of custom rig ini files. --- IcomClockOmniRig/OmniRigBase.cs | 11 --- IcomClockOmniRig/OmniRigV1.cs | 2 - IcomClockOmniRig/Program.cs | 1 - IcomClockOmniRig/ProgramOptions.cs | 15 ++-- IcomClockOmniRigTests/ProgramOptionsTests.cs | 93 +++++++++++++------- 5 files changed, 69 insertions(+), 53 deletions(-) diff --git a/IcomClockOmniRig/OmniRigBase.cs b/IcomClockOmniRig/OmniRigBase.cs index 3787246..2c190fa 100644 --- a/IcomClockOmniRig/OmniRigBase.cs +++ b/IcomClockOmniRig/OmniRigBase.cs @@ -53,17 +53,6 @@ public void DisplayRigInfo() { Console.WriteLine(); } - public void CheckTransceiverModel() { - if (programOptions.ForceTranceiverModel) { - return; - } - - (string rigType, string rigStatus) rigInfo = RigInfo(programOptions.RigNumber); - if (programOptions.TransceiverModel != programOptions.LookupTransceiverModel(rigInfo.rigType)) { - throw new ExitException(ExitCode.OPTION_TRANSCEIVER_MODEL, "Error: Transceiver model doesn't match transceiver in OmniRig. This check can be overwritten via the '-f' flag but be careful."); - } - } - public void SetTime() { if (!programOptions.Quiet) { Console.WriteLine("Waiting for the full minute to set time"); diff --git a/IcomClockOmniRig/OmniRigV1.cs b/IcomClockOmniRig/OmniRigV1.cs index efd9dd9..5afc8cf 100644 --- a/IcomClockOmniRig/OmniRigV1.cs +++ b/IcomClockOmniRig/OmniRigV1.cs @@ -32,10 +32,8 @@ public OmniRigV1(ProgramOptions programOptions) : base(programOptions) { } catch (COMException e) { throw new ExitException(ExitCode.OMNIRIG_COM_CREATE, "Error: OmniRig not found (Is OmniRig installed?)", e); } - OmniRig = new OmniRigX(); OmniRig.CustomReply += OmniRig_CustomReply; programOptions.InitRigBasedDefaults(OmniRig.Rig1.RigType); - } protected override string SoftwareVersion() { diff --git a/IcomClockOmniRig/Program.cs b/IcomClockOmniRig/Program.cs index 7c0cf98..030fa7b 100644 --- a/IcomClockOmniRig/Program.cs +++ b/IcomClockOmniRig/Program.cs @@ -40,7 +40,6 @@ static void Main(string[] args) { omnirig.DisplayRigInfo(); } omnirig.CheckRigStatus(); - omnirig.CheckTransceiverModel(); omnirig.SetTime(); omnirig.SetDate(); omnirig.SetOffset(); diff --git a/IcomClockOmniRig/ProgramOptions.cs b/IcomClockOmniRig/ProgramOptions.cs index e59dd50..ad7055b 100644 --- a/IcomClockOmniRig/ProgramOptions.cs +++ b/IcomClockOmniRig/ProgramOptions.cs @@ -142,8 +142,6 @@ public ProgramOptions(string[] args) { } } else if (arg == "-q") { Quiet = true; - } else if (arg == "-f") { - ForceTranceiverModel = true; } else if (arg == "-h") { PrintHelp(); throw new ExitException(ExitCode.SUCCESS); @@ -188,7 +186,9 @@ private void PrintProgramInfo() { } private void PrintHelp() { - PrintProgramInfo(); + if (Quiet) { + PrintProgramInfo(); + } Console.Write( "Usage: " + AppDomain.CurrentDomain.FriendlyName + " [options]\n" + "Options:\n" + @@ -202,7 +202,6 @@ private void PrintHelp() { "\t\t\t1 = original OmniRig by VE3NEA\n" + "\t\t\t2 = updated OmniRig by HB9RYZ\n\n" + "\t-q\t\tQuiet, don't output messages\n\n" + - "\t-f\t\tForce tranceiver model, allow mismatch between OmniRig and this program. Avoid this option if possible.\n\n" + "\t-h\t\tShow this help message\n\n" ); } @@ -236,12 +235,16 @@ private bool IsValidTransceiverModel(string transceiverModel) { return Transceivers.ContainsKey(transceiverModel); } - public string LookupTransceiverModel(string rigType) { + private string LookupTransceiverModel(string rigType) { try { return RigTypes[rigType]; } catch (KeyNotFoundException e) { + foreach (KeyValuePair rigTypeMapping in RigTypes) { + if (rigType.StartsWith(rigTypeMapping.Key + "-")) { + return rigTypeMapping.Value; + } + } throw new KeyNotFoundException("OmniRig's rig type '" + rigType + "' not found", e); - } } diff --git a/IcomClockOmniRigTests/ProgramOptionsTests.cs b/IcomClockOmniRigTests/ProgramOptionsTests.cs index 108e3bc..9323994 100644 --- a/IcomClockOmniRigTests/ProgramOptionsTests.cs +++ b/IcomClockOmniRigTests/ProgramOptionsTests.cs @@ -28,19 +28,39 @@ public class ProgramOptionsTests { "\t\t\t1 = original OmniRig by VE3NEA\n" + "\t\t\t2 = updated OmniRig by HB9RYZ\n\n" + "\t-q\t\tQuiet, don't output messages\n\n" + - "\t-f\t\tForce tranceiver model, allow mismatch between OmniRig and this program. Avoid this option if possible.\n\n" + "\t-h\t\tShow this help message\n\n"; [TestMethod()] - public void Args_Defaults() { + public void AutoDetect_StandardRig() { ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7300-DATA"); Assert.IsFalse(programOptions.ReversedTimeZone); Assert.AreEqual(1, programOptions.RigNumber); Assert.AreEqual("IC-7300", programOptions.TransceiverModel); Assert.AreEqual("94", programOptions.TransceiverAddress); Assert.AreEqual("E0", programOptions.ControllerAddress); Assert.IsFalse(programOptions.Quiet); - Assert.IsFalse(programOptions.ForceTranceiverModel); + } + + [TestMethod()] + public void AutoDetect_CustomRig() { + ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7300-DATA-foobar"); + Assert.IsFalse(programOptions.ReversedTimeZone); + Assert.AreEqual(1, programOptions.RigNumber); + Assert.AreEqual("IC-7300", programOptions.TransceiverModel); + Assert.AreEqual("94", programOptions.TransceiverAddress); + Assert.AreEqual("E0", programOptions.ControllerAddress); + Assert.IsFalse(programOptions.Quiet); + } + + [TestMethod()] + public void Args_Defaults() { + ProgramOptions programOptions = new ProgramOptions(new string[0]); + Assert.IsFalse(programOptions.ReversedTimeZone); + Assert.AreEqual(1, programOptions.RigNumber); + Assert.AreEqual("E0", programOptions.ControllerAddress); + Assert.IsFalse(programOptions.Quiet); } [TestMethod()] @@ -81,8 +101,7 @@ public void Args_Rig_Missing() { Assert.AreEqual(ExitCode.OPTION_RIG_NUMBER, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -98,8 +117,7 @@ public void Args_Rig_Invalid() { Assert.AreEqual(ExitCode.OPTION_RIG_NUMBER, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -115,14 +133,14 @@ public void Args_Rig_InvalidNumber() { Assert.AreEqual(ExitCode.OPTION_RIG_NUMBER, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } [TestMethod()] public void Args_TransceiverModel() { ProgramOptions programOptions = new ProgramOptions(new string[2] { "-m", "IC-7100" }); + programOptions.InitRigBasedDefaults("IC-7300"); Assert.AreEqual("IC-7100", programOptions.TransceiverModel); } @@ -138,8 +156,7 @@ public void Args_TransceiverModel_Missing() { Assert.AreEqual(ExitCode.OPTION_TRANSCEIVER_MODEL, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -155,14 +172,14 @@ public void Args_TransceiverModel_Invalid() { Assert.AreEqual(ExitCode.OPTION_TRANSCEIVER_MODEL, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } [TestMethod()] public void Args_TransceiverAddress() { ProgramOptions programOptions = new ProgramOptions(new string[2] { "-a", "3D" }); + programOptions.InitRigBasedDefaults("IC-7300"); Assert.AreEqual("3D", programOptions.TransceiverAddress); } @@ -178,8 +195,7 @@ public void Args_TransceiverAddress_Missing() { Assert.AreEqual(ExitCode.OPTION_TRANSCEIVER_ADDRESS, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -195,8 +211,7 @@ public void Args_TransceiverAddress_Invalid() { Assert.AreEqual(ExitCode.OPTION_TRANSCEIVER_ADDRESS, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -218,8 +233,7 @@ public void Args_ControllerAddress_Missing() { Assert.AreEqual(ExitCode.OPTION_CONTROLLER_ADDRESS, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -235,8 +249,7 @@ public void Args_ControllerAddress_Invalid() { Assert.AreEqual(ExitCode.OPTION_CONTROLLER_ADDRESS, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -260,8 +273,7 @@ public void Args_OmniRigVersion_Missing() { Assert.AreEqual(ExitCode.OPTION_OMNIRIG_VERSION, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -277,8 +289,7 @@ public void Args_OmniRigVersion_Invalid() { Assert.AreEqual(ExitCode.OPTION_OMNIRIG_VERSION, e.ExitCode); Assert.AreEqual("", e.Message); } - StringAssert.StartsWith(sw.ToString(), expectedErrorMessage + help_beginning); - StringAssert.EndsWith(sw.ToString(), help_ending); + StringAssert.Contains(sw.ToString(), expectedErrorMessage); } } @@ -289,17 +300,27 @@ public void Args_Quiet() { } [TestMethod()] - public void Args_ForceTranceiverModel() { - ProgramOptions programOptions = new ProgramOptions(new string[1] { "-f" }); - Assert.IsTrue(programOptions.ForceTranceiverModel); + public void Args_Help() { + using (StringWriter sw = new StringWriter()) { + Console.SetOut(sw); + try { + ProgramOptions programOptions = new ProgramOptions(new string[1] { "-h" }); + } catch (ExitException e) { + // Help throws an ExitCode.SUCCESS to terminate the program nicely. + Assert.AreEqual(ExitCode.SUCCESS, e.ExitCode); + Assert.AreEqual("", e.Message); + } + StringAssert.StartsWith(sw.ToString(), help_beginning); + StringAssert.EndsWith(sw.ToString(), help_ending); + } } [TestMethod()] - public void Args_Help() { + public void Args_Help_Quiet() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); try { - ProgramOptions programOptions = new ProgramOptions(new string[1] { "-h" }); + ProgramOptions programOptions = new ProgramOptions(new string[2] { "-h", "-q" }); } catch (ExitException e) { // Help throws an ExitCode.SUCCESS to terminate the program nicely. Assert.AreEqual(ExitCode.SUCCESS, e.ExitCode); @@ -313,8 +334,9 @@ public void Args_Help() { [TestMethod()] public void LookupTransceiverAddress() { ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7300"); Assert.AreEqual("94", programOptions.LookupTransceiverAddress()); - programOptions = new ProgramOptions(new string[2] { "-m", "IC-7100" }); + programOptions = new ProgramOptions(new string[2] { "-m", "IC-7100" }); Assert.AreEqual("88", programOptions.LookupTransceiverAddress()); programOptions = new ProgramOptions(new string[2] { "-m", "IC-7300" }); Assert.AreEqual("94", programOptions.LookupTransceiverAddress()); @@ -326,6 +348,7 @@ public void LookupTransceiverAddress() { [TestMethod()] public void LookupCommandTest_Default() { ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7300"); Assert.AreEqual("FEFE94E01A05009420200524FD", programOptions.LookupCommand("setDateCommand", "20200524")); Assert.AreEqual("FEFE94E01A0500951340FD", programOptions.LookupCommand("setTimeCommand", "1340")); Assert.AreEqual("FEFE94E01A05009650001FD", programOptions.LookupCommand("setUtcOffsetCommand", "50001")); @@ -334,6 +357,7 @@ public void LookupCommandTest_Default() { [TestMethod()] public void LookupCommandTest_Custom_Addresses() { ProgramOptions programOptions = new ProgramOptions(new string[4] { "-a", "C8", "-c", "44" }); + programOptions.InitRigBasedDefaults("IC-7300"); Assert.AreEqual("FEFEC8441A05009420200524FD", programOptions.LookupCommand("setDateCommand", "20200524")); Assert.AreEqual("FEFEC8441A0500951340FD", programOptions.LookupCommand("setTimeCommand", "1340")); Assert.AreEqual("FEFEC8441A05009650001FD", programOptions.LookupCommand("setUtcOffsetCommand", "50001")); @@ -341,7 +365,8 @@ public void LookupCommandTest_Custom_Addresses() { [TestMethod()] public void LookupCommandTest_IC7100() { - ProgramOptions programOptions = new ProgramOptions(new string[2] { "-m", "IC-7100" }); + ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7100"); Assert.AreEqual("FEFE88E01A05012020200524FD", programOptions.LookupCommand("setDateCommand", "20200524")); Assert.AreEqual("FEFE88E01A0501211340FD", programOptions.LookupCommand("setTimeCommand", "1340")); Assert.AreEqual("FEFE88E01A05012350001FD", programOptions.LookupCommand("setUtcOffsetCommand", "50001")); @@ -349,7 +374,8 @@ public void LookupCommandTest_IC7100() { [TestMethod()] public void LookupCommandTest_IC7610() { - ProgramOptions programOptions = new ProgramOptions(new string[2] { "-m", "IC-7610" }); + ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7610"); Assert.AreEqual("FEFE98E01A05015820200524FD", programOptions.LookupCommand("setDateCommand", "20200524")); Assert.AreEqual("FEFE98E01A0501591340FD", programOptions.LookupCommand("setTimeCommand", "1340")); Assert.AreEqual("FEFE98E01A05016250001FD", programOptions.LookupCommand("setUtcOffsetCommand", "50001")); @@ -359,6 +385,7 @@ public void LookupCommandTest_IC7610() { [ExpectedException(typeof(KeyNotFoundException), "Command setFooBar not found for tranceiver IC-7300")] public void LookupCommandTest_MissingCommand() { ProgramOptions programOptions = new ProgramOptions(new string[0]); + programOptions.InitRigBasedDefaults("IC-7300"); programOptions.LookupCommand("setFooBar", "20200524"); } } From 3bf1faa22a31010b93718fb8605af1d37670dc0e Mon Sep 17 00:00:00 2001 From: Claus Niesen Date: Sun, 24 Oct 2021 06:15:09 -0500 Subject: [PATCH 3/3] Added support for IC-705 --- IcomClockOmniRig/ProgramOptions.cs | 2 ++ IcomClockOmniRigTests/ProgramOptionsTests.cs | 2 +- README.md | 15 +++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/IcomClockOmniRig/ProgramOptions.cs b/IcomClockOmniRig/ProgramOptions.cs index ad7055b..b430a4e 100644 --- a/IcomClockOmniRig/ProgramOptions.cs +++ b/IcomClockOmniRig/ProgramOptions.cs @@ -39,6 +39,7 @@ public class ProgramOptions { private const string Postamble = "FD"; private readonly IDictionary> Transceivers = new Dictionary>() { + {"IC-705", new Dictionary {{"setDateCommand", "1A050165"}, {"setTimeCommand", "1A050166"}, {"setUtcOffsetCommand", "1A050170"}, {"transceiverAddress", "A4"}}}, {"IC-7100", new Dictionary {{"setDateCommand", "1A050120"}, {"setTimeCommand", "1A050121"}, {"setUtcOffsetCommand", "1A050123"}, {"transceiverAddress", "88"}}}, {"IC-7300", new Dictionary {{"setDateCommand", "1A050094"}, {"setTimeCommand", "1A050095"}, {"setUtcOffsetCommand", "1A050096"}, {"transceiverAddress", "94"}}}, {"IC-7600", new Dictionary {{"setDateCommand", "1A050053"}, {"setTimeCommand", "1A050054"}, {"setUtcOffsetCommand", "1A050056"}, {"transceiverAddress", "7A"}}}, @@ -52,6 +53,7 @@ public class ProgramOptions { }; private readonly IDictionary RigTypes = new Dictionary() { + {"IC-705", "IC-705"}, {"IC-705-DATA", "IC-705-DATA"}, {"IC-7100", "IC-7100"}, {"IC-7100-DATA-FIL1", "IC-7100"}, {"IC-7100e4", "IC-7100"}, {"IC-7100e4-DATA", "IC-7100"}, {"IC-7300", "IC-7300"}, {"IC-7300-DATA", "IC-7300"}, {"IC-7600", "IC-7600"}, {"IC-7600v2", "IC-7600"}, {"IC-7600v2-DATA", "IC-7600"}, diff --git a/IcomClockOmniRigTests/ProgramOptionsTests.cs b/IcomClockOmniRigTests/ProgramOptionsTests.cs index 9323994..66bd535 100644 --- a/IcomClockOmniRigTests/ProgramOptionsTests.cs +++ b/IcomClockOmniRigTests/ProgramOptionsTests.cs @@ -21,7 +21,7 @@ public class ProgramOptionsTests { "\t-u\t\tReverse local and UTC time (show UTC as clock and local time as on UTC display)\n\n" + "\t-r \tThe selected rig in OmniRig (default: 1)\n\n" + "\t-m \tThe Icom transceiver model (default: auto detect from OmniRig)\n" + - "\t\t\tValid models: IC-7100, IC-7300, IC-7600, IC-7610, IC-7700, IC-7850, IC-7851, IC-9700, IC-R8600, IC-R9500\n\n" + + "\t\t\tValid models: IC-705, IC-7100, IC-7300, IC-7600, IC-7610, IC-7700, IC-7850, IC-7851, IC-9700, IC-R8600, IC-R9500\n\n" + "\t-a \tThe Icom transceiver address (default: rig default address)\n\n" + "\t-c \tThe controller address (default: E0)\n\n" + "\t-o \tOmniRig version number (default: 1)\n" + diff --git a/README.md b/README.md index 7e928e2..6eca3dc 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Program Options C:\>IcomClockOmniRig.exe -h :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: :: - :: IcomClockOmniRig 2.0 - https://github.com/cniesen/IcomClockOmniRig :: + :: IcomClockOmniRig 2.1 - https://github.com/cniesen/IcomClockOmniRig :: :: :: :: A program to set the Icom tranceiver clock to your computer's time :: :: :: @@ -23,10 +23,10 @@ Options: -r The selected rig in OmniRig (default: 1) - -m The Icom transceiver model (default: IC-7300) - Valid models: IC-7100, IC-7300, IC-7600, IC-7610, IC-7700, IC-7850, IC-7851, IC-9700, IC-R8600, IC-R9500 + -m The Icom transceiver model (default: auto detect from OminiRig) + Valid models: IC-705, IC-7100, IC-7300, IC-7600, IC-7610, IC-7700, IC-7850, IC-7851, IC-9700, IC-R8600, IC-R9500 - -a The Icom transceiver address (default: 94) + -a The Icom transceiver address (default: rig default address) -c The controller address (default: E0) @@ -35,9 +35,7 @@ Options: 2 = updated OmniRig by HB9RYZ -q Quiet, don't output messages - - -f Force tranceiver model, allow mismatch between OmniRig and this program. Avoid this option if possible. - + -h Show this help message ``` @@ -47,8 +45,9 @@ Supported Transceivers | Transceiver | Date Command | Time Command | UTC Offset Command | Transceiver Address | Tested with OmniRig | Tested with OmniRig 2 | |---------------|--------------|--------------|--------------------|---------------------|---------------------|-----------------------| +| Icom IC-705 | 1A050165 | 1A050166 | 1A050170 | A4 | | | | Icom IC-7100 | 1A050120 | 1A050121 | 1A050123 | 88 | | | -| Icom IC-7300 | 1A050094 | 1A050095 | 1A050096 | 94 | AE0S (2.0) | AE0S (2.0) | +| Icom IC-7300 | 1A050094 | 1A050095 | 1A050096 | 94 | AE0S (2.1) | AE0S (2.0) | | Icom IC-7600 | 1A050053 | 1A050054 | 1A050056 | 7A | | | | Icom IC-7610 | 1A050158 | 1A050159 | 1A050162 | 98 | VE3NEA (2.0) | | | Icom IC-7700 | 1A050058 | 1A050059 | 1A050061 | 74 | | |