HamBook – Diff between revs 44 and 46
?pathlinks?
Rev 44 | Rev 46 | |||
---|---|---|---|---|
Line 23... | Line 23... | |||
23 | |
23 | |
|
Line 24... | Line 24... | |||
24 | 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 | |
25 | |
|
26 | public MD(SerialPortStream serialPort) : base(serialPort) |
26 | public MD(SerialPortStream serialPort) : base(serialPort) |
|
27 | { |
27 | { |
|
Line 28... | Line 28... | |||
28 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
28 | readRegex = new Regex($"^MD0(?<mode>[123456789ABCD]){Constants.EOT}$", RegexOptions.Compiled); |
|
29 | } |
29 | } |
|
30 | |
30 | |
|
Line 31... | Line 31... | |||
31 | public override bool Set(Generic.RadioMode radioMode) |
31 | public override bool Set(Generic.RadioMode radioMode) |
|
32 | { |
32 | { |
|
Line 33... | Line 33... | |||
33 | SerialPort.Write($"{Name}0{radioMode.Code}{Generic.Constants.EOT}"); |
33 | SerialPort.Write($"{Name}0{radioMode.Code}{Constants.EOT}"); |
|
34 | |
34 | |
|
35 | return Read() == radioMode; |
35 | return Read() == radioMode; |
|
Line 36... | Line 36... | |||
36 | } |
36 | } |
|
Line 37... | Line 37... | |||
37 | |
37 | |
|
38 | public override async Task<bool> SetAsync(Generic.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.Code}{Generic.Constants.EOT}"); |
40 | var payload = Constants.Encoding.GetBytes($"{Name}0{radioMode.Code}{Constants.EOT}"); |
|
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)).Code == radioMode.Code; |
44 | return (await ReadAsync(cancellationToken)).Code == radioMode.Code; |
|
45 | } |
45 | } |
|
46 | |
46 | |
|
Line 62... | Line 62... | |||
62 | var radioMode = char.Parse(match.Result("${mode}")); |
62 | var radioMode = char.Parse(match.Result("${mode}")); |
|
63 | return new RadioMode(radioMode); |
63 | return new RadioMode(radioMode); |
|
64 | } |
64 | } |
|
65 | public override async Task<Generic.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{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) |
|
71 | { |
71 | { |
|
72 | throw new UnexpectedRadioResponseException(Name, buffer); |
72 | throw new UnexpectedRadioResponseException(Name, buffer); |