HamBook – Diff between revs 46 and 54
?pathlinks?
Rev 46 | Rev 54 | |||
---|---|---|---|---|
Line 1... | Line -... | |||
1 | using System; |
- | ||
2 | using System.Collections.Generic; |
- | ||
3 | using System.IO.Ports; |
- | ||
4 | using System.Linq; |
- | ||
5 | using System.Text; |
- | ||
6 | using System.Threading.Tasks; |
- | ||
7 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
- | ||
8 | using RJCP.IO.Ports; |
- | ||
9 | using System.Text.RegularExpressions; |
1 | using System.Text.RegularExpressions; |
|
10 | using HamBook.Radios.Generic; |
2 | using HamBook.Radios.Generic; |
|
- | 3 | using RJCP.IO.Ports; |
||
- | 4 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
||
Line 11... | Line 5... | |||
11 | |
5 | |
|
12 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
6 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
|
13 | { |
7 | { |
|
14 | [Radio("Yaesu FT-891")] |
8 | [Radio("Yaesu FT-891")] |
|
15 | public class BY : Generic.CAT.BY |
9 | public class By : Generic.CAT.By |
|
16 | { |
10 | { |
|
Line 17... | Line -... | |||
17 | private readonly Regex readRegex; |
- | ||
18 | |
- | ||
19 | public override CatLength CatLength => new CatLength { Read = 3, Answer = 5 }; |
11 | private readonly Regex _readRegex; |
|
20 | |
12 | |
|
21 | public BY(SerialPortStream serialPort) : base(serialPort) |
13 | public By(SerialPortStream serialPort) : base(serialPort) |
|
22 | { |
14 | { |
|
Line -... | Line 15... | |||
- | 15 | _readRegex = new Regex($"^{Name}(?<state>[01])0{Eot}$", RegexOptions.Compiled); |
||
- | 16 | } |
||
23 | readRegex = new Regex($"^{Name}(?<state>[01])0{Constants.EOT}$", RegexOptions.Compiled); |
17 | |
|
24 | } |
18 | public override CatLength CatLength => new CatLength { Read = 3, Answer = 5 }; |
|
25 | |
19 | |
|
26 | public override BusyState Parse(string input) |
- | ||
27 | { |
- | ||
28 | var match = readRegex.Match(input); |
20 | public override BusyState Parse(string input) |
|
29 | if(!match.Success) |
- | ||
Line 30... | Line 21... | |||
30 | { |
21 | { |
|
31 | throw new UnmatchedRadioResponseException(Name, input); |
22 | var match = _readRegex.Match(input); |
|
Line 32... | Line 23... | |||
32 | } |
23 | if (!match.Success) throw new UnmatchedRadioResponseException(Name, input); |
|
33 | |
24 | |
|
34 | return (BusyState)int.Parse(match.Result("${state}")); |
25 | return (BusyState)int.Parse(match.Result("${state}")); |
|
35 | } |
26 | } |
|
36 | |
27 | |
|
37 | public override BusyState Read() |
- | ||
38 | { |
28 | public override BusyState Read() |
|
39 | SerialPort.Write($"{Name}{Constants.EOT}"); |
- | ||
Line 40... | Line 29... | |||
40 | var buffer = new byte[CatLength.Answer]; |
29 | { |
|
41 | if(SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
30 | SerialPort.Write($"{Name}{Eot}"); |
|
42 | { |
- | ||
43 | throw new UnexpectedRadioResponseException(Name, buffer); |
- | ||
44 | } |
31 | var buffer = new byte[CatLength.Answer]; |
|
45 | |
- | ||
Line 46... | Line 32... | |||
46 | var answer = Constants.Encoding.GetString(buffer); |
32 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
47 | var match = readRegex.Match(answer); |
33 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
48 | if (!match.Success) |
34 | |
|
49 | { |
35 | var answer = Encoding.GetString(buffer); |
|
50 | throw new UnmatchedRadioResponseException(Name, answer); |
36 | var match = _readRegex.Match(answer); |