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