HamBook – Blame information for rev 54
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
54 | office | 1 | using System.Text.RegularExpressions; |
2 | using HamBook.Radios.Generic; |
||
3 | using RJCP.IO.Ports; |
||
1 | office | 4 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
5 | |||
9 | office | 6 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
1 | office | 7 | { |
8 | [Radio("Yaesu FT-891")] |
||
54 | office | 9 | public class Sc : Generic.CAT.Sc |
1 | office | 10 | { |
54 | office | 11 | private readonly Regex _readRegex; |
1 | office | 12 | |
54 | office | 13 | public Sc(SerialPortStream serialPort) : base(serialPort) |
1 | office | 14 | { |
54 | office | 15 | _readRegex = new Regex($"^{Name}(?<state>[012]){Eot}$", RegexOptions.Compiled); |
1 | office | 16 | } |
17 | |||
54 | office | 18 | public override CatLength CatLength => new CatLength { Set = 4, Answer = 4, Read = 3 }; |
19 | |||
1 | office | 20 | public override ScanState Read() |
21 | { |
||
54 | office | 22 | SerialPort.Write($"{Name}{Eot}"); |
9 | office | 23 | var buffer = new byte[CatLength.Answer]; |
24 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
||
11 | office | 25 | throw new UnexpectedRadioResponseException(Name, buffer); |
9 | office | 26 | |
54 | office | 27 | var answer = Encoding.GetString(buffer); |
28 | var match = _readRegex.Match(answer); |
||
29 | if (!match.Success) throw new UnmatchedRadioResponseException(Name, answer); |
||
1 | office | 30 | var state = char.Parse(match.Result("${state}")); |
54 | office | 31 | switch (state) |
1 | office | 32 | { |
33 | case '0': |
||
34 | return ScanState.OFF; |
||
35 | case '1': |
||
36 | return ScanState.UP; |
||
37 | case '2': |
||
38 | return ScanState.DOWN; |
||
39 | } |
||
40 | |||
41 | return ScanState.NONE; |
||
42 | } |
||
43 | |||
7 | office | 44 | public override bool Set(ScanState state) |
1 | office | 45 | { |
54 | office | 46 | switch (state) |
1 | office | 47 | { |
48 | case ScanState.OFF: |
||
54 | office | 49 | SerialPort.Write($"{Name}0{Eot}"); |
1 | office | 50 | break; |
51 | case ScanState.UP: |
||
54 | office | 52 | SerialPort.Write($"{Name}1{Eot}"); |
1 | office | 53 | break; |
54 | case ScanState.DOWN: |
||
54 | office | 55 | SerialPort.Write($"{Name}2{Eot}"); |
1 | office | 56 | break; |
57 | } |
||
7 | office | 58 | |
59 | return Read() == state; |
||
1 | office | 60 | } |
61 | } |
||
54 | office | 62 | } |