HamBook – Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
3 office 1 using HamBook.Radios.Generic;
2 using Newtonsoft.Json.Linq;
3 using System;
4 using System.Collections.Concurrent;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.IO.Ports;
8 using System.Linq;
9 using System.Reflection;
10 using System.Text;
11 using System.Text.RegularExpressions;
12 using System.Threading.Tasks;
13 using static HamBook.Radios.Yaesu.FT_891.Constants;
14  
15  
16 namespace HamBook.Radios.Yaesu.FT_891.CAT
17 {
18 [Radio("Yaesu FT-891")]
19 public class AI : Generic.CAT.AI
20 {
21 private static readonly Regex readRegex = new Regex(@"^AI(?<state>[0,1])$", RegexOptions.Compiled);
22  
23 public AI(SerialPort serialPort) : base(serialPort)
24 {
25 }
26  
27 public override InformationState Read()
28 {
29 SerialPort.Write($"{Name}{Generic.Constants.EOT}");
30 var result = SerialPort.ReadTo(Generic.Constants.EOT);
31 var match = readRegex.Match(result);
32 var state = (InformationState)int.Parse(match.Result("${state}"));
33  
34 return state;
35 }
36  
37 public override void Set(InformationState state)
38 {
39 SerialPort.Write($"{Name}{(int)state}{Generic.Constants.EOT}");
40 }
41  
42 public override Information Parse(string input)
43 {
44 var match = InformationRegex.Match(input);
45  
46 if(!match.Success)
47 {
48 return null;
49 }
50  
51 var radioBank = int.Parse(match.Result("${radioBank}"));
52 var frequency = int.Parse(match.Result("${frequency}"));
53 var clarifierDirection = char.Parse(match.Result("${clarifierDirection}"));
54 var clarifierOffset = int.Parse(match.Result("${clarifierOffset}"));
55 var clar = int.Parse(match.Result("${clar}"));
56 var radioMode = char.Parse(match.Result("${mode}"));
57 var storage = (RadioStorage)int.Parse(match.Result("${storage}"));
58 var ctcssMode = (CtcssMode)int.Parse(match.Result("${ctcssMode}"));
59 var phase = (RadioPhase)int.Parse(match.Result("${phase}"));
60  
61 var information = new Information
62 {
63 RadioBank = radioBank,
64 Frequency = frequency,
65 ClarifierDirection = clarifierDirection,
66 ClarifierOffset = clarifierOffset,
67 Clar = clar,
68 RadioMode = radioMode,
69 Storage = storage,
70 CtcssMode = ctcssMode,
71 Phase =phase
72 };
73  
74 return information;
75 }
76 }
77 }