HamBook – Diff between revs 9 and 11

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 9 Rev 11
Line 35... Line 35...
35   35  
36 public override async Task<bool> SetAsync(int frequency, CancellationToken cancellation) 36 public override async Task<bool> SetAsync(int frequency, CancellationToken cancellation)
37 { 37 {
Line 38... Line 38...
38 var f = $"{frequency:000000000}"; 38 var f = $"{frequency:000000000}";
Line 39... Line 39...
39   39  
Line 40... Line 40...
40 var payload = Encoding.ASCII.GetBytes($"{Name}{f}{Generic.Constants.EOT}"); 40 var payload = Constants.Encoding.GetBytes($"{Name}{f}{Generic.Constants.EOT}");
41   41  
Line 48... Line 48...
48 { 48 {
49 SerialPort.Write($"{Name}{Generic.Constants.EOT}"); 49 SerialPort.Write($"{Name}{Generic.Constants.EOT}");
50 var buffer = new byte[CatLength.Answer]; 50 var buffer = new byte[CatLength.Answer];
51 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) 51 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer)
52 { 52 {
53 throw new ArgumentException(); 53 throw new UnexpectedRadioResponseException(Name, buffer);
54 } 54 }
Line 55... Line 55...
55   55  
56 var answer = Encoding.ASCII.GetString(buffer); 56 var answer = Constants.Encoding.GetString(buffer);
57 var match = readRegex.Match(answer); 57 var match = readRegex.Match(answer);
58 if (!match.Success) 58 if (!match.Success)
59 { 59 {
60 throw new ArgumentException(); 60 throw new UnmatchedRadioResponseException(Name, answer);
61 } 61 }
62 return int.Parse(match.Result("${frequency}")); 62 return int.Parse(match.Result("${frequency}"));
Line 63... Line 63...
63 } 63 }
64   64  
65 public override async Task<int> ReadAsync(CancellationToken cancellationToken) 65 public override async Task<int> ReadAsync(CancellationToken cancellationToken)
66 { 66 {
67 var payload = Encoding.ASCII.GetBytes($"{Name}{Generic.Constants.EOT}"); 67 var payload = Constants.Encoding.GetBytes($"{Name}{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, CatLength.Answer, cancellationToken) != CatLength.Answer) 70 if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer)
71 { 71 {
Line 72... Line 72...
72 throw new ArgumentException(); 72 throw new UnexpectedRadioResponseException(Name, buffer);
73 } 73 }
74   74  
75 var answer = Encoding.ASCII.GetString(buffer); 75 var answer = Constants.Encoding.GetString(buffer);
76 var match = readRegex.Match(answer); 76 var match = readRegex.Match(answer);
77 if (!match.Success) 77 if (!match.Success)
Line 78... Line 78...
78 { 78 {
79 throw new ArgumentException(); 79 throw new UnmatchedRadioResponseException(Name, answer);
Line 91... Line 91...
91   91  
92 public override async Task WriteAsync(int frequency, CancellationToken cancellationToken) 92 public override async Task WriteAsync(int frequency, CancellationToken cancellationToken)
93 { 93 {
Line 94... Line 94...
94 var f = $"{frequency:000000000}"; 94 var f = $"{frequency:000000000}";
Line 95... Line 95...
95   95  
96 var payload = Encoding.ASCII.GetBytes($"{Name}{f}{Generic.Constants.EOT}"); 96 var payload = Constants.Encoding.GetBytes($"{Name}{f}{Generic.Constants.EOT}");
97   97  
98 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); 98 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken);