HamBook – Diff between revs 9 and 11

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 9 Rev 11
Line 34... Line 34...
34 { 34 {
35 SerialPort.Write($"{Name}0{Generic.Constants.EOT}"); 35 SerialPort.Write($"{Name}0{Generic.Constants.EOT}");
36 var buffer = new byte[CatLength.Answer]; 36 var buffer = new byte[CatLength.Answer];
37 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) 37 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer)
38 { 38 {
39 throw new ArgumentException(); 39 throw new UnexpectedRadioResponseException(Name, buffer);
40 } 40 }
Line 41... Line 41...
41   41  
42 var answer = Encoding.ASCII.GetString(buffer); 42 var answer = Constants.Encoding.GetString(buffer);
43 var match = readRegex.Match(answer); 43 var match = readRegex.Match(answer);
44 if (!match.Success) 44 if (!match.Success)
45 { 45 {
46 throw new ArgumentException(); 46 throw new UnmatchedRadioResponseException(Name, answer);
47 } 47 }
48 var level = int.Parse(match.Result("${squelch}")); 48 var level = int.Parse(match.Result("${squelch}"));
49 return level; 49 return level;
Line 50... Line 50...
50 } 50 }
51   51  
52 public override async Task<int> ReadAsync(CancellationToken cancellationToken) 52 public override async Task<int> ReadAsync(CancellationToken cancellationToken)
53 { 53 {
Line 54... Line 54...
54 var payload = Encoding.ASCII.GetBytes($"{Name}0{Generic.Constants.EOT}"); 54 var payload = Constants.Encoding.GetBytes($"{Name}0{Generic.Constants.EOT}");
55 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); 55 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken);
56   56  
57 var buffer = new byte[CatLength.Answer]; 57 var buffer = new byte[CatLength.Answer];
58 if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) 58 if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer)
Line 59... Line 59...
59 { 59 {
60 throw new ArgumentException(); 60 throw new UnexpectedRadioResponseException(Name, buffer);
61 } 61 }
62   62  
63 var answer = Encoding.ASCII.GetString(buffer); 63 var answer = Constants.Encoding.GetString(buffer);
64 var match = readRegex.Match(answer); 64 var match = readRegex.Match(answer);
Line 65... Line 65...
65 if (!match.Success) 65 if (!match.Success)
66 { 66 {
67 throw new ArgumentException(); 67 throw new UnmatchedRadioResponseException(Name, answer);
Line 78... Line 78...
78 return Read() == level; 78 return Read() == level;
79 } 79 }
Line 80... Line 80...
80   80  
81 public override async Task<bool> SetAsync(int level, CancellationToken cancellationToken) 81 public override async Task<bool> SetAsync(int level, CancellationToken cancellationToken)
82 { 82 {
83 var payload = Encoding.ASCII.GetBytes($"{Name}0{level:000}{Generic.Constants.EOT}"); 83 var payload = Constants.Encoding.GetBytes($"{Name}0{level:000}{Generic.Constants.EOT}");
Line 84... Line 84...
84 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); 84 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken);
85   85  
Line 91... Line 91...
91 SerialPort.Write($"{Name}0{level:000}{Generic.Constants.EOT}"); 91 SerialPort.Write($"{Name}0{level:000}{Generic.Constants.EOT}");
92 } 92 }
Line 93... Line 93...
93   93  
94 public override async Task WriteAsync(int level, CancellationToken cancellationToken) 94 public override async Task WriteAsync(int level, CancellationToken cancellationToken)
95 { 95 {
Line 96... Line 96...
96 var payload = Encoding.ASCII.GetBytes($"{Name}0{level:000}{Generic.Constants.EOT}"); 96 var payload = Constants.Encoding.GetBytes($"{Name}0{level:000}{Generic.Constants.EOT}");
97   97  
98 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); 98 await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken);
99 } 99 }