HamBook – Diff between revs 46 and 54
?pathlinks?
Rev 46 | Rev 54 | |||
---|---|---|---|---|
Line 1... | Line -... | |||
1 | using HamBook.Radios.Generic; |
- | ||
2 | using HamBook.Radios.Generic.CAT; |
- | ||
3 | using System; |
- | ||
4 | using System.Collections.Generic; |
- | ||
5 | using System.IO.Ports; |
- | ||
6 | using System.Linq; |
- | ||
7 | using System.Text; |
- | ||
8 | using System.Text.RegularExpressions; |
1 | using System.Text.RegularExpressions; |
|
9 | using System.Threading.Tasks; |
- | ||
10 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
2 | using HamBook.Radios.Generic; |
|
11 | using RJCP.IO.Ports; |
3 | using RJCP.IO.Ports; |
|
- | 4 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
||
Line 12... | Line 5... | |||
12 | |
5 | |
|
13 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
6 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
|
14 | { |
7 | { |
|
15 | [Radio("Yaesu FT-891")] |
8 | [Radio("Yaesu FT-891")] |
|
16 | public class SC : HamBook.Radios.Generic.CAT.SC |
9 | public class Sc : Generic.CAT.Sc |
|
17 | { |
10 | { |
|
18 | private readonly Regex readRegex; |
- | ||
19 | |
- | ||
Line 20... | Line 11... | |||
20 | public override CatLength CatLength => new CatLength { Set = 4, Answer = 4, Read = 3 }; |
11 | private readonly Regex _readRegex; |
|
21 | |
12 | |
|
22 | public SC(SerialPortStream serialPort) : base(serialPort) |
13 | public Sc(SerialPortStream serialPort) : base(serialPort) |
|
23 | { |
14 | { |
|
Line -... | Line 15... | |||
- | 15 | _readRegex = new Regex($"^{Name}(?<state>[012]){Eot}$", RegexOptions.Compiled); |
||
- | 16 | } |
||
24 | readRegex = new Regex($"^{Name}(?<state>[012]){Constants.EOT}$", RegexOptions.Compiled); |
17 | |
|
25 | } |
18 | public override CatLength CatLength => new CatLength { Set = 4, Answer = 4, Read = 3 }; |
|
26 | |
19 | |
|
27 | public override ScanState Read() |
20 | public override ScanState Read() |
|
28 | { |
21 | { |
|
29 | SerialPort.Write($"{Name}{Constants.EOT}"); |
- | ||
30 | var buffer = new byte[CatLength.Answer]; |
22 | SerialPort.Write($"{Name}{Eot}"); |
|
31 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
- | ||
Line 32... | Line 23... | |||
32 | { |
23 | var buffer = new byte[CatLength.Answer]; |
|
33 | throw new UnexpectedRadioResponseException(Name, buffer); |
24 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
34 | } |
- | ||
35 | |
- | ||
36 | var answer = Constants.Encoding.GetString(buffer); |
25 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
37 | var match = readRegex.Match(answer); |
- | ||
38 | if (!match.Success) |
26 | |
|
39 | { |
27 | var answer = Encoding.GetString(buffer); |
|
40 | throw new UnmatchedRadioResponseException(Name, answer); |
28 | var match = _readRegex.Match(answer); |
|
41 | } |
29 | if (!match.Success) throw new UnmatchedRadioResponseException(Name, answer); |
|
42 | var state = char.Parse(match.Result("${state}")); |
30 | var state = char.Parse(match.Result("${state}")); |
|
43 | switch(state) |
31 | switch (state) |
|
44 | { |
32 | { |
|
Line 53... | Line 41... | |||
53 | return ScanState.NONE; |
41 | return ScanState.NONE; |
|
54 | } |
42 | } |
|
Line 55... | Line 43... | |||
55 | |
43 | |
|
56 | public override bool Set(ScanState state) |
44 | public override bool Set(ScanState state) |
|
57 | { |
45 | { |
|
58 | switch(state) |
46 | switch (state) |
|
59 | { |
47 | { |
|
60 | case ScanState.OFF: |
48 | case ScanState.OFF: |
|
61 | SerialPort.Write($"{Name}0{Constants.EOT}"); |
49 | SerialPort.Write($"{Name}0{Eot}"); |
|
62 | break; |
50 | break; |
|
63 | case ScanState.UP: |
51 | case ScanState.UP: |
|
64 | SerialPort.Write($"{Name}1{Constants.EOT}"); |
52 | SerialPort.Write($"{Name}1{Eot}"); |
|
65 | break; |
53 | break; |
|
66 | case ScanState.DOWN: |
54 | case ScanState.DOWN: |
|
67 | SerialPort.Write($"{Name}2{Constants.EOT}"); |
55 | SerialPort.Write($"{Name}2{Eot}"); |
|
68 | break; |
56 | break; |
|
Line 69... | Line 57... | |||
69 | } |
57 | } |
|
70 | |
58 | |
|
71 | return Read() == state; |
- | ||
72 | } |
- | ||
73 | |
59 | return Read() == state; |
|
74 | |
60 | } |
|
75 | } |
61 | } |