HamBook – Diff between revs 11 and 46
?pathlinks?
Rev 11 | Rev 46 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | |
20 | |
|
Line 21... | Line 21... | |||
21 | public override CatLength CatLength => new CatLength { Set = 12, Answer = 12, Read = 3 }; |
21 | public override CatLength CatLength => new CatLength { Set = 12, Answer = 12, Read = 3 }; |
|
22 | |
22 | |
|
23 | public FB(SerialPortStream serialPort) : base(serialPort) |
23 | public FB(SerialPortStream serialPort) : base(serialPort) |
|
24 | { |
24 | { |
|
Line 25... | Line 25... | |||
25 | readRegex = new Regex($"^{Name}(?<frequency>[0-9]{{9}}){HamBook.Radios.Generic.Constants.EOT}$", RegexOptions.Compiled); |
25 | readRegex = new Regex($"^{Name}(?<frequency>[0-9]{{9}}){Constants.EOT}$", RegexOptions.Compiled); |
|
26 | } |
26 | } |
|
27 | |
27 | |
|
Line 28... | Line 28... | |||
28 | public override bool Set(int frequency) |
28 | public override bool Set(int frequency) |
|
29 | { |
29 | { |
|
30 | var f = $"{frequency:000000000}"; |
30 | var f = $"{frequency:000000000}"; |
|
Line 31... | Line 31... | |||
31 | |
31 | |
|
32 | SerialPort.Write($"{Name}{f}{Generic.Constants.EOT}"); |
32 | SerialPort.Write($"{Name}{f}{Constants.EOT}"); |
|
33 | return Read() == frequency; |
33 | return Read() == frequency; |
|
Line 34... | Line 34... | |||
34 | } |
34 | } |
|
Line 35... | Line 35... | |||
35 | |
35 | |
|
Line 36... | Line 36... | |||
36 | public override async Task<bool> SetAsync(int frequency, CancellationToken cancellation) |
36 | public override async Task<bool> SetAsync(int frequency, CancellationToken cancellation) |
|
37 | { |
37 | { |
|
Line 38... | Line 38... | |||
38 | var f = $"{frequency:000000000}"; |
38 | var f = $"{frequency:000000000}"; |
|
39 | |
39 | |
|
40 | var payload = Constants.Encoding.GetBytes($"{Name}{f}{Generic.Constants.EOT}"); |
40 | var payload = Constants.Encoding.GetBytes($"{Name}{f}{Constants.EOT}"); |
|
41 | |
41 | |
|
42 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellation); |
42 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellation); |
|
43 | |
43 | |
|
44 | return await ReadAsync(cancellation) == frequency; |
44 | return await ReadAsync(cancellation) == frequency; |
|
45 | } |
45 | } |
|
Line 62... | Line 62... | |||
62 | return int.Parse(match.Result("${frequency}")); |
62 | return int.Parse(match.Result("${frequency}")); |
|
63 | } |
63 | } |
|
Line 64... | Line 64... | |||
64 | |
64 | |
|
65 | public override async Task<int> ReadAsync(CancellationToken cancellationToken) |
65 | public override async Task<int> ReadAsync(CancellationToken cancellationToken) |
|
66 | { |
66 | { |
|
67 | var payload = Constants.Encoding.GetBytes($"{Name}{Generic.Constants.EOT}"); |
67 | var payload = Constants.Encoding.GetBytes($"{Name}{Constants.EOT}"); |
|
68 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
68 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
69 | var buffer = new byte[CatLength.Answer]; |
69 | var buffer = new byte[CatLength.Answer]; |
|
70 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
70 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
|
71 | { |
71 | { |
|
Line 84... | Line 84... | |||
84 | |
84 | |
|
85 | public override void Write(int frequency) |
85 | public override void Write(int frequency) |
|
86 | { |
86 | { |
|
Line 87... | Line 87... | |||
87 | var f = $"{frequency:000000000}"; |
87 | var f = $"{frequency:000000000}"; |
|
88 | |
88 | |
|
Line 89... | Line 89... | |||
89 | SerialPort.Write($"{Name}{f}{Generic.Constants.EOT}"); |
89 | SerialPort.Write($"{Name}{f}{Constants.EOT}"); |
|
90 | } |
90 | } |
|
91 | |
91 | |
|
Line 92... | Line 92... | |||
92 | public override async Task WriteAsync(int frequency, CancellationToken cancellationToken) |
92 | public override async Task WriteAsync(int frequency, CancellationToken cancellationToken) |
|
Line 93... | Line 93... | |||
93 | { |
93 | { |
|
94 | var f = $"{frequency:000000000}"; |
94 | var f = $"{frequency:000000000}"; |
|
95 | |
95 | |
|
96 | var payload = Constants.Encoding.GetBytes($"{Name}{f}{Generic.Constants.EOT}"); |
96 | var payload = Constants.Encoding.GetBytes($"{Name}{f}{Constants.EOT}"); |