HamBook – Diff between revs 1 and 3

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 3
Line 32... Line 32...
32 private SettingsForm _settingsForm; 32 private SettingsForm _settingsForm;
33 private SparkleUpdater _sparkle; 33 private SparkleUpdater _sparkle;
34 private readonly CancellationToken _cancellationToken; 34 private readonly CancellationToken _cancellationToken;
35 private readonly CancellationTokenSource _cancellationTokenSource; 35 private readonly CancellationTokenSource _cancellationTokenSource;
36 private CatAssemblies _catAssemblies; 36 private CatAssemblies _catAssemblies;
-   37 private CancellationTokenSource _scanningCancellationTokenSource;
37 private int _radioVFOA; 38 private CancellationToken _scanningCancellationToken;
38 private int _radioVFOB; 39 private BandScan _bandScan;
Line 39... Line 40...
39   40  
Line 40... Line 41...
40 public bool MemorySinkEnabled { get; set; } 41 public bool MemorySinkEnabled { get; set; }
41   42  
42 private Form1() 43 private Form1()
43 { 44 {
Line 44... Line 45...
44 _cancellationTokenSource = new CancellationTokenSource(); 45 _cancellationTokenSource = new CancellationTokenSource();
-   46 _cancellationToken = _cancellationTokenSource.Token;
45 _cancellationToken = _cancellationTokenSource.Token; 47  
Line 46... Line 48...
46   48 _changedConfigurationContinuation = new ScheduledContinuation();
47 _changedConfigurationContinuation = new ScheduledContinuation(); 49  
48 } 50 }
Line 81... Line 83...
81 _serialPort = new SerialPort(Configuration.Port, Configuration.Speed, Configuration.Parity, Configuration.DataBits, Configuration.StopBits); 83 _serialPort = new SerialPort(Configuration.Port, Configuration.Speed, Configuration.Parity, Configuration.DataBits, Configuration.StopBits);
82 //TODO: move to settings 84 //TODO: move to settings
83 //_serialPort.ReadTimeout = TimeSpan.FromSeconds(1).Milliseconds; 85 //_serialPort.ReadTimeout = TimeSpan.FromSeconds(1).Milliseconds;
Line 84... Line 86...
84   86  
-   87 _catAssemblies = new CatAssemblies(_serialPort, Configuration.Radio);
Line 85... Line 88...
85 _catAssemblies = new CatAssemblies(_serialPort, Configuration.Radio); 88 _catAssemblies.CatSet<InformationState>("AI", new object[] { InformationState.OFF });
86   89  
87 try 90 try
88 { 91 {
Line 198... Line 201...
198   201  
199 switch (await Serialization.Serialize(Configuration, Constants.ConfigurationFile, "Configuration", 202 switch (await Serialization.Serialize(Configuration, Constants.ConfigurationFile, "Configuration",
200 "<!ATTLIST Configuration xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>", 203 "<!ATTLIST Configuration xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>",
201 CancellationToken.None)) 204 CancellationToken.None))
202 { 205 {
203 case SerializationSuccess<Configuration.Configuration> _: 206 case SerializationSuccess<Configuration.Configuration> configuration:
204 Log.Information("Serialized configuration."); 207 Log.Information("Serialized configuration.");
205 break; 208 break;
206 case SerializationFailure serializationFailure: 209 case SerializationFailure serializationFailure:
207 Log.Warning(serializationFailure.Exception.Message, "Failed to serialize configuration."); 210 Log.Warning(serializationFailure.Exception.Message, "Failed to serialize configuration.");
Line 235... Line 238...
235 private void Initialize() 238 private void Initialize()
236 { 239 {
237 try 240 try
238 { 241 {
239 var mode = _catAssemblies.CatRead<RadioMode>("MD", new object[] { }); 242 var mode = _catAssemblies.CatRead<RadioMode>("MD", new object[] { });
240 toolStripComboBox1.Text = Enum.GetName(typeof(RadioMode), mode); 243 toolStripComboBox1.Text = mode;
241 } 244 }
242 catch(Exception exception) 245 catch(Exception exception)
243 { 246 {
244 Log.Error(exception, Resources.Failed_to_read_radio_mode); 247 Log.Error(exception, Resources.Failed_to_read_radio_mode);
245 } 248 }
Line 246... Line 249...
246   249  
247 try 250 try
248 { 251 {
249 var fa = _catAssemblies.CatRead<int>("FA", new object[] { }); 252 var fa = _catAssemblies.CatRead<int>("FA", new object[] { });
250 toolStripTextBox1.Text = $"{fa}"; 253 scrollableToolStripComboBox1.Text = $"{fa}";
251 } 254 }
252 catch(Exception exception) 255 catch(Exception exception)
253 { 256 {
254 Log.Error(exception, Resources.Failed_to_read_VFO_A); 257 Log.Error(exception, Resources.Failed_to_read_VFO_A);
Line 255... Line 258...
255 } 258 }
256   259  
257 try 260 try
258 { 261 {
259 var fb = _catAssemblies.CatRead<int>("FB", new object[] { }); 262 var fb = _catAssemblies.CatRead<int>("FB", new object[] { });
260 toolStripTextBox2.Text = $"{fb}"; 263 scrollableToolStripComboBox2.Text = $"{fb}";
261 } 264 }
262 catch (Exception exception) 265 catch (Exception exception)
263 { 266 {
Line 284... Line 287...
284 } 287 }
Line 285... Line 288...
285   288  
286 private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e) 289 private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
287 { 290 {
288 var toolStripComboBox = (ToolStripComboBox)sender; 291 var toolStripComboBox = (ToolStripComboBox)sender;
289 foreach (var name in Enum.GetNames(typeof(RadioMode))) 292 if(RadioMode.TryParse(toolStripComboBox.Text, out var radioMode))
290 { 293 {
291 if (string.Equals(name, toolStripComboBox.Text, StringComparison.OrdinalIgnoreCase)) 294 try
292 { -  
293 var field = typeof(RadioMode).GetField(name); -  
294 var mode = (RadioMode)field.GetValue(null); -  
295   -  
296 try -  
297 { 295 {
298 _catAssemblies.CatSet<RadioMode>("MD", new object[] { mode }); 296 _catAssemblies.CatSet<RadioMode>("MD", new object[] { radioMode });
299 } 297 }
300 catch(Exception exception) 298 catch (Exception exception)
301 { 299 {
302 Log.Error(exception, Resources.Failed_to_set_radio_mode, mode); -  
303 } 300 Log.Error(exception, Resources.Failed_to_set_radio_mode, radioMode);
304 } 301 }
305 } 302 }
Line 306... Line 303...
306 } 303 }
Line 328... Line 325...
328 { 325 {
329 Log.Error(exception, Resources.Failed_to_set_power_state); 326 Log.Error(exception, Resources.Failed_to_set_power_state);
330 } 327 }
331 } 328 }
Line 332... Line 329...
332   329  
333 private void toolStripTextBox1_Click(object sender, EventArgs e) 330 private void toolStripComboBox2_MouseWheel(object sender, MouseEventArgs e)
334 { 331 {
335 var toolStripTextBox = (ToolStripTextBox)sender; 332 var toolStripComboBox = (ToolStripComboBox)sender;
336 if(int.TryParse(toolStripTextBox.Text, out var frequency)) 333 if (int.TryParse(toolStripComboBox.Text, out var frequency))
-   334 {
-   335 switch(Math.Sign(e.Delta))
-   336 {
-   337 case -1:
-   338 frequency = frequency - 100;
-   339 break;
337 { 340 case 1:
-   341 frequency = frequency + 100;
-   342 break;
-   343 }
-   344
-   345 try
-   346 {
-   347 _catAssemblies.CatSet<int>("FA", new object[] { frequency });
-   348 toolStripComboBox.Text = $"{frequency}";
-   349 }
-   350 catch (Exception exception)
-   351 {
-   352 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency);
338 _radioVFOA = frequency; 353 }
339 } 354 }
Line 340... Line 355...
340 } 355 }
341   356  
342 private void toolStripTextBox1_TextChanged(object sender, EventArgs e) 357 private void scrollableToolStripComboBox1_MouseWheel(object sender, MouseEventArgs e)
343 { 358 {
344 var toolStripTextBox = (ToolStripTextBox)sender; 359 var toolStripComboBox = (ToolStripComboBox)sender;
-   360 if (int.TryParse(toolStripComboBox.Text, out var frequency))
-   361 {
-   362 switch (Math.Sign(e.Delta))
-   363 {
-   364 case -1:
-   365 frequency = frequency - 100;
-   366 break;
-   367 case 1:
-   368 frequency = frequency + 100;
-   369 break;
345 if(int.TryParse(toolStripTextBox.Text, out var frequency)) 370 }
346 { 371  
347 try 372 try
-   373 {
348 { 374 _catAssemblies.CatSet<int>("FB", new object[] { frequency });
349 _catAssemblies.CatSet<int>("FA", new object[] { frequency }); 375 toolStripComboBox.Text = $"{frequency}";
350 } 376 }
351 catch (Exception exception) 377 catch (Exception exception)
352 { 378 {
353 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); -  
354 } 379 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency);
355 return; -  
356 } -  
357   380 }
Line 358... Line 381...
358 toolStripTextBox.Text = $"{_radioVFOA}"; 381 }
359 } 382 }
360   383  
361 private void toolStripTextBox2_TextChanged(object sender, EventArgs e) 384 private void scrollableToolStripComboBox1_TextChanged(object sender, EventArgs e)
362 { 385 {
-   386 var toolStripComboBox = (ToolStripComboBox)sender;
-   387 if (int.TryParse(toolStripComboBox.Text, out var frequency))
-   388 {
-   389 try
363 var toolStripTextBox = (ToolStripTextBox)sender; 390 {
-   391 _catAssemblies.CatSet<int>("FA", new object[] { frequency });
-   392 }
-   393 catch (Exception exception)
364 if (int.TryParse(toolStripTextBox.Text, out var frequency)) 394 {
365 { 395 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency);
Line 366... Line 396...
366 _radioVFOB = frequency; 396 }
367 } 397 }
368 } 398 }
369   399  
370 private void toolStripTextBox2_Click(object sender, EventArgs e) 400 private void scrollableToolStripComboBox2_TextChanged(object sender, EventArgs e)
371 { 401 {
372 var toolStripTextBox = (ToolStripTextBox)sender; 402 var toolStripComboBox = (ToolStripComboBox)sender;
373 if (int.TryParse(toolStripTextBox.Text, out var frequency)) 403 if (int.TryParse(toolStripComboBox.Text, out var frequency))
374 { 404 {
375 try 405 try
376 { 406 {
377 _catAssemblies.CatSet<int>("FB", new object[] { frequency }); 407 _catAssemblies.CatSet<int>("FB", new object[] { frequency });
378 } 408 }
-   409 catch (Exception exception)
-   410 {
-   411 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency);
-   412 }
-   413 }
-   414 }
-   415  
379 catch (Exception exception) 416 private void toolStripMenuItem1_Click(object sender, EventArgs e)
380 { 417 {
Line -... Line 418...
-   418 if (_bandScan == null)
-   419 {
-   420 return;
-   421 }
-   422  
-   423 _bandScan.Stop();
-   424 _bandScan = null;
-   425 }
-   426  
-   427 private void metersToolStripMenuItem1_Click(object sender, EventArgs e)
-   428 {
-   429 if(_bandScan != null)
-   430 {
-   431 _bandScan.Stop();
-   432 }
381 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); 433  
-   434 _bandScan = new BandScan(_catAssemblies, 028000000, 029700000, _serialPort);
-   435 _bandScan.Start();
-   436 }
-   437  
-   438 private void metersToolStripMenuItem_Click(object sender, EventArgs e)
-   439 {
-   440 if (_bandScan != null)
-   441 {
-   442 _bandScan.Stop();
-   443 }
-   444  
-   445 _bandScan = new BandScan(_catAssemblies, 026965000, 027405000, _serialPort);
-   446 _bandScan.Start();
-   447 }
-   448  
-   449 private void metersToolStripMenuItem2_Click(object sender, EventArgs e)
-   450 {
-   451 if (_bandScan != null)
-   452 {
-   453 _bandScan.Stop();
-   454 }
-   455  
-   456 _bandScan = new BandScan(_catAssemblies, 024920000, 024990000, _serialPort);
-   457 _bandScan.Start();
-   458 }
-   459  
-   460 private void metersToolStripMenuItem3_Click(object sender, EventArgs e)
-   461 {
-   462 if (_bandScan != null)
-   463 {
-   464 _bandScan.Stop();
-   465 }
-   466  
-   467 _bandScan = new BandScan(_catAssemblies, 021000000, 021450000, _serialPort);
-   468 _bandScan.Start();
-   469 }
-   470  
-   471 private void metersToolStripMenuItem4_Click(object sender, EventArgs e)
-   472 {
-   473 if (_bandScan != null)
-   474 {
-   475 _bandScan.Stop();
-   476 }
-   477  
-   478 _bandScan = new BandScan(_catAssemblies, 018068000, 018168000, _serialPort);
-   479 _bandScan.Start();
-   480 }
-   481  
-   482 private void metersToolStripMenuItem5_Click(object sender, EventArgs e)
-   483 {
-   484 if (_bandScan != null)
-   485 {
-   486 _bandScan.Stop();
-   487 }
-   488  
-   489 _bandScan = new BandScan(_catAssemblies, 014000000, 014350000, _serialPort);
-   490 _bandScan.Start();
-   491 }
-   492  
-   493 private void metersToolStripMenuItem6_Click(object sender, EventArgs e)
-   494 {
-   495 if (_bandScan != null)
-   496 {
-   497 _bandScan.Stop();
-   498 }
-   499  
-   500 _bandScan = new BandScan(_catAssemblies, 010100000, 010150000, _serialPort);
-   501 _bandScan.Start();
-   502 }
-   503  
-   504 private void metersToolStripMenuItem7_Click(object sender, EventArgs e)
-   505 {
-   506 if (_bandScan != null)
-   507 {
-   508 _bandScan.Stop();
-   509 }
-   510  
-   511 _bandScan = new BandScan(_catAssemblies, 007000000, 007300000, _serialPort);
-   512 _bandScan.Start();
-   513 }
-   514  
-   515 private void metersToolStripMenuItem8_Click(object sender, EventArgs e)
-   516 {
-   517 if (_bandScan != null)
-   518 {
382 } 519 _bandScan.Stop();
383 return; 520 }
384 } 521