HamBook – Diff between revs 9 and 11
?pathlinks?
Rev 9 | Rev 11 | |||
---|---|---|---|---|
Line 18... | Line 18... | |||
18 | { |
18 | { |
|
19 | [Radio("Yaesu FT-891")] |
19 | [Radio("Yaesu FT-891")] |
|
20 | public class MD : Generic.CAT.MD |
20 | public class MD : Generic.CAT.MD |
|
21 | { |
21 | { |
|
22 | private readonly Regex readRegex; |
22 | private readonly Regex readRegex; |
|
- | 23 | |
||
23 | public override CatLength CatLength => new CatLength { Set = 5, Answer = 5, Read = 4 }; |
24 | public override CatLength CatLength => new CatLength { Set = 5, Answer = 5, Read = 4 }; |
|
- | 25 | |
||
24 | public MD(SerialPortStream serialPort) : base(serialPort) |
26 | public MD(SerialPortStream serialPort) : base(serialPort) |
|
25 | { |
27 | { |
|
26 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
28 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
|
27 | } |
29 | } |
|
Line 28... | Line 30... | |||
28 | |
30 | |
|
29 | public override bool Set(RadioMode radioMode) |
31 | public override bool Set(RadioMode radioMode) |
|
30 | { |
32 | { |
|
- | 33 | SerialPort.Write($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
||
31 | SerialPort.Write($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
34 | |
|
32 | return Read() == radioMode; |
35 | return Read() == radioMode; |
|
Line 33... | Line 36... | |||
33 | } |
36 | } |
|
34 | |
37 | |
|
35 | public override async Task<bool> SetAsync(RadioMode radioMode, CancellationToken cancellationToken) |
38 | public override async Task<bool> SetAsync(RadioMode radioMode, CancellationToken cancellationToken) |
|
Line 36... | Line 39... | |||
36 | { |
39 | { |
|
Line 37... | Line 40... | |||
37 | var payload = Encoding.ASCII.GetBytes($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
40 | var payload = Constants.Encoding.GetBytes($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
|
38 | |
41 | |
|
Line 45... | Line 48... | |||
45 | { |
48 | { |
|
46 | SerialPort.Write($"{Name}0{Generic.Constants.EOT}"); |
49 | SerialPort.Write($"{Name}0{Generic.Constants.EOT}"); |
|
47 | var buffer = new byte[CatLength.Answer]; |
50 | var buffer = new byte[CatLength.Answer]; |
|
48 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
51 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
49 | { |
52 | { |
|
50 | throw new ArgumentException(); |
53 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
51 | } |
54 | } |
|
Line 52... | Line 55... | |||
52 | |
55 | |
|
53 | var answer = Encoding.ASCII.GetString(buffer); |
56 | var answer = Constants.Encoding.GetString(buffer); |
|
54 | var match = readRegex.Match(answer); |
57 | var match = readRegex.Match(answer); |
|
55 | if (!match.Success) |
58 | if (!match.Success) |
|
56 | { |
59 | { |
|
57 | throw new ArgumentException(); |
60 | throw new UnmatchedRadioResponseException(Name, answer); |
|
58 | } |
61 | } |
|
59 | var radioMode = char.Parse(match.Result("${mode}")); |
62 | var radioMode = char.Parse(match.Result("${mode}")); |
|
60 | return radioMode; |
63 | return radioMode; |
|
61 | } |
64 | } |
|
62 | public override async Task<RadioMode> ReadAsync(CancellationToken cancellationToken) |
65 | public override async Task<RadioMode> ReadAsync(CancellationToken cancellationToken) |
|
63 | { |
66 | { |
|
64 | var payload = Encoding.ASCII.GetBytes($"{Name}0{Generic.Constants.EOT}"); |
67 | var payload = Constants.Encoding.GetBytes($"{Name}0{Generic.Constants.EOT}"); |
|
65 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
68 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
66 | var buffer = new byte[CatLength.Answer]; |
69 | var buffer = new byte[CatLength.Answer]; |
|
67 | if(await SerialPort.ReadAsync(buffer, 0, buffer.Length, cancellationToken) != CatLength.Answer) |
70 | if (await SerialPort.ReadAsync(buffer, 0, buffer.Length, cancellationToken) != CatLength.Answer) |
|
68 | { |
71 | { |
|
69 | throw new ArgumentException(); |
72 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
Line 70... | Line 73... | |||
70 | } |
73 | } |
|
71 | |
74 | |
|
72 | var answer = Encoding.ASCII.GetString(buffer); |
75 | var answer = Constants.Encoding.GetString(buffer); |
|
73 | var match = readRegex.Match(answer); |
76 | var match = readRegex.Match(answer); |
|
74 | if (!match.Success) |
77 | if (!match.Success) |
|
75 | { |
78 | { |
|
Line 76... | Line 79... | |||
76 | throw new ArgumentException(); |
79 | throw new UnmatchedRadioResponseException(Name, answer); |
|
77 | } |
80 | } |
|
78 | |
81 | |