HamBook – Diff between revs 53 and 54

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 53 Rev 54
Line 1... Line 1...
1 using HamBook.Radios; 1 using System;
2 using HamBook.Utilities; -  
3 using HamBook.Utilities.Serialization; 2 using System.Collections.Concurrent;
4 using NetSparkleUpdater.Enums; 3 using System.Collections.Generic;
5 using NetSparkleUpdater.SignatureVerifiers; -  
6 using NetSparkleUpdater.UI.WinForms; -  
7 using NetSparkleUpdater; -  
8 using Serilog; -  
9 using System; -  
10 using System.ComponentModel; 4 using System.ComponentModel;
11 using System.Drawing; 5 using System.Drawing;
12 using System.IO; 6 using System.IO;
-   7 using System.Linq;
13 using System.IO.Ports; 8 using System.Media;
14 using System.Reflection; 9 using System.Reflection;
-   10 using System.Text;
15 using System.Threading; 11 using System.Threading;
16 using System.Threading.Tasks; 12 using System.Threading.Tasks;
17 using System.Windows.Forms; 13 using System.Windows.Forms;
18 using HamBook.Properties; 14 using HamBook.Properties;
-   15 using HamBook.Radios;
19 using HamBook.Radios.Generic; 16 using HamBook.Radios.Generic;
20 using PowerState = HamBook.Radios.Generic.PowerState; -  
21 using System.Media; 17 using HamBook.Utilities;
22 using HamBook.Utilities.Controls; 18 using HamBook.Utilities.Controls;
-   19 using HamBook.Utilities.Serialization;
-   20 using NetSparkleUpdater;
-   21 using NetSparkleUpdater.Enums;
-   22 using NetSparkleUpdater.SignatureVerifiers;
-   23 using NetSparkleUpdater.UI.WinForms;
23 using RJCP.IO.Ports; 24 using RJCP.IO.Ports;
24 using System.Text; 25 using Serilog;
25 using System.Collections.ObjectModel; -  
26 using Configuration; -  
27 using System.Collections.Generic; -  
28 using NAudio.Utils; -  
29 using System.Linq; -  
30 using static System.Net.Mime.MediaTypeNames; -  
31 using System.Diagnostics; -  
32 using Newtonsoft.Json.Linq; -  
33 using System.Collections.Concurrent; -  
34 using Org.BouncyCastle.Math.Field; -  
35 using System.Runtime.Remoting.Channels; -  
36 using HamBook.Radios.Generic.CAT; 26 using PowerState = HamBook.Radios.Generic.PowerState;
37 using Org.BouncyCastle.Asn1.X509.Qualified; -  
38 using Jot; -  
Line 39... Line 27...
39   27  
40 namespace HamBook 28 namespace HamBook
41 { 29 {
42 public partial class Form1 : Form 30 public partial class Form1 : Form
43 { -  
44 private ScheduledContinuation _changedConfigurationContinuation; -  
45 private ScheduledContinuation _squelchScheduledContinuation; -  
46 private ScheduledContinuation _powerScheduledContinuation; -  
47 private MemoryBanks _memoryBanks; -  
48   -  
49 private Configuration.Configuration Configuration { get; set; } -  
50 private SerialPortStream _serialPort; -  
51 private LogMemorySink _memorySink; -  
52 private ViewLogsForm _viewLogsForm; -  
53 private AboutForm _aboutForm; -  
54 private SettingsForm _settingsForm; -  
55 private SparkleUpdater _sparkle; 31 {
56 private readonly CancellationToken _cancellationToken; 32 private readonly CancellationToken _cancellationToken;
-   33 private readonly CancellationTokenSource _cancellationTokenSource;
-   34 private readonly ScheduledContinuation _changedConfigurationContinuation;
-   35  
-   36 private readonly ConcurrentDictionary<string, MemoryChannel> _memoryChannelStore =
-   37 new ConcurrentDictionary<string, MemoryChannel>();
-   38  
-   39 private readonly LogMemorySink _memorySink;
-   40 private readonly SparkleUpdater _sparkle;
57 private readonly CancellationTokenSource _cancellationTokenSource; 41 private readonly ScheduledContinuation _squelchScheduledContinuation;
58 private CatAssemblies _catAssemblies; 42 private AboutForm _aboutForm;
-   43 private BandScan _bandScan;
59 private BandScan _bandScan; 44 private CatAssemblies _catAssemblies;
60 private SpectrogramForm _spectrogramForm; 45 private MemoryBanks _memoryBanks;
-   46 private MemoryOrganizerForm _memoryOrganizerForm;
-   47 private MemoryTune _memoryTune;
-   48 private MenuForm _menuForm;
-   49 private ScheduledContinuation _powerScheduledContinuation;
-   50 private SerialPortStream _serialPort;
-   51 private SettingsForm _settingsForm;
-   52 private SpectrogramForm _spectrogramForm;
-   53 private string _storedMemoryChannelLocation;
-   54 private string _storedMemoryChannelTagText;
Line 61... Line 55...
61 private MemoryOrganizerForm _memoryOrganizerForm; 55 private CancellationToken _tagTickerCancellationToken;
62   -  
63 private CancellationTokenSource _tagTickerCancellationTokenSource; -  
64 private CancellationToken _tagTickerCancellationToken; -  
65 private string _storedMemoryChannelTagText; -  
66 private string _storedMemoryChannelLocation; 56  
67 private MemoryChannel _tickerTextMemoryChannel; 57 private CancellationTokenSource _tagTickerCancellationTokenSource;
68 private Task _tickerTask; -  
69 private volatile bool _tickerTaskRunning; -  
70   58 private Task _tickerTask;
71 private ConcurrentDictionary<string, MemoryChannel> _memoryChannelStore = new ConcurrentDictionary<string, MemoryChannel>(); -  
72 private MemoryTune _memoryTune; 59 private volatile bool _tickerTaskRunning;
Line 73... Line 60...
73   60 private MemoryChannel _tickerTextMemoryChannel;
74 public bool MemorySinkEnabled { get; set; } 61 private ViewLogsForm _viewLogsForm;
75   62  
76 private Form1() 63 private Form1()
Line 107... Line 94...
107 UIFactory = new UIFactory(icon), 94 UIFactory = new UIFactory(icon),
108 RelaunchAfterUpdate = true 95 RelaunchAfterUpdate = true
109 }; 96 };
110 } 97 }
Line -... Line 98...
-   98  
-   99 private Configuration.Configuration Configuration { get; set; }
-   100  
-   101 public bool MemorySinkEnabled { get; set; }
111   102  
112 private async void Form1_Load(object sender, EventArgs e) 103 private async void Form1_Load(object sender, EventArgs e)
113 { 104 {
Line 114... Line 105...
114 _sparkle.StartLoop(true, true); 105 _sparkle.StartLoop(true, true);
Line 126... Line 117...
126 { 117 {
127 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken)) 118 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken))
128 { 119 {
129 case PowerState.ON: 120 case PowerState.ON:
130 Log.Information(Resources.Attempting_to_initialize_radio); 121 Log.Information(Resources.Attempting_to_initialize_radio);
131 if(!await InitializeRadio()) 122 if (!await InitializeRadio()) return;
132 { -  
133 return; -  
134 } -  
Line 135... Line 123...
135   123  
136 Log.Information(Resources.Initializing_GUI); 124 Log.Information(Resources.Initializing_GUI);
137 break; 125 break;
138 } 126 }
139 } 127 }
140 catch(Exception exception) 128 catch (Exception exception)
141 { 129 {
142 Log.Error(exception, Resources.Failed_to_read_power_state); 130 Log.Error(exception, Resources.Failed_to_read_power_state);
Line 143... Line 131...
143 } 131 }
Line 152... Line 140...
152   140  
153 try 141 try
154 { 142 {
155 if (!memoryBankQueue.TryDequeue(out var memoryBank)) 143 if (!memoryBankQueue.TryDequeue(out var memoryBank))
156 { 144 {
Line 157... Line 145...
157 System.Windows.Forms.Application.Idle -= IdleHandler; 145 Application.Idle -= IdleHandler;
158   146  
Line 159... Line 147...
159 return; 147 return;
Line 160... Line 148...
160 } 148 }
Line 161... Line 149...
161   149  
162 scrollableToolStripComboBox12.Items.Add(memoryBank); 150 scrollableToolStripComboBox12.Items.Add(memoryBank);
163   151  
164 MemoryChannel memoryChannel = MemoryChannel.Create(Configuration.Radio); -  
165   152 var memoryChannel = MemoryChannel.Create(Configuration.Radio);
Line -... Line 153...
-   153  
166 try 154 try
167 { 155 {
168 memoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { memoryBank }, _cancellationToken); 156 memoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT",
169 157 new object[] { memoryBank }, _cancellationToken);
Line 170... Line 158...
170 scrollableToolStripComboBox5.Items.Add(memoryBank); 158  
171   159 scrollableToolStripComboBox5.Items.Add(memoryBank);
Line 172... Line 160...
172 } 160 }
173 catch(Exception exception) -  
174 { 161 catch (Exception exception)
175 Log.Warning(exception, Resources.Could_not_read_memory_bank); 162 {
176   163 Log.Warning(exception, Resources.Could_not_read_memory_bank);
177 return; 164  
178 } 165 return;
179   166 }
Line 180... Line 167...
180 _memoryChannelStore.TryAdd(memoryBank, memoryChannel); 167  
181   168 _memoryChannelStore.TryAdd(memoryBank, memoryChannel);
182 } 169 }
183 catch (Exception exception) 170 catch (Exception exception)
184 { -  
185 Log.Error(exception, Resources.Could_not_update_data_grid_view); -  
186 } -  
Line 187... Line 171...
187 } 171 {
188   172 Log.Error(exception, Resources.Could_not_update_data_grid_view);
189 System.Windows.Forms.Application.Idle += IdleHandler; 173 }
190 try 174 }
191 { 175  
Line 192... Line 176...
192 foreach (var memoryBank in _memoryBanks.GetMemoryBanks()) 176 Application.Idle += IdleHandler;
193 { 177 try
Line 194... Line 178...
194 memoryBankQueue.Enqueue(memoryBank); 178 {
195 } 179 foreach (var memoryBank in _memoryBanks.GetMemoryBanks()) memoryBankQueue.Enqueue(memoryBank);
196   180  
-   181 memoryBankTaskCompletionSource.TrySetResult(true);
197 memoryBankTaskCompletionSource.TrySetResult(true); 182 }
198 } 183 catch (Exception exception)
199 catch (Exception exception) 184 {
200 { 185 Application.Idle -= IdleHandler;
201 System.Windows.Forms.Application.Idle -= IdleHandler; 186  
202   187 Log.Error(exception, Resources.Unable_to_read_memory_banks);
203 Log.Error(exception, Resources.Unable_to_read_memory_banks); 188 }
Line 223... Line 208...
223 } 208 }
224 } 209 }
Line 225... Line 210...
225   210  
226 private async void quitToolStripMenuItem_Click(object sender, EventArgs e) 211 private async void quitToolStripMenuItem_Click(object sender, EventArgs e)
227 { 212 {
228 if(_bandScan != null) 213 if (_bandScan != null)
229 { 214 {
230 _bandScan.Stop(); 215 _bandScan.Stop();
231 _bandScan = null; 216 _bandScan = null;
Line 243... Line 228...
243 Close(); 228 Close();
244 } 229 }
Line 245... Line 230...
245   230  
246 private void viewLogsToolStripMenuItem_Click(object sender, EventArgs e) 231 private void viewLogsToolStripMenuItem_Click(object sender, EventArgs e)
247 { 232 {
248 if (_viewLogsForm != null) -  
249 { -  
250 return; -  
Line 251... Line 233...
251 } 233 if (_viewLogsForm != null) return;
252   234  
253 _viewLogsForm = new ViewLogsForm(this, _memorySink, _cancellationToken); 235 _viewLogsForm = new ViewLogsForm(this, _memorySink, _cancellationToken);
254 _viewLogsForm.Closing += ViewLogsForm_Closing; 236 _viewLogsForm.Closing += ViewLogsForm_Closing;
Line 255... Line 237...
255 _viewLogsForm.Show(); 237 _viewLogsForm.Show();
256 } 238 }
257   239  
258 private void ViewLogsForm_Closing(object sender, CancelEventArgs e) -  
259 { -  
260 if (_viewLogsForm == null) -  
Line 261... Line 240...
261 { 240 private void ViewLogsForm_Closing(object sender, CancelEventArgs e)
262 return; 241 {
263 } 242 if (_viewLogsForm == null) return;
264   243  
Line 265... Line 244...
265 _viewLogsForm.Closing -= ViewLogsForm_Closing; 244 _viewLogsForm.Closing -= ViewLogsForm_Closing;
266 _viewLogsForm.Close(); 245 _viewLogsForm.Close();
267 _viewLogsForm = null; 246 _viewLogsForm = null;
268 } -  
269   -  
270 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) -  
Line 271... Line 247...
271 { 247 }
272 if (_aboutForm != null) 248  
273 { 249 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
274 return; 250 {
Line 275... Line 251...
275 } 251 if (_aboutForm != null) return;
276   252  
277 _aboutForm = new AboutForm(_cancellationToken); 253 _aboutForm = new AboutForm(_cancellationToken);
278 _aboutForm.Closing += AboutForm_Closing; -  
279 _aboutForm.Show(); -  
280 } -  
Line 281... Line 254...
281   254 _aboutForm.Closing += AboutForm_Closing;
282 private void AboutForm_Closing(object sender, CancelEventArgs e) 255 _aboutForm.Show();
283 { 256 }
Line 284... Line 257...
284 if (_aboutForm == null) 257  
285 { 258 private void AboutForm_Closing(object sender, CancelEventArgs e)
286 return; 259 {
287 } -  
288   -  
289 _aboutForm.Dispose(); -  
Line 290... Line 260...
290 _aboutForm = null; 260 if (_aboutForm == null) return;
291 } 261  
292   262 _aboutForm.Dispose();
293 private void settingsToolStripMenuItem_Click(object sender, EventArgs e) 263 _aboutForm = null;
Line 294... Line 264...
294 { 264 }
295 if (_settingsForm != null) 265  
296 { 266 private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
297 return; -  
298 } -  
299   -  
Line 300... Line 267...
300 _settingsForm = new SettingsForm(Configuration, _cancellationToken); 267 {
301 _settingsForm.Closing += SettingsForm_Closing; -  
302 _settingsForm.Show(); 268 if (_settingsForm != null) return;
303 } 269  
304   270 _settingsForm = new SettingsForm(Configuration, _cancellationToken);
-   271 _settingsForm.Closing += SettingsForm_Closing;
305 private void SettingsForm_Closing(object sender, CancelEventArgs e) 272 _settingsForm.Show();
Line 306... Line 273...
306 { 273 }
307 if (_settingsForm == null) 274  
308 { 275 private void SettingsForm_Closing(object sender, CancelEventArgs e)
309 return; 276 {
310 } 277 if (_settingsForm == null) return;
Line 326... Line 293...
326 { 293 {
327 _memoryTune.Stop(); 294 _memoryTune.Stop();
328 _memoryTune = null; 295 _memoryTune = null;
329 } 296 }
Line 330... Line 297...
330   297  
Line 331... Line 298...
331 _memoryBanks = Radios.Generic.MemoryBanks.Create(Configuration.Radio); 298 _memoryBanks = MemoryBanks.Create(Configuration.Radio);
Line 332... Line 299...
332   299  
Line 333... Line 300...
333 Miscellaneous.LaunchOnBootSet(Configuration.LaunchOnBoot); 300 Miscellaneous.LaunchOnBootSet(Configuration.LaunchOnBoot);
Line 334... Line 301...
334   301  
335 _serialPort = InitializeSerialPort(Configuration); 302 _serialPort = InitializeSerialPort(Configuration);
336   303  
-   304 _catAssemblies = InitializeAssemblies(_serialPort);
337 _catAssemblies = InitializeAssemblies(_serialPort); 305  
338   306 try
339 try 307 {
340 { 308 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { },
341 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken)) -  
342 { -  
343 case PowerState.ON: -  
344 Log.Information(Resources.Attempting_to_initialize_radio); 309 _cancellationToken))
345 if (!await InitializeRadio()) 310 {
346 { 311 case PowerState.ON:
347 return; 312 Log.Information(Resources.Attempting_to_initialize_radio);
348 } 313 if (!await InitializeRadio()) return;
349 Log.Information(Resources.Initializing_GUI); 314 Log.Information(Resources.Initializing_GUI);
350 break; 315 break;
351 } 316 }
352 } -  
353 catch (Exception exception) 317 }
354 { -  
Line 355... Line 318...
355 Log.Error(exception, Resources.Failed_to_read_power_state); 318 catch (Exception exception)
356 } 319 {
357   320 Log.Error(exception, Resources.Failed_to_read_power_state);
Line 358... Line 321...
358 }, _cancellationToken); 321 }
359 } 322 }, _cancellationToken);
360   323  
361 _settingsForm.Dispose(); -  
362 _settingsForm = null; 324 _settingsForm.Dispose();
363 } -  
Line 364... Line 325...
364   325 _settingsForm = null;
365 public async Task SaveConfiguration() 326 }
366 { 327  
367 if (!Directory.Exists(Constants.UserApplicationDirectory)) 328 public async Task SaveConfiguration()
Line 383... Line 344...
383 } 344 }
Line 384... Line 345...
384   345  
385 public static async Task<Configuration.Configuration> LoadConfiguration() 346 public static async Task<Configuration.Configuration> LoadConfiguration()
386 { 347 {
387 if (!Directory.Exists(Constants.UserApplicationDirectory)) -  
388 { 348 if (!Directory.Exists(Constants.UserApplicationDirectory))
389 Directory.CreateDirectory(Constants.UserApplicationDirectory); -  
Line 390... Line 349...
390 } 349 Directory.CreateDirectory(Constants.UserApplicationDirectory);
391   350  
392 var deserializationResult = 351 var deserializationResult =
Line 407... Line 366...
407   366  
408 private async Task<bool> InitializeRadio() 367 private async Task<bool> InitializeRadio()
409 { 368 {
410 try 369 try
411 { 370 {
-   371 await _catAssemblies.CatWriteAsync<InformationState>("AI", new object[] { InformationState.OFF },
Line 412... Line 372...
412 await _catAssemblies.CatWriteAsync<InformationState>("AI", new object[] { InformationState.OFF }, _cancellationToken); 372 _cancellationToken);
413   373  
414 return await _catAssemblies.CatReadAsync<bool>("ID", new object[] { }, _cancellationToken); 374 return await _catAssemblies.CatReadAsync<bool>("ID", new object[] { }, _cancellationToken);
415 } 375 }
416 catch(Exception exception) 376 catch (Exception exception)
Line 417... Line 377...
417 { 377 {
418 Log.Error(exception, Resources.Unable_to_initialize_radio); 378 Log.Error(exception, Resources.Unable_to_initialize_radio);
419   379  
Line 420... Line 380...
420 return false; 380 return false;
421 } 381 }
422 } 382 }
423   383  
424 private CatAssemblies InitializeAssemblies(SerialPortStream serialPort) 384 private CatAssemblies InitializeAssemblies(SerialPortStream serialPort)
425 { 385 {
426 if(_catAssemblies != null) 386 if (_catAssemblies != null)
Line 434... Line 394...
434   394  
435 private SerialPortStream InitializeSerialPort(Configuration.Configuration configuration) 395 private SerialPortStream InitializeSerialPort(Configuration.Configuration configuration)
436 { 396 {
437 if (_serialPort != null) 397 if (_serialPort != null)
438 { 398 {
439 if (_serialPort.IsOpen) -  
440 { -  
441 _serialPort.Close(); -  
Line 442... Line 399...
442 } 399 if (_serialPort.IsOpen) _serialPort.Close();
443   400  
444 _serialPort.Dispose(); 401 _serialPort.Dispose();
Line 445... Line 402...
445 _serialPort = null; 402 _serialPort = null;
446 } 403 }
-   404  
447   405 // Set up serial connection.
448 // Set up serial connection. 406 var serialPort = new SerialPortStream(configuration.Port, configuration.Speed, configuration.DataBits,
449 var serialPort = new SerialPortStream(configuration.Port, configuration.Speed, configuration.DataBits, configuration.Parity, configuration.StopBits); 407 configuration.Parity, configuration.StopBits);
450 serialPort.ReadTimeout = configuration.SerialPortTimeout.Read; 408 serialPort.ReadTimeout = configuration.SerialPortTimeout.Read;
Line -... Line 409...
-   409 serialPort.WriteTimeout = configuration.SerialPortTimeout.Write;
451 serialPort.WriteTimeout = configuration.SerialPortTimeout.Write; 410 serialPort.Handshake = configuration.Handshake;
Line 452... Line 411...
452 serialPort.Handshake = configuration.Handshake; 411 serialPort.Encoding = Encoding.ASCII;
453 serialPort.Encoding = Encoding.ASCII; 412  
Line 454... Line 413...
454   413 Log.Information(
455 Log.Information($"{Resources.Initialized_serial_port} {configuration.Port} {configuration.Speed} {configuration.Parity} {configuration.DataBits} {configuration.StopBits}"); 414 $"{Resources.Initialized_serial_port} {configuration.Port} {configuration.Speed} {configuration.Parity} {configuration.DataBits} {configuration.StopBits}");
456   415  
457 return serialPort; 416 return serialPort;
458 } 417 }
459   418  
460 private async void updateToolStripMenuItem_Click(object sender, EventArgs e) 419 private async void updateToolStripMenuItem_Click(object sender, EventArgs e)
461 { 420 {
462 // Manually check for updates, this will not show a ui 421 // Manually check for updates, this will not show a ui
463 var result = await _sparkle.CheckForUpdatesQuietly(); 422 var result = await _sparkle.CheckForUpdatesQuietly();
Line 475... Line 434...
475   434  
476 private async void onToolStripMenuItem_Click(object sender, EventArgs e) 435 private async void onToolStripMenuItem_Click(object sender, EventArgs e)
477 { 436 {
478 try 437 try
479 { 438 {
-   439 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.ON },
480 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.ON }, _cancellationToken); 440 _cancellationToken);
481 } 441 }
482 catch(Exception exception) 442 catch (Exception exception)
483 { 443 {
484 Log.Error(exception, Resources.Failed_to_set_power_state); 444 Log.Error(exception, Resources.Failed_to_set_power_state);
485 } 445 }
Line 486... Line 446...
486 } 446 }
487   447  
488 private async void offToolStripMenuItem_Click(object sender, EventArgs e) 448 private async void offToolStripMenuItem_Click(object sender, EventArgs e)
489 { 449 {
490 try 450 try
-   451 {
491 { 452 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.OFF },
492 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.OFF }, _cancellationToken); 453 _cancellationToken);
493 } 454 }
494 catch(Exception exception) 455 catch (Exception exception)
495 { 456 {
496 Log.Error(exception, Resources.Failed_to_set_power_state); 457 Log.Error(exception, Resources.Failed_to_set_power_state);
Line 512... Line 473...
512 break; 473 break;
513 } 474 }
Line 514... Line 475...
514   475  
515 try 476 try
516 { 477 {
-   478 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
517 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 479 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
518 { 480 {
-   481 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency },
519 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken)) 482 _cancellationToken))
520 { 483 {
Line 521... Line 484...
521 toolStripComboBox.Text = $"{frequency}"; 484 toolStripComboBox.Text = $"{frequency}";
522   -  
523 if (Configuration.Navigation.MouseScrollSound) -  
524 { -  
525 soundPlayer.Play(); 485  
526 } 486 if (Configuration.Navigation.MouseScrollSound) soundPlayer.Play();
527 } 487 }
528 } 488 }
529 } 489 }
Line 540... Line 500...
540 { 500 {
541 case (char)Keys.Enter: 501 case (char)Keys.Enter:
542 var toolStripComboBox = (ScrollableToolStripComboBox)sender; 502 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
Line 543... Line 503...
543   503  
544 if (int.TryParse(toolStripComboBox.Text, out var frequency)) -  
545 { 504 if (int.TryParse(toolStripComboBox.Text, out var frequency))
546 try 505 try
547 { 506 {
-   507 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
548 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 508 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
549 { 509 {
-   510 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency },
550 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken)) 511 _cancellationToken))
551 { 512 {
Line 552... Line 513...
552 e.Handled = true; 513 e.Handled = true;
553   -  
554 if (Configuration.Navigation.MouseScrollSound) -  
555 { -  
556 soundPlayer.Play(); 514  
557 } 515 if (Configuration.Navigation.MouseScrollSound) soundPlayer.Play();
558 } 516 }
559 } 517 }
560 } 518 }
561 catch (Exception exception) 519 catch (Exception exception)
562 { 520 {
563 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); -  
-   521 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency);
564 } 522 }
565 } 523  
566 break; 524 break;
Line 567... Line 525...
567 } 525 }
568 } 526 }
569   527  
570 private void toolStripMenuItem1_Click(object sender, EventArgs e) -  
571 { -  
572 if (_bandScan == null) -  
Line 573... Line 528...
573 { 528 private void toolStripMenuItem1_Click(object sender, EventArgs e)
574 return; 529 {
575 } 530 if (_bandScan == null) return;
Line 590... Line 545...
590 _memoryTune.Start(); 545 _memoryTune.Start();
591 } 546 }
Line 592... Line 547...
592   547  
593 private void stopToolStripMenuItem_Click(object sender, EventArgs e) 548 private void stopToolStripMenuItem_Click(object sender, EventArgs e)
594 { 549 {
595 if (_memoryTune == null) -  
596 { -  
597 return; -  
Line 598... Line 550...
598 } 550 if (_memoryTune == null) return;
599   551  
600 _memoryTune.Stop(); 552 _memoryTune.Stop();
Line 601... Line 553...
601 _memoryTune = null; 553 _memoryTune = null;
602 } 554 }
603   555  
604 private void scanToolStripMenuItem_Click(object sender, EventArgs e) 556 private void scanToolStripMenuItem_Click(object sender, EventArgs e)
605 { -  
606 if (!(sender is ToolStripMenuItem toolStripMenuItem) || 557 {
607 !int.TryParse(toolStripMenuItem.Tag.ToString(), out var meters)) -  
Line 608... Line 558...
608 { 558 if (!(sender is ToolStripMenuItem toolStripMenuItem) ||
609 return; -  
610 } -  
611   -  
Line 612... Line 559...
612 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause)) 559 !int.TryParse(toolStripMenuItem.Tag.ToString(), out var meters))
613 { -  
614 pause = 5; -  
615 } -  
Line 616... Line 560...
616   560 return;
617 if(!int.TryParse(scrollableToolStripComboBox4.Text, out var step)) -  
618 { -  
619 step = 5000; -  
Line 620... Line 561...
620 } 561  
621   -  
622 if(!int.TryParse(scrollableToolStripComboBox6.Text, out var scanDetectPause)) -  
623 { -  
Line 624... Line 562...
624 scanDetectPause = 10; 562 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause)) pause = 5;
625 } 563  
626   564 if (!int.TryParse(scrollableToolStripComboBox4.Text, out var step)) step = 5000;
627 if (!Configuration.Definitions.TryGetBand(meters, out var band)) 565  
Line 651... Line 589...
651 { 589 {
652 try 590 try
653 { 591 {
654 var mode = await _catAssemblies.CatReadAsync<RadioMode>("MD", new object[] { }, _cancellationToken); 592 var mode = await _catAssemblies.CatReadAsync<RadioMode>("MD", new object[] { }, _cancellationToken);
Line 655... Line 593...
655   593  
656 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => -  
657 { -  
658 toolStripComboBox1.Text = mode.Name; -  
659 }); 594 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => { toolStripComboBox1.Text = mode.Name; });
660 } 595 }
661 catch (Exception exception) 596 catch (Exception exception)
662 { 597 {
663 Log.Error(exception, Resources.Failed_to_read_radio_mode); 598 Log.Error(exception, Resources.Failed_to_read_radio_mode);
Line 668... Line 603...
668 var fa = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken); 603 var fa = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken);
Line 669... Line 604...
669   604  
670 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 605 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
671 { 606 {
672 scrollableToolStripComboBox1.Text = $"{fa}"; -  
673   607 scrollableToolStripComboBox1.Text = $"{fa}";
674 }); -  
675   608 });
676 } 609 }
677 catch (Exception exception) 610 catch (Exception exception)
678 { 611 {
679 Log.Error(exception, Resources.Failed_to_read_VFO_A); 612 Log.Error(exception, Resources.Failed_to_read_VFO_A);
Line 684... Line 617...
684 var fb = await _catAssemblies.CatReadAsync<int>("FB", new object[] { }, _cancellationToken); 617 var fb = await _catAssemblies.CatReadAsync<int>("FB", new object[] { }, _cancellationToken);
Line 685... Line 618...
685   618  
686 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 619 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
687 { 620 {
688 scrollableToolStripComboBox2.Text = $"{fb}"; -  
689   621 scrollableToolStripComboBox2.Text = $"{fb}";
690 }); 622 });
691 } 623 }
692 catch (Exception exception) 624 catch (Exception exception)
693 { 625 {
Line 701... Line 633...
701 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 633 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
702 { 634 {
703 scrollableToolStripComboBox5.Text = mc; 635 scrollableToolStripComboBox5.Text = mc;
Line 704... Line 636...
704   636  
705 if (_memoryChannelStore.TryGetValue(mc, out var memoryChannel)) -  
706 { 637 if (_memoryChannelStore.TryGetValue(mc, out var memoryChannel))
707 toolStripMenuItem27.Text = memoryChannel.Text; -  
708 } -  
709   638 toolStripMenuItem27.Text = memoryChannel.Text;
710 }); 639 });
711 } 640 }
712 catch (Exception exception) 641 catch (Exception exception)
713 { 642 {
Line 719... Line 648...
719 var pc = await _catAssemblies.CatReadAsync<int>("PC", new object[] { }, _cancellationToken); 648 var pc = await _catAssemblies.CatReadAsync<int>("PC", new object[] { }, _cancellationToken);
Line 720... Line 649...
720   649  
721 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 650 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
722 { 651 {
723 scrollableToolStripComboBox7.Text = $"{pc}"; -  
724   652 scrollableToolStripComboBox7.Text = $"{pc}";
725 }); 653 });
726 } 654 }
727 catch (Exception exception) 655 catch (Exception exception)
728 { 656 {
Line 734... Line 662...
734 var sq = await _catAssemblies.CatReadAsync<int>("SQ", new object[] { }, _cancellationToken); 662 var sq = await _catAssemblies.CatReadAsync<int>("SQ", new object[] { }, _cancellationToken);
Line 735... Line 663...
735   663  
736 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 664 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
737 { 665 {
738 scrollableToolStripComboBox11.Text = $"{sq}"; -  
739   666 scrollableToolStripComboBox11.Text = $"{sq}";
740 }); 667 });
741 } 668 }
742 catch (Exception exception) 669 catch (Exception exception)
743 { 670 {
Line 749... Line 676...
749 var st = await _catAssemblies.CatReadAsync<SplitState>("ST", new object[] { }, _cancellationToken); 676 var st = await _catAssemblies.CatReadAsync<SplitState>("ST", new object[] { }, _cancellationToken);
Line 750... Line 677...
750   677  
751 contextMenuStrip1.InvokeIfRequired(contextMenuStrip => 678 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
752 { 679 {
753 scrollableToolStripComboBox8.Text = $"{(string)st}"; -  
754   680 scrollableToolStripComboBox8.Text = $"{(string)st}";
755 }); 681 });
756 } 682 }
757 catch (Exception exception) 683 catch (Exception exception)
758 { 684 {
759 Log.Error(exception, Resources.Failed_to_read_split_state); 685 Log.Error(exception, Resources.Failed_to_read_split_state);
Line 760... Line 686...
760 } 686 }
761   687  
-   688 try
762 try 689 {
763 { 690 var lockState =
764 var lockState = await _catAssemblies.CatReadAsync<LockState>("LK", new object[] { }, _cancellationToken); 691 await _catAssemblies.CatReadAsync<LockState>("LK", new object[] { }, _cancellationToken);
765 switch (lockState) 692 switch (lockState)
766 { 693 {
767 case LockState.OFF: 694 case LockState.OFF:
Line 778... Line 705...
778 } 705 }
779 } 706 }
Line 780... Line 707...
780   707  
781 private void spectrogramToolStripMenuItem_Click(object sender, EventArgs e) 708 private void spectrogramToolStripMenuItem_Click(object sender, EventArgs e)
782 { 709 {
783 if (_spectrogramForm != null) -  
784 { -  
785 return; -  
Line 786... Line 710...
786 } 710 if (_spectrogramForm != null) return;
787   711  
788 _spectrogramForm = new SpectrogramForm(Configuration, _cancellationToken); 712 _spectrogramForm = new SpectrogramForm(Configuration, _cancellationToken);
789 _spectrogramForm.Closing += SpectrogramForm_Closing; 713 _spectrogramForm.Closing += SpectrogramForm_Closing;
Line 790... Line 714...
790 _spectrogramForm.Show(); 714 _spectrogramForm.Show();
791 } 715 }
792   716  
793 private void SpectrogramForm_Closing(object sender, CancelEventArgs e) -  
794 { -  
795 if (_spectrogramForm == null) -  
Line 796... Line 717...
796 { 717 private void SpectrogramForm_Closing(object sender, CancelEventArgs e)
797 return; 718 {
Line 798... Line 719...
798 } 719 if (_spectrogramForm == null) return;
799   720  
800 _spectrogramForm.Dispose(); -  
801 _spectrogramForm = null; -  
802   721 _spectrogramForm.Dispose();
803 // Commit the configuration. -  
804 _changedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1), 722 _spectrogramForm = null;
Line 805... Line 723...
805 async () => 723  
806 { 724 // Commit the configuration.
807 await SaveConfiguration(); 725 _changedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1),
808 }, _cancellationToken); -  
809 } -  
810   -  
Line 811... Line 726...
811 private void toolStripMenuItem3_Click(object sender, EventArgs e) 726 async () => { await SaveConfiguration(); }, _cancellationToken);
812 { 727 }
813 if (_memoryOrganizerForm != null) 728  
814 { 729 private void toolStripMenuItem3_Click(object sender, EventArgs e)
Line 815... Line 730...
815 return; 730 {
816 } 731 if (_memoryOrganizerForm != null) return;
817   732  
818 _memoryOrganizerForm = new MemoryOrganizerForm(Configuration, _catAssemblies, _cancellationToken); -  
819 _memoryOrganizerForm.Closing += MemoryOrganizerForm_Closing; -  
820 _memoryOrganizerForm.Show(); -  
Line 821... Line 733...
821 } 733 _memoryOrganizerForm = new MemoryOrganizerForm(Configuration, _catAssemblies, _cancellationToken);
822   734 _memoryOrganizerForm.Closing += MemoryOrganizerForm_Closing;
823 private void MemoryOrganizerForm_Closing(object sender, CancelEventArgs e) -  
824 { 735 _memoryOrganizerForm.Show();
Line 825... Line 736...
825 if (_memoryOrganizerForm == null) 736 }
826 { 737  
827 return; 738 private void MemoryOrganizerForm_Closing(object sender, CancelEventArgs e)
828 } -  
829   -  
830 _memoryOrganizerForm.Dispose(); -  
Line 831... Line 739...
831 _memoryOrganizerForm = null; 739 {
Line 832... Line 740...
832   740 if (_memoryOrganizerForm == null) return;
833 } 741  
-   742 _memoryOrganizerForm.Dispose();
834   743 _memoryOrganizerForm = null;
Line 835... Line 744...
835 private async void toolStripMenuItem4_Click(object sender, EventArgs e) 744 }
-   745  
Line 836... Line 746...
836 { 746 private async void toolStripMenuItem4_Click(object sender, EventArgs e)
837 if (_tickerTaskRunning) 747 {
838 { 748 if (_tickerTaskRunning) return;
839 return; 749  
840 } 750 var toolStripTextBox = toolStripTextBox6;
841   751  
842 var toolStripTextBox = (ToolStripTextBox)toolStripTextBox6; 752 try
Line 843... Line 753...
843   753 {
Line 844... Line 754...
844 try 754 var result =
845 { 755 await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { "001" }, _cancellationToken);
Line 846... Line 756...
846 var result = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { "001" }, _cancellationToken); 756  
847   757 _tickerTextMemoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT",
848 _tickerTextMemoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { $"{result.CurrentLocation}" }, _cancellationToken); 758 new object[] { $"{result.CurrentLocation}" }, _cancellationToken);
849   759  
Line 850... Line 760...
850 _storedMemoryChannelTagText = _tickerTextMemoryChannel.Text; 760 _storedMemoryChannelTagText = _tickerTextMemoryChannel.Text;
851 _storedMemoryChannelLocation = _tickerTextMemoryChannel.CurrentLocation; 761 _storedMemoryChannelLocation = _tickerTextMemoryChannel.CurrentLocation;
852 } 762 }
853 catch(Exception exception) 763 catch (Exception exception)
854 { 764 {
Line 855... Line 765...
855 Log.Error(exception, Resources.Could_not_read_memory_bank); 765 Log.Error(exception, Resources.Could_not_read_memory_bank);
856 } 766 }
857   767  
858 var tickerText = $"{toolStripTextBox.Text,-12}"; 768 var tickerText = $"{toolStripTextBox.Text,-12}";
859   769  
860 _tagTickerCancellationTokenSource = new CancellationTokenSource(); 770 _tagTickerCancellationTokenSource = new CancellationTokenSource();
861 _tagTickerCancellationToken = _tagTickerCancellationTokenSource.Token; 771 _tagTickerCancellationToken = _tagTickerCancellationTokenSource.Token;
Line 862... Line 772...
862   772  
863 var characterQueue = new Queue<char>(12); 773 var characterQueue = new Queue<char>(12);
864 foreach(var i in Enumerable.Range(0, 12)) 774 foreach (var i in Enumerable.Range(0, 12))
865 { -  
866 var x = tickerText.ElementAtOrDefault(i); -  
867   -  
Line 868... Line 775...
868 if(x == default) 775 {
869 { 776 var x = tickerText.ElementAtOrDefault(i);
870 characterQueue.Enqueue(' '); 777  
871 continue; 778 if (x == default)
Line 894... Line 801...
894 } 801 }
Line 895... Line 802...
895   802  
896 try 803 try
897 { 804 {
898 _tickerTextMemoryChannel.CurrentLocation = $"{_storedMemoryChannelLocation:000}"; 805 _tickerTextMemoryChannel.CurrentLocation = $"{_storedMemoryChannelLocation:000}";
Line 899... Line 806...
899 _tickerTextMemoryChannel.Text = $"{_storedMemoryChannelTagText, -12}"; 806 _tickerTextMemoryChannel.Text = $"{_storedMemoryChannelTagText,-12}";
-   807  
900   808 var success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT",
901 var success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken); 809 new object[] { _tickerTextMemoryChannel }, _cancellationToken);
902 if (!success) 810 if (!success)
903 { -  
904 Log.Error(Resources.Error_while_restoring_memory_text); -  
905   811 {
906 return; 812 Log.Error(Resources.Error_while_restoring_memory_text);
907 } 813 }
908 } 814 }
909 catch(Exception exception) 815 catch (Exception exception)
910 { 816 {
911 Log.Error(exception, Resources.Error_while_restoring_memory_text); 817 Log.Error(exception, Resources.Error_while_restoring_memory_text);
912 } 818 }
Line 925... Line 831...
925 { 831 {
926 var text = string.Join("", characterQueue.OfType<char>()); 832 var text = string.Join("", characterQueue.OfType<char>());
Line 927... Line 833...
927   833  
Line 928... Line 834...
928 _tickerTextMemoryChannel.Text = text; 834 _tickerTextMemoryChannel.Text = text;
-   835  
Line 929... Line 836...
929   836 await _catAssemblies.CatWriteAsync<MemoryChannel>("MT", new object[] { _tickerTextMemoryChannel },
930 await _catAssemblies.CatWriteAsync<MemoryChannel>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken); 837 _cancellationToken);
Line 931... Line 838...
931   838  
932 var x = characterQueue.Dequeue(); -  
933 characterQueue.Enqueue(x); 839 var x = characterQueue.Dequeue();
934   840 characterQueue.Enqueue(x);
935 await Task.Delay(250); 841  
936   842 await Task.Delay(250);
937 } while (!_tagTickerCancellationToken.IsCancellationRequested); 843 } while (!_tagTickerCancellationToken.IsCancellationRequested);
938 } 844 }
939 catch(Exception exception) 845 catch (Exception exception)
Line 947... Line 853...
947 var toolStripComboBox = (ScrollableToolStripComboBox)sender; 853 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
Line 948... Line 854...
948   854  
Line 949... Line 855...
949 var channel = toolStripComboBox.Text; 855 var channel = toolStripComboBox.Text;
950   -  
951 if (!string.IsNullOrEmpty(channel)) 856  
952 { -  
953 if (_memoryChannelStore.TryGetValue(channel, out var memoryChannel)) 857 if (!string.IsNullOrEmpty(channel))
954 { 858 if (_memoryChannelStore.TryGetValue(channel, out var memoryChannel))
955 try 859 try
-   860 {
956 { 861 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
957 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 862 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
-   863 {
Line 958... Line 864...
958 { 864 await _catAssemblies.CatWriteAsync<string>("MC", new object[] { channel },
Line 959... Line 865...
959 await _catAssemblies.CatWriteAsync<string>("MC", new object[] { channel }, _cancellationToken); 865 _cancellationToken);
Line 967... Line 873...
967 } 873 }
968 catch (Exception exception) 874 catch (Exception exception)
969 { 875 {
970 Log.Error(exception, Resources.Failed_to_set_memory_channel); 876 Log.Error(exception, Resources.Failed_to_set_memory_channel);
971 } 877 }
972 } -  
973 } -  
974 } 878 }
Line 975... Line 879...
975   879  
976 private async void powerToolStripMenuItem_DropDownOpening(object sender, EventArgs e) 880 private async void powerToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
977 { 881 {
Line 997... Line 901...
997   901  
998 private async void toolStripMenuItem17_Click(object sender, EventArgs e) 902 private async void toolStripMenuItem17_Click(object sender, EventArgs e)
999 { 903 {
1000 try 904 try
1001 { 905 {
-   906 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON },
Line 1002... Line 907...
1002 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken); 907 _cancellationToken);
-   908  
1003   909 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START },
1004 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START }, _cancellationToken); 910 _cancellationToken);
1005 } 911 }
1006 catch (Exception exception) 912 catch (Exception exception)
1007 { 913 {
Line 1014... Line 920...
1014 var toolStripMenuItem = (ToolStripMenuItem)sender; 920 var toolStripMenuItem = (ToolStripMenuItem)sender;
1015 try 921 try
1016 { 922 {
1017 if (toolStripMenuItem.Checked) 923 if (toolStripMenuItem.Checked)
1018 { 924 {
1019 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.IPO }, _cancellationToken); 925 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.IPO },
-   926 _cancellationToken);
1020 return; 927 return;
1021 } 928 }
Line 1022... Line 929...
1022   929  
1023 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.AMP }, _cancellationToken); 930 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.AMP }, _cancellationToken);
Line 1034... Line 941...
1034   941  
1035 try 942 try
1036 { 943 {
1037 if (toolStripMenuItem.Checked) 944 if (toolStripMenuItem.Checked)
1038 { 945 {
-   946 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON },
Line 1039... Line 947...
1039 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken); 947 _cancellationToken);
1040   948  
Line 1041... Line 949...
1041 return; 949 return;
-   950 }
1042 } 951  
1043   952 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_OFF },
1044 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_OFF }, _cancellationToken); 953 _cancellationToken);
1045 } 954 }
1046 catch (Exception exception) 955 catch (Exception exception)
Line 1051... Line 960...
1051   960  
1052 private async void toolStripMenuItem24_Click(object sender, EventArgs e) 961 private async void toolStripMenuItem24_Click(object sender, EventArgs e)
1053 { 962 {
1054 try 963 try
1055 { 964 {
-   965 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON },
Line 1056... Line 966...
1056 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken); 966 _cancellationToken);
1057   967  
1058 do 968 do
Line 1059... Line 969...
1059 { 969 {
1060 await Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken); 970 await Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken);
-   971  
1061   972 try
Line 1062... Line 973...
1062 try 973 {
1063 { -  
1064 var tuneState = await _catAssemblies.CatReadAsync<TunerState>("AC", new object[] { }, _cancellationToken); -  
1065   -  
1066 if (tuneState == TunerState.TUNER_ON) 974 var tuneState =
1067 { 975 await _catAssemblies.CatReadAsync<TunerState>("AC", new object[] { }, _cancellationToken);
1068 break; 976  
1069 } 977 if (tuneState == TunerState.TUNER_ON) break;
1070 } 978 }
1071 catch (Exception) -  
1072 { 979 catch (Exception)
Line 1073... Line 980...
1073 // retry 980 {
-   981 // retry
1074 } 982 }
1075   983 } while (!_cancellationToken.IsCancellationRequested);
1076 } while (!_cancellationToken.IsCancellationRequested); 984  
1077   985 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START },
1078 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START }, _cancellationToken); 986 _cancellationToken);
1079 } 987 }
Line 1101... Line 1009...
1101 break; 1009 break;
1102 case TunerState.TUNER_OFF: 1010 case TunerState.TUNER_OFF:
1103 toolStripMenuItem23.Checked = false; 1011 toolStripMenuItem23.Checked = false;
1104 break; 1012 break;
1105 } 1013 }
1106   -  
1107   -  
1108 }); 1014 });
1109 } 1015 }
1110 catch (Exception exception) 1016 catch (Exception exception)
1111 { 1017 {
1112 Log.Error(exception, Resources.Failed_to_read_the_tuner_state); 1018 Log.Error(exception, Resources.Failed_to_read_the_tuner_state);
Line 1125... Line 1031...
1125 break; 1031 break;
1126 case IpoState.IPO: 1032 case IpoState.IPO:
1127 toolStripMenuItem22.Checked = true; 1033 toolStripMenuItem22.Checked = true;
1128 break; 1034 break;
1129 } 1035 }
1130   -  
1131   -  
1132 }); 1036 });
1133 } 1037 }
1134 catch (Exception exception) 1038 catch (Exception exception)
1135 { 1039 {
1136 Log.Error(exception, Resources.Failed_to_read_IPO); 1040 Log.Error(exception, Resources.Failed_to_read_IPO);
Line 1153... Line 1057...
1153 break; 1057 break;
1154 } 1058 }
Line 1155... Line 1059...
1155   1059  
1156 try 1060 try
1157 { 1061 {
-   1062 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
1158 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 1063 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
1159 { 1064 {
-   1065 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency },
1160 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken)) 1066 _cancellationToken))
1161 { 1067 {
Line 1162... Line 1068...
1162 toolStripComboBox.Text = $"{frequency}"; 1068 toolStripComboBox.Text = $"{frequency}";
1163   -  
1164 if (Configuration.Navigation.MouseScrollSound) -  
1165 { -  
1166 soundPlayer.Play(); 1069  
1167 } 1070 if (Configuration.Navigation.MouseScrollSound) soundPlayer.Play();
1168 } 1071 }
1169 } 1072 }
1170 } 1073 }
Line 1178... Line 1081...
1178 private async void scrollableToolStripComboBox1_KeyPress(object sender, KeyPressEventArgs e) 1081 private async void scrollableToolStripComboBox1_KeyPress(object sender, KeyPressEventArgs e)
1179 { 1082 {
1180 switch (e.KeyChar) 1083 switch (e.KeyChar)
1181 { 1084 {
1182 case (char)Keys.Enter: 1085 case (char)Keys.Enter:
1183 1086  
Line 1184... Line 1087...
1184   1087  
Line 1185... Line 1088...
1185 var toolStripComboBox = (ScrollableToolStripComboBox)sender; 1088 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1186   -  
1187 if (int.TryParse(toolStripComboBox.Text, out var frequency)) 1089  
1188 { 1090 if (int.TryParse(toolStripComboBox.Text, out var frequency))
1189 try 1091 try
-   1092 {
1190 { 1093 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
1191 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 1094 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
-   1095 {
1192 { 1096 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency },
1193 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken)) 1097 _cancellationToken))
Line 1194... Line 1098...
1194 { 1098 {
1195 e.Handled = true; -  
1196   -  
1197 if (Configuration.Navigation.MouseScrollSound) -  
1198 { 1099 e.Handled = true;
1199 soundPlayer.Play(); 1100  
1200 } 1101 if (Configuration.Navigation.MouseScrollSound) soundPlayer.Play();
1201 } 1102 }
1202 } 1103 }
1203 } 1104 }
1204 catch (Exception exception) 1105 catch (Exception exception)
1205 { -  
-   1106 {
1206 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); 1107 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency);
1207 } 1108 }
1208 } 1109  
Line 1209... Line 1110...
1209 break; 1110 break;
Line 1217... Line 1118...
1217 _squelchScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => 1118 _squelchScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () =>
1218 { 1119 {
1219 contextMenuStrip1.InvokeIfRequired(async contextMenuStrip1 => 1120 contextMenuStrip1.InvokeIfRequired(async contextMenuStrip1 =>
1220 { 1121 {
1221 if (int.TryParse(toolStripComboBox.Text, out var squelch)) 1122 if (int.TryParse(toolStripComboBox.Text, out var squelch))
1222 { -  
1223   -  
1224 try 1123 try
1225 { 1124 {
1226 await _catAssemblies.CatWriteAsync<int>("SQ", new object[] { squelch }, _cancellationToken); 1125 await _catAssemblies.CatWriteAsync<int>("SQ", new object[] { squelch }, _cancellationToken);
Line 1227... Line 1126...
1227   1126  
Line 1231... Line 1130...
1231 } 1130 }
1232 catch (Exception exception) 1131 catch (Exception exception)
1233 { 1132 {
1234 Log.Error(exception, Resources.Failed_to_set_squelch); 1133 Log.Error(exception, Resources.Failed_to_set_squelch);
1235 } 1134 }
1236 } -  
1237 }); 1135 });
1238 }, _cancellationToken); 1136 }, _cancellationToken);
1239 } 1137 }
Line 1240... Line 1138...
1240   1138  
Line 1244... Line 1142...
1244   1142  
Line 1245... Line 1143...
1245 var radioMode = RadioMode.Create(Configuration.Radio, toolStripComboBox.Text); 1143 var radioMode = RadioMode.Create(Configuration.Radio, toolStripComboBox.Text);
1246   1144  
1247 try -  
1248 { 1145 try
1249 1146 {
1250 await _catAssemblies.CatSetAsync<RadioMode, bool>("MD", new object[] { radioMode }, _cancellationToken); 1147 await _catAssemblies.CatSetAsync<RadioMode, bool>("MD", new object[] { radioMode }, _cancellationToken);
1251 } 1148 }
1252 catch (Exception exception) 1149 catch (Exception exception)
Line 1258... Line 1155...
1258 private async void scrollableToolStripComboBox7_SelectedIndexChanged(object sender, EventArgs e) 1155 private async void scrollableToolStripComboBox7_SelectedIndexChanged(object sender, EventArgs e)
1259 { 1156 {
1260 var toolStripComboBox = (ScrollableToolStripComboBox)sender; 1157 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
Line 1261... Line 1158...
1261   1158  
1262 if (int.TryParse(toolStripComboBox.Text, out var amplification)) -  
1263 { -  
1264   1159 if (int.TryParse(toolStripComboBox.Text, out var amplification))
1265 try 1160 try
1266 { 1161 {
-   1162 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification },
1267 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification }, _cancellationToken)) 1163 _cancellationToken))
1268 { -  
1269   1164 {
Line 1270... Line 1165...
1270 toolStripComboBox.Text = $"{amplification}"; 1165 toolStripComboBox.Text = $"{amplification}";
1271   1166  
1272 Log.Information($"{Resources.Amplification_set} {amplification}W"); 1167 Log.Information($"{Resources.Amplification_set} {amplification}W");
1273 } 1168 }
1274 } 1169 }
1275 catch (Exception exception) 1170 catch (Exception exception)
1276 { 1171 {
1277 Log.Error(exception, Resources.Failed_to_set_amplification); -  
1278 } 1172 Log.Error(exception, Resources.Failed_to_set_amplification);
Line 1279... Line 1173...
1279 } 1173 }
1280 } 1174 }
1281   1175  
1282 private async void scrollableToolStripComboBox7_KeyPress(object sender, KeyPressEventArgs e) 1176 private async void scrollableToolStripComboBox7_KeyPress(object sender, KeyPressEventArgs e)
1283 { 1177 {
1284 switch (e.KeyChar) 1178 switch (e.KeyChar)
Line 1285... Line 1179...
1285 { 1179 {
1286 case (char)Keys.Enter: -  
1287 var toolStripComboBox = (ScrollableToolStripComboBox)sender; -  
1288   1180 case (char)Keys.Enter:
1289 if (int.TryParse(toolStripComboBox.Text, out var amplification)) 1181 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1290 { 1182  
-   1183 if (int.TryParse(toolStripComboBox.Text, out var amplification))
1291   1184 try
1292 try -  
1293 { 1185 {
Line 1294... Line 1186...
1294 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification }, _cancellationToken)) 1186 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification },
Line 1295... Line 1187...
1295 { 1187 _cancellationToken))
Line 1303... Line 1195...
1303 } 1195 }
1304 catch (Exception exception) 1196 catch (Exception exception)
1305 { 1197 {
1306 Log.Error(exception, Resources.Failed_to_set_amplification); 1198 Log.Error(exception, Resources.Failed_to_set_amplification);
1307 } 1199 }
1308 } -  
-   1200  
1309 break; 1201 break;
1310 } 1202 }
1311 } 1203 }
Line 1312... Line 1204...
1312   1204  
1313 private void toolStripMenuItem30_Click(object sender, EventArgs e) 1205 private void toolStripMenuItem30_Click(object sender, EventArgs e)
1314 { 1206 {
1315 if (!int.TryParse(scrollableToolStripComboBox9.Text, out var start) 1207 if (!int.TryParse(scrollableToolStripComboBox9.Text, out var start)
1316 || !int.TryParse(scrollableToolStripComboBox10.Text, out var stop)) -  
1317 { 1208 || !int.TryParse(scrollableToolStripComboBox10.Text, out var stop))
1318 return; -  
Line 1319... Line 1209...
1319 } 1209 return;
1320   -  
1321 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause)) -  
1322 { -  
Line 1323... Line 1210...
1323 pause = 5; 1210  
1324 } -  
1325   -  
1326 if (!int.TryParse(scrollableToolStripComboBox4.Text, out var step)) -  
Line 1327... Line 1211...
1327 { 1211 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause)) pause = 5;
1328 step = 5000; -  
1329 } -  
1330   -  
Line 1331... Line 1212...
1331 if (!int.TryParse(scrollableToolStripComboBox6.Text, out var scanDetectPause)) 1212  
1332 { 1213 if (!int.TryParse(scrollableToolStripComboBox4.Text, out var step)) step = 5000;
1333 scanDetectPause = 10; 1214  
1334 } 1215 if (!int.TryParse(scrollableToolStripComboBox6.Text, out var scanDetectPause)) scanDetectPause = 10;
Line 1355... Line 1236...
1355 { 1236 {
1356 var toolStripMenuItem = toolStripMenuItem31; 1237 var toolStripMenuItem = toolStripMenuItem31;
Line 1357... Line 1238...
1357   1238  
1358 try 1239 try
1359 { 1240 {
-   1241 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.ON },
1360 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.ON }, _cancellationToken)) 1242 _cancellationToken))
1361 { 1243 {
1362 toolStripMenuItem.Text = Resources.On; -  
1363 return; 1244 toolStripMenuItem.Text = Resources.On;
1364 } 1245 }
1365 } 1246 }
1366 catch (Exception exception) 1247 catch (Exception exception)
1367 { 1248 {
Line 1373... Line 1254...
1373 { 1254 {
1374 var toolStripMenuItem = toolStripMenuItem31; 1255 var toolStripMenuItem = toolStripMenuItem31;
Line 1375... Line 1256...
1375   1256  
1376 try 1257 try
1377 { 1258 {
-   1259 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.OFF },
1378 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.OFF }, _cancellationToken)) 1260 _cancellationToken))
1379 { 1261 {
1380 toolStripMenuItem.Text = Resources.Off; -  
1381 return; 1262 toolStripMenuItem.Text = Resources.Off;
1382 } 1263 }
1383 } 1264 }
1384 catch (Exception exception) 1265 catch (Exception exception)
1385 { 1266 {
Line 1412... Line 1293...
1412 private async void scrollableToolStripComboBox8_SelectedIndexChanged(object sender, EventArgs e) 1293 private async void scrollableToolStripComboBox8_SelectedIndexChanged(object sender, EventArgs e)
1413 { 1294 {
1414 var toolStripComboBox = (ScrollableToolStripComboBox)sender; 1295 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
Line 1415... Line 1296...
1415   1296  
1416 if (SplitState.TryParse(toolStripComboBox.Text, out var splitState)) -  
1417 { 1297 if (SplitState.TryParse(toolStripComboBox.Text, out var splitState))
1418 try 1298 try
1419 { 1299 {
1420 if (await _catAssemblies.CatSetAsync<int, bool>("ST", new object[] { splitState }, _cancellationToken)) -  
1421 { 1300 if (await _catAssemblies.CatSetAsync<int, bool>("ST", new object[] { splitState },
1422 Log.Information($"{Resources.Split_state_set} {splitState}W"); -  
1423 } 1301 _cancellationToken)) Log.Information($"{Resources.Split_state_set} {splitState}W");
1424 } 1302 }
1425 catch (Exception exception) 1303 catch (Exception exception)
1426 { 1304 {
1427 Log.Error(exception, Resources.Failed_to_set_split_state); 1305 Log.Error(exception, Resources.Failed_to_set_split_state);
1428 } -  
1429 } 1306 }
Line 1430... Line 1307...
1430 } 1307 }
1431   1308  
1432 private async void toolStripMenuItem35_Click(object sender, EventArgs e) 1309 private async void toolStripMenuItem35_Click(object sender, EventArgs e)
Line 1438... Line 1315...
1438 { 1315 {
1439 if (!_memoryChannelStore.TryGetValue(channel, out var memoryChannel)) 1316 if (!_memoryChannelStore.TryGetValue(channel, out var memoryChannel))
1440 { 1317 {
1441 memoryChannel = MemoryChannel.Create(Configuration.Radio); 1318 memoryChannel = MemoryChannel.Create(Configuration.Radio);
1442 memoryChannel.CurrentLocation = channel; 1319 memoryChannel.CurrentLocation = channel;
-   1320 memoryChannel.MemoryRadioMode =
1443 memoryChannel.MemoryRadioMode = MemoryRadioMode.Create(Configuration.Radio, toolStripComboBox1.Text); 1321 MemoryRadioMode.Create(Configuration.Radio, toolStripComboBox1.Text);
1444 } 1322 }
Line 1445... Line 1323...
1445   1323  
1446 if (memoryChannel.Tag = !string.IsNullOrEmpty(toolStripTextBox1.Text)) -  
1447 { 1324 if (memoryChannel.Tag = !string.IsNullOrEmpty(toolStripTextBox1.Text))
1448 memoryChannel.Text = $"{toolStripTextBox1.Text, -12}"; -  
Line 1449... Line 1325...
1449 } 1325 memoryChannel.Text = $"{toolStripTextBox1.Text,-12}";
1450   1326  
1451 if (int.TryParse(scrollableToolStripComboBox1.Text, out var frequency)) 1327 if (int.TryParse(scrollableToolStripComboBox1.Text, out var frequency))
Line 1452... Line 1328...
1452 { 1328 {
1453 memoryChannel.Frequency = frequency; 1329 memoryChannel.Frequency = frequency;
1454   1330  
1455 try -  
1456 { 1331 try
1457 if (await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { memoryChannel }, _cancellationToken)) -  
1458 { 1332 {
1459 Log.Information(Resources.Stored_VFO_A_to_memory); 1333 if (await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { memoryChannel },
1460 } 1334 _cancellationToken)) Log.Information(Resources.Stored_VFO_A_to_memory);
1461 } 1335 }
1462 catch (Exception exception) 1336 catch (Exception exception)
Line 1514... Line 1388...
1514 default: 1388 default:
1515 state = LockState.OFF; 1389 state = LockState.OFF;
1516 break; 1390 break;
1517 } 1391 }
Line 1518... Line 1392...
1518   1392  
1519 if (!await _catAssemblies.CatSetAsync<LockState, bool>("LK", new object[] { state }, _cancellationToken)) -  
1520 { 1393 if (!await _catAssemblies.CatSetAsync<LockState, bool>("LK", new object[] { state },
1521 Log.Error(Resources.Failed_to_set_lock_state); -  
1522 } 1394 _cancellationToken)) Log.Error(Resources.Failed_to_set_lock_state);
1523 } 1395 }
1524 catch (Exception exception) 1396 catch (Exception exception)
1525 { 1397 {
1526 Log.Error(exception, Resources.Failed_to_read_lock_state); 1398 Log.Error(exception, Resources.Failed_to_read_lock_state);
1527 } 1399 }
-   1400 }
-   1401  
-   1402 private void menuToolStripMenuItem_Click(object sender, EventArgs e)
-   1403 {
-   1404 if (_menuForm != null) return;
-   1405  
-   1406 _menuForm = new MenuForm(Configuration, _catAssemblies, _cancellationToken);
-   1407 _menuForm.Closing += MenuForm_Closing;
-   1408 _menuForm.Show();
-   1409 }
-   1410  
-   1411 private void MenuForm_Closing(object sender, CancelEventArgs e)
-   1412 {
-   1413 if (_menuForm == null) return;
-   1414  
-   1415 _menuForm.Dispose();
-   1416 _menuForm = null;
1528 } 1417 }
1529 } 1418 }
1530 } 1419 }