@@ -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 \t Reverse local and UTC time (show UTC as clock and local time as on UTC display)\n \n " +
188198 "\t -r <number>\t The selected rig in OmniRig (default: 1)\n \n " +
189- "\t -m <model>\t The Icom transceiver model (default: IC-7300 )\n " +
199+ "\t -m <model>\t The Icom transceiver model (default: auto detect from OmniRig )\n " +
190200 "\t \t \t Valid models: " + ListValidTransceiverModels ( ) + "\n \n " +
191- "\t -a <hex>\t The Icom transceiver address (default: 94 )\n \n " +
201+ "\t -a <hex>\t The Icom transceiver address (default: rig default address )\n \n " +
192202 "\t -c <hex>\t The controller address (default: E0)\n \n " +
193203 "\t -o <number>\t OmniRig version number (default: 1)\n " +
194204 "\t \t \t 1 = original OmniRig by VE3NEA\n " +
195205 "\t \t \t 2 = updated OmniRig by HB9RYZ\n \n " +
196206 "\t -q\t \t Quiet, don't output messages\n \n " +
197- "\t -f\t \t Force tranceiver model, allow mismatch between OmniRig and this program. Avoid this option if possible.\n \n " +
198207 "\t -h\t \t Show 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 }
0 commit comments