HamBook – Blame information for rev 3
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using HamBook.Radios.Generic; |
3 | office | 2 | using HamBook.Radios.Generic.CAT; |
1 | office | 3 | using System; |
4 | using System.Collections.Generic; |
||
5 | using System.Drawing; |
||
6 | using System.IO.Ports; |
||
7 | using System.Linq; |
||
8 | using System.Text; |
||
9 | using System.Text.RegularExpressions; |
||
10 | using System.Threading.Tasks; |
||
11 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
||
12 | |||
13 | namespace HamBook.Radios.Yaesu.FT_891 |
||
14 | { |
||
15 | [Radio("Yaesu FT-891")] |
||
3 | office | 16 | public class PS : HamBook.Radios.Generic.CAT.PS |
1 | office | 17 | { |
18 | private static readonly Regex readRegex = new Regex(@"^PS(?<state>[0,1])$", RegexOptions.Compiled); |
||
19 | |||
20 | public PS(SerialPort serialPort) : base(serialPort) |
||
21 | { |
||
22 | } |
||
23 | |||
24 | public override async Task Set(PowerState state) |
||
25 | { |
||
26 | var taskCompletionSource = new TaskCompletionSource<bool>(); |
||
27 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
28 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(ca => |
||
29 | { |
||
30 | switch(state) |
||
31 | { |
||
32 | case PowerState.ON: |
||
3 | office | 33 | SerialPort.Write($"{Name}1{Generic.Constants.EOT}"); |
1 | office | 34 | Task.Delay(Constants.TIME_TO_WARM).ContinueWith(cb => |
35 | { |
||
36 | taskCompletionSource.TrySetResult(true); |
||
37 | }); |
||
38 | return; |
||
39 | case PowerState.OFF: |
||
3 | office | 40 | SerialPort.Write($"{Name}0{Generic.Constants.EOT}"); |
1 | office | 41 | break; |
42 | } |
||
43 | taskCompletionSource.TrySetResult(true); |
||
44 | }); |
||
45 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
46 | |||
47 | SerialPort.Write($"POWER"); |
||
48 | await taskCompletionSource.Task; |
||
49 | } |
||
50 | |||
51 | public override async Task<PowerState> Read() |
||
52 | { |
||
53 | var taskCompletionSource = new TaskCompletionSource<int>(); |
||
54 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
55 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(_ => |
||
56 | { |
||
3 | office | 57 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
58 | var result = SerialPort.ReadTo(Generic.Constants.EOT); |
||
1 | office | 59 | var match = readRegex.Match(result); |
60 | var state = int.Parse(match.Result("${state}")); |
||
61 | |||
62 | taskCompletionSource.TrySetResult(state); |
||
63 | }); |
||
64 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
||
65 | |||
66 | SerialPort.Write($"POWER"); |
||
67 | var onoff = await taskCompletionSource.Task; |
||
68 | switch(onoff) |
||
69 | { |
||
70 | case 1: |
||
71 | return PowerState.ON; |
||
72 | case 0: |
||
73 | return PowerState.OFF; |
||
74 | } |
||
75 | |||
76 | return PowerState.NONE; |
||
77 | } |
||
78 | } |
||
79 | } |