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