HamBook – Diff between revs 19 and 41
?pathlinks?
Rev 19 | Rev 41 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | |
20 | |
|
Line 21... | Line 21... | |||
21 | public override CatLength CatLength => new CatLength { Set = 6, Read = 3, Answer = 6 }; |
21 | public override CatLength CatLength => new CatLength { Set = 6, Read = 3, Answer = 6 }; |
|
22 | |
22 | |
|
23 | public MC(SerialPortStream serialPort) : base(serialPort) |
23 | public MC(SerialPortStream serialPort) : base(serialPort) |
|
24 | { |
24 | { |
|
Line 25... | Line 25... | |||
25 | readRegex = new Regex($"^{Name}(?<channel>[0-9]{{3}}){HamBook.Radios.Generic.Constants.EOT}$", RegexOptions.Compiled); |
25 | readRegex = new Regex($"^{Name}(?<channel>[0-9PLU]{{3}}){HamBook.Radios.Generic.Constants.EOT}$", RegexOptions.Compiled); |
|
26 | } |
26 | } |
|
27 | |
27 | |
|
28 | public override int Read() |
28 | public override string Read() |
|
29 | { |
29 | { |
|
30 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
30 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
|
Line 38... | Line 38... | |||
38 | var match = readRegex.Match(answer); |
38 | var match = readRegex.Match(answer); |
|
39 | if (!match.Success) |
39 | if (!match.Success) |
|
40 | { |
40 | { |
|
41 | throw new UnmatchedRadioResponseException(Name, answer); |
41 | throw new UnmatchedRadioResponseException(Name, answer); |
|
42 | } |
42 | } |
|
43 | return int.Parse(match.Result("${channel}")); |
43 | return $"{match.Result("${channel}")}"; |
|
44 | } |
44 | } |
|
Line 45... | Line 45... | |||
45 | |
45 | |
|
46 | public override async Task<int> ReadAsync(CancellationToken cancellationToken) |
46 | public override async Task<string> ReadAsync(CancellationToken cancellationToken) |
|
47 | { |
47 | { |
|
48 | var payload = Constants.Encoding.GetBytes($"{Name}{Generic.Constants.EOT}"); |
48 | var payload = Constants.Encoding.GetBytes($"{Name}{Generic.Constants.EOT}"); |
|
49 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
49 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
50 | var buffer = new byte[CatLength.Answer]; |
50 | var buffer = new byte[CatLength.Answer]; |
|
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 | } |
|
Line 62... | Line 62... | |||
62 | |
62 | |
|
63 | return int.Parse(match.Result("${channel}")); |
63 | return $"{match.Result("${channel}")}"; |
|
Line 64... | Line 64... | |||
64 | } |
64 | } |
|
65 | |
65 | |
|
66 | public override bool Set(int channel) |
66 | public override bool Set(string channel) |
|
Line 67... | Line 67... | |||
67 | { |
67 | { |
|
Line 68... | Line 68... | |||
68 | var payload = Constants.Encoding.GetBytes($"{Name}{channel:000}{Generic.Constants.EOT}"); |
68 | var payload = Constants.Encoding.GetBytes($"{Name}{channel}{Generic.Constants.EOT}"); |
|
69 | |
69 | |
|
Line 70... | Line 70... | |||
70 | SerialPort.Write(payload, 0, payload.Length); |
70 | SerialPort.Write(payload, 0, payload.Length); |
|
71 | |
71 | |
|
72 | return Read() == channel; |
72 | return Read() == channel; |
|
Line 73... | Line 73... | |||
73 | } |
73 | } |
|
Line 74... | Line 74... | |||
74 | |
74 | |
|
75 | public override async Task<bool> SetAsync(int channel, CancellationToken cancellationToken) |
75 | public override async Task<bool> SetAsync(string channel, CancellationToken cancellationToken) |
|
Line 76... | Line 76... | |||
76 | { |
76 | { |
|
77 | var payload = Constants.Encoding.GetBytes($"{Name}{channel:000}{Generic.Constants.EOT}"); |
77 | var payload = Constants.Encoding.GetBytes($"{Name}{channel}{Generic.Constants.EOT}"); |
|
78 | |
78 | |
|
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
Line 80... | Line 80... | |||
80 | |
80 | |
|
81 | return await ReadAsync(cancellationToken) == channel; |
81 | return await ReadAsync(cancellationToken) == channel; |
|
82 | } |
82 | } |
|
Line 83... | Line 83... | |||
83 | |
83 | |
|
84 | public override void Write(int channel) |
84 | public override void Write(string channel) |
|
85 | { |
85 | { |
|
86 | SerialPort.Write($"{Name}{channel:000}{Generic.Constants.EOT}"); |
86 | SerialPort.Write($"{Name}{channel}{Generic.Constants.EOT}"); |