Skip to content

Commit 47c0d20

Browse files
authored
Merge pull request #12 from cniesen/rig-type-detection
Added rig type detection. Fixes #10.
2 parents 7045948 + 3bf1faa commit 47c0d20

File tree

8 files changed

+134
-83
lines changed

8 files changed

+134
-83
lines changed

IcomClockOmniRig/OmniRigBase.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ public void DisplayRigInfo() {
5353
Console.WriteLine();
5454
}
5555

56-
public void CheckTransceiverModel() {
57-
if (programOptions.ForceTranceiverModel) {
58-
return;
59-
}
60-
61-
(string rigType, string rigStatus) rigInfo = RigInfo(programOptions.RigNumber);
62-
if (programOptions.TransceiverModel != rigInfo.rigType) {
63-
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.");
64-
}
65-
}
66-
6756
public void SetTime() {
6857
if (!programOptions.Quiet) {
6958
Console.WriteLine("Waiting for the full minute to set time");

IcomClockOmniRig/OmniRigV1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public OmniRigV1(ProgramOptions programOptions) : base(programOptions) {
3232
} catch (COMException e) {
3333
throw new ExitException(ExitCode.OMNIRIG_COM_CREATE, "Error: OmniRig not found (Is OmniRig installed?)", e);
3434
}
35-
OmniRig = new OmniRigX();
3635
OmniRig.CustomReply += OmniRig_CustomReply;
36+
programOptions.InitRigBasedDefaults(OmniRig.Rig1.RigType);
3737
}
3838

3939
protected override string SoftwareVersion() {

IcomClockOmniRig/OmniRigV2.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public OmniRigV2(ProgramOptions programOptions) : base(programOptions) {
3636
// OmniRig 2 does some file copying while starting - we need to wait
3737
Sleep(3000);
3838
OmniRig.CustomReply += OmniRig_CustomReply;
39+
programOptions.InitRigBasedDefaults(OmniRig.Rig1.RigType);
3940
}
4041

4142
protected override string SoftwareVersion() {

IcomClockOmniRig/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static void Main(string[] args) {
4040
omnirig.DisplayRigInfo();
4141
}
4242
omnirig.CheckRigStatus();
43-
omnirig.CheckTransceiverModel();
4443
omnirig.SetTime();
4544
omnirig.SetDate();
4645
omnirig.SetOffset();

IcomClockOmniRig/ProgramOptions.cs

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public enum OmniRigVersion {
2828
public class ProgramOptions {
2929
public bool ReversedTimeZone { get; } = false;
3030
public int RigNumber { get; } = 1;
31-
public string TransceiverAddress { get; } = "94";
31+
public string TransceiverAddress { get; private set; } = null;
3232
public string ControllerAddress { get; } = "E0";
33-
public string TransceiverModel { get; } = "IC-7300";
33+
public string TransceiverModel { get; private set; } = null;
3434
public OmniRigVersion OmnirigVersion { get; } = OmniRigVersion.OmniRigVersion1;
3535
public bool Quiet { get; } = false;
3636
public bool ForceTranceiverModel { get; } = false;
@@ -39,21 +39,38 @@ public class ProgramOptions {
3939
private const string Postamble = "FD";
4040

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

55+
private readonly IDictionary<string, string> RigTypes = new Dictionary<string, string>() {
56+
{"IC-705", "IC-705"}, {"IC-705-DATA", "IC-705-DATA"},
57+
{"IC-7100", "IC-7100"}, {"IC-7100-DATA-FIL1", "IC-7100"}, {"IC-7100e4", "IC-7100"}, {"IC-7100e4-DATA", "IC-7100"},
58+
{"IC-7300", "IC-7300"}, {"IC-7300-DATA", "IC-7300"},
59+
{"IC-7600", "IC-7600"}, {"IC-7600v2", "IC-7600"}, {"IC-7600v2-DATA", "IC-7600"},
60+
{"IC-7610", "IC-7610"}, {"IC-7610-DATA", "IC-7610"}, {"IC-7610-DATA-FIL1", "IC-7610"},
61+
{"IC-7700", "IC-7700"}, {"IC-7700v2", "IC-7700"}, {"IC-7700v2-DATA", "IC-7700"},
62+
{"IC-7850", "IC-7850"}, {"IC-7850-DATA", ""}, {"IC-7850-DATA-FIL1", ""},
63+
{"IC-7851", "IC-7851"}, {"IC-7851-DATA", "IC-7851"}, {"IC-7851-DATA-FIL1", "IC-7851"},
64+
{"IC-9700", "IC-9700"}, {"IC-9700-DATA", "IC-9700"}, {"IC-9700-SAT", "IC-9700"},
65+
{"IC-R8600", "IC-R8600"},
66+
{"IC-R9500", "IC-R9500"}
67+
};
68+
5469
public ProgramOptions(string[] args) {
55-
string TransceiverAddressOverride = null;
56-
70+
if (!Quiet) {
71+
PrintProgramInfo();
72+
}
73+
5774
for (int i = 0; i < args.Length; ++i) {
5875
string arg = args[i];
5976
if(arg == "-u") {
@@ -91,7 +108,7 @@ public ProgramOptions(string[] args) {
91108
throw new ExitException(ExitCode.OPTION_TRANSCEIVER_ADDRESS);
92109
}
93110
if (Utilities.IsHex(args[i])) {
94-
TransceiverAddressOverride = args[i];
111+
TransceiverAddress = args[i];
95112
} else {
96113
Console.WriteLine("ERROR: Invalid transceiver address specified: " + args[i] + "\n\n");
97114
PrintHelp();
@@ -127,8 +144,6 @@ public ProgramOptions(string[] args) {
127144
}
128145
} else if (arg == "-q") {
129146
Quiet = true;
130-
} else if (arg == "-f") {
131-
ForceTranceiverModel = true;
132147
} else if (arg == "-h") {
133148
PrintHelp();
134149
throw new ExitException(ExitCode.SUCCESS);
@@ -158,20 +173,13 @@ public ProgramOptions(string[] args) {
158173
default:
159174
throw new ArgumentException("Invalid OmniRigVersion: " + OmnirigVersion);
160175
}
161-
162-
TransceiverAddress = (TransceiverAddressOverride == null) ? LookupTransceiverAddress() : TransceiverAddressOverride;
163-
164-
if (!Quiet) {
165-
PrintProgramInfo();
166-
PrintOptions();
167-
}
168176
}
169177

170178
private void PrintProgramInfo() {
171179
Console.Write(
172180
" ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n" +
173181
" :: ::\n" +
174-
" :: IcomClockOmniRig 2.0 - https://github.com/cniesen/IcomClockOmniRig ::\n" +
182+
" :: IcomClockOmniRig 2.1 - https://github.com/cniesen/IcomClockOmniRig ::\n" +
175183
" :: ::\n" +
176184
" :: A program to set the Icom tranceiver clock to your computer's time ::\n" +
177185
" :: ::\n" +
@@ -180,21 +188,22 @@ private void PrintProgramInfo() {
180188
}
181189

182190
private void PrintHelp() {
183-
PrintProgramInfo();
191+
if (Quiet) {
192+
PrintProgramInfo();
193+
}
184194
Console.Write(
185195
"Usage: " + AppDomain.CurrentDomain.FriendlyName + " [options]\n" +
186196
"Options:\n" +
187197
"\t-u\t\tReverse local and UTC time (show UTC as clock and local time as on UTC display)\n\n" +
188198
"\t-r <number>\tThe selected rig in OmniRig (default: 1)\n\n" +
189-
"\t-m <model>\tThe Icom transceiver model (default: IC-7300)\n" +
199+
"\t-m <model>\tThe Icom transceiver model (default: auto detect from OmniRig)\n" +
190200
"\t\t\tValid models: " + ListValidTransceiverModels() + "\n\n" +
191-
"\t-a <hex>\tThe Icom transceiver address (default: 94)\n\n" +
201+
"\t-a <hex>\tThe Icom transceiver address (default: rig default address)\n\n" +
192202
"\t-c <hex>\tThe controller address (default: E0)\n\n" +
193203
"\t-o <number>\tOmniRig version number (default: 1)\n" +
194204
"\t\t\t1 = original OmniRig by VE3NEA\n" +
195205
"\t\t\t2 = updated OmniRig by HB9RYZ\n\n" +
196206
"\t-q\t\tQuiet, don't output messages\n\n" +
197-
"\t-f\t\tForce tranceiver model, allow mismatch between OmniRig and this program. Avoid this option if possible.\n\n" +
198207
"\t-h\t\tShow this help message\n\n"
199208
);
200209
}
@@ -210,10 +219,37 @@ private void PrintOptions() {
210219

211220
}
212221

222+
public void InitRigBasedDefaults(string rigType) {
223+
if (TransceiverModel == null) {
224+
TransceiverModel = LookupTransceiverModel(rigType);
225+
}
226+
227+
if (TransceiverAddress == null) {
228+
TransceiverAddress = LookupTransceiverAddress();
229+
}
230+
231+
if (!Quiet) {
232+
PrintOptions();
233+
}
234+
}
235+
213236
private bool IsValidTransceiverModel(string transceiverModel) {
214237
return Transceivers.ContainsKey(transceiverModel);
215238
}
216239

240+
private string LookupTransceiverModel(string rigType) {
241+
try {
242+
return RigTypes[rigType];
243+
} catch (KeyNotFoundException e) {
244+
foreach (KeyValuePair<String, String> rigTypeMapping in RigTypes) {
245+
if (rigType.StartsWith(rigTypeMapping.Key + "-")) {
246+
return rigTypeMapping.Value;
247+
}
248+
}
249+
throw new KeyNotFoundException("OmniRig's rig type '" + rigType + "' not found", e);
250+
}
251+
}
252+
217253
public string LookupTransceiverAddress() {
218254
try {
219255
return Transceivers[TransceiverModel]["transceiverAddress"];
@@ -227,7 +263,7 @@ public string LookupCommand(string command, string data) {
227263
try {
228264
return Preamble + TransceiverAddress + ControllerAddress + Transceivers[TransceiverModel][command] + data + Postamble;
229265
} catch (KeyNotFoundException e) {
230-
throw new KeyNotFoundException("Command " + command + " not found for tranceiver " + TransceiverModel, e);
266+
throw new KeyNotFoundException("Command '" + command + "' not found for tranceiver " + TransceiverModel, e);
231267

232268
}
233269
}

IcomClockOmniRig/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.0.0")]
36-
[assembly: AssemblyFileVersion("2.0.0.0")]
35+
[assembly: AssemblyVersion("2.1.0.0")]
36+
[assembly: AssemblyFileVersion("2.1.0.0")]

0 commit comments

Comments
 (0)