-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheqmodbase.cpp
More file actions
3768 lines (3407 loc) · 129 KB
/
eqmodbase.cpp
File metadata and controls
3768 lines (3407 loc) · 129 KB
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 2012 Geehalel (geehalel AT gmail DOT com) */
/* This file is part of the Skywatcher Protocol INDI driver.
The Skywatcher Protocol INDI driver is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Skywatcher Protocol INDI driver 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Skywatcher Protocol INDI driver. If not, see <http://www.gnu.org/licenses/>.
2013-10-20: Fixed a few bugs and init/update properties issue (Jasem Mutlaq)
2013-10-24: Use updateTime from new INDI framework (Jasem Mutlaq)
2013-10-31: Added support for joysticks (Jasem Mutlaq)
2013-11-01: Fixed issues with logger and Skywatcher's readout for InquireHighSpeedRatio.
2018-04-27: Added abnormalDisconnect to properly disconnect the driver in case of unrecoverable errors (Jasem Mutlaq)
2018-04-27: Since all dispatch_command are always followed by read_eqmod, we decided to include it inside
and on failure, we retries up to the EQMOD_MAX_RETRY before giving up in case of occasional traient errors. (Jasem Mutlaq)
*/
/* TODO */
/* HORIZONTAL_COORDS -> HORIZONTAL_COORD - OK */
/* DATE -> TIME_LST/LST and TIME_UTC/UTC - OK */
/* Problem in time initialization using gettimeofday/gmtime: 1h after UTC on summer, because of DST ?? */
/* TELESCOPE_MOTION_RATE in arcmin/s */
/* use/snoop a GPS ??*/
#include "eqmodbase.h"
#include "mach_gettime.h"
#include <cmath>
#include <memory>
#include <cstring>
#include <unistd.h>
#include <assert.h>
#include <indicom.h>
#include <connectionplugins/connectiontcp.h>
#ifdef WITH_ALIGN
#include <alignment/DriverCommon.h> // For DBG_ALIGNMENT
using namespace INDI::AlignmentSubsystem;
#endif
#include <libnova/sidereal_time.h>
#include <libnova/transform.h>
#include <libnova/utility.h>
#define GOTO_RATE 2 /* slew rate, degrees/s */
#define SLEW_RATE 0.5 /* slew rate, degrees/s */
#define FINE_SLEW_RATE 0.1 /* slew rate, degrees/s */
#define SID_RATE 0.004178 /* sidereal rate, degrees/s */
#define GOTO_LIMIT 5 /* Move at GOTO_RATE until distance from target is GOTO_LIMIT degrees */
#define SLEW_LIMIT 2 /* Move at SLEW_LIMIT until distance from target is SLEW_LIMIT degrees */
#define FINE_SLEW_LIMIT 0.5 /* Move at FINE_SLEW_RATE until distance from target is FINE_SLEW_LIMIT degrees */
#define GOTO_ITERATIVE_LIMIT 5 /* Max GOTO Iterations */
#define RAGOTORESOLUTION 5 /* GOTO Resolution in arcsecs */
#define DEGOTORESOLUTION 5 /* GOTO Resolution in arcsecs */
/* Preset Slew Speeds */
#define SLEWMODES 11
int slewspeeds[SLEWMODES - 1] = { 1, 2, 4, 8, 32, 64, 128, 600, 700, 800 };
#define RA_AXIS 0
#define DEC_AXIS 1
#define GUIDE_NORTH 0
#define GUIDE_SOUTH 1
#define GUIDE_WEST 0
#define GUIDE_EAST 1
#if 0
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
{
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_usec < y->tv_usec)
{
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000)
{
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_usec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
#endif
EQMod::EQMod(): GI(this)
{
//ctor
setVersion(EQMOD_VERSION_MAJOR, EQMOD_VERSION_MINOR);
// Do not define dynamic properties on startup, and do not delete them from memory
setDynamicPropertiesBehavior(false, false);
currentRA = 0;
currentDEC = 90;
gotoparams.completed = true;
last_motion_ns = -1;
last_motion_ew = -1;
pulseInProgress = 0;
DBG_SCOPE_STATUS = INDI::Logger::getInstance().addDebugLevel("Scope Status", "SCOPE");
DBG_COMM = INDI::Logger::getInstance().addDebugLevel("Serial Port", "COMM");
DBG_MOUNT = INDI::Logger::getInstance().addDebugLevel("Verbose Mount", "MOUNT");
mount = new Skywatcher(this);
SetTelescopeCapability(TELESCOPE_CAN_PARK | TELESCOPE_CAN_SYNC | TELESCOPE_CAN_GOTO | TELESCOPE_CAN_ABORT |
TELESCOPE_HAS_TIME | TELESCOPE_HAS_LOCATION
| TELESCOPE_HAS_PIER_SIDE | TELESCOPE_HAS_TRACK_RATE | TELESCOPE_HAS_TRACK_MODE | TELESCOPE_CAN_CONTROL_TRACK,
SLEWMODES);
RAInverted = DEInverted = false;
bzero(&syncdata, sizeof(syncdata));
bzero(&syncdata2, sizeof(syncdata2));
#ifdef WITH_ALIGN_GEEHALEL
align = new Align(this);
#endif
simulator = new EQModSimulator(this);
#ifdef WITH_SCOPE_LIMITS
horizon = new HorizonLimits(this);
#endif
/* initialize time */
tzset();
gettimeofday(&lasttimeupdate, nullptr); // takes care of DST
gmtime_r(&lasttimeupdate.tv_sec, &utc);
lndate.seconds = utc.tm_sec + ((double)lasttimeupdate.tv_usec / 1000000);
lndate.minutes = utc.tm_min;
lndate.hours = utc.tm_hour;
lndate.days = utc.tm_mday;
lndate.months = utc.tm_mon + 1;
lndate.years = utc.tm_year + 1900;
get_utc_time(&lastclockupdate);
/* initialize random seed: */
srand(time(nullptr));
// Others
AutohomeState = AUTO_HOME_IDLE;
restartguidePPEC = false;
}
EQMod::~EQMod()
{
//dtor
delete mount;
mount = nullptr;
}
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
bool EQMod::isStandardSync()
{
return AlignSyncModeSP.findOnSwitch()->isNameMatch("ALIGNSTANDARDSYNC");
}
#endif
void EQMod::setStepperSimulation(bool enable)
{
mount->setSimulation(enable);
if (!simulator->updateProperties(enable))
LOG_WARN("setStepperSimulator: Disable/Enable error");
INDI::Telescope::setSimulation(enable);
}
const char *EQMod::getDefaultName()
{
return "EQMod Mount";
}
double EQMod::getLongitude()
{
auto number = LocationNP.findWidgetByName("LONG");
if (number)
return number->getValue();
else
return 0;
}
double EQMod::getLatitude()
{
auto number = LocationNP.findWidgetByName("LAT");
if(number)
return number->getValue();
else
return 0;
}
double EQMod::getJulianDate()
{
/*
struct timeval currenttime, difftime;
double usecs;
gettimeofday(¤ttime, nullptr);
if (timeval_subtract(&difftime, ¤ttime, &lasttimeupdate) == -1)
return juliandate;
*/
struct timespec currentclock, diffclock;
double nsecs;
get_utc_time(¤tclock);
diffclock.tv_sec = currentclock.tv_sec - lastclockupdate.tv_sec;
diffclock.tv_nsec = currentclock.tv_nsec - lastclockupdate.tv_nsec;
while (diffclock.tv_nsec > 1000000000)
{
diffclock.tv_sec++;
diffclock.tv_nsec -= 1000000000;
}
while (diffclock.tv_nsec < 0)
{
diffclock.tv_sec--;
diffclock.tv_nsec += 1000000000;
}
//IDLog("Get Julian; ln_date was %02d:%02d:%.9f\n", lndate.hours, lndate.minutes, lndate.seconds);
//IDLog("Clocks last: %d secs %d nsecs current: %d secs %d nsecs\n", lastclockupdate.tv_sec, lastclockupdate.tv_nsec, currentclock.tv_sec, currentclock.tv_nsec);
//IDLog("Diff %d secs %d nsecs\n", diffclock.tv_sec, diffclock.tv_nsec);
//IDLog("Diff %d %d\n", difftime.tv_sec, difftime.tv_usec);
//lndate.seconds += (difftime.tv_sec + (difftime.tv_usec / 1000000));
//usecs=lndate.seconds - floor(lndate.seconds);
lndate.seconds += (diffclock.tv_sec + ((double)diffclock.tv_nsec / 1000000000.0));
nsecs = lndate.seconds - floor(lndate.seconds);
utc.tm_sec = lndate.seconds;
utc.tm_isdst = -1; // let mktime find if DST already in effect in utc
//IDLog("Get julian: setting UTC secs to %f", utc.tm_sec);
mktime(&utc); // normalize time
//IDLog("Get Julian; UTC is now %s", asctime(&utc));
ln_get_date_from_tm(&utc, &lndate);
//IDLog("Get Julian; ln_date is now %02d:%02d:%.9f\n", lndate.hours, lndate.minutes, lndate.seconds);
//lndate.seconds+=usecs;
//lasttimeupdate = currenttime;
lndate.seconds += nsecs;
//IDLog(" ln_date with nsecs %02d:%02d:%.9f\n", lndate.hours, lndate.minutes, lndate.seconds);
lastclockupdate = currentclock;
juliandate = ln_get_julian_day(&lndate);
//IDLog("julian diff: %g\n", juliandate - ln_get_julian_from_sys());
return juliandate;
//return ln_get_julian_from_sys();
}
double EQMod::getLst(double jd, double lng)
{
double lst;
//lst=ln_get_mean_sidereal_time(jd);
lst = ln_get_apparent_sidereal_time(jd);
lst += (lng / 15.0);
lst = range24(lst);
return lst;
}
bool EQMod::initProperties()
{
/* Make sure to init parent properties first */
INDI::Telescope::initProperties();
loadProperties();
initSlewRates();
AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
AddTrackMode("TRACK_SOLAR", "Solar");
AddTrackMode("TRACK_LUNAR", "Lunar");
AddTrackMode("TRACK_CUSTOM", "Custom");
SetParkDataType(PARK_RA_DEC_ENCODER);
setDriverInterface(getDriverInterface() | GUIDER_INTERFACE);
#ifdef WITH_ALIGN
InitAlignmentProperties(this);
// Force the alignment system to always be on
getSwitch("ALIGNMENT_SUBSYSTEM_ACTIVE")[0].setState(ISS_ON);
#endif
tcpConnection->setDefaultHost("192.168.4.1");
tcpConnection->setDefaultPort(11880);
tcpConnection->setConnectionType(Connection::TCP::TYPE_UDP);
addAuxControls();
return true;
}
void EQMod::initSlewRates()
{
for (size_t i = 0; i < SlewRateSP.count() - 1; i++)
{
SlewRateSP[i].setState(ISS_OFF);
SlewRateSP[i].setLabel(std::to_string(slewspeeds[i]) + "x");
SlewRateSP[i].setAux((void *)&slewspeeds[i]);
}
// Since last item is NOT maximum (but custom), let's set item before custom to SLEWMAX
SlewRateSP[SlewRateSP.count() - 2].setState(ISS_ON);
SlewRateSP[SlewRateSP.count() - 2].setName("SLEW_MAX");
// Last is custom
SlewRateSP[SlewRateSP.count() - 1].setName("SLEWCUSTOM");
SlewRateSP[SlewRateSP.count() - 1].setLabel("Custom");
}
void EQMod::ISGetProperties(const char *dev)
{
INDI::Telescope::ISGetProperties(dev);
if (isConnected())
{
GI::updateProperties();
defineProperty(SlewSpeedsNP);
defineProperty(GuideRateNP);
defineProperty(PulseLimitsNP);
defineProperty(MountInformationTP);
defineProperty(SteppersNP);
defineProperty(CurrentSteppersNP);
defineProperty(PeriodsNP);
defineProperty(JulianNP);
defineProperty(TimeLSTNP);
defineProperty(RAStatusLP);
defineProperty(DEStatusLP);
defineProperty(HemisphereSP);
defineProperty(HorizontalCoordNP);
defineProperty(ReverseDECSP);
defineProperty(TargetPierSideSP);
defineProperty(StandardSyncNP);
defineProperty(StandardSyncPointNP);
defineProperty(SyncPolarAlignNP);
defineProperty(SyncManageSP);
defineProperty(BacklashNP);
defineProperty(UseBacklashSP);
defineProperty(TrackDefaultSP);
defineProperty(ST4GuideRateNSSP);
defineProperty(ST4GuideRateWESP);
#if defined WITH_ALIGN && defined WITH_ALIGN_GEEHALEL
defineProperty(&AlignMethodSP);
#endif
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
defineProperty(AlignSyncModeSP);
#endif
if (mount->HasAuxEncoders())
{
defineProperty(AuxEncoderSP);
defineProperty(AuxEncoderNP);
}
if (mount->HasPPEC())
{
defineProperty(PPECTrainingSP);
defineProperty(PPECSP);
}
if (mount->HasSnapPort1())
{
defineProperty(SNAPPORT1SP);
}
if (mount->HasSnapPort2())
{
defineProperty(SNAPPORT2SP);
}
if (mount->HasPolarLed())
{
defineProperty(LEDBrightnessNP);
}
#ifdef WITH_ALIGN_GEEHALEL
if (align)
{
align->ISGetProperties();
}
#endif
#ifdef WITH_SCOPE_LIMITS
if (horizon)
{
horizon->ISGetProperties();
}
#endif
simulator->updateProperties(isSimulation());
}
}
bool EQMod::loadProperties()
{
buildSkeleton("indi_eqmod_sk.xml");
GuideRateNP = getNumber("GUIDE_RATE");
// GuideRateN = GuideRateNP->np;
PulseLimitsNP = getNumber("PULSE_LIMITS");
MinPulseN = PulseLimitsNP.findWidgetByName("MIN_PULSE");
MinPulseTimerN = PulseLimitsNP.findWidgetByName("MIN_PULSE_TIMER");
MountInformationTP = getText("MOUNTINFORMATION");
SteppersNP = getNumber("STEPPERS");
CurrentSteppersNP = getNumber("CURRENTSTEPPERS");
PeriodsNP = getNumber("PERIODS");
JulianNP = getNumber("JULIAN");
TimeLSTNP = getNumber("TIME_LST");
RAStatusLP = getLight("RASTATUS");
DEStatusLP = getLight("DESTATUS");
SlewSpeedsNP = getNumber("SLEWSPEEDS");
HemisphereSP = getSwitch("HEMISPHERE");
TrackDefaultSP = getSwitch("TELESCOPE_TRACK_DEFAULT");
ReverseDECSP = getSwitch("REVERSEDEC");
TargetPierSideSP = getSwitch("TARGETPIERSIDE");
HorizontalCoordNP = getNumber("HORIZONTAL_COORD");
StandardSyncNP = getNumber("STANDARDSYNC");
StandardSyncPointNP = getNumber("STANDARDSYNCPOINT");
SyncPolarAlignNP = getNumber("SYNCPOLARALIGN");
SyncManageSP = getSwitch("SYNCMANAGE");
BacklashNP = getNumber("BACKLASH");
UseBacklashSP = getSwitch("USEBACKLASH");
AuxEncoderSP = getSwitch("AUXENCODER");
AuxEncoderNP = getNumber("AUXENCODERVALUES");
ST4GuideRateNSSP = getSwitch("ST4_GUIDE_RATE_NS");
ST4GuideRateWESP = getSwitch("ST4_GUIDE_RATE_WE");
PPECTrainingSP = getSwitch("PPEC_TRAINING");
PPECSP = getSwitch("PPEC");
LEDBrightnessNP = getNumber("LED_BRIGHTNESS");
SNAPPORT1SP = getSwitch("SNAPPORT1");
SNAPPORT2SP = getSwitch("SNAPPORT2");
#ifdef WITH_ALIGN_GEEHALEL
align->initProperties();
#endif
#if defined WITH_ALIGN && defined WITH_ALIGN_GEEHALEL
IUFillSwitch(&AlignMethodS[0], "ALIGN_METHOD_EQMOD", "EQMod Align", ISS_ON);
IUFillSwitch(&AlignMethodS[1], "ALIGN_METHOD_SUBSYSTEM", "Alignment Subsystem", ISS_OFF);
IUFillSwitchVector(&AlignMethodSP, AlignMethodS, NARRAY(AlignMethodS), getDeviceName(), "ALIGN_METHOD",
"Align Method", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
#endif
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
AlignSyncModeSP = getSwitch("ALIGNSYNCMODE");
#endif
simulator->initProperties();
GI::initProperties(MOTION_TAB);
#ifdef WITH_SCOPE_LIMITS
if (horizon)
{
if (!horizon->initProperties())
return false;
}
#endif
return true;
}
bool EQMod::updateProperties()
{
// JM 2024.07.29: Need to run this *before* Telescope::updateProperty so we can check if
// the mount supports homing since we need to update the telescope capabilities accordingly.
if (isConnected())
{
try
{
mount->InquireBoardVersion(MountInformationTP);
for (const auto &it : MountInformationTP)
{
LOGF_DEBUG("Got Board Property %s: %s", it.getName(), it.getText());
}
mount->InquireRAEncoderInfo(SteppersNP);
mount->InquireDEEncoderInfo(SteppersNP);
for (const auto &it : SteppersNP)
{
LOGF_DEBUG("Got Encoder Property %s: %.0f", it.getLabel(), it.getValue());
}
mount->InquireFeatures();
if (mount->HasHomeIndexers())
{
LOG_INFO("Mount has home indexers. Enabling Autohome.");
SetTelescopeCapability(GetTelescopeCapability() | TELESCOPE_CAN_HOME_FIND, SLEWMODES);
initSlewRates();
}
}
catch (EQModError &e)
{
return (e.DefaultHandleException(this));
}
}
INDI::Telescope::updateProperties();
if (isConnected())
{
defineProperty(SlewSpeedsNP);
defineProperty(GuideRateNP);
defineProperty(PulseLimitsNP);
defineProperty(MountInformationTP);
defineProperty(SteppersNP);
defineProperty(CurrentSteppersNP);
defineProperty(PeriodsNP);
defineProperty(JulianNP);
defineProperty(TimeLSTNP);
defineProperty(RAStatusLP);
defineProperty(DEStatusLP);
defineProperty(HemisphereSP);
defineProperty(HorizontalCoordNP);
defineProperty(ReverseDECSP);
defineProperty(TargetPierSideSP);
defineProperty(StandardSyncNP);
defineProperty(StandardSyncPointNP);
defineProperty(SyncPolarAlignNP);
defineProperty(SyncManageSP);
defineProperty(BacklashNP);
defineProperty(UseBacklashSP);
defineProperty(TrackDefaultSP);
defineProperty(ST4GuideRateNSSP);
defineProperty(ST4GuideRateWESP);
#if defined WITH_ALIGN && defined WITH_ALIGN_GEEHALEL
defineProperty(&AlignMethodSP);
#endif
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
defineProperty(AlignSyncModeSP);
#endif
try
{
if (mount->HasAuxEncoders())
{
defineProperty(AuxEncoderSP);
defineProperty(AuxEncoderNP);
LOG_INFO("Mount has auxiliary encoders. Turning them off.");
mount->TurnRAEncoder(false);
mount->TurnDEEncoder(false);
}
if (mount->HasPPEC())
{
bool intraining, inppec;
defineProperty(PPECTrainingSP);
defineProperty(PPECSP);
LOG_INFO("Mount has PPEC.");
mount->GetPPECStatus(&intraining, &inppec);
if (intraining)
{
PPECTrainingSP[0].setState(ISS_OFF);
PPECTrainingSP[1].setState(ISS_ON);
PPECTrainingSP.setState(IPS_BUSY);
PPECTrainingSP.apply();
}
if (inppec)
{
PPECSP[0].setState(ISS_OFF);
PPECSP[1].setState(ISS_ON);
PPECSP.setState(IPS_BUSY);
PPECSP.apply();
}
}
if (mount->HasPolarLed())
{
defineProperty(LEDBrightnessNP);
}
LOG_DEBUG("Init backlash.");
mount->SetBacklashUseRA(UseBacklashSP.findWidgetByName("USEBACKLASHRA")->getState() == ISS_ON ? true : false);
mount->SetBacklashUseDE(UseBacklashSP.findWidgetByName("USEBACKLASHDE")->getState() == ISS_ON ? true : false);
mount->SetBacklashRA((uint32_t)(BacklashNP.findWidgetByName("BACKLASHRA")->getValue()));
mount->SetBacklashDE((uint32_t)(BacklashNP.findWidgetByName("BACKLASHDE")->getValue()));
if (mount->HasSnapPort1())
{
defineProperty(SNAPPORT1SP);
}
if (mount->HasSnapPort2())
{
defineProperty(SNAPPORT2SP);
}
mount->Init();
zeroRAEncoder = mount->GetRAEncoderZero();
totalRAEncoder = mount->GetRAEncoderTotal();
homeRAEncoder = mount->GetRAEncoderHome();
zeroDEEncoder = mount->GetDEEncoderZero();
totalDEEncoder = mount->GetDEEncoderTotal();
homeDEEncoder = mount->GetDEEncoderHome();
parkRAEncoder = GetAxis1Park();
parkDEEncoder = GetAxis2Park();
auto latitude = LocationNP.findWidgetByName("LAT");
auto longitude = LocationNP.findWidgetByName("LONG");
auto elevation = LocationNP.findWidgetByName("ELEV");
if (latitude && longitude && elevation)
updateLocation(latitude->getValue(), longitude->getValue(), elevation->getValue());
sendTimeFromSystem();
}
catch (EQModError &e)
{
return (e.DefaultHandleException(this));
}
}
else
{
deleteProperty(GuideRateNP);
deleteProperty(PulseLimitsNP);
deleteProperty(MountInformationTP);
deleteProperty(SteppersNP);
deleteProperty(CurrentSteppersNP);
deleteProperty(PeriodsNP);
deleteProperty(JulianNP);
deleteProperty(TimeLSTNP);
deleteProperty(RAStatusLP);
deleteProperty(DEStatusLP);
deleteProperty(SlewSpeedsNP);
deleteProperty(HemisphereSP);
deleteProperty(HorizontalCoordNP);
deleteProperty(ReverseDECSP);
deleteProperty(TargetPierSideSP);
deleteProperty(StandardSyncNP);
deleteProperty(StandardSyncPointNP);
deleteProperty(SyncPolarAlignNP);
deleteProperty(SyncManageSP);
deleteProperty(TrackDefaultSP);
deleteProperty(BacklashNP);
deleteProperty(UseBacklashSP);
deleteProperty(ST4GuideRateNSSP);
deleteProperty(ST4GuideRateWESP);
deleteProperty(LEDBrightnessNP);
if (mount->HasAuxEncoders())
{
deleteProperty(AuxEncoderSP);
deleteProperty(AuxEncoderNP);
}
if (mount->HasPPEC())
{
deleteProperty(PPECTrainingSP);
deleteProperty(PPECSP);
}
if (mount->HasSnapPort1())
{
deleteProperty(SNAPPORT1SP);
}
if (mount->HasSnapPort2())
{
deleteProperty(SNAPPORT2SP);
}
if (mount->HasPolarLed())
{
deleteProperty(LEDBrightnessNP);
}
#if defined WITH_ALIGN && defined WITH_ALIGN_GEEHALEL
deleteProperty(AlignMethodSP.name);
#endif
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
deleteProperty(AlignSyncModeSP);
#endif
//MountInformationTP=nullptr;
//}
}
#ifdef WITH_ALIGN_GEEHALEL
if (align)
{
if (!align->updateProperties())
return false;
}
#endif
#ifdef WITH_SCOPE_LIMITS
if (horizon)
{
if (!horizon->updateProperties())
return false;
}
#endif
GI::updateProperties();
mount->setSimulation(isSimulation());
simulator->updateProperties(isSimulation());
return true;
}
bool EQMod::Handshake()
{
try
{
if (!getActiveConnection()->name().compare("CONNECTION_TCP")
&& tcpConnection->connectionType() == Connection::TCP::TYPE_UDP)
{
tty_set_generic_udp_format(1);
}
mount->setPortFD(PortFD);
mount->Handshake();
// Mount initialisation is in updateProperties as it sets directly Indi properties which should be defined
}
catch (EQModError &e)
{
return false;
//return (e.DefaultHandleException(this));
}
#ifdef WITH_ALIGN
// Set this according to mount type
SetApproximateMountAlignmentFromMountType(EQUATORIAL);
#endif
LOG_INFO("Successfully connected to EQMod Mount.");
return true;
}
void EQMod::abnormalDisconnectCallback(void *userpointer)
{
EQMod *p = static_cast<EQMod *>(userpointer);
if (p->Connect())
{
p->setConnected(true, IPS_OK);
p->updateProperties();
}
}
void EQMod::abnormalDisconnect()
{
// Ignore disconnect errors
INDI::Telescope::Disconnect();
// Set Disconnected
setConnected(false, IPS_IDLE);
// Update properties
updateProperties();
// Reconnect in 2 seconds
IEAddTimer(2000, (IE_TCF *)abnormalDisconnectCallback, this);
}
bool EQMod::Disconnect()
{
if (isConnected())
{
try
{
mount->Disconnect();
}
catch (EQModError &e)
{
LOGF_ERROR("Error when disconnecting mount -> %s", e.message);
return (false);
}
return INDI::Telescope::Disconnect();
}
else
return false;
}
void EQMod::TimerHit()
{
if (isConnected())
{
bool rc;
// Skip reading scope status if we are in a middle of a pulse
// to avoid delaying it
if (pulseInProgress != 0)
{
rc = true;
}
else
{
rc = ReadScopeStatus();
}
if (rc == false)
{
// read was not good
EqNP.setState(IPS_ALERT);
EqNP.apply();
}
SetTimer(getCurrentPollingPeriod());
}
}
bool EQMod::ReadScopeStatus()
{
// Time
double juliandate = 0;
double lst = 0;
char hrlst[12] = {0};
const char *datenames[] = { "LST", "JULIANDATE", "UTC" };
double periods[2];
const char *periodsnames[] = { "RAPERIOD", "DEPERIOD" };
double horizvalues[2];
const char *horiznames[2] = { "AZ", "ALT" };
double steppervalues[2];
const char *steppernames[] = { "RAStepsCurrent", "DEStepsCurrent" };
juliandate = getJulianDate();
lst = getLst(juliandate, getLongitude());
fs_sexa(hrlst, lst, 2, 360000);
hrlst[11] = '\0';
DEBUGF(DBG_SCOPE_STATUS, "Compute local time: lst=%2.8f (%s) - julian date=%8.8f", lst, hrlst, juliandate);
TimeLSTNP.update(&lst, (char **)(datenames), 1);
TimeLSTNP.setState(IPS_OK);
TimeLSTNP.apply();
JulianNP.update(&juliandate, (char **)(datenames + 1), 1);
JulianNP.setState(IPS_OK);
JulianNP.apply();
try
{
TelescopePierSide pierSide;
currentRAEncoder = mount->GetRAEncoder();
currentDEEncoder = mount->GetDEEncoder();
DEBUGF(DBG_SCOPE_STATUS, "Current encoders RA=%ld DE=%ld", static_cast<long>(currentRAEncoder),
static_cast<long>(currentDEEncoder));
EncodersToRADec(currentRAEncoder, currentDEEncoder, lst, ¤tRA, ¤tDEC, ¤tHA, &pierSide);
setPierSide(pierSide);
alignedRA = currentRA;
alignedDEC = currentDEC;
ghalignedRA = currentRA;
ghalignedDEC = currentDEC;
bool aligned = false;
#ifdef WITH_ALIGN_GEEHALEL
if (align)
{
align->GetAlignedCoords(syncdata, juliandate, &m_Location, currentRA, currentDEC, &ghalignedRA,
&ghalignedDEC);
aligned = true;
}
// else
#endif
#ifdef WITH_ALIGN
// Only use INDI Alignment Subsystem if it is active.
if (AlignMethodSP.sp[1].s == ISS_ON)
{
const char *maligns[3] = { "ZENITH", "NORTH", "SOUTH" };
INDI::IEquatorialCoordinates RaDec;
// Use HA/Dec as telescope coordinate system
RaDec.rightascension = currentRA;
RaDec.declination = currentDEC;
TelescopeDirectionVector TDV = TelescopeDirectionVectorFromEquatorialCoordinates(RaDec);
DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT,
"Status: Mnt. Algnt. %s Date %lf encoders RA=%ld DE=%ld Telescope RA %lf DEC %lf",
maligns[GetApproximateMountAlignment()], juliandate,
static_cast<long>(currentRAEncoder), static_cast<long>(currentDEEncoder),
currentRA, currentDEC);
DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, " Direction RA(deg.) %lf DEC %lf TDV(x %lf y %lf z %lf)",
RaDec.rightascension, RaDec.declination, TDV.x, TDV.y, TDV.z);
aligned = true;
if (!TransformTelescopeToCelestial(TDV, alignedRA, alignedDEC))
{
aligned = false;
DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT,
"Failed TransformTelescopeToCelestial: Scope RA=%g Scope DE=%f, Aligned RA=%f DE=%f", currentRA,
currentDEC, alignedRA, alignedDEC);
}
else
{
DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT,
"TransformTelescopeToCelestial: Scope RA=%f Scope DE=%f, Aligned RA=%f DE=%f", currentRA, currentDEC,
alignedRA, alignedDEC);
}
}
#endif
if (!aligned && (syncdata.lst != 0.0))
{
DEBUGF(DBG_SCOPE_STATUS, "Aligning with last sync delta RA %g DE %g", syncdata.deltaRA, syncdata.deltaDEC);
// should check values are in range!
alignedRA += syncdata.deltaRA;
alignedDEC += syncdata.deltaDEC;
if (alignedDEC > 90.0 || alignedDEC < -90.0)
{
alignedRA += 12.00;
if (alignedDEC > 0.0)
alignedDEC = 180.0 - alignedDEC;
else
alignedDEC = -180.0 - alignedDEC;
}
alignedRA = range24(alignedRA);
}
#if defined WITH_ALIGN_GEEHALEL && !defined WITH_ALIGN
alignedRA = ghalignedRA;
alignedDEC = ghalignedDEC;
#endif
#if defined WITH_ALIGN_GEEHALEL && defined WITH_ALIGN
if (AlignMethodSP.sp[0].s == ISS_ON)
{
alignedRA = ghalignedRA;
alignedDEC = ghalignedDEC;
}
#endif
lnradec.rightascension = alignedRA;
lnradec.declination = alignedDEC;
// Only update Alt/Az if the scope is not idle.
if (TrackState != SCOPE_IDLE && TrackState != SCOPE_PARKED)
{
/* uses sidereal time, not local sidereal time */
INDI::EquatorialToHorizontal(&lnradec, &m_Location, juliandate, &lnaltaz);
horizvalues[0] = lnaltaz.azimuth;
horizvalues[1] = lnaltaz.altitude;
HorizontalCoordNP.update(horizvalues, (char **)horiznames, 2);
HorizontalCoordNP.apply();
}
steppervalues[0] = currentRAEncoder;
steppervalues[1] = currentDEEncoder;
CurrentSteppersNP.update(steppervalues, (char **)steppernames, 2);
CurrentSteppersNP.apply();
mount->GetRAMotorStatus(RAStatusLP);
mount->GetDEMotorStatus(DEStatusLP);
RAStatusLP.apply();
DEStatusLP.apply();
periods[0] = mount->GetRAPeriod();
periods[1] = mount->GetDEPeriod();
PeriodsNP.update(periods, (char **)periodsnames, 2);
PeriodsNP.apply();
// Log all coords
{
char CurrentRAString[64] = {0}, CurrentDEString[64] = {0},
AlignedRAString[64] = {0}, AlignedDEString[64] = {0},
AZString[64] = {0}, ALString[64] = {0};
fs_sexa(CurrentRAString, currentRA, 2, 3600);
fs_sexa(CurrentDEString, currentDEC, 2, 3600);
fs_sexa(AlignedRAString, alignedRA, 2, 3600);
fs_sexa(AlignedDEString, alignedDEC, 2, 3600);
fs_sexa(AZString, horizvalues[0], 2, 3600);
fs_sexa(ALString, horizvalues[1], 2, 3600);
LOGF_DEBUG("Scope RA (%s) DE (%s) Aligned RA (%s) DE (%s) AZ (%s) ALT (%s), PierSide (%s)",
CurrentRAString,
CurrentDEString,
AlignedRAString,
AlignedDEString,
AZString,
ALString,
pierSide == PIER_EAST ? "East" : (pierSide == PIER_WEST ? "West" : "Unknown"));
}
if (mount->HasAuxEncoders())
{
double auxencodervalues[2];
const char *auxencodernames[] = { "AUXENCRASteps", "AUXENCDESteps" };
auxencodervalues[0] = mount->GetRAAuxEncoder();
auxencodervalues[1] = mount->GetDEAuxEncoder();
AuxEncoderNP.update(auxencodervalues, (char **)auxencodernames, 2);
AuxEncoderNP.apply();
}
if (gotoInProgress())
{
if (!(mount->IsRARunning()) && !(mount->IsDERunning()))
{
// Goto iteration
gotoparams.iterative_count += 1;
LOGF_INFO(
"Iterative Goto (%d): RA diff = %4.2f arcsecs DE diff = %4.2f arcsecs",
gotoparams.iterative_count, 3600 * fabs(gotoparams.ratarget - currentRA),
3600 * fabs(gotoparams.detarget - currentDEC));
if ((gotoparams.iterative_count <= GOTO_ITERATIVE_LIMIT) &&
(((3600 * fabs(gotoparams.ratarget - currentRA)) > RAGOTORESOLUTION) ||
((3600 * fabs(gotoparams.detarget - currentDEC)) > DEGOTORESOLUTION)))
{
gotoparams.racurrent = currentRA;
gotoparams.decurrent = currentDEC;
gotoparams.racurrentencoder = currentRAEncoder;
gotoparams.decurrentencoder = currentDEEncoder;
EncoderTarget(&gotoparams);
// Start iterative slewing
LOGF_INFO(
"Iterative goto (%d): slew mount to RA increment = %d, DE increment = %d",
gotoparams.iterative_count, static_cast<int>(gotoparams.ratargetencoder - gotoparams.racurrentencoder),
static_cast<int>(gotoparams.detargetencoder - gotoparams.decurrentencoder));
mount->SlewTo(static_cast<int>(gotoparams.ratargetencoder - gotoparams.racurrentencoder),