HamBook – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 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 namespace HamBook.Radios.Yaesu.FT_891
16 {
17 [Radio("Yaesu FT-891")]
18 public class MD : Generic.CAT.MD
19 {
20 private static readonly Regex readRegex = new Regex(@"^MD0(?<mode>[1,2,3,4,5,6,7,8,9,A,B,C,D])$", RegexOptions.Compiled);
21  
22 public MD(SerialPort serialPort) : base(serialPort)
23 {
24 }
25  
26 public override void Set(RadioMode mode)
27 {
28 switch(mode)
29 {
30 case RadioMode.SSB_1:
31 SerialPort.Write($"{Name}01{EOT}");
32 break;
33 case RadioMode.SSB_2:
34 SerialPort.Write($"{Name}02{EOT}");
35 break;
36 case RadioMode.AM:
37 SerialPort.Write($"{Name}05{EOT}");
38 break;
39 case RadioMode.FM:
40 SerialPort.Write($"{Name}04{EOT}");
41 break;
42 case RadioMode.CW:
43 SerialPort.Write($"{Name}03{EOT}");
44 break;
45 }
46 }
47  
48 public override RadioMode Read()
49 {
50 SerialPort.Write($"{Name}0{EOT}");
51 var result = SerialPort.ReadTo(EOT);
52 var match = readRegex.Match(result);
53 var value = char.Parse(match.Result("${mode}"));
54 switch(value)
55 {
56 case '1':
57 return RadioMode.SSB_1;
58 case '2':
59 return RadioMode.SSB_2;
60 case '5':
61 return RadioMode.AM;
62 case '4':
63 return RadioMode.FM;
64 case '3':
65 return RadioMode.CW;
66 }
67  
68 return RadioMode.NONE;
69 }
70 }
71 }