HamBook – Diff between revs 1 and 3
?pathlinks?
Rev 1 | Rev 3 | |||
---|---|---|---|---|
Line 21... | Line 21... | |||
21 | |
21 | |
|
22 | private int _count; |
22 | private int _count; |
|
23 | private SerialPort _serialPort; |
23 | private SerialPort _serialPort; |
|
Line 24... | Line 24... | |||
24 | private string _radio; |
24 | private string _radio; |
|
Line 25... | Line 25... | |||
25 | |
25 | |
|
26 | private readonly ConcurrentDictionary<string, Cat> _catCommands; |
26 | private ConcurrentDictionary<string, Cat> _catCommands; |
|
27 | |
27 | |
|
28 | private CatAssemblies() |
28 | private CatAssemblies() |
|
Line 122... | Line 122... | |||
122 | _catCommands.Clear(); |
122 | _catCommands.Clear(); |
|
123 | } |
123 | } |
|
Line 124... | Line 124... | |||
124 | |
124 | |
|
125 | public async Task CatSet<T>(string command, object[] param, CancellationToken cancellationToken) |
125 | public async Task CatSet<T>(string command, object[] param, CancellationToken cancellationToken) |
|
- | 126 | { |
||
- | 127 | if (!_serialPort.IsOpen) |
||
126 | { |
128 | { |
|
- | 129 | _serialPort.Open(); |
||
- | 130 | } |
||
127 | _serialPort.Open(); |
131 | |
|
128 | try |
132 | try |
|
129 | { |
133 | { |
|
130 | if (_catCommands.TryGetValue(command, out var catCommand)) |
134 | if (_catCommands.TryGetValue(command, out var catCommand)) |
|
131 | { |
135 | { |
|
Line 139... | Line 143... | |||
139 | } |
143 | } |
|
140 | } |
144 | } |
|
141 | } |
145 | } |
|
142 | finally |
146 | finally |
|
143 | { |
147 | { |
|
- | 148 | if (_serialPort.IsOpen) |
||
- | 149 | { |
||
144 | _serialPort.Close(); |
150 | _serialPort.Close(); |
|
- | 151 | } |
||
145 | } |
152 | } |
|
146 | } |
153 | } |
|
Line 147... | Line 154... | |||
147 | |
154 | |
|
148 | public void CatSet<T>(string command, object[] param) |
155 | public void CatSet<T>(string command, object[] param) |
|
- | 156 | { |
||
- | 157 | if (!_serialPort.IsOpen) |
||
149 | { |
158 | { |
|
- | 159 | _serialPort.Open(); |
||
- | 160 | } |
||
150 | _serialPort.Open(); |
161 | |
|
151 | try |
162 | try |
|
152 | { |
163 | { |
|
153 | if (_catCommands.TryGetValue(command, out var catCommand)) |
164 | if (_catCommands.TryGetValue(command, out var catCommand)) |
|
154 | { |
165 | { |
|
Line 159... | Line 170... | |||
159 | } |
170 | } |
|
160 | } |
171 | } |
|
161 | } |
172 | } |
|
162 | finally |
173 | finally |
|
163 | { |
174 | { |
|
- | 175 | if (_serialPort.IsOpen) |
||
- | 176 | { |
||
- | 177 | _serialPort.Close(); |
||
- | 178 | } |
||
- | 179 | } |
||
- | 180 | } |
||
- | 181 | |
||
- | 182 | public T CatGetDefault<T>(string command, object[] param) |
||
- | 183 | { |
||
- | 184 | if (!_serialPort.IsOpen) |
||
- | 185 | { |
||
- | 186 | _serialPort.Open(); |
||
- | 187 | } |
||
- | 188 | |
||
- | 189 | try |
||
- | 190 | { |
||
- | 191 | if (_catCommands.TryGetValue(command, out var catCommand)) |
||
- | 192 | { |
||
- | 193 | var methodInfo = catCommand.GetType().GetMethod("GetDefault"); |
||
- | 194 | if (methodInfo != null) |
||
- | 195 | { |
||
- | 196 | return (T)methodInfo.Invoke(catCommand, param); |
||
- | 197 | } |
||
- | 198 | } |
||
- | 199 | } |
||
- | 200 | finally |
||
- | 201 | { |
||
- | 202 | if (_serialPort.IsOpen) |
||
- | 203 | { |
||
- | 204 | _serialPort.Close(); |
||
- | 205 | } |
||
- | 206 | } |
||
- | 207 | |
||
- | 208 | return default; |
||
- | 209 | } |
||
- | 210 | |
||
- | 211 | public T CatParse<T>(string command, object[] param) |
||
- | 212 | { |
||
- | 213 | if (!_serialPort.IsOpen) |
||
- | 214 | { |
||
- | 215 | _serialPort.Open(); |
||
- | 216 | } |
||
- | 217 | |
||
- | 218 | try |
||
- | 219 | { |
||
- | 220 | if (_catCommands.TryGetValue(command, out var catCommand)) |
||
- | 221 | { |
||
- | 222 | var methodInfo = catCommand.GetType().GetMethod("Parse"); |
||
- | 223 | if (methodInfo != null) |
||
- | 224 | { |
||
- | 225 | return (T)methodInfo.Invoke(catCommand, param); |
||
- | 226 | } |
||
- | 227 | } |
||
- | 228 | } |
||
- | 229 | finally |
||
- | 230 | { |
||
- | 231 | if (_serialPort.IsOpen) |
||
- | 232 | { |
||
164 | _serialPort.Close(); |
233 | _serialPort.Close(); |
|
- | 234 | } |
||
165 | } |
235 | } |
|
- | 236 | |
||
- | 237 | return default; |
||
166 | } |
238 | } |
|
Line 167... | Line 239... | |||
167 | |
239 | |
|
168 | public T CatRead<T>(string command, object[] param) |
240 | public T CatRead<T>(string command, object[] param) |
|
- | 241 | { |
||
- | 242 | if (!_serialPort.IsOpen) |
||
169 | { |
243 | { |
|
- | 244 | _serialPort.Open(); |
||
- | 245 | } |
||
170 | _serialPort.Open(); |
246 | |
|
171 | try |
247 | try |
|
172 | { |
248 | { |
|
173 | if (_catCommands.TryGetValue(command, out var catCommand)) |
249 | if (_catCommands.TryGetValue(command, out var catCommand)) |
|
174 | { |
250 | { |
|
Line 179... | Line 255... | |||
179 | } |
255 | } |
|
180 | } |
256 | } |
|
181 | } |
257 | } |
|
182 | finally |
258 | finally |
|
183 | { |
259 | { |
|
- | 260 | if (_serialPort.IsOpen) |
||
- | 261 | { |
||
184 | _serialPort.Close(); |
262 | _serialPort.Close(); |
|
- | 263 | } |
||
185 | } |
264 | } |
|
Line 186... | Line 265... | |||
186 | |
265 | |
|
187 | return default; |
266 | return default; |
|
Line 188... | Line 267... | |||
188 | } |
267 | } |
|
189 | |
268 | |
|
- | 269 | public async Task<T> CatRead<T>(string command, object[] param, CancellationToken cancellationToken) |
||
- | 270 | { |
||
190 | public async Task<T> CatRead<T>(string command, object[] param, CancellationToken cancellationToken) |
271 | if (!_serialPort.IsOpen) |
|
- | 272 | { |
||
- | 273 | _serialPort.Open(); |
||
191 | { |
274 | } |
|
192 | _serialPort.Open(); |
275 | |
|
193 | try |
276 | try |
|
194 | { |
277 | { |
|
195 | if (_catCommands.TryGetValue(command, out var catCommand)) |
278 | if (_catCommands.TryGetValue(command, out var catCommand)) |
|
Line 204... | Line 287... | |||
204 | } |
287 | } |
|
205 | } |
288 | } |
|
206 | } |
289 | } |
|
207 | finally |
290 | finally |
|
208 | { |
291 | { |
|
- | 292 | if (_serialPort.IsOpen) |
||
- | 293 | { |
||
209 | _serialPort.Close(); |
294 | _serialPort.Close(); |
|
- | 295 | } |
||
210 | } |
296 | } |
|
Line 211... | Line 297... | |||
211 | |
297 | |
|
212 | return default; |
298 | return default; |
|
213 | } |
299 | } |