HamBook – Diff between revs 25 and 26
?pathlinks?
Rev 25 | Rev 26 | |||
---|---|---|---|---|
Line 28... | Line 28... | |||
28 | using NAudio.Utils; |
28 | using NAudio.Utils; |
|
29 | using System.Linq; |
29 | using System.Linq; |
|
30 | using static System.Net.Mime.MediaTypeNames; |
30 | using static System.Net.Mime.MediaTypeNames; |
|
31 | using System.Diagnostics; |
31 | using System.Diagnostics; |
|
32 | using Newtonsoft.Json.Linq; |
32 | using Newtonsoft.Json.Linq; |
|
- | 33 | using System.Collections.Concurrent; |
||
- | 34 | using Org.BouncyCastle.Math.Field; |
||
Line 33... | Line 35... | |||
33 | |
35 | |
|
34 | namespace HamBook |
36 | namespace HamBook |
|
35 | { |
37 | { |
|
36 | public partial class Form1 : Form |
38 | public partial class Form1 : Form |
|
Line 59... | Line 61... | |||
59 | private string _storedMemoryChannelLocation; |
61 | private string _storedMemoryChannelLocation; |
|
60 | private MemoryChannel _tickerTextMemoryChannel; |
62 | private MemoryChannel _tickerTextMemoryChannel; |
|
61 | private Task _tickerTask; |
63 | private Task _tickerTask; |
|
62 | private volatile bool _tickerTaskRunning; |
64 | private volatile bool _tickerTaskRunning; |
|
Line -... | Line 65... | |||
- | 65 | |
||
- | 66 | private ConcurrentDictionary<int, MemoryChannel> _memoryChannelStore = new ConcurrentDictionary<int, MemoryChannel>(); |
||
63 | |
67 | |
|
Line 64... | Line 68... | |||
64 | public bool MemorySinkEnabled { get; set; } |
68 | public bool MemorySinkEnabled { get; set; } |
|
65 | |
69 | |
|
66 | private Form1() |
70 | private Form1() |
|
Line 127... | Line 131... | |||
127 | } |
131 | } |
|
128 | catch(Exception exception) |
132 | catch(Exception exception) |
|
129 | { |
133 | { |
|
130 | Log.Error(exception, Resources.Failed_to_read_power_state); |
134 | Log.Error(exception, Resources.Failed_to_read_power_state); |
|
131 | } |
135 | } |
|
- | 136 | |
||
- | 137 | var memoryBankQueue = new ConcurrentQueue<int>(); |
||
- | 138 | var memoryBankTaskCompletionSource = new TaskCompletionSource<bool>(); |
||
- | 139 | |
||
- | 140 | async void IdleHandler(object idleHandlerSender, EventArgs idleHandlerArgs) |
||
- | 141 | { |
||
- | 142 | await memoryBankTaskCompletionSource.Task; |
||
- | 143 | |
||
- | 144 | try |
||
- | 145 | { |
||
- | 146 | if (!memoryBankQueue.TryDequeue(out var memoryBank)) |
||
- | 147 | { |
||
- | 148 | System.Windows.Forms.Application.Idle -= IdleHandler; |
||
- | 149 | |
||
- | 150 | return; |
||
- | 151 | } |
||
- | 152 | |
||
- | 153 | var location = $"{memoryBank:000}"; |
||
- | 154 | |
||
- | 155 | MemoryChannel memoryChannel = new MemoryChannel(); |
||
- | 156 | |
||
- | 157 | try |
||
- | 158 | { |
||
- | 159 | memoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { location }, _cancellationToken); |
||
- | 160 | |
||
- | 161 | scrollableToolStripComboBox5.Items.Add(location); |
||
- | 162 | |
||
- | 163 | } |
||
- | 164 | catch(Exception exception) |
||
- | 165 | { |
||
- | 166 | Log.Warning(exception, Resources.Could_not_read_memory_bank); |
||
- | 167 | |
||
- | 168 | return; |
||
- | 169 | } |
||
- | 170 | |
||
- | 171 | _memoryChannelStore.TryAdd(memoryBank, memoryChannel); |
||
- | 172 | |
||
- | 173 | } |
||
- | 174 | catch (Exception exception) |
||
- | 175 | { |
||
- | 176 | Log.Error(exception, Resources.Could_not_update_data_grid_view); |
||
- | 177 | } |
||
- | 178 | } |
||
- | 179 | |
||
- | 180 | System.Windows.Forms.Application.Idle += IdleHandler; |
||
- | 181 | try |
||
- | 182 | { |
||
- | 183 | foreach (var memoryBank in Enumerable.Range(1, 99)) |
||
- | 184 | { |
||
- | 185 | memoryBankQueue.Enqueue(memoryBank); |
||
- | 186 | } |
||
- | 187 | |
||
- | 188 | memoryBankTaskCompletionSource.TrySetResult(true); |
||
- | 189 | } |
||
- | 190 | catch (Exception exception) |
||
- | 191 | { |
||
- | 192 | System.Windows.Forms.Application.Idle -= IdleHandler; |
||
- | 193 | |
||
- | 194 | Log.Error(exception, Resources.Unable_to_create_memory_banks); |
||
- | 195 | } |
||
132 | } |
196 | } |
|
Line 133... | Line 197... | |||
133 | |
197 | |
|
134 | private async void quitToolStripMenuItem_Click(object sender, EventArgs e) |
198 | private async void quitToolStripMenuItem_Click(object sender, EventArgs e) |
|
135 | { |
199 | { |
|
Line 333... | Line 397... | |||
333 | { |
397 | { |
|
334 | if (_serialPort.IsOpen) |
398 | if (_serialPort.IsOpen) |
|
335 | { |
399 | { |
|
336 | _serialPort.Close(); |
400 | _serialPort.Close(); |
|
337 | } |
401 | } |
|
- | 402 | |
||
338 | _serialPort.Dispose(); |
403 | _serialPort.Dispose(); |
|
339 | _serialPort = null; |
404 | _serialPort = null; |
|
340 | } |
405 | } |
|
Line 341... | Line 406... | |||
341 | |
406 | |
|
Line 628... | Line 693... | |||
628 | { |
693 | { |
|
629 | var mc = await _catAssemblies.CatReadAsync<int>("MC", new object[] { }, _cancellationToken); |
694 | var mc = await _catAssemblies.CatReadAsync<int>("MC", new object[] { }, _cancellationToken); |
|
Line 630... | Line 695... | |||
630 | |
695 | |
|
631 | contextMenuStrip1.InvokeIfRequired(contextMenuStrip => |
696 | contextMenuStrip1.InvokeIfRequired(contextMenuStrip => |
|
632 | { |
697 | { |
|
- | 698 | scrollableToolStripComboBox5.Text = $"{mc:000}"; |
||
- | 699 | |
||
- | 700 | if(_memoryChannelStore.TryGetValue(mc, out var memoryChannel)) |
||
- | 701 | { |
||
- | 702 | toolStripMenuItem27.Text = memoryChannel.Text; |
||
Line 633... | Line 703... | |||
633 | scrollableToolStripComboBox5.Text = $"{mc}"; |
703 | } |
|
634 | |
704 | |
|
635 | }); |
705 | }); |
|
636 | } |
706 | } |
|
Line 848... | Line 918... | |||
848 | } |
918 | } |
|
Line 849... | Line 919... | |||
849 | |
919 | |
|
850 | private async void scrollableToolStripComboBox5_TextChanged(object sender, EventArgs e) |
920 | private async void scrollableToolStripComboBox5_TextChanged(object sender, EventArgs e) |
|
851 | { |
921 | { |
|
852 | var toolStripComboBox = (ToolStripComboBox)sender; |
922 | var toolStripComboBox = (ToolStripComboBox)sender; |
|
853 | if (int.TryParse(toolStripComboBox.Text, out var memoryChannel)) |
923 | if (int.TryParse(toolStripComboBox.Text, out var channel)) |
|
854 | { |
924 | { |
|
855 | try |
925 | if (_memoryChannelStore.TryGetValue(channel, out var memoryChannel)) |
|
- | 926 | { |
||
- | 927 | try |
||
856 | { |
928 | { |
|
- | 929 | await _catAssemblies.CatWriteAsync<int>("MC", new object[] { channel }, _cancellationToken); |
||
- | 930 | |
||
857 | await _catAssemblies.CatWriteAsync<int>("MC", new object[] { memoryChannel }, _cancellationToken); |
931 | toolStripMenuItem27.Text = memoryChannel.Text; |
|
858 | } |
932 | } |
|
859 | catch (Exception exception) |
933 | catch (Exception exception) |
|
860 | { |
934 | { |
|
- | 935 | Log.Error(exception, Resources.Failed_to_set_memory_channel); |
||
861 | Log.Error(exception, Resources.Failed_to_set_memory_channel); |
936 | } |
|
862 | } |
937 | } |
|
863 | } |
938 | } |
|
Line 864... | Line 939... | |||
864 | } |
939 | } |