HamBook – Diff between revs 46 and 54
?pathlinks?
Rev 46 | Rev 54 | |||
---|---|---|---|---|
Line 1... | Line -... | |||
1 | using HamBook.Radios.Generic; |
- | ||
2 | using System; |
1 | using System; |
|
3 | using System.IO.Ports; |
- | ||
4 | using System.Text.RegularExpressions; |
2 | using System.Text.RegularExpressions; |
|
- | 3 | using HamBook.Radios.Generic; |
||
5 | using RJCP.IO.Ports; |
4 | using RJCP.IO.Ports; |
|
6 | using System.Text; |
- | ||
Line 7... | Line 5... | |||
7 | |
5 | |
|
8 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
6 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
|
9 | { |
7 | { |
|
10 | [Radio("Yaesu FT-891")] |
8 | [Radio("Yaesu FT-891")] |
|
11 | public class RI : Generic.CAT.RI |
9 | public class Ri : Generic.CAT.Ri |
|
12 | { |
10 | { |
|
Line 13... | Line -... | |||
13 | private readonly Regex readRegex; |
- | ||
14 | |
- | ||
15 | public override CatLength CatLength => new CatLength { Answer = 5, Read = 4 }; |
11 | private readonly Regex _readRegex; |
|
16 | |
12 | |
|
17 | public RI(SerialPortStream serialPort) : base(serialPort) |
13 | public Ri(SerialPortStream serialPort) : base(serialPort) |
|
- | 14 | { |
||
18 | { |
15 | _readRegex = new Regex($"^{Name}(?<type>[03AB]{{1}})(?<state>[01]{{1}}){Constants.Eot}$", |
|
Line -... | Line 16... | |||
- | 16 | RegexOptions.Compiled); |
||
- | 17 | } |
||
19 | readRegex = new Regex($"^{Name}(?<type>[03AB]{{1}})(?<state>[01]{{1}}){Constants.EOT}$", RegexOptions.Compiled); |
18 | |
|
20 | } |
19 | public override CatLength CatLength => new CatLength { Answer = 5, Read = 4 }; |
|
21 | |
20 | |
|
22 | public override bool Read(RadioInformationType type) |
21 | public override bool Read(RadioInformationType type) |
|
23 | { |
22 | { |
|
24 | SerialPort.Write($"{Name}{P1(type)}{Constants.EOT}"); |
- | ||
25 | var buffer = new byte[CatLength.Answer]; |
23 | SerialPort.Write($"{Name}{P1(type)}{Constants.Eot}"); |
|
26 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
- | ||
Line 27... | Line 24... | |||
27 | { |
24 | var buffer = new byte[CatLength.Answer]; |
|
28 | throw new UnexpectedRadioResponseException(Name, buffer); |
25 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
29 | } |
- | ||
30 | |
- | ||
31 | var answer = Constants.Encoding.GetString(buffer); |
26 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
32 | var match = readRegex.Match(answer); |
- | ||
Line 33... | Line 27... | |||
33 | if (!match.Success) |
27 | |
|
Line 34... | Line -... | |||
34 | { |
- | ||
35 | throw new UnmatchedRadioResponseException(Name, answer); |
- | ||
36 | } |
28 | var answer = Constants.Encoding.GetString(buffer); |
|
37 | |
- | ||
Line 38... | Line 29... | |||
38 | var information = P1(char.Parse(match.Result("${type}"))); |
29 | var match = _readRegex.Match(answer); |
|
39 | |
30 | if (!match.Success) throw new UnmatchedRadioResponseException(Name, answer); |
|
40 | if(information != type) |
31 | |
|
Line 82... | Line 73... | |||
82 | default: |
73 | default: |
|
83 | throw new ArgumentException(); |
74 | throw new ArgumentException(); |
|
84 | } |
75 | } |
|
85 | } |
76 | } |
|
86 | } |
77 | } |
|
87 | } |
78 | } |
|
88 | |
79 | |