HamBook – Diff between revs 46 and 54

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 46 Rev 54
Line 1... Line -...
1 using System; -  
2 using System.Collections.Generic; 1 using System.Text.RegularExpressions;
3 using System.ComponentModel; -  
4 using System.IO.Ports; -  
5 using System.Linq; -  
6 using System.Text; 2 using System.Threading;
7 using System.Threading.Tasks; 3 using System.Threading.Tasks;
8 using HamBook.Radios.Generic; 4 using HamBook.Radios.Generic;
9 using static HamBook.Radios.Yaesu.FT_891.Constants; -  
10 using RJCP.IO.Ports; 5 using RJCP.IO.Ports;
11 using System.Text.RegularExpressions; 6 using static HamBook.Radios.Yaesu.FT_891.Constants;
12 using System.Threading; -  
Line 13... Line 7...
13   7  
14 namespace HamBook.Radios.Yaesu.FT_891.CAT 8 namespace HamBook.Radios.Yaesu.FT_891.CAT
15 { 9 {
16 [Radio("Yaesu FT-891")] 10 [Radio("Yaesu FT-891")]
17 public class MR : Generic.CAT.MR 11 public class Mr : Generic.CAT.Mr
18 { 12 {
19 private readonly Regex readRegex; -  
20   -  
Line 21... Line 13...
21 public override CatLength CatLength => new CatLength { Set = 41, Read = 6, Answer = 41 }; 13 private readonly Regex _readRegex;
22   14  
23 public MR(SerialPortStream serialPort) : base(serialPort) 15 public Mr(SerialPortStream serialPort) : base(serialPort)
24 { 16 {
25 /// MTP9U026965000+0000004100001AAAAAAAAAAAA; 17 /// MTP9U026965000+0000004100001AAAAAAAAAAAA;
-   18 /// ^---- fixed: 0 in operation manual, but responds 1; looks like a radio bug
-   19 _readRegex = new Regex(
26 /// ^---- fixed: 0 in operation manual, but responds 1; looks like a radio bug 20 $"^{Name}(?<currentLocation>[0-9PLU]{{3}})(?<frequency>[0-9]{{9}})(?<clarifierDirection>[\\+\\-]{{1}})(?<clarifierOffset>[0-9]{{4}})(?<clar>[01]{{1}})0(?<mode>[123456789ABCD]{{1}})[0-9]{{1}}(?<storage>[01]{{1}})(?<ctcssMode>[012]{{1}})00(?<phase>[012]{{1}}){Eot}$",
Line -... Line 21...
-   21 RegexOptions.Compiled);
-   22 }
27 readRegex = new Regex($"^{Name}(?<currentLocation>[0-9PLU]{{3}})(?<frequency>[0-9]{{9}})(?<clarifierDirection>[\\+\\-]{{1}})(?<clarifierOffset>[0-9]{{4}})(?<clar>[01]{{1}})0(?<mode>[123456789ABCD]{{1}})[0-9]{{1}}(?<storage>[01]{{1}})(?<ctcssMode>[012]{{1}})00(?<phase>[012]{{1}}){Constants.EOT}$", RegexOptions.Compiled); 23  
28 } 24 public override CatLength CatLength => new CatLength { Set = 41, Read = 6, Answer = 41 };
29   25  
30 public override Generic.MemoryChannel Read(string location) 26 public override Generic.MemoryChannel Read(string location)
31 { 27 {
32 SerialPort.Write($"{Name}{location}{Constants.EOT}"); -  
33 var buffer = new byte[CatLength.Answer]; 28 SerialPort.Write($"{Name}{location}{Eot}");
34 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) -  
Line 35... Line 29...
35 { 29 var buffer = new byte[CatLength.Answer];
Line 36... Line 30...
36 throw new UnexpectedRadioResponseException(Name, buffer); 30 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer)
37 } 31 throw new UnexpectedRadioResponseException(Name, buffer);
Line 38... Line 32...
38   32  
-   33 var answer = Encoding.GetString(buffer);
39 var answer = Constants.Encoding.GetString(buffer); 34  
40   35 return Parse(answer);
41 return Parse(answer); 36 }
42 } 37  
43   38 public override async Task<Generic.MemoryChannel> ReadAsync(string location,
44 public override async Task<Generic.MemoryChannel> ReadAsync(string location, CancellationToken cancellationToken) -  
45 { 39 CancellationToken cancellationToken)
46 var payload = Constants.Encoding.GetBytes($"{Name}{location}{Constants.EOT}"); -  
Line 47... Line 40...
47 await SerialPort.WriteAsync(payload, 0, payload.Length); 40 {
Line 48... Line 41...
48 var buffer = new byte[CatLength.Answer]; 41 var payload = Encoding.GetBytes($"{Name}{location}{Eot}");
49 if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer) != CatLength.Answer) 42 await SerialPort.WriteAsync(payload, 0, payload.Length);
Line 50... Line 43...
50 { 43 var buffer = new byte[CatLength.Answer];
51 throw new UnexpectedRadioResponseException(Name, buffer); 44 if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer) != CatLength.Answer)
52 } 45 throw new UnexpectedRadioResponseException(Name, buffer);
Line 53... Line -...
53   -  
54 var answer = Constants.Encoding.GetString(buffer); -  
55   46  
56 return Parse(answer); -  
Line 57... Line 47...
57 } 47 var answer = Encoding.GetString(buffer);
58   48  
59 private MemoryChannel Parse(string input) 49 return Parse(answer);
60 { 50 }
Line 86... Line 76...
86 MemoryRadioMode = new MemoryRadioMode(radioMode), 76 MemoryRadioMode = new MemoryRadioMode(radioMode),
87 Ctcss = new Ctcss(ctcss), 77 Ctcss = new Ctcss(ctcss),
88 Phase = new Phase(phase), 78 Phase = new Phase(phase),
89 Tag = tag, 79 Tag = tag,
90 Text = text 80 Text = text
91   -  
92 }; 81 };
Line 93... Line 82...
93   82  
94 return memoryChannel; 83 return memoryChannel;
95 } 84 }
96 } 85 }
97 } 86 }