forked from iliaplatone/indisharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INDIDevice.cs
673 lines (645 loc) · 17.7 KB
/
INDIDevice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
/*
MIT License
Copyright (c) 2015-2021 Ilia Platone
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
namespace INDI
{
public class INDIMessageEventArgs : IsNewMessageEventArgs
{
public INDIMessageEventArgs(string message, DateTime timestamp, string dev)
:base (message, timestamp, dev)
{
}
}
#region Enums
public enum INDIUploadMode
{
CLIENT = 0,
LOCAL,
BOTH
};
[Flags]
public enum DRIVER_INTERFACE
{
GENERAL_INTERFACE = 0, /**< Default interface for all INDI devices */
TELESCOPE_INTERFACE = (1 << 0), /**< Telescope interface, must subclass INDI::Telescope */
CCD_INTERFACE = (1 << 1), /**< CCD interface, must subclass INDI::CCD */
GUIDER_INTERFACE = (1 << 2), /**< Guider interface, must subclass INDI::GuiderInterface */
FOCUSER_INTERFACE = (1 << 3), /**< Focuser interface, must subclass INDI::FocuserInterface */
FILTER_INTERFACE = (1 << 4), /**< Filter interface, must subclass INDI::FilterInterface */
DOME_INTERFACE = (1 << 5), /**< Dome interface, must subclass INDI::Dome */
GPS_INTERFACE = (1 << 6), /**< GPS interface, must subclass INDI::GPS */
WEATHER_INTERFACE = (1 << 7), /**< Weather interface, must subclass INDI::Weather */
AO_INTERFACE = (1 << 8), /**< Adaptive Optics Interface */
DUSTCAP_INTERFACE = (1 << 9), /**< Dust Cap Interface */
LIGHTBOX_INTERFACE = (1 << 10), /**< Light Box Interface */
DETECTOR_INTERFACE = (1 << 11), /**< Detector interface, must subclass INDI::Detector */
ROTATOR_INTERFACE = (1 << 12), /**< Rotator interface, must subclass INDI::RotatorInterface */
SPECTROGRAPH_INTERFACE = (1 << 13), /**< Spectrograph interface */
AUX_INTERFACE = (1 << 15), /**< Auxiliary interface */
};
#endregion
public class INDIDevice : INDIBaseDevice, IDisposable
{
#region Constructors / Initialization
public INDIDevice(string name, INDIClient host, bool client = true)
: base(name, host, client)
{
Host.AddDevice(this);
if (!client) {
AddSwitchVector (new ISwitchVector (Name, "CONNECTION", "Connection", "", "rw", "OneOfMany", new List<INDISwitch> {
new INDISwitch ("CONNECT", "Connect", true),
new INDISwitch ("DISCONNECT", "Disconnect", false)
}));
AddTextVector (new ITextVector (Name, "DEVICE_PORT", "Connection port", "Connection", "ro", "", new List<INDIText> {
new INDIText ("PORT", "Connection port", "COM1")
}));
AddNumberVector (new INumberVector (Name, "TIME_LST", "Local sidereal time", "Device Properties", "ro", "", new List<INDINumber> {
new INDINumber ("LST", "Local sidereal time", "%16.0f", 0.0, 800000000.0, 0.0, 0.0)
}));
AddTextVector (new ITextVector (Name, "TIME_UTC", "UTC Time & Offset", "Device Properties", "ro", "", new List<INDIText> {
new INDIText ("UTC", "UTC time", "0"),
new INDIText ("OFFSET", "UTC offset", "0")
}));
AddNumberVector (new INumberVector (Name, "GEOGRAPHIC_COORD", "Earth geodetic coordinate", "Device Properties", "ro", "", new List<INDINumber> {
new INDINumber ("LAT", "Site latitude", "%2.3f", -90.0, 90.0, 0.0, 0.0),
new INDINumber ("LONG", "Site longitude", "%2.3f", 0.0, 360.0, 0.0, 0.0),
new INDINumber ("ELEV", "Site elevation", "%2.3f", 0.0, 360.0, 0.0, 0.0)
}));
AddNumberVector (new INumberVector (Name, "ATMOSPHERE", "Weather conditions", "Device Properties", "ro", "", new List<INDINumber> {
new INDINumber ("TEMPERATURE", "Temperature (K)", "%3.3f", -273.0, 180.0, 0.0, 0.0),
new INDINumber ("PRESSURE", "Pressure (hPa)", "%5.3f", 0.0, 400.0, 0.0, 0.0),
new INDINumber ("HUMIDITY", "Humidity (%)", "%3.3f", 0.0, 100.0, 0.0, 0.0)
}));
DriverInterface = DRIVER_INTERFACE.GENERAL_INTERFACE;
DriverExec = Assembly.GetCallingAssembly ().GetName ().Name;
DriverVersion = Assembly.GetCallingAssembly ().GetName ().Version.ToString ();
DriverName = Name;
}
}
public void Dispose()
{
Connected = false;
GC.Collect();
}
#endregion
#region Standard Properties
public Boolean Connected
{
get
{
try
{
return GetSwitch("CONNECTION", "CONNECT").value;
}
catch
{
}
return false;
}
set
{
try
{
if (value == true)
SetSwitchVector("CONNECTION", 0);
else
SetSwitchVector("CONNECTION", 1);
}
catch
{
}
}
}
public string DevicePort
{
get
{
try
{
return GetText("DEVICE_PORT", "PORT").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("DEVICE_PORT", "PORT", value);
}
catch { }
}
}
public Double SiderealTime
{
get
{
try
{
return GetNumber("TIME_LST", "LST").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("TIME_LST", "LST", value);
}
catch { }
}
}
public DateTime UtcTime
{
get
{
try
{
return DateTime.Parse(GetText("TIME_UTC", "UTC").value);
}
catch
{
return DateTime.UtcNow;
}
}
set
{
try
{
SetText("TIME_UTC", "UTC", value.ToShortDateString());
}
catch { }
}
}
public DateTime UtcOffset
{
get
{
try
{
return DateTime.Parse(GetText("TIME_UTC", "OFFSET").value);
}
catch
{
return new DateTime(0);
}
}
set
{
try
{
SetText("TIME_UTC", "OFFSET", value.ToShortDateString());
}
catch { }
}
}
public Double Latitude
{
get
{
try
{
return GetNumber("GEOGRAPHIC_COORD", "LAT").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("GEOGRAPHIC_COORD", "LAT", value);
}
catch { }
}
}
public Double Longitude
{
get
{
try
{
return GetNumber("GEOGRAPHIC_COORD", "Int64").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("GEOGRAPHIC_COORD", "Int64", value);
}
catch { }
}
}
public Double Elevation
{
get
{
try
{
return GetNumber("GEOGRAPHIC_COORD", "ELEV").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("GEOGRAPHIC_COORD", "ELEV", value);
}
catch { }
}
}
public Double AmbientTemperature
{
get
{
try
{
return GetNumber("ATMOSPHERE", "TEMPERATURE").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("ATMOSPHERE", "TEMPERATURE", value);
}
catch { }
}
}
public Double AmbientPressure
{
get
{
try
{
return GetNumber("ATMOSPHERE", "PRESSURE").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("ATMOSPHERE", "PRESSURE", value);
}
catch { }
}
}
public Double AmbientHumidity
{
get
{
try
{
return GetNumber("ATMOSPHERE", "HUMIDITY").value;
}
catch
{
return 0;
}
}
set
{
try
{
SetNumber("ATMOSPHERE", "HUMIDITY", value);
}
catch { }
}
}
public INDIUploadMode UploadMode
{
get
{
try
{
return (INDIUploadMode)GetSwitchVector("UPLOAD_MODE").Index;
}
catch
{
return INDIUploadMode.CLIENT;
}
}
set
{
try
{
SetSwitchVector("UPLOAD_MODE", (Int32)value);
}
catch
{
}
}
}
public string UploadDirectory
{
get
{
try
{
return GetText("UPLOAD_SETTINGS", "UPLOAD_DIR").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("UPLOAD_SETTINGS", "UPLOAD_DIR", value);
}
catch { }
}
}
public string UploadPrefix
{
get
{
try
{
return GetText("UPLOAD_SETTINGS", "UPLOAD_PREFIX").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("UPLOAD_SETTINGS", "UPLOAD_PREFIX", value);
}
catch { }
}
}
public string ActiveTelescope
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_TELESCOPE").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_TELESCOPE", value);
}
catch { }
}
}
public string ActiveCCD
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_CCD").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_CCD", value);
}
catch { }
}
}
public string ActiveFilterWheel
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_FILTER").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_FILTER", value);
}
catch { }
}
}
public string ActiveFocuser
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_FOCUSER").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_FOCUSER", value);
}
catch { }
}
}
public string ActiveDome
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_DOME").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_DOME", value);
}
catch { }
}
}
public string ActiveGPS
{
get
{
try
{
return GetText("ACTIVE_DEVICES", "ACTIVE_GPS").value;
}
catch
{
return "";
}
}
set
{
try
{
SetText("ACTIVE_DEVICES", "ACTIVE_GPS", value);
}
catch { }
}
}
public string DriverVersion
{
get
{
try
{
return GetText("DRIVER_INFO", "DRIVER_VERSION").value;
}
catch
{
return "";
}
}
internal set
{
try
{
SetText("DRIVER_INFO", "DRIVER_VERSION", value);
}
catch { }
}
}
public string DriverName
{
get
{
try
{
return GetText("DRIVER_INFO", "DRIVER_NAME").value;
}
catch
{
return "";
}
}
internal set
{
try
{
SetText("DRIVER_INFO", "DRIVER_NAME", value);
}
catch { }
}
}
public string DriverExec
{
get
{
try
{
return GetText("DRIVER_INFO", "DRIVER_EXEC").value;
}
catch
{
return "";
}
}
internal set
{
try
{
SetText("DRIVER_INFO", "DRIVER_EXEC", value);
}
catch { }
}
}
public DRIVER_INTERFACE DriverInterface
{
get
{
try
{
DRIVER_INTERFACE intf = DRIVER_INTERFACE.GENERAL_INTERFACE;
if(!Enum.TryParse(GetText("DRIVER_INFO", "DRIVER_INTERFACE").value, out intf))
return DRIVER_INTERFACE.GENERAL_INTERFACE;
return intf;
}
catch
{
return DRIVER_INTERFACE.GENERAL_INTERFACE;
}
}
internal set
{
try
{
SetText("DRIVER_INFO", "DRIVER_INTERFACE", value.ToString());
}
catch { }
}
}
#endregion
}
}