HamBook – Diff between revs 15 and 43
?pathlinks?
Rev 15 | Rev 43 | |||
---|---|---|---|---|
Line 26... | Line 26... | |||
26 | public MD(SerialPortStream serialPort) : base(serialPort) |
26 | public MD(SerialPortStream serialPort) : base(serialPort) |
|
27 | { |
27 | { |
|
28 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
28 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
|
29 | } |
29 | } |
|
Line 30... | Line 30... | |||
30 | |
30 | |
|
31 | public override bool Set(RadioMode radioMode) |
31 | public override bool Set(Generic.RadioMode radioMode) |
|
32 | { |
32 | { |
|
Line 33... | Line 33... | |||
33 | SerialPort.Write($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
33 | SerialPort.Write($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
|
34 | |
34 | |
|
Line 35... | Line 35... | |||
35 | return Read() == radioMode; |
35 | return Read() == radioMode; |
|
36 | } |
36 | } |
|
37 | |
37 | |
|
Line 38... | Line 38... | |||
38 | public override async Task<bool> SetAsync(RadioMode radioMode, CancellationToken cancellationToken) |
38 | public override async Task<bool> SetAsync(Generic.RadioMode radioMode, CancellationToken cancellationToken) |
|
Line 39... | Line 39... | |||
39 | { |
39 | { |
|
40 | var payload = Constants.Encoding.GetBytes($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
40 | var payload = Constants.Encoding.GetBytes($"{Name}0{radioMode.Mode}{Generic.Constants.EOT}"); |
|
Line 41... | Line 41... | |||
41 | |
41 | |
|
42 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
42 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
43 | |
43 | |
|
44 | return (await ReadAsync(cancellationToken)).Mode == radioMode.Mode; |
44 | return (await ReadAsync(cancellationToken)).Mode == radioMode.Mode; |
|
45 | } |
45 | } |
|
46 | |
46 | |
|
Line 58... | Line 58... | |||
58 | if (!match.Success) |
58 | if (!match.Success) |
|
59 | { |
59 | { |
|
60 | throw new UnmatchedRadioResponseException(Name, answer); |
60 | throw new UnmatchedRadioResponseException(Name, answer); |
|
61 | } |
61 | } |
|
62 | var radioMode = char.Parse(match.Result("${mode}")); |
62 | var radioMode = char.Parse(match.Result("${mode}")); |
|
63 | return radioMode; |
63 | return new RadioMode(radioMode); |
|
64 | } |
64 | } |
|
65 | public override async Task<RadioMode> ReadAsync(CancellationToken cancellationToken) |
65 | public override async Task<Generic.RadioMode> ReadAsync(CancellationToken cancellationToken) |
|
66 | { |
66 | { |
|
67 | var payload = Constants.Encoding.GetBytes($"{Name}0{Generic.Constants.EOT}"); |
67 | var payload = Constants.Encoding.GetBytes($"{Name}0{Generic.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, buffer.Length, cancellationToken) != CatLength.Answer) |
70 | if (await SerialPort.ReadAsync(buffer, 0, buffer.Length, cancellationToken) != CatLength.Answer) |
|
Line 78... | Line 78... | |||
78 | { |
78 | { |
|
79 | throw new UnmatchedRadioResponseException(Name, answer); |
79 | throw new UnmatchedRadioResponseException(Name, answer); |
|
80 | } |
80 | } |
|
Line 81... | Line 81... | |||
81 | |
81 | |
|
82 | var radioMode = char.Parse(match.Result("${mode}")); |
82 | var radioMode = char.Parse(match.Result("${mode}")); |
|
83 | return radioMode; |
83 | return new RadioMode(radioMode); |
|
84 | } |
84 | } |
|
85 | } |
85 | } |