HamBook – Blame information for rev 15

Subversion Repositories:
Rev:
Rev Author Line No. Line
15 office 1 using Org.BouncyCastle.Crypto.Tls;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7  
8 namespace HamBook.Radios.Generic
9 {
10 public class MemoryRadioMode
11 {
12 public char Mode { get; private set; }
13  
14 public MemoryRadioMode(string mode)
15 {
16 Mode = Parse(mode);
17 }
18  
19 public MemoryRadioMode(char mode)
20 {
21 Mode = Parse(mode);
22 }
23  
24 public static bool TryParse(string mode, out MemoryRadioMode memoryRadioMode)
25 {
26 switch (mode)
27 {
28  
29 case "LSB":
30 case "USB":
31 case "CW":
32 case "FM":
33 case "AM":
34 case "RTTY-LSB":
35 case "CW-R":
36 case "DATA-LSB":
37 case "RTTY-USB":
38 case "FM-N":
39 case "DATA-USB":
40 case "AM-N":
41 memoryRadioMode = new MemoryRadioMode(mode);
42 return true;
43 default:
44 memoryRadioMode = null;
45 return false;
46 }
47 }
48  
49 public static bool TryParse(char mode, out MemoryRadioMode memoryRadioMode)
50 {
51 switch (mode)
52 {
53 case '1':
54 case '2':
55 case '3':
56 case '4':
57 case '5':
58 case '6':
59 case '7':
60 case '8':
61 case '9':
62 case 'B':
63 case 'C':
64 case 'D':
65 memoryRadioMode = new MemoryRadioMode(mode);
66 return true;
67 default:
68 memoryRadioMode = null;
69 return false;
70 }
71 }
72  
73 private char Parse(string mode)
74 {
75 switch (mode)
76 {
77 case "LSB":
78 return '1';
79 case "USB":
80 return '2';
81 case "CW":
82 return '3';
83 case "FM":
84 return '4';
85 case "AM":
86 return '5';
87 case "RTTY-LSB":
88 return '6';
89 case "CW-R":
90 return '7';
91 case "DATA-LSB":
92 return '8';
93 case "RTTY-USB":
94 return '9';
95 case "FM-N":
96 return 'B';
97 case "DATA-USB":
98 return 'C';
99 case "AM-N":
100 return 'D';
101 default:
102 throw new ArgumentException();
103 }
104 }
105  
106 private char Parse(char mode)
107 {
108 switch (mode)
109 {
110 case '1':
111 case '2':
112 case '3':
113 case '4':
114 case '5':
115 case '6':
116 case '7':
117 case '8':
118 case '9':
119 case 'B':
120 case 'C':
121 case 'D':
122 return mode;
123 default:
124 throw new ArgumentException();
125 }
126 }
127  
128 public static implicit operator MemoryRadioMode(string mode)
129 {
130 return new MemoryRadioMode(mode);
131 }
132  
133 public static implicit operator string(MemoryRadioMode memoryRadioMode)
134 {
135 switch (memoryRadioMode.Mode)
136 {
137 case '1':
138 return "LSB";
139 case '2':
140 return "USB";
141 case '3':
142 return "CW";
143 case '4':
144 return "FM";
145 case '5':
146 return "AM";
147 case '6':
148 return "RTTY-USB";
149 case '7':
150 return "CW-R";
151 case '8':
152 return "DATA-LSB";
153 case '9':
154 return "RTTY-USB";
155 case 'B':
156 return "FM-N";
157 case 'C':
158 return "DATA-USB";
159 case 'D':
160 return "AM-N";
161 default:
162 throw new ArgumentException();
163 }
164 }
165  
166 public static implicit operator MemoryRadioMode(char mode)
167 {
168 return new MemoryRadioMode(mode);
169 }
170  
171 public static implicit operator char(MemoryRadioMode memoryRadioMode)
172 {
173 return memoryRadioMode.Mode;
174 }
175 }
176 }