/
inditelescope.cpp
3128 lines (2725 loc) · 104 KB
/
inditelescope.cpp
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
Copyright(c) 2011 Gerry Rozema, Jasem Mutlaq. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/
#include "inditelescope.h"
#include "indicom.h"
#include "indicontroller.h"
#include "connectionplugins/connectionserial.h"
#include "connectionplugins/connectiontcp.h"
#include <libnova/sidereal_time.h>
#include <libnova/transform.h>
#include <cmath>
#include <cerrno>
#include <pwd.h>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <unistd.h>
#include <wordexp.h>
#include <limits>
namespace INDI
{
Telescope::Telescope()
: DefaultDevice(), ScopeConfigFileName(GetHomeDirectory() + "/.indi/ScopeConfig.xml"),
ParkDataFileName(GetHomeDirectory() + "/.indi/ParkData.xml")
{
controller = new Controller(this);
controller->setJoystickCallback(joystickHelper);
controller->setAxisCallback(axisHelper);
controller->setButtonCallback(buttonHelper);
currentPierSide = PIER_EAST;
lastPierSide = PIER_UNKNOWN;
currentPECState = PEC_OFF;
lastPECState = PEC_UNKNOWN;
}
Telescope::~Telescope()
{
if (ParkdataXmlRoot)
delXMLEle(ParkdataXmlRoot);
delete (controller);
}
bool Telescope::initProperties()
{
DefaultDevice::initProperties();
// Active Devices
IUFillText(&ActiveDeviceT[0], "ACTIVE_GPS", "GPS", "GPS Simulator");
IUFillText(&ActiveDeviceT[1], "ACTIVE_DOME", "DOME", "Dome Simulator");
IUFillTextVector(&ActiveDeviceTP, ActiveDeviceT, 2, getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB,
IP_RW, 60, IPS_IDLE);
// Use locking if dome is closed (and or) park scope if dome is closing
IUFillSwitch(&DomePolicyS[DOME_IGNORED], "DOME_IGNORED", "Dome ignored", ISS_ON);
IUFillSwitch(&DomePolicyS[DOME_LOCKS], "DOME_LOCKS", "Dome locks", ISS_OFF);
// IUFillSwitch(&DomeClosedLockT[2], "FORCE_CLOSE", "Dome parks", ISS_OFF);
// IUFillSwitch(&DomeClosedLockT[3], "LOCK_AND_FORCE", "Both", ISS_OFF);
IUFillSwitchVector(&DomePolicySP, DomePolicyS, 2, getDeviceName(), "DOME_POLICY", "Dome Policy", OPTIONS_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_IDLE);
IUFillNumber(&EqN[AXIS_RA], "RA", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
IUFillNumber(&EqN[AXIS_DE], "DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
IUFillNumberVector(&EqNP, EqN, 2, getDeviceName(), "EQUATORIAL_EOD_COORD", "Eq. Coordinates", MAIN_CONTROL_TAB,
IP_RW, 60, IPS_IDLE);
lastEqState = IPS_IDLE;
IUFillNumber(&TargetN[AXIS_RA], "RA", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
IUFillNumber(&TargetN[AXIS_DE], "DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
IUFillNumberVector(&TargetNP, TargetN, 2, getDeviceName(), "TARGET_EOD_COORD", "Slew Target", MOTION_TAB, IP_RO, 60,
IPS_IDLE);
IUFillSwitch(&ParkOptionS[PARK_CURRENT], "PARK_CURRENT", "Current", ISS_OFF);
IUFillSwitch(&ParkOptionS[PARK_DEFAULT], "PARK_DEFAULT", "Default", ISS_OFF);
IUFillSwitch(&ParkOptionS[PARK_WRITE_DATA], "PARK_WRITE_DATA", "Write Data", ISS_OFF);
IUFillSwitch(&ParkOptionS[PARK_PURGE_DATA], "PARK_PURGE_DATA", "Purge Data", ISS_OFF);
IUFillSwitchVector(&ParkOptionSP, ParkOptionS, 4, getDeviceName(), "TELESCOPE_PARK_OPTION", "Park Options",
SITE_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
IUFillText(&TimeT[0], "UTC", "UTC Time", nullptr);
IUFillText(&TimeT[1], "OFFSET", "UTC Offset", nullptr);
IUFillTextVector(&TimeTP, TimeT, 2, getDeviceName(), "TIME_UTC", "UTC", SITE_TAB, IP_RW, 60, IPS_IDLE);
IUFillNumber(&LocationN[LOCATION_LATITUDE], "LAT", "Lat (dd:mm:ss.s)", "%012.8m", -90, 90, 0, 0.0);
IUFillNumber(&LocationN[LOCATION_LONGITUDE], "LONG", "Lon (dd:mm:ss.s)", "%012.8m", 0, 360, 0, 0.0);
IUFillNumber(&LocationN[LOCATION_ELEVATION], "ELEV", "Elevation (m)", "%g", -200, 10000, 0, 0);
IUFillNumberVector(&LocationNP, LocationN, 3, getDeviceName(), "GEOGRAPHIC_COORD", "Scope Location", SITE_TAB,
IP_RW, 60, IPS_IDLE);
// Pier Side
IUFillSwitch(&PierSideS[PIER_WEST], "PIER_WEST", "West (pointing east)", ISS_OFF);
IUFillSwitch(&PierSideS[PIER_EAST], "PIER_EAST", "East (pointing west)", ISS_OFF);
IUFillSwitchVector(&PierSideSP, PierSideS, 2, getDeviceName(), "TELESCOPE_PIER_SIDE", "Pier Side", MAIN_CONTROL_TAB,
IP_RO, ISR_ATMOST1, 60, IPS_IDLE);
// Pier Side Simulation
IUFillSwitch(&SimulatePierSideS[0], "SIMULATE_YES", "Yes", ISS_OFF);
IUFillSwitch(&SimulatePierSideS[1], "SIMULATE_NO", "No", ISS_ON);
IUFillSwitchVector(&SimulatePierSideSP, SimulatePierSideS, 2, getDeviceName(), "SIMULATE_PIER_SIDE", "Simulate Pier Side",
MAIN_CONTROL_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
// PEC State
IUFillSwitch(&PECStateS[PEC_OFF], "PEC OFF", "PEC OFF", ISS_ON);
IUFillSwitch(&PECStateS[PEC_ON], "PEC ON", "PEC ON", ISS_OFF);
IUFillSwitchVector(&PECStateSP, PECStateS, 2, getDeviceName(), "PEC", "PEC Playback", MOTION_TAB, IP_RW, ISR_1OFMANY, 0,
IPS_IDLE);
// Track Mode. Child class must call AddTrackMode to add members
IUFillSwitchVector(&TrackModeSP, TrackModeS, 0, getDeviceName(), "TELESCOPE_TRACK_MODE", "Track Mode", MAIN_CONTROL_TAB,
IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
// Track State
IUFillSwitch(&TrackStateS[TRACK_ON], "TRACK_ON", "On", ISS_OFF);
IUFillSwitch(&TrackStateS[TRACK_OFF], "TRACK_OFF", "Off", ISS_ON);
IUFillSwitchVector(&TrackStateSP, TrackStateS, 2, getDeviceName(), "TELESCOPE_TRACK_STATE", "Tracking", MAIN_CONTROL_TAB,
IP_RW, ISR_1OFMANY, 0,
IPS_IDLE);
// Track Rate
IUFillNumber(&TrackRateN[AXIS_RA], "TRACK_RATE_RA", "RA (arcsecs/s)", "%.6f", -16384.0, 16384.0, 0.000001,
TRACKRATE_SIDEREAL);
IUFillNumber(&TrackRateN[AXIS_DE], "TRACK_RATE_DE", "DE (arcsecs/s)", "%.6f", -16384.0, 16384.0, 0.000001, 0.0);
IUFillNumberVector(&TrackRateNP, TrackRateN, 2, getDeviceName(), "TELESCOPE_TRACK_RATE", "Track Rates", MAIN_CONTROL_TAB,
IP_RW, 60, IPS_IDLE);
// On Coord Set actions
IUFillSwitch(&CoordS[0], "TRACK", "Track", ISS_ON);
IUFillSwitch(&CoordS[1], "SLEW", "Slew", ISS_OFF);
IUFillSwitch(&CoordS[2], "SYNC", "Sync", ISS_OFF);
// If both GOTO and SYNC are supported
if (CanGOTO() && CanSync())
IUFillSwitchVector(&CoordSP, CoordS, 3, getDeviceName(), "ON_COORD_SET", "On Set", MAIN_CONTROL_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_IDLE);
// If ONLY GOTO is supported
else if (CanGOTO())
IUFillSwitchVector(&CoordSP, CoordS, 2, getDeviceName(), "ON_COORD_SET", "On Set", MAIN_CONTROL_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_IDLE);
// If ONLY SYNC is supported
else if (CanSync())
{
IUFillSwitch(&CoordS[0], "SYNC", "Sync", ISS_ON);
IUFillSwitchVector(&CoordSP, CoordS, 1, getDeviceName(), "ON_COORD_SET", "On Set", MAIN_CONTROL_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_IDLE);
}
if (nSlewRate >= 4)
IUFillSwitchVector(&SlewRateSP, SlewRateS, nSlewRate, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate",
MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
if (CanTrackSatellite())
{
IUFillText(&TLEtoTrackT[0], "TLE", "TLE", "");
IUFillTextVector(&TLEtoTrackTP, TLEtoTrackT, 1, getDeviceName(), "SAT_TLE_TEXT", "Orbit Params", SATELLITE_TAB,
IP_RW, 60, IPS_IDLE);
char curTime[32] = {0};
std::time_t t = std::time(nullptr);
struct std::tm *utctimeinfo = std::gmtime(&t);
strftime(curTime, sizeof(curTime), "%Y-%m-%dT%H:%M:%S", utctimeinfo);
IUFillText(&SatPassWindowT[SAT_PASS_WINDOW_END], "SAT_PASS_WINDOW_END", "End UTC", curTime);
IUFillText(&SatPassWindowT[SAT_PASS_WINDOW_START], "SAT_PASS_WINDOW_START", "Start UTC", curTime);
IUFillTextVector(&SatPassWindowTP, SatPassWindowT, SAT_PASS_WINDOW_COUNT, getDeviceName(),
"SAT_PASS_WINDOW", "Pass Window", SATELLITE_TAB, IP_RW, 60, IPS_IDLE);
IUFillSwitch(&TrackSatS[SAT_TRACK], "SAT_TRACK", "Track", ISS_OFF);
IUFillSwitch(&TrackSatS[SAT_HALT], "SAT_HALT", "Halt", ISS_ON);
IUFillSwitchVector(&TrackSatSP, TrackSatS, SAT_TRACK_COUNT, getDeviceName(), "SAT_TRACKING_STAT",
"Sat tracking", SATELLITE_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
}
IUFillSwitch(&ParkS[0], "PARK", "Park(ed)", ISS_OFF);
IUFillSwitch(&ParkS[1], "UNPARK", "UnPark(ed)", ISS_OFF);
IUFillSwitchVector(&ParkSP, ParkS, 2, getDeviceName(), "TELESCOPE_PARK", "Parking", MAIN_CONTROL_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitch(&AbortS[0], "ABORT", "Abort", ISS_OFF);
IUFillSwitchVector(&AbortSP, AbortS, 1, getDeviceName(), "TELESCOPE_ABORT_MOTION", "Abort Motion", MAIN_CONTROL_TAB,
IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
IUFillSwitch(&MovementNSS[DIRECTION_NORTH], "MOTION_NORTH", "North", ISS_OFF);
IUFillSwitch(&MovementNSS[DIRECTION_SOUTH], "MOTION_SOUTH", "South", ISS_OFF);
IUFillSwitchVector(&MovementNSSP, MovementNSS, 2, getDeviceName(), "TELESCOPE_MOTION_NS", "Motion N/S", MOTION_TAB,
IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
IUFillSwitch(&MovementWES[DIRECTION_WEST], "MOTION_WEST", "West", ISS_OFF);
IUFillSwitch(&MovementWES[DIRECTION_EAST], "MOTION_EAST", "East", ISS_OFF);
IUFillSwitchVector(&MovementWESP, MovementWES, 2, getDeviceName(), "TELESCOPE_MOTION_WE", "Motion W/E", MOTION_TAB,
IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
// Reverse NS or WE
ReverseMovementSP[REVERSE_NS].fill("REVERSE_NS", "North/South", ISS_OFF);
ReverseMovementSP[REVERSE_WE].fill("REVERSE_WE", "West/East", ISS_OFF);
ReverseMovementSP.fill(getDeviceName(), "TELESCOPE_REVERSE_MOTION", "Reverse", MOTION_TAB, IP_RW, ISR_NOFMANY, 60,
IPS_IDLE);
IUFillNumber(&ScopeParametersN[0], "TELESCOPE_APERTURE", "Aperture (mm)", "%g", 10, 5000, 0, 0.0);
IUFillNumber(&ScopeParametersN[1], "TELESCOPE_FOCAL_LENGTH", "Focal Length (mm)", "%g", 10, 10000, 0, 0.0);
IUFillNumber(&ScopeParametersN[2], "GUIDER_APERTURE", "Guider Aperture (mm)", "%g", 10, 5000, 0, 0.0);
IUFillNumber(&ScopeParametersN[3], "GUIDER_FOCAL_LENGTH", "Guider Focal Length (mm)", "%g", 10, 10000, 0, 0.0);
IUFillNumberVector(&ScopeParametersNP, ScopeParametersN, 4, getDeviceName(), "TELESCOPE_INFO", "Scope Properties",
OPTIONS_TAB, IP_RW, 60, IPS_OK);
// Scope config name
IUFillText(&ScopeConfigNameT[0], "SCOPE_CONFIG_NAME", "Config Name", "");
IUFillTextVector(&ScopeConfigNameTP, ScopeConfigNameT, 1, getDeviceName(), "SCOPE_CONFIG_NAME", "Scope Name",
OPTIONS_TAB, IP_RW, 60, IPS_OK);
// Switch for aperture/focal length configs
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG1], "SCOPE_CONFIG1", "Config #1", ISS_ON);
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG2], "SCOPE_CONFIG2", "Config #2", ISS_OFF);
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG3], "SCOPE_CONFIG3", "Config #3", ISS_OFF);
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG4], "SCOPE_CONFIG4", "Config #4", ISS_OFF);
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG5], "SCOPE_CONFIG5", "Config #5", ISS_OFF);
IUFillSwitch(&ScopeConfigs[SCOPE_CONFIG6], "SCOPE_CONFIG6", "Config #6", ISS_OFF);
IUFillSwitchVector(&ScopeConfigsSP, ScopeConfigs, 6, getDeviceName(), "APPLY_SCOPE_CONFIG", "Scope Configs",
OPTIONS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_OK);
controller->initProperties();
// Joystick motion control
IUFillSwitch(&MotionControlModeT[0], "MOTION_CONTROL_MODE_JOYSTICK", "4-Way Joystick", ISS_ON);
IUFillSwitch(&MotionControlModeT[1], "MOTION_CONTROL_MODE_AXES", "Two Separate Axes", ISS_OFF);
IUFillSwitchVector(&MotionControlModeTP, MotionControlModeT, 2, getDeviceName(), "MOTION_CONTROL_MODE", "Motion Control",
"Joystick", IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
// Lock Axis
IUFillSwitch(&LockAxisS[0], "LOCK_AXIS_1", "West/East", ISS_OFF);
IUFillSwitch(&LockAxisS[1], "LOCK_AXIS_2", "North/South", ISS_OFF);
IUFillSwitchVector(&LockAxisSP, LockAxisS, 2, getDeviceName(), "JOYSTICK_LOCK_AXIS", "Lock Axis", "Joystick", IP_RW,
ISR_ATMOST1, 60, IPS_IDLE);
TrackState = SCOPE_IDLE;
setDriverInterface(TELESCOPE_INTERFACE);
if (telescopeConnection & CONNECTION_SERIAL)
{
serialConnection = new Connection::Serial(this);
serialConnection->registerHandshake([&]()
{
return callHandshake();
});
registerConnection(serialConnection);
}
if (telescopeConnection & CONNECTION_TCP)
{
tcpConnection = new Connection::TCP(this);
tcpConnection->registerHandshake([&]()
{
return callHandshake();
});
registerConnection(tcpConnection);
}
IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD");
IDSnoopDevice(ActiveDeviceT[0].text, "TIME_UTC");
IDSnoopDevice(ActiveDeviceT[1].text, "DOME_PARK");
IDSnoopDevice(ActiveDeviceT[1].text, "DOME_SHUTTER");
addPollPeriodControl();
double longitude = 0, latitude = 0, elevation = 0;
// Get value from config file if it exists.
if (IUGetConfigNumber(getDeviceName(), LocationNP.name, LocationN[LOCATION_LONGITUDE].name, &longitude) == 0)
{
LocationN[LOCATION_LONGITUDE].value = longitude;
m_Location.longitude = longitude;
}
if (IUGetConfigNumber(getDeviceName(), LocationNP.name, LocationN[LOCATION_LATITUDE].name, &latitude) == 0)
{
LocationN[LOCATION_LATITUDE].value = latitude;
m_Location.latitude = latitude;
}
if (IUGetConfigNumber(getDeviceName(), LocationNP.name, LocationN[LOCATION_ELEVATION].name, &elevation) == 0)
{
LocationN[LOCATION_ELEVATION].value = elevation;
m_Location.elevation = elevation;
}
return true;
}
void Telescope::ISGetProperties(const char *dev)
{
// First we let our parent populate
DefaultDevice::ISGetProperties(dev);
if (CanGOTO())
{
defineProperty(&ActiveDeviceTP);
loadConfig(true, "ACTIVE_DEVICES");
ISState isDomeIgnored = ISS_OFF;
if (IUGetConfigSwitch(getDeviceName(), DomePolicySP.name, DomePolicyS[DOME_IGNORED].name, &isDomeIgnored) == 0)
{
DomePolicyS[DOME_IGNORED].s = isDomeIgnored;
DomePolicyS[DOME_LOCKS].s = (isDomeIgnored == ISS_ON) ? ISS_OFF : ISS_ON;
}
defineProperty(&DomePolicySP);
}
defineProperty(&ScopeParametersNP);
defineProperty(&ScopeConfigNameTP);
if (HasDefaultScopeConfig())
{
LoadScopeConfig();
}
else
{
loadConfig(true, "TELESCOPE_INFO");
loadConfig(true, "SCOPE_CONFIG_NAME");
}
if (CanGOTO())
controller->ISGetProperties(dev);
}
bool Telescope::updateProperties()
{
if (isConnected())
{
controller->mapController("MOTIONDIR", "N/S/W/E Control", Controller::CONTROLLER_JOYSTICK, "JOYSTICK_1");
controller->mapController("MOTIONDIRNS", "N/S Control", Controller::CONTROLLER_AXIS, "AXIS_8");
controller->mapController("MOTIONDIRWE", "W/E Control", Controller::CONTROLLER_AXIS, "AXIS_7");
if (nSlewRate >= 4)
{
controller->mapController("SLEWPRESET", "Slew Rate", Controller::CONTROLLER_JOYSTICK, "JOYSTICK_2");
controller->mapController("SLEWPRESETUP", "Slew Rate Up", Controller::CONTROLLER_BUTTON, "BUTTON_5");
controller->mapController("SLEWPRESETDOWN", "Slew Rate Down", Controller::CONTROLLER_BUTTON,
"BUTTON_6");
}
if (CanAbort())
controller->mapController("ABORTBUTTON", "Abort", Controller::CONTROLLER_BUTTON, "BUTTON_1");
if (CanPark())
{
controller->mapController("PARKBUTTON", "Park", Controller::CONTROLLER_BUTTON, "BUTTON_2");
controller->mapController("UNPARKBUTTON", "UnPark", Controller::CONTROLLER_BUTTON, "BUTTON_3");
}
// Now we add our telescope specific stuff
if (CanGOTO() || CanSync())
defineProperty(&CoordSP);
defineProperty(&EqNP);
if (CanAbort())
defineProperty(&AbortSP);
if (HasTrackMode() && TrackModeS != nullptr)
defineProperty(&TrackModeSP);
if (CanControlTrack())
defineProperty(&TrackStateSP);
if (HasTrackRate())
defineProperty(&TrackRateNP);
if (CanGOTO())
{
defineProperty(&MovementNSSP);
defineProperty(&MovementWESP);
defineProperty(&ReverseMovementSP);
if (nSlewRate >= 4)
defineProperty(&SlewRateSP);
defineProperty(&TargetNP);
}
if (HasTime())
defineProperty(&TimeTP);
if (HasLocation())
defineProperty(&LocationNP);
if (CanPark())
{
defineProperty(&ParkSP);
if (parkDataType != PARK_NONE)
{
defineProperty(&ParkPositionNP);
defineProperty(&ParkOptionSP);
}
}
if (HasPierSide())
defineProperty(&PierSideSP);
if (HasPierSideSimulation())
{
defineProperty(&SimulatePierSideSP);
ISState value;
if (IUGetConfigSwitch(getDefaultName(), "SIMULATE_PIER_SIDE", "SIMULATE_YES", &value) )
setSimulatePierSide(value == ISS_ON);
}
if (CanTrackSatellite())
{
defineProperty(&TLEtoTrackTP);
defineProperty(&SatPassWindowTP);
defineProperty(&TrackSatSP);
}
if (HasPECState())
defineProperty(&PECStateSP);
defineProperty(&ScopeConfigNameTP);
defineProperty(&ScopeConfigsSP);
}
else
{
if (CanGOTO() || CanSync())
deleteProperty(CoordSP.name);
deleteProperty(EqNP.name);
if (CanAbort())
deleteProperty(AbortSP.name);
if (HasTrackMode() && TrackModeS != nullptr)
deleteProperty(TrackModeSP.name);
if (HasTrackRate())
deleteProperty(TrackRateNP.name);
if (CanControlTrack())
deleteProperty(TrackStateSP.name);
if (CanGOTO())
{
deleteProperty(MovementNSSP.name);
deleteProperty(MovementWESP.name);
deleteProperty(ReverseMovementSP.getName());
if (nSlewRate >= 4)
deleteProperty(SlewRateSP.name);
deleteProperty(TargetNP.name);
}
if (HasTime())
deleteProperty(TimeTP.name);
if (HasLocation())
deleteProperty(LocationNP.name);
if (CanPark())
{
deleteProperty(ParkSP.name);
if (parkDataType != PARK_NONE)
{
deleteProperty(ParkPositionNP.name);
deleteProperty(ParkOptionSP.name);
}
}
if (HasPierSide())
deleteProperty(PierSideSP.name);
if (HasPierSideSimulation())
{
deleteProperty(SimulatePierSideSP.name);
if (getSimulatePierSide() == true)
deleteProperty(PierSideSP.name);
}
if (CanTrackSatellite())
{
deleteProperty(TLEtoTrackTP.name);
deleteProperty(SatPassWindowTP.name);
deleteProperty(TrackSatSP.name);
}
if (HasPECState())
deleteProperty(PECStateSP.name);
deleteProperty(ScopeConfigNameTP.name);
deleteProperty(ScopeConfigsSP.name);
}
if (CanGOTO())
{
controller->updateProperties();
ISwitchVectorProperty *useJoystick = getSwitch("USEJOYSTICK");
if (useJoystick)
{
if (isConnected())
{
if (useJoystick->sp[0].s == ISS_ON)
{
defineProperty(&MotionControlModeTP);
loadConfig(true, "MOTION_CONTROL_MODE");
defineProperty(&LockAxisSP);
loadConfig(true, "LOCK_AXIS");
}
else
{
deleteProperty(MotionControlModeTP.name);
deleteProperty(LockAxisSP.name);
}
}
else
{
deleteProperty(MotionControlModeTP.name);
deleteProperty(LockAxisSP.name);
}
}
}
return true;
}
bool Telescope::ISSnoopDevice(XMLEle *root)
{
controller->ISSnoopDevice(root);
XMLEle *ep = nullptr;
const char *propName = findXMLAttValu(root, "name");
if (isConnected())
{
if (HasLocation() && !strcmp(propName, "GEOGRAPHIC_COORD"))
{
// Only accept IPS_OK state
if (strcmp(findXMLAttValu(root, "state"), "Ok"))
return false;
double longitude = -1, latitude = -1, elevation = -1;
for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
{
const char *elemName = findXMLAttValu(ep, "name");
if (!strcmp(elemName, "LAT"))
latitude = atof(pcdataXMLEle(ep));
else if (!strcmp(elemName, "LONG"))
longitude = atof(pcdataXMLEle(ep));
else if (!strcmp(elemName, "ELEV"))
elevation = atof(pcdataXMLEle(ep));
}
return processLocationInfo(latitude, longitude, elevation);
}
else if (HasTime() && !strcmp(propName, "TIME_UTC"))
{
// Only accept IPS_OK state
if (strcmp(findXMLAttValu(root, "state"), "Ok"))
return false;
char utc[MAXINDITSTAMP], offset[MAXINDITSTAMP];
for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
{
const char *elemName = findXMLAttValu(ep, "name");
if (!strcmp(elemName, "UTC"))
strncpy(utc, pcdataXMLEle(ep), MAXINDITSTAMP);
else if (!strcmp(elemName, "OFFSET"))
strncpy(offset, pcdataXMLEle(ep), MAXINDITSTAMP);
}
return processTimeInfo(utc, offset);
}
else if (!strcmp(propName, "DOME_PARK")/* || !strcmp(propName, "DOME_SHUTTER")*/)
{
// This is handled by Watchdog driver.
// Mount shouldn't park due to dome closing in INDI::Telescope
#if 0
if (strcmp(findXMLAttValu(root, "state"), "Ok"))
{
// Dome options is dome parks or both and dome is parking.
if ((DomeClosedLockT[2].s == ISS_ON || DomeClosedLockT[3].s == ISS_ON) && !IsLocked && !IsParked)
{
for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
{
const char * elemName = findXMLAttValu(ep, "name");
if (( (!strcmp(elemName, "SHUTTER_CLOSE") || !strcmp(elemName, "PARK"))
&& !strcmp(pcdataXMLEle(ep), "On")))
{
RememberTrackState = TrackState;
Park();
LOG_INFO("Dome is closing, parking mount...");
}
}
}
} // Dome is changing state and Dome options is lock or both. d
else
#endif
if (!strcmp(findXMLAttValu(root, "state"), "Ok"))
{
bool prevState = IsLocked;
for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
{
const char *elemName = findXMLAttValu(ep, "name");
if (!IsLocked && (!strcmp(elemName, "PARK")) && !strcmp(pcdataXMLEle(ep), "On"))
IsLocked = true;
else if (IsLocked && (!strcmp(elemName, "UNPARK")) && !strcmp(pcdataXMLEle(ep), "On"))
IsLocked = false;
}
if (prevState != IsLocked && (DomePolicyS[DOME_LOCKS].s == ISS_ON))
LOGF_INFO("Dome status changed. Lock is set to: %s", IsLocked ? "locked" : "unlock");
}
return true;
}
}
return DefaultDevice::ISSnoopDevice(root);
}
void Telescope::triggerSnoop(const char *driverName, const char *snoopedProp)
{
LOGF_DEBUG("Active Snoop, driver: %s, property: %s", driverName, snoopedProp);
IDSnoopDevice(driverName, snoopedProp);
}
uint8_t Telescope::getTelescopeConnection() const
{
return telescopeConnection;
}
void Telescope::setTelescopeConnection(const uint8_t &value)
{
uint8_t mask = CONNECTION_SERIAL | CONNECTION_TCP | CONNECTION_NONE;
if (value == 0 || (mask & value) == 0)
{
DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
return;
}
telescopeConnection = value;
}
bool Telescope::saveConfigItems(FILE *fp)
{
DefaultDevice::saveConfigItems(fp);
IUSaveConfigText(fp, &ActiveDeviceTP);
IUSaveConfigSwitch(fp, &DomePolicySP);
// Ensure that we only save valid locations
if (HasLocation() && (LocationN[LOCATION_LONGITUDE].value != 0 || LocationN[LOCATION_LATITUDE].value != 0))
IUSaveConfigNumber(fp, &LocationNP);
if (!HasDefaultScopeConfig())
{
if (ScopeParametersNP.s == IPS_OK)
IUSaveConfigNumber(fp, &ScopeParametersNP);
if (ScopeConfigNameTP.s == IPS_OK)
IUSaveConfigText(fp, &ScopeConfigNameTP);
}
if (CanGOTO())
IUSaveConfigSwitch(fp, &ReverseMovementSP);
if (SlewRateS != nullptr)
IUSaveConfigSwitch(fp, &SlewRateSP);
if (HasPECState())
IUSaveConfigSwitch(fp, &PECStateSP);
if (HasTrackMode())
IUSaveConfigSwitch(fp, &TrackModeSP);
if (HasTrackRate())
IUSaveConfigNumber(fp, &TrackRateNP);
controller->saveConfigItems(fp);
IUSaveConfigSwitch(fp, &MotionControlModeTP);
IUSaveConfigSwitch(fp, &LockAxisSP);
IUSaveConfigSwitch(fp, &SimulatePierSideSP);
return true;
}
void Telescope::NewRaDec(double ra, double dec)
{
switch (TrackState)
{
case SCOPE_PARKED:
case SCOPE_IDLE:
EqNP.s = IPS_IDLE;
break;
case SCOPE_SLEWING:
case SCOPE_PARKING:
EqNP.s = IPS_BUSY;
break;
case SCOPE_TRACKING:
EqNP.s = IPS_OK;
break;
}
if (TrackState != SCOPE_TRACKING && CanControlTrack() && TrackStateS[TRACK_ON].s == ISS_ON)
{
TrackStateSP.s = IPS_IDLE;
TrackStateS[TRACK_ON].s = ISS_OFF;
TrackStateS[TRACK_OFF].s = ISS_ON;
IDSetSwitch(&TrackStateSP, nullptr);
}
else if (TrackState == SCOPE_TRACKING && CanControlTrack() && TrackStateS[TRACK_OFF].s == ISS_ON)
{
TrackStateSP.s = IPS_BUSY;
TrackStateS[TRACK_ON].s = ISS_ON;
TrackStateS[TRACK_OFF].s = ISS_OFF;
IDSetSwitch(&TrackStateSP, nullptr);
}
if (std::abs(EqN[AXIS_RA].value - ra) > EQ_NOTIFY_THRESHOLD ||
std::abs(EqN[AXIS_DE].value - dec) > EQ_NOTIFY_THRESHOLD ||
EqNP.s != lastEqState)
{
EqN[AXIS_RA].value = ra;
EqN[AXIS_DE].value = dec;
lastEqState = EqNP.s;
IDSetNumber(&EqNP, nullptr);
}
}
bool Telescope::Sync(double ra, double dec)
{
INDI_UNUSED(ra);
INDI_UNUSED(dec);
// if we get here, our mount doesn't support sync
DEBUG(Logger::DBG_ERROR, "Telescope does not support Sync.");
return false;
}
bool Telescope::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
{
INDI_UNUSED(dir);
INDI_UNUSED(command);
DEBUG(Logger::DBG_ERROR, "Telescope does not support North/South motion.");
IUResetSwitch(&MovementNSSP);
MovementNSSP.s = IPS_IDLE;
IDSetSwitch(&MovementNSSP, nullptr);
return false;
}
bool Telescope::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
{
INDI_UNUSED(dir);
INDI_UNUSED(command);
DEBUG(Logger::DBG_ERROR, "Telescope does not support West/East motion.");
IUResetSwitch(&MovementWESP);
MovementWESP.s = IPS_IDLE;
IDSetSwitch(&MovementWESP, nullptr);
return false;
}
/**************************************************************************************
** Process Text properties
***************************************************************************************/
bool Telescope::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
{
// first check if it's for our device
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
if (!strcmp(name, TimeTP.name))
{
int utcindex = IUFindIndex("UTC", names, n);
int offsetindex = IUFindIndex("OFFSET", names, n);
return processTimeInfo(texts[utcindex], texts[offsetindex]);
}
if (!strcmp(name, ActiveDeviceTP.name))
{
ActiveDeviceTP.s = IPS_OK;
IUUpdateText(&ActiveDeviceTP, texts, names, n);
// Update client display
IDSetText(&ActiveDeviceTP, nullptr);
IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD");
IDSnoopDevice(ActiveDeviceT[0].text, "TIME_UTC");
IDSnoopDevice(ActiveDeviceT[1].text, "DOME_PARK");
IDSnoopDevice(ActiveDeviceT[1].text, "DOME_SHUTTER");
return true;
}
if (name && std::string(name) == "SCOPE_CONFIG_NAME")
{
ScopeConfigNameTP.s = IPS_OK;
IUUpdateText(&ScopeConfigNameTP, texts, names, n);
IDSetText(&ScopeConfigNameTP, nullptr);
UpdateScopeConfig();
return true;
}
}
controller->ISNewText(dev, name, texts, names, n);
return DefaultDevice::ISNewText(dev, name, texts, names, n);
}
/**************************************************************************************
**
***************************************************************************************/
bool Telescope::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
{
// first check if it's for our device
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
///////////////////////////////////
// Goto & Sync for Equatorial Coords
///////////////////////////////////
if (strcmp(name, "EQUATORIAL_EOD_COORD") == 0)
{
// this is for us, and it is a goto
bool rc = false;
double ra = -1;
double dec = -100;
for (int x = 0; x < n; x++)
{
INumber *eqp = IUFindNumber(&EqNP, names[x]);
if (eqp == &EqN[AXIS_RA])
{
ra = values[x];
}
else if (eqp == &EqN[AXIS_DE])
{
dec = values[x];
}
}
if ((ra >= 0) && (ra <= 24) && (dec >= -90) && (dec <= 90))
{
// Check if it is already parked.
if (CanPark())
{
if (isParked())
{
DEBUG(Logger::DBG_WARNING,
"Please unpark the mount before issuing any motion/sync commands.");
EqNP.s = lastEqState = IPS_IDLE;
IDSetNumber(&EqNP, nullptr);
return false;
}
}
// Check if it can sync
if (CanSync())
{
ISwitch *sw;
sw = IUFindSwitch(&CoordSP, "SYNC");
if ((sw != nullptr) && (sw->s == ISS_ON))
{
rc = Sync(ra, dec);
if (rc)
EqNP.s = lastEqState = IPS_OK;
else
EqNP.s = lastEqState = IPS_ALERT;
IDSetNumber(&EqNP, nullptr);
return rc;
}
}
// Remember Track State
RememberTrackState = TrackState;
// Issue GOTO
rc = Goto(ra, dec);
if (rc)
{
EqNP.s = lastEqState = IPS_BUSY;
// Now fill in target co-ords, so domes can start turning
TargetN[AXIS_RA].value = ra;
TargetN[AXIS_DE].value = dec;
IDSetNumber(&TargetNP, nullptr);
}
else
{
EqNP.s = lastEqState = IPS_ALERT;
}
IDSetNumber(&EqNP, nullptr);
}
return rc;
}
///////////////////////////////////
// Geographic Coords
///////////////////////////////////
if (strcmp(name, "GEOGRAPHIC_COORD") == 0)
{
int latindex = IUFindIndex("LAT", names, n);
int longindex = IUFindIndex("LONG", names, n);
int elevationindex = IUFindIndex("ELEV", names, n);
if (latindex == -1 || longindex == -1 || elevationindex == -1)
{
LocationNP.s = IPS_ALERT;
IDSetNumber(&LocationNP, "Location data missing or corrupted.");
}
double targetLat = values[latindex];
double targetLong = values[longindex];
double targetElev = values[elevationindex];
return processLocationInfo(targetLat, targetLong, targetElev);
}
///////////////////////////////////
// Telescope Info
///////////////////////////////////
if (strcmp(name, "TELESCOPE_INFO") == 0)
{
ScopeParametersNP.s = IPS_OK;
IUUpdateNumber(&ScopeParametersNP, values, names, n);
IDSetNumber(&ScopeParametersNP, nullptr);
UpdateScopeConfig();
return true;
}
///////////////////////////////////
// Park Position
///////////////////////////////////
if (strcmp(name, ParkPositionNP.name) == 0)
{
double axis1 = std::numeric_limits<double>::quiet_NaN(), axis2 = std::numeric_limits<double>::quiet_NaN();
for (int x = 0; x < n; x++)
{
INumber *parkPosAxis = IUFindNumber(&ParkPositionNP, names[x]);
if (parkPosAxis == &ParkPositionN[AXIS_RA])
{
axis1 = values[x];
}
else if (parkPosAxis == &ParkPositionN[AXIS_DE])
{
axis2 = values[x];
}
}
if (std::isnan(axis1) == false && std::isnan(axis2) == false)
{
bool rc = false;
rc = SetParkPosition(axis1, axis2);
if (rc)
{
IUUpdateNumber(&ParkPositionNP, values, names, n);
Axis1ParkPosition = ParkPositionN[AXIS_RA].value;
Axis2ParkPosition = ParkPositionN[AXIS_DE].value;
}
ParkPositionNP.s = rc ? IPS_OK : IPS_ALERT;
}
else
ParkPositionNP.s = IPS_ALERT;
IDSetNumber(&ParkPositionNP, nullptr);
return true;
}
///////////////////////////////////
// Track Rate
///////////////////////////////////
if (strcmp(name, TrackRateNP.name) == 0)
{
double preAxis1 = TrackRateN[AXIS_RA].value, preAxis2 = TrackRateN[AXIS_DE].value;
bool rc = (IUUpdateNumber(&TrackRateNP, values, names, n) == 0);
if (!rc)
{
TrackRateNP.s = IPS_ALERT;
IDSetNumber(&TrackRateNP, nullptr);
return false;
}
if (TrackState == SCOPE_TRACKING && !strcmp(IUFindOnSwitch(&TrackModeSP)->name, "TRACK_CUSTOM"))
{
// Check that we do not abruplty change positive tracking rates to negative ones.
// tracking must be stopped first.
// Give warning is tracking sign would cause a reverse in direction
if ( (preAxis1 * TrackRateN[AXIS_RA].value < 0) || (preAxis2 * TrackRateN[AXIS_DE].value < 0) )
{
LOG_ERROR("Cannot reverse tracking while tracking is engaged. Disengage tracking then try again.");
return false;
}
// All is fine, ask mount to change tracking rate
rc = SetTrackRate(TrackRateN[AXIS_RA].value, TrackRateN[AXIS_DE].value);
if (!rc)
{