HamBook – Diff between revs 14 and 15
?pathlinks?
Rev 14 | Rev 15 | |||
---|---|---|---|---|
Line 23... | Line 23... | |||
23 | using RJCP.IO.Ports; |
23 | using RJCP.IO.Ports; |
|
24 | using System.Text; |
24 | using System.Text; |
|
25 | using System.Collections.ObjectModel; |
25 | using System.Collections.ObjectModel; |
|
26 | using Configuration; |
26 | using Configuration; |
|
27 | using System.Collections.Generic; |
27 | using System.Collections.Generic; |
|
- | 28 | using NAudio.Utils; |
||
- | 29 | using System.Linq; |
||
- | 30 | using static System.Net.Mime.MediaTypeNames; |
||
Line 28... | Line 31... | |||
28 | |
31 | |
|
29 | namespace HamBook |
32 | namespace HamBook |
|
30 | { |
33 | { |
|
31 | public partial class Form1 : Form |
34 | public partial class Form1 : Form |
|
Line 41... | Line 44... | |||
41 | private readonly CancellationToken _cancellationToken; |
44 | private readonly CancellationToken _cancellationToken; |
|
42 | private readonly CancellationTokenSource _cancellationTokenSource; |
45 | private readonly CancellationTokenSource _cancellationTokenSource; |
|
43 | private CatAssemblies _catAssemblies; |
46 | private CatAssemblies _catAssemblies; |
|
44 | private BandScan _bandScan; |
47 | private BandScan _bandScan; |
|
45 | private SpectrogramForm _spectrogramForm; |
48 | private SpectrogramForm _spectrogramForm; |
|
- | 49 | private MemoryOrganizerForm _memoryOrganizerForm; |
||
- | 50 | |
||
- | 51 | private CancellationTokenSource _tagTickerCancellationTokenSource; |
||
- | 52 | private CancellationToken _tagTickerCancellationToken; |
||
- | 53 | private string _storedMemoryChannelTagText; |
||
- | 54 | private string _storedMemoryChannelLocation; |
||
- | 55 | private MemoryChannel _tickerTextMemoryChannel; |
||
- | 56 | private Task _tickerTask; |
||
- | 57 | private volatile bool _tickerTaskRunning; |
||
Line 46... | Line 58... | |||
46 | |
58 | |
|
Line 47... | Line 59... | |||
47 | public bool MemorySinkEnabled { get; set; } |
59 | public bool MemorySinkEnabled { get; set; } |
|
48 | |
60 | |
|
Line 352... | Line 364... | |||
352 | var toolStripComboBox = (ToolStripComboBox)sender; |
364 | var toolStripComboBox = (ToolStripComboBox)sender; |
|
353 | if(RadioMode.TryParse(toolStripComboBox.Text, out var radioMode)) |
365 | if(RadioMode.TryParse(toolStripComboBox.Text, out var radioMode)) |
|
354 | { |
366 | { |
|
355 | try |
367 | try |
|
356 | { |
368 | { |
|
357 | await _catAssemblies.CatSetAsync<RadioMode>("MD", new object[] { radioMode }, _cancellationToken); |
369 | await _catAssemblies.CatSetAsync<RadioMode, bool>("MD", new object[] { radioMode }, _cancellationToken); |
|
358 | } |
370 | } |
|
359 | catch (Exception exception) |
371 | catch (Exception exception) |
|
360 | { |
372 | { |
|
361 | Log.Error(exception, Resources.Failed_to_set_radio_mode, radioMode); |
373 | Log.Error(exception, Resources.Failed_to_set_radio_mode, radioMode); |
|
362 | } |
374 | } |
|
Line 365... | Line 377... | |||
365 | |
377 | |
|
366 | private async void onToolStripMenuItem_Click(object sender, EventArgs e) |
378 | private async void onToolStripMenuItem_Click(object sender, EventArgs e) |
|
367 | { |
379 | { |
|
368 | try |
380 | try |
|
369 | { |
381 | { |
|
370 | await _catAssemblies.CatSetAsync<PowerState>("PS", new object[] { PowerState.ON }, _cancellationToken); |
382 | await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.ON }, _cancellationToken); |
|
371 | } |
383 | } |
|
372 | catch(Exception exception) |
384 | catch(Exception exception) |
|
373 | { |
385 | { |
|
374 | Log.Error(exception, Resources.Failed_to_set_power_state); |
386 | Log.Error(exception, Resources.Failed_to_set_power_state); |
|
Line 377... | Line 389... | |||
377 | |
389 | |
|
378 | private async void offToolStripMenuItem_Click(object sender, EventArgs e) |
390 | private async void offToolStripMenuItem_Click(object sender, EventArgs e) |
|
379 | { |
391 | { |
|
380 | try |
392 | try |
|
381 | { |
393 | { |
|
382 | await _catAssemblies.CatSetAsync<PowerState>("PS", new object[] { PowerState.OFF }, _cancellationToken); |
394 | await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.OFF }, _cancellationToken); |
|
383 | } |
395 | } |
|
384 | catch(Exception exception) |
396 | catch(Exception exception) |
|
385 | { |
397 | { |
|
386 | Log.Error(exception, Resources.Failed_to_set_power_state); |
398 | Log.Error(exception, Resources.Failed_to_set_power_state); |
|
Line 406... | Line 418... | |||
406 | |
418 | |
|
Line 407... | Line 419... | |||
407 | soundPlayer.Play(); |
419 | soundPlayer.Play(); |
|
408 | |
420 | |
|
409 | try |
421 | try |
|
410 | { |
422 | { |
|
Line 411... | Line 423... | |||
411 | await _catAssemblies.CatSetAsync<int>("FA", new object[] { frequency }, _cancellationToken); |
423 | await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken); |
|
412 | toolStripComboBox.Text = $"{frequency}"; |
424 | toolStripComboBox.Text = $"{frequency}"; |
|
413 | |
425 | |
|
Line 440... | Line 452... | |||
440 | |
452 | |
|
Line 441... | Line 453... | |||
441 | soundPlayer.Play(); |
453 | soundPlayer.Play(); |
|
442 | |
454 | |
|
443 | try |
455 | try |
|
444 | { |
456 | { |
|
Line 445... | Line 457... | |||
445 | await _catAssemblies.CatSetAsync<int>("FB", new object[] { frequency }, _cancellationToken); |
457 | await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken); |
|
446 | toolStripComboBox.Text = $"{frequency}"; |
458 | toolStripComboBox.Text = $"{frequency}"; |
|
447 | |
459 | |
|
Line 460... | Line 472... | |||
460 | var toolStripComboBox = (ToolStripComboBox)sender; |
472 | var toolStripComboBox = (ToolStripComboBox)sender; |
|
461 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
473 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
|
462 | { |
474 | { |
|
463 | try |
475 | try |
|
464 | { |
476 | { |
|
465 | await _catAssemblies.CatSetAsync<int>("FA", new object[] { frequency }, _cancellationToken); |
477 | await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken); |
|
466 | } |
478 | } |
|
467 | catch (Exception exception) |
479 | catch (Exception exception) |
|
468 | { |
480 | { |
|
469 | Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); |
481 | Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); |
|
470 | } |
482 | } |
|
Line 476... | Line 488... | |||
476 | var toolStripComboBox = (ToolStripComboBox)sender; |
488 | var toolStripComboBox = (ToolStripComboBox)sender; |
|
477 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
489 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
|
478 | { |
490 | { |
|
479 | try |
491 | try |
|
480 | { |
492 | { |
|
481 | await _catAssemblies.CatSetAsync<int>("FB", new object[] { frequency }, _cancellationToken); |
493 | await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken); |
|
482 | } |
494 | } |
|
483 | catch (Exception exception) |
495 | catch (Exception exception) |
|
484 | { |
496 | { |
|
485 | Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); |
497 | Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); |
|
486 | } |
498 | } |
|
Line 610... | Line 622... | |||
610 | async () => |
622 | async () => |
|
611 | { |
623 | { |
|
612 | await SaveConfiguration(); |
624 | await SaveConfiguration(); |
|
613 | }, _cancellationToken); |
625 | }, _cancellationToken); |
|
614 | } |
626 | } |
|
- | 627 | |
||
- | 628 | private void toolStripMenuItem3_Click(object sender, EventArgs e) |
||
- | 629 | { |
||
- | 630 | if (_memoryOrganizerForm != null) |
||
- | 631 | { |
||
- | 632 | return; |
||
- | 633 | } |
||
- | 634 | |
||
- | 635 | _memoryOrganizerForm = new MemoryOrganizerForm(Configuration, _catAssemblies, _cancellationToken); |
||
- | 636 | _memoryOrganizerForm.Closing += MemoryOrganizerForm_Closing; |
||
- | 637 | _memoryOrganizerForm.Show(); |
||
- | 638 | } |
||
- | 639 | |
||
- | 640 | private void MemoryOrganizerForm_Closing(object sender, CancelEventArgs e) |
||
- | 641 | { |
||
- | 642 | if (_memoryOrganizerForm == null) |
||
- | 643 | { |
||
- | 644 | return; |
||
- | 645 | } |
||
- | 646 | |
||
- | 647 | _memoryOrganizerForm.Dispose(); |
||
- | 648 | _memoryOrganizerForm = null; |
||
- | 649 | |
||
- | 650 | } |
||
- | 651 | |
||
- | 652 | private async void toolStripMenuItem4_Click(object sender, EventArgs e) |
||
- | 653 | { |
||
- | 654 | if (_tickerTaskRunning) |
||
- | 655 | { |
||
- | 656 | return; |
||
- | 657 | } |
||
- | 658 | |
||
- | 659 | var toolStripTextBox = (ToolStripTextBox)toolStripTextBox6; |
||
- | 660 | |
||
- | 661 | try |
||
- | 662 | { |
||
- | 663 | var result = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { "001" }, _cancellationToken); |
||
- | 664 | |
||
- | 665 | _tickerTextMemoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { $"{result.CurrentLocation}" }, _cancellationToken); |
||
- | 666 | |
||
- | 667 | _storedMemoryChannelTagText = _tickerTextMemoryChannel.Text; |
||
- | 668 | _storedMemoryChannelLocation = _tickerTextMemoryChannel.CurrentLocation; |
||
- | 669 | } |
||
- | 670 | catch(Exception exception) |
||
- | 671 | { |
||
- | 672 | Log.Error(exception, Resources.Could_not_read_memory_bank); |
||
- | 673 | } |
||
- | 674 | |
||
- | 675 | var tickerText = $"{toolStripTextBox.Text,-12}"; |
||
- | 676 | |
||
- | 677 | _tagTickerCancellationTokenSource = new CancellationTokenSource(); |
||
- | 678 | _tagTickerCancellationToken = _tagTickerCancellationTokenSource.Token; |
||
- | 679 | |
||
- | 680 | var characterQueue = new Queue<char>(12); |
||
- | 681 | foreach(var i in Enumerable.Range(0, 12)) |
||
- | 682 | { |
||
- | 683 | var x = tickerText.ElementAtOrDefault(i); |
||
- | 684 | |
||
- | 685 | if(x == default) |
||
- | 686 | { |
||
- | 687 | characterQueue.Enqueue(' '); |
||
- | 688 | continue; |
||
- | 689 | } |
||
- | 690 | |
||
- | 691 | characterQueue.Enqueue(x); |
||
- | 692 | } |
||
- | 693 | |
||
- | 694 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
- | 695 | _tickerTask = Task.Run(() => CycleText(characterQueue), _cancellationToken); |
||
- | 696 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
- | 697 | } |
||
- | 698 | |
||
- | 699 | private async void toolStripMenuItem5_Click(object sender, EventArgs e) |
||
- | 700 | { |
||
- | 701 | if(!_tickerTaskRunning) |
||
- | 702 | { |
||
- | 703 | return; |
||
- | 704 | } |
||
- | 705 | |
||
- | 706 | _tagTickerCancellationTokenSource.Cancel(); |
||
- | 707 | if (_tickerTask != null) |
||
- | 708 | { |
||
- | 709 | await _tickerTask; |
||
- | 710 | _tickerTask = null; |
||
- | 711 | } |
||
- | 712 | |
||
- | 713 | try |
||
- | 714 | { |
||
- | 715 | _tickerTextMemoryChannel.CurrentLocation = $"{_storedMemoryChannelLocation:000}"; |
||
- | 716 | _tickerTextMemoryChannel.Text = $"{_storedMemoryChannelTagText, 12}"; |
||
- | 717 | |
||
- | 718 | var success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken); |
||
- | 719 | if (!success) |
||
- | 720 | { |
||
- | 721 | Log.Error(Resources.Error_while_restoring_memory_text); |
||
- | 722 | |
||
- | 723 | return; |
||
- | 724 | } |
||
- | 725 | } |
||
- | 726 | catch(Exception exception) |
||
- | 727 | { |
||
- | 728 | Log.Error(exception, Resources.Error_while_restoring_memory_text); |
||
- | 729 | } |
||
- | 730 | } |
||
- | 731 | |
||
- | 732 | private async Task CycleText(Queue<char> characterQueue) |
||
- | 733 | { |
||
- | 734 | _tickerTaskRunning = true; |
||
- | 735 | try |
||
- | 736 | { |
||
- | 737 | do |
||
- | 738 | { |
||
- | 739 | var text = string.Join("", characterQueue.OfType<char>()); |
||
- | 740 | |
||
- | 741 | _tickerTextMemoryChannel.Text = text; |
||
- | 742 | |
||
- | 743 | await _catAssemblies.CatWriteAsync<MemoryChannel>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken); |
||
- | 744 | |
||
- | 745 | var x = characterQueue.Dequeue(); |
||
- | 746 | characterQueue.Enqueue(x); |
||
- | 747 | |
||
- | 748 | await Task.Delay(250); |
||
- | 749 | |
||
- | 750 | } while (!_tagTickerCancellationToken.IsCancellationRequested); |
||
- | 751 | } |
||
- | 752 | catch(Exception exception) |
||
- | 753 | { |
||
- | 754 | Log.Error(exception, Resources.Error_while_cycling_text); |
||
- | 755 | } |
||
- | 756 | } |
||
615 | } |
757 | } |
|
616 | } |
758 | } |