Skip to content

Commit

Permalink
Merge pull request #12 from cniesen/rig-type-detection
Browse files Browse the repository at this point in the history
Added rig type detection.  Fixes #10.
  • Loading branch information
cniesen authored Oct 24, 2021
2 parents 7045948 + 3bf1faa commit 47c0d20
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 83 deletions.
11 changes: 0 additions & 11 deletions IcomClockOmniRig/OmniRigBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 != 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");
Expand Down
2 changes: 1 addition & 1 deletion IcomClockOmniRig/OmniRigV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +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() {
Expand Down
1 change: 1 addition & 0 deletions IcomClockOmniRig/OmniRigV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion IcomClockOmniRig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static void Main(string[] args) {
omnirig.DisplayRigInfo();
}
omnirig.CheckRigStatus();
omnirig.CheckTransceiverModel();
omnirig.SetTime();
omnirig.SetDate();
omnirig.SetOffset();
Expand Down
82 changes: 59 additions & 23 deletions IcomClockOmniRig/ProgramOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,21 +39,38 @@ public class ProgramOptions {
private const string Postamble = "FD";

private readonly IDictionary<string, IDictionary<string, string>> Transceivers = new Dictionary<string, IDictionary<string, string>>() {
{"IC-7100", new Dictionary<string, string> {{"setDateCommand", "1A050120"}, {"setTimeCommand", "1A050121"}, {"setUtcOffsetCommand", "1A050123"}, {"transceiverAddress", "88"}}},
{"IC-7300", new Dictionary<string, string> {{"setDateCommand", "1A050094"}, {"setTimeCommand", "1A050095"}, {"setUtcOffsetCommand", "1A050096"}, {"transceiverAddress", "94"}}},
{"IC-705", new Dictionary<string, string> {{"setDateCommand", "1A050165"}, {"setTimeCommand", "1A050166"}, {"setUtcOffsetCommand", "1A050170"}, {"transceiverAddress", "A4"}}},
{"IC-7100", new Dictionary<string, string> {{"setDateCommand", "1A050120"}, {"setTimeCommand", "1A050121"}, {"setUtcOffsetCommand", "1A050123"}, {"transceiverAddress", "88"}}},
{"IC-7300", new Dictionary<string, string> {{"setDateCommand", "1A050094"}, {"setTimeCommand", "1A050095"}, {"setUtcOffsetCommand", "1A050096"}, {"transceiverAddress", "94"}}},
{"IC-7600", new Dictionary<string, string> {{"setDateCommand", "1A050053"}, {"setTimeCommand", "1A050054"}, {"setUtcOffsetCommand", "1A050056"}, {"transceiverAddress", "7A"}}},
{"IC-7610", new Dictionary<string, string> {{"setDateCommand", "1A050158"}, {"setTimeCommand", "1A050159"}, {"setUtcOffsetCommand", "1A050162"}, {"transceiverAddress", "98"}}},
{"IC-7700", new Dictionary<string, string> {{"setDateCommand", "1A050058"}, {"setTimeCommand", "1A050059"}, {"setUtcOffsetCommand", "1A050061"}, {"transceiverAddress", "74"}}},
{"IC-7850", new Dictionary<string, string> {{"setDateCommand", "1A050095"}, {"setTimeCommand", "1A050096"}, {"setUtcOffsetCommand", "1A050099"}, {"transceiverAddress", "8E"}}},
{"IC-7851", new Dictionary<string, string> {{"setDateCommand", "1A050095"}, {"setTimeCommand", "1A050096"}, {"setUtcOffsetCommand", "1A050099"}, {"transceiverAddress", "8E"}}},
{"IC-9700", new Dictionary<string, string> {{"setDateCommand", "1A050179"}, {"setTimeCommand", "1A050180"}, {"setUtcOffsetCommand", "1A050184"}, {"transceiverAddress", "A2"}}},
{"IC-9700", new Dictionary<string, string> {{"setDateCommand", "1A050179"}, {"setTimeCommand", "1A050180"}, {"setUtcOffsetCommand", "1A050184"}, {"transceiverAddress", "A2"}}},
{"IC-R8600", new Dictionary<string, string> {{"setDateCommand", "1A050131"}, {"setTimeCommand", "1A050132"}, {"setUtcOffsetCommand", "1A050135"}, {"transceiverAddress", "96"}}},
{"IC-R9500", new Dictionary<string, string> {{"setDateCommand", "1A050048"}, {"setTimeCommand", "1A050049"}, {"setUtcOffsetCommand", "1A050051"}, {"transceiverAddress", "72"}}}
};

private readonly IDictionary<string, string> RigTypes = new Dictionary<string, string>() {
{"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"},
{"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") {
Expand Down Expand Up @@ -91,7 +108,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();
Expand Down Expand Up @@ -127,8 +144,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);
Expand Down Expand Up @@ -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" +
Expand All @@ -180,21 +188,22 @@ private void PrintProgramInfo() {
}

private void PrintHelp() {
PrintProgramInfo();
if (Quiet) {
PrintProgramInfo();
}
Console.Write(
"Usage: " + AppDomain.CurrentDomain.FriendlyName + " [options]\n" +
"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 <number>\tThe selected rig in OmniRig (default: 1)\n\n" +
"\t-m <model>\tThe Icom transceiver model (default: IC-7300)\n" +
"\t-m <model>\tThe Icom transceiver model (default: auto detect from OmniRig)\n" +
"\t\t\tValid models: " + ListValidTransceiverModels() + "\n\n" +
"\t-a <hex>\tThe Icom transceiver address (default: 94)\n\n" +
"\t-a <hex>\tThe Icom transceiver address (default: rig default address)\n\n" +
"\t-c <hex>\tThe controller address (default: E0)\n\n" +
"\t-o <number>\tOmniRig version number (default: 1)\n" +
"\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"
);
}
Expand All @@ -210,10 +219,37 @@ 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);
}

private string LookupTransceiverModel(string rigType) {
try {
return RigTypes[rigType];
} catch (KeyNotFoundException e) {
foreach (KeyValuePair<String, String> rigTypeMapping in RigTypes) {
if (rigType.StartsWith(rigTypeMapping.Key + "-")) {
return rigTypeMapping.Value;
}
}
throw new KeyNotFoundException("OmniRig's rig type '" + rigType + "' not found", e);
}
}

public string LookupTransceiverAddress() {
try {
return Transceivers[TransceiverModel]["transceiverAddress"];
Expand All @@ -227,7 +263,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);

}
}
Expand Down
4 changes: 2 additions & 2 deletions IcomClockOmniRig/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
Loading

0 comments on commit 47c0d20

Please sign in to comment.