HamBook – Blame information for rev 54
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
54 | office | 1 | using System.Text.RegularExpressions; |
2 | using System.Threading; |
||
15 | office | 3 | using System.Threading.Tasks; |
4 | using HamBook.Radios.Generic; |
||
54 | office | 5 | using RJCP.IO.Ports; |
15 | office | 6 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
7 | |||
8 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
||
9 | { |
||
10 | [Radio("Yaesu FT-891")] |
||
54 | office | 11 | public class Mr : Generic.CAT.Mr |
15 | office | 12 | { |
54 | office | 13 | private readonly Regex _readRegex; |
15 | office | 14 | |
54 | office | 15 | public Mr(SerialPortStream serialPort) : base(serialPort) |
15 | office | 16 | { |
17 | /// MTP9U026965000+0000004100001AAAAAAAAAAAA; |
||
41 | office | 18 | /// ^---- fixed: 0 in operation manual, but responds 1; looks like a radio bug |
54 | office | 19 | _readRegex = new Regex( |
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}$", |
||
21 | RegexOptions.Compiled); |
||
15 | office | 22 | } |
23 | |||
54 | office | 24 | public override CatLength CatLength => new CatLength { Set = 41, Read = 6, Answer = 41 }; |
25 | |||
46 | office | 26 | public override Generic.MemoryChannel Read(string location) |
15 | office | 27 | { |
54 | office | 28 | SerialPort.Write($"{Name}{location}{Eot}"); |
15 | office | 29 | var buffer = new byte[CatLength.Answer]; |
30 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
||
31 | throw new UnexpectedRadioResponseException(Name, buffer); |
||
32 | |||
54 | office | 33 | var answer = Encoding.GetString(buffer); |
15 | office | 34 | |
35 | return Parse(answer); |
||
36 | } |
||
37 | |||
54 | office | 38 | public override async Task<Generic.MemoryChannel> ReadAsync(string location, |
39 | CancellationToken cancellationToken) |
||
15 | office | 40 | { |
54 | office | 41 | var payload = Encoding.GetBytes($"{Name}{location}{Eot}"); |
15 | office | 42 | await SerialPort.WriteAsync(payload, 0, payload.Length); |
43 | var buffer = new byte[CatLength.Answer]; |
||
44 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer) != CatLength.Answer) |
||
45 | throw new UnexpectedRadioResponseException(Name, buffer); |
||
46 | |||
54 | office | 47 | var answer = Encoding.GetString(buffer); |
15 | office | 48 | |
49 | return Parse(answer); |
||
50 | } |
||
51 | |||
46 | office | 52 | private MemoryChannel Parse(string input) |
15 | office | 53 | { |
54 | office | 54 | var match = _readRegex.Match(input); |
15 | office | 55 | |
54 | office | 56 | if (!match.Success) throw new UnmatchedRadioResponseException(Name, input); |
15 | office | 57 | |
58 | var currentLocation = match.Result("${currentLocation}"); |
||
59 | var frequency = int.Parse(match.Result("${frequency}")); |
||
60 | var clarifierDirection = char.Parse(match.Result("${clarifierDirection}")); |
||
61 | var clarifierOffset = int.Parse(match.Result("${clarifierOffset}")); |
||
62 | var clar = int.Parse(match.Result("${clar}")) == 0 ? false : true; |
||
63 | var radioMode = char.Parse(match.Result("${mode}")); |
||
46 | office | 64 | var ctcss = int.Parse(match.Result("${ctcssMode}")); |
15 | office | 65 | var phase = int.Parse(match.Result("${phase}")); |
66 | var tag = int.Parse(match.Result("${tag}")) == 0 ? false : true; |
||
67 | var text = match.Result("${text}"); |
||
68 | |||
69 | var memoryChannel = new MemoryChannel |
||
70 | { |
||
71 | CurrentLocation = currentLocation, |
||
72 | Frequency = frequency, |
||
73 | ClarifierDirection = clarifierDirection, |
||
74 | ClarifierOffset = clarifierOffset, |
||
75 | Clar = clar, |
||
44 | office | 76 | MemoryRadioMode = new MemoryRadioMode(radioMode), |
46 | office | 77 | Ctcss = new Ctcss(ctcss), |
78 | Phase = new Phase(phase), |
||
15 | office | 79 | Tag = tag, |
80 | Text = text |
||
81 | }; |
||
82 | |||
83 | return memoryChannel; |
||
84 | } |
||
85 | } |
||
54 | office | 86 | } |