HamBook – Diff between revs 6 and 7
?pathlinks?
Rev 6 | Rev 7 | |||
---|---|---|---|---|
Line 17... | Line 17... | |||
17 | using System.Windows.Forms; |
17 | using System.Windows.Forms; |
|
18 | using HamBook.Properties; |
18 | using HamBook.Properties; |
|
19 | using HamBook.Radios.Generic; |
19 | using HamBook.Radios.Generic; |
|
20 | using PowerState = HamBook.Radios.Generic.PowerState; |
20 | using PowerState = HamBook.Radios.Generic.PowerState; |
|
21 | using System.Media; |
21 | using System.Media; |
|
- | 22 | using HamBook.Utilities.Controls; |
||
Line 22... | Line 23... | |||
22 | |
23 | |
|
23 | namespace HamBook |
24 | namespace HamBook |
|
24 | { |
25 | { |
|
25 | public partial class Form1 : Form |
26 | public partial class Form1 : Form |
|
Line 33... | Line 34... | |||
33 | private SettingsForm _settingsForm; |
34 | private SettingsForm _settingsForm; |
|
34 | private SparkleUpdater _sparkle; |
35 | private SparkleUpdater _sparkle; |
|
35 | private readonly CancellationToken _cancellationToken; |
36 | private readonly CancellationToken _cancellationToken; |
|
36 | private readonly CancellationTokenSource _cancellationTokenSource; |
37 | private readonly CancellationTokenSource _cancellationTokenSource; |
|
37 | private CatAssemblies _catAssemblies; |
38 | private CatAssemblies _catAssemblies; |
|
38 | private CancellationTokenSource _scanningCancellationTokenSource; |
- | ||
39 | private CancellationToken _scanningCancellationToken; |
- | ||
40 | private BandScan _bandScan; |
39 | private BandScan _bandScan; |
|
Line 41... | Line 40... | |||
41 | |
40 | |
|
Line 42... | Line 41... | |||
42 | public bool MemorySinkEnabled { get; set; } |
41 | public bool MemorySinkEnabled { get; set; } |
|
Line 78... | Line 77... | |||
78 | |
77 | |
|
79 | private async void Form1_Load(object sender, EventArgs e) |
78 | private async void Form1_Load(object sender, EventArgs e) |
|
80 | { |
79 | { |
|
Line 81... | Line -... | |||
81 | Configuration = await LoadConfiguration(); |
- | ||
82 | |
- | ||
83 | // Set up serial connection. |
- | ||
84 | _serialPort = new SerialPort(Configuration.Port, Configuration.Speed, Configuration.Parity, Configuration.DataBits, Configuration.StopBits); |
80 | Configuration = await LoadConfiguration(); |
|
Line 85... | Line 81... | |||
85 | //TODO: move to settings |
81 | |
|
86 | //_serialPort.ReadTimeout = TimeSpan.FromSeconds(1).Milliseconds; |
- | ||
Line 87... | Line 82... | |||
87 | |
82 | _serialPort = InitializeSerialPort(Configuration); |
|
88 | _catAssemblies = new CatAssemblies(_serialPort, Configuration.Radio); |
83 | |
|
89 | _catAssemblies.CatSet<InformationState>("AI", new object[] { InformationState.OFF }); |
84 | _catAssemblies = InitializeAssemblies(_serialPort); |
|
90 | |
85 | |
|
91 | try |
86 | try |
|
- | 87 | { |
||
92 | { |
88 | switch (await _catAssemblies.CatRead<PowerState>("PS", new object[] { }, _cancellationToken)) |
|
- | 89 | { |
||
- | 90 | case PowerState.ON: |
||
- | 91 | Log.Information(Resources.Attempting_to_initialize_radio); |
||
- | 92 | if(!InitializeRadio()) |
||
- | 93 | { |
||
93 | switch (await _catAssemblies.CatRead<PowerState>("PS", new object[] { }, _cancellationToken)) |
94 | return; |
|
94 | { |
95 | } |
|
95 | case PowerState.ON: |
96 | |
|
96 | Initialize(); |
97 | Log.Information(Resources.Initializing_GUI); |
|
97 | break; |
98 | break; |
|
Line 181... | Line 182... | |||
181 | async () => { |
182 | async () => { |
|
182 | await SaveConfiguration(); |
183 | await SaveConfiguration(); |
|
Line 183... | Line 184... | |||
183 | |
184 | |
|
Line -... | Line 185... | |||
- | 185 | Miscellaneous.LaunchOnBootSet(Configuration.LaunchOnBoot); |
||
- | 186 | |
||
- | 187 | _serialPort = InitializeSerialPort(Configuration); |
||
- | 188 | |
||
- | 189 | _catAssemblies = InitializeAssemblies(_serialPort); |
||
- | 190 | |
||
- | 191 | try |
||
- | 192 | { |
||
184 | Miscellaneous.LaunchOnBootSet(Configuration.LaunchOnBoot); |
193 | switch (await _catAssemblies.CatRead<PowerState>("PS", new object[] { }, _cancellationToken)) |
|
185 | |
194 | { |
|
- | 195 | case PowerState.ON: |
||
- | 196 | Log.Information(Resources.Attempting_to_initialize_radio); |
||
- | 197 | if (!InitializeRadio()) |
||
- | 198 | { |
||
- | 199 | return; |
||
- | 200 | } |
||
- | 201 | Log.Information(Resources.Initializing_GUI); |
||
- | 202 | break; |
||
- | 203 | } |
||
- | 204 | } |
||
- | 205 | catch (Exception exception) |
||
- | 206 | { |
||
Line 186... | Line 207... | |||
186 | _serialPort.Dispose(); |
207 | Log.Error(exception, Resources.Failed_to_read_power_state); |
|
187 | _serialPort = new SerialPort(Configuration.Port, Configuration.Speed, Configuration.Parity, Configuration.DataBits, Configuration.StopBits); |
208 | } |
|
Line 188... | Line 209... | |||
188 | |
209 | |
|
Line 234... | Line 255... | |||
234 | default: |
255 | default: |
|
235 | return new Configuration.Configuration(); |
256 | return new Configuration.Configuration(); |
|
236 | } |
257 | } |
|
237 | } |
258 | } |
|
Line 238... | Line 259... | |||
238 | |
259 | |
|
239 | private void Initialize() |
260 | private bool InitializeRadio() |
|
240 | { |
261 | { |
|
241 | try |
262 | try |
|
242 | { |
263 | { |
|
243 | var mode = _catAssemblies.CatRead<RadioMode>("MD", new object[] { }); |
- | ||
244 | toolStripComboBox1.Text = mode; |
264 | if (!_catAssemblies.CatRead<bool>("ID", new object[] { })) |
|
245 | } |
265 | { |
|
246 | catch(Exception exception) |
- | ||
247 | { |
- | ||
248 | Log.Error(exception, Resources.Failed_to_read_radio_mode); |
266 | return false; |
|
Line 249... | Line -... | |||
249 | } |
- | ||
250 | |
- | ||
251 | try |
267 | } |
|
252 | { |
- | ||
253 | var fa = _catAssemblies.CatRead<int>("FA", new object[] { }); |
268 | |
|
254 | scrollableToolStripComboBox1.Text = $"{fa}"; |
269 | _catAssemblies.CatSet<InformationState>("AI", new object[] { InformationState.OFF }); |
|
255 | } |
270 | } |
|
256 | catch(Exception exception) |
271 | catch(Exception exception) |
|
- | 272 | { |
||
257 | { |
273 | Log.Error(exception, Resources.Unable_to_initialize_radio); |
|
Line 258... | Line 274... | |||
258 | Log.Error(exception, Resources.Failed_to_read_VFO_A); |
274 | return false; |
|
- | 275 | } |
||
- | 276 | |
||
- | 277 | return true; |
||
- | 278 | } |
||
- | 279 | |
||
259 | } |
280 | private CatAssemblies InitializeAssemblies(SerialPort serialPort) |
|
260 | |
281 | { |
|
261 | try |
282 | if(_catAssemblies != null) |
|
262 | { |
283 | { |
|
- | 284 | _catAssemblies.Dispose(); |
||
- | 285 | _catAssemblies = null; |
||
- | 286 | } |
||
- | 287 | |
||
- | 288 | return new CatAssemblies(serialPort, Configuration.Radio); |
||
- | 289 | } |
||
263 | var fb = _catAssemblies.CatRead<int>("FB", new object[] { }); |
290 | |
|
264 | scrollableToolStripComboBox2.Text = $"{fb}"; |
291 | private SerialPort InitializeSerialPort(Configuration.Configuration configuration) |
|
- | 292 | { |
||
- | 293 | if (_serialPort != null) |
||
265 | } |
294 | { |
|
- | 295 | if (_serialPort.IsOpen) |
||
- | 296 | { |
||
- | 297 | _serialPort.Close(); |
||
266 | catch (Exception exception) |
298 | } |
|
Line -... | Line 299... | |||
- | 299 | _serialPort.Dispose(); |
||
- | 300 | _serialPort = null; |
||
- | 301 | } |
||
- | 302 | |
||
- | 303 | // Set up serial connection. |
||
- | 304 | var serialPort = new SerialPort(configuration.Port, configuration.Speed, configuration.Parity, configuration.DataBits, configuration.StopBits); |
||
- | 305 | serialPort.ReadTimeout = configuration.SerialPortTimeout.Read; |
||
Line -... | Line 306... | |||
- | 306 | serialPort.WriteTimeout = configuration.SerialPortTimeout.Write; |
||
267 | { |
307 | serialPort.Handshake = configuration.Handshake; |
|
Line 268... | Line 308... | |||
268 | Log.Error(exception, Resources.Failed_to_read_VFO_B); |
308 | |
|
269 | } |
309 | Log.Information($"{Resources.Initialized_serial_port} {configuration.Port} {configuration.Speed} {configuration.Parity} {configuration.DataBits} {configuration.StopBits}"); |
|
270 | |
310 | |
|
Line 306... | Line 346... | |||
306 | private async void onToolStripMenuItem_Click(object sender, EventArgs e) |
346 | private async void onToolStripMenuItem_Click(object sender, EventArgs e) |
|
307 | { |
347 | { |
|
308 | try |
348 | try |
|
309 | { |
349 | { |
|
310 | await _catAssemblies.CatSet<PowerState>("PS", new object[] { PowerState.ON }, _cancellationToken); |
350 | await _catAssemblies.CatSet<PowerState>("PS", new object[] { PowerState.ON }, _cancellationToken); |
|
311 | Initialize(); |
- | ||
312 | } |
351 | } |
|
313 | catch(Exception exception) |
352 | catch(Exception exception) |
|
314 | { |
353 | { |
|
315 | Log.Error(exception, Resources.Failed_to_set_power_state); |
354 | Log.Error(exception, Resources.Failed_to_set_power_state); |
|
316 | } |
355 | } |
|
Line 330... | Line 369... | |||
330 | |
369 | |
|
331 | private void toolStripComboBox2_MouseWheel(object sender, MouseEventArgs e) |
370 | private void toolStripComboBox2_MouseWheel(object sender, MouseEventArgs e) |
|
332 | { |
371 | { |
|
333 | using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) |
372 | using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) |
|
334 | { |
373 | { |
|
335 | var toolStripComboBox = (ToolStripComboBox)sender; |
374 | var toolStripComboBox = (ScrollableToolStripComboBox)sender; |
|
336 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
375 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
|
337 | { |
376 | { |
|
338 | switch (Math.Sign(e.Delta)) |
377 | switch (Math.Sign(e.Delta)) |
|
339 | { |
378 | { |
|
Line 349... | Line 388... | |||
349 | |
388 | |
|
350 | try |
389 | try |
|
351 | { |
390 | { |
|
352 | _catAssemblies.CatSet<int>("FA", new object[] { frequency }); |
391 | _catAssemblies.CatSet<int>("FA", new object[] { frequency }); |
|
- | 392 | toolStripComboBox.Text = $"{frequency}"; |
||
- | 393 | |
||
353 | toolStripComboBox.Text = $"{frequency}"; |
394 | Log.Information($"{Resources.Set_VFO_A_frequency} {frequency}Hz"); |
|
354 | } |
395 | } |
|
355 | catch (Exception exception) |
396 | catch (Exception exception) |
|
356 | { |
397 | { |
|
357 | Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); |
398 | Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency); |
|
Line 362... | Line 403... | |||
362 | |
403 | |
|
363 | private void scrollableToolStripComboBox1_MouseWheel(object sender, MouseEventArgs e) |
404 | private void scrollableToolStripComboBox1_MouseWheel(object sender, MouseEventArgs e) |
|
364 | { |
405 | { |
|
365 | using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) |
406 | using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) |
|
366 | { |
407 | { |
|
367 | var toolStripComboBox = (ToolStripComboBox)sender; |
408 | var toolStripComboBox = (ScrollableToolStripComboBox)sender; |
|
368 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
409 | if (int.TryParse(toolStripComboBox.Text, out var frequency)) |
|
369 | { |
410 | { |
|
370 | switch (Math.Sign(e.Delta)) |
411 | switch (Math.Sign(e.Delta)) |
|
371 | { |
412 | { |
|
Line 381... | Line 422... | |||
381 | |
422 | |
|
382 | try |
423 | try |
|
383 | { |
424 | { |
|
384 | _catAssemblies.CatSet<int>("FB", new object[] { frequency }); |
425 | _catAssemblies.CatSet<int>("FB", new object[] { frequency }); |
|
- | 426 | toolStripComboBox.Text = $"{frequency}"; |
||
- | 427 | |
||
385 | toolStripComboBox.Text = $"{frequency}"; |
428 | Log.Information($"{Resources.Set_VFO_B_frequency} {frequency}Hz"); |
|
386 | } |
429 | } |
|
387 | catch (Exception exception) |
430 | catch (Exception exception) |
|
388 | { |
431 | { |
|
389 | Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); |
432 | Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency); |
|
Line 469... | Line 512... | |||
469 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
512 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
|
470 | } |
513 | } |
|
Line 471... | Line 514... | |||
471 | |
514 | |
|
472 | private void modeToolStripMenuItem_DropDownOpened(object sender, EventArgs e) |
515 | private void modeToolStripMenuItem_DropDownOpened(object sender, EventArgs e) |
|
473 | { |
516 | { |
|
- | 517 | try |
||
- | 518 | { |
||
- | 519 | var mode = _catAssemblies.CatRead<RadioMode>("MD", new object[] { }); |
||
- | 520 | toolStripComboBox1.Text = mode; |
||
- | 521 | } |
||
- | 522 | catch (Exception exception) |
||
- | 523 | { |
||
- | 524 | Log.Error(exception, Resources.Failed_to_read_radio_mode); |
||
- | 525 | } |
||
- | 526 | |
||
- | 527 | try |
||
- | 528 | { |
||
- | 529 | var fa = _catAssemblies.CatRead<int>("FA", new object[] { }); |
||
- | 530 | scrollableToolStripComboBox1.Text = $"{fa}"; |
||
- | 531 | } |
||
- | 532 | catch (Exception exception) |
||
- | 533 | { |
||
- | 534 | Log.Error(exception, Resources.Failed_to_read_VFO_A); |
||
- | 535 | } |
||
- | 536 | |
||
- | 537 | try |
||
- | 538 | { |
||
- | 539 | var fb = _catAssemblies.CatRead<int>("FB", new object[] { }); |
||
- | 540 | scrollableToolStripComboBox2.Text = $"{fb}"; |
||
- | 541 | } |
||
- | 542 | catch (Exception exception) |
||
- | 543 | { |
||
- | 544 | Log.Error(exception, Resources.Failed_to_read_VFO_B); |
||
- | 545 | } |
||
474 | Initialize(); |
546 | |
|
475 | } |
547 | } |
|
476 | } |
548 | } |