Instrument Neutral Distributed Interface INDI 2.2.5
lx200telescope.cpp
Go to the documentation of this file.
1/*
2 * Standard LX200 implementation.
3
4 Copyright (C) 2003 - 2018 Jasem Mutlaq ([email protected])
5 Minor changes Copyright (C) 2021 James Lancaster
6
7 This library is free software;
8 you can redistribute it and / or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation;
11 either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY;
16 without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library;
22 if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
24 */
25
26#include "lx200telescope.h"
27
28#include "indicom.h"
29#include "lx200driver.h"
30
31#include <libnova/sidereal_time.h>
32
33#include <cmath>
34#include <memory>
35#include <cstring>
36#include <unistd.h>
37#include <time.h>
38
39/* Simulation Parameters */
40#define LX200_GENERIC_SLEWRATE 5 /* slew rate, degrees/s */
41#define SIDRATE 0.004178 /* sidereal rate, degrees/s */
42
44{
45}
46
52
54{
55 return getDefaultName();
56}
57
59{
60 return static_cast<const char *>("Standard LX200");
61}
62
63
65{
66 /* Make sure to init parent properties first */
68
69 IUFillSwitch(&AlignmentS[0], "Polar", "", ISS_ON);
70 IUFillSwitch(&AlignmentS[1], "AltAz", "", ISS_OFF);
71 IUFillSwitch(&AlignmentS[2], "Land", "", ISS_OFF);
74
75#if 0
76 IUFillSwitch(&SlewRateS[SLEW_GUIDE], "SLEW_GUIDE", "Guide", ISS_OFF);
77 IUFillSwitch(&SlewRateS[SLEW_CENTERING], "SLEW_CENTERING", "Centering", ISS_OFF);
78 IUFillSwitch(&SlewRateS[SLEW_FIND], "SLEW_FIND", "Find", ISS_OFF);
79 IUFillSwitch(&SlewRateS[SLEW_MAX], "SLEW_MAX", "Max", ISS_ON);
80 IUFillSwitchVector(&SlewRateSP, SlewRateS, 4, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW,
82#endif
83
84#if 0
85 IUFillSwitch(&TrackModeS[0], "TRACK_SIDEREAL", "Sidereal", ISS_ON);
86 IUFillSwitch(&TrackModeS[1], "TRACK_SOLAR", "Solar", ISS_OFF);
87 IUFillSwitch(&TrackModeS[2], "TRACK_LUNAR", "Lunar", ISS_OFF);
88 IUFillSwitch(&TrackModeS[3], "TRACK_CUSTOM", "Custom", ISS_OFF);
89 IUFillSwitchVector(&TrackModeSP, TrackModeS, 4, getDeviceName(), "TELESCOPE_TRACK_MODE", "Track Mode", MOTION_TAB,
91#endif
92
93 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
94 AddTrackMode("TRACK_SOLAR", "Solar");
95 AddTrackMode("TRACK_LUNAR", "Lunar");
96 AddTrackMode("TRACK_CUSTOM", "Custom");
97
99 {
100 IUFillNumber(&TrackFreqN[0], "trackFreq", "Freq", "%g", 55, 65, 0.00001, 60.16427);
101 }
102 else
103 {
104 IUFillNumber(&TrackFreqN[0], "trackFreq", "Freq", "%g", 56.4, 60.1, 0.1, 60.1);
105 }
106 IUFillNumberVector(&TrackFreqNP, TrackFreqN, 1, getDeviceName(), "Tracking Frequency", "", MOTION_TAB, IP_RW, 0,
107 IPS_IDLE);
108
109 IUFillSwitch(&UsePulseCmdS[0], "Off", "Off", ISS_OFF);
110 IUFillSwitch(&UsePulseCmdS[1], "On", "On", ISS_ON);
113
114 int selectedSite = 0;
115 IUGetConfigOnSwitchIndex(getDeviceName(), "Sites", &selectedSite);
116 IUFillSwitch(&SiteS[0], "Site 1", "Site 1", selectedSite == 0 ? ISS_ON : ISS_OFF);
117 IUFillSwitch(&SiteS[1], "Site 2", "Site 2", selectedSite == 1 ? ISS_ON : ISS_OFF);
118 IUFillSwitch(&SiteS[2], "Site 3", "Site 3", selectedSite == 2 ? ISS_ON : ISS_OFF);
119 IUFillSwitch(&SiteS[3], "Site 4", "Site 4", selectedSite == 3 ? ISS_ON : ISS_OFF);
121
122 char siteName[64] = {"NA"};
123 IUGetConfigText(getDeviceName(), "Site Name", "Name", siteName, 64);
124 IUFillText(&SiteNameT[0], "Name", "Name", siteName);
125 IUFillTextVector(&SiteNameTP, SiteNameT, 1, getDeviceName(), "Site Name", "Site Name", SITE_TAB, IP_RW, 0, IPS_IDLE);
126
127
129 {
132
133 // IUFillSwitch(&FocusModeS[0], "FOCUS_HALT", "Halt", ISS_ON);
134 // IUFillSwitch(&FocusModeS[1], "FOCUS_SLOW", "Slow", ISS_OFF);
135 // IUFillSwitch(&FocusModeS[2], "FOCUS_FAST", "Fast", ISS_OFF);
136 // IUFillSwitchVector(&FocusModeSP, FocusModeS, 3, getDeviceName(), "FOCUS_MODE", "Mode", FOCUS_TAB, IP_RW,
137 // ISR_1OFMANY, 0, IPS_IDLE);
138
139 // Classical speeds slow or fast
140 FocusSpeedNP[0].setMin(1);
141 FocusSpeedNP[0].setMax(2);
142 FocusSpeedNP[0].setValue(1);
144 }
145
147
149
150 /* Add debug/simulation/config controls so we may debug driver if necessary */
152
154
155 if (m_Location.longitude > 0)
157 if (m_Location.latitude != 0)
158 currentDEC = m_Location.latitude > 0 ? 90 : -90;
159 return true;
160}
161
163{
164 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
165 return;
166
168
169 /*
170 if (isConnected())
171 {
172 if (genericCapability & LX200_HAS_ALIGNMENT_TYPE)
173 defineProperty(&AlignmentSP);
174
175 if (genericCapability & LX200_HAS_TRACKING_FREQ)
176 defineProperty(&TrackFreqNP);
177
178 if (genericCapability & LX200_HAS_PULSE_GUIDING)
179 defineProperty(&UsePulseCmdSP);
180
181 if (genericCapability & LX200_HAS_SITES)
182 {
183 defineProperty(&SiteSP);
184 defineProperty(&SiteNameTP);
185 }
186
187 defineProperty(&GuideNSNP);
188 defineProperty(&GuideWENP);
189
190 if (genericCapability & LX200_HAS_FOCUS)
191 {
192 defineProperty(&FocusMotionSP);
193 defineProperty(&FocusTimerNP);
194 defineProperty(&FocusModeSP);
195 }
196 }
197 */
198}
199
201{
203
204 if (isConnected())
205 {
208
211
214
216 {
219 }
220
222
223
225 {
227 //defineProperty(&FocusModeSP);
228 }
229
230 getBasicData();
231 }
232 else
233 {
236
239
242
244 {
247 }
248
250
252 {
254 //deleteProperty(FocusModeSP.name);
255 }
256 }
257
258 return true;
259}
260
262{
263 if (isSimulation())
264 return true;
265
266 return (check_lx200_connection(PortFD) == 0);
267}
268
270{
271 return checkConnection();
272}
273
275{
276 return (::isSlewComplete(PortFD) == 1);
277}
278
280{
281 if (!isConnected())
282 return false;
283
284 if (isSimulation())
285 {
286 mountSim();
287 return true;
288 }
289
290 //if (check_lx200_connection(PortFD))
291 //return false;
292
294 {
295 // Check if LX200 is done slewing
296 if (isSlewComplete())
297 {
298 // Set slew mode to "Centering"
299 SlewRateSP.reset();
301 SlewRateSP.apply();
302
304 LOG_INFO("Slew is complete. Tracking...");
305 }
306 }
307 else if (TrackState == SCOPE_PARKING)
308 {
309 if (isSlewComplete())
310 {
311 SetParked(true);
312 }
313 }
314
316 {
317 EqNP.setState(IPS_ALERT);
318 LOG_ERROR("Error reading RA/DEC.");
319 EqNP.apply();
320 return false;
321 }
322
324
325 return true;
326}
327
328bool LX200Telescope::Goto(double ra, double dec)
329{
330 const struct timespec timeout = {0, 100000000L};
331
332 targetRA = ra;
333 targetDEC = dec;
334 char RAStr[64] = {0}, DecStr[64] = {0};
335 int fracbase = 0;
336
337 switch (getLX200EquatorialFormat())
338 {
340 fracbase = 360000;
341 break;
344 default:
345 fracbase = 3600;
346 break;
347 }
348
349 fs_sexa(RAStr, targetRA, 2, fracbase);
350 fs_sexa(DecStr, targetDEC, 2, fracbase);
351
352 // If moving, let's stop it first.
353 if (EqNP.getState() == IPS_BUSY)
354 {
355 if (!isSimulation() && abortSlew(PortFD) < 0)
356 {
357 AbortSP.setState(IPS_ALERT);
358 LOG_ERROR("Abort slew failed.");
359 AbortSP.apply();
360 return false;
361 }
362
363 AbortSP.setState(IPS_OK);
364 EqNP.setState(IPS_IDLE);
365 LOG_ERROR("Slew aborted.");
366 AbortSP.apply();
367 EqNP.apply();
368
369 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
370 {
371 MovementNSSP.setState(IPS_IDLE);
372 MovementWESP.setState(IPS_IDLE);
373 EqNP.setState(IPS_IDLE);
374 MovementNSSP.reset();
375 MovementWESP.reset();
376 MovementNSSP.apply();
377 MovementWESP.apply();
378 }
379
380 // sleep for 100 mseconds
381 nanosleep(&timeout, nullptr);
382 }
383
384 if (!isSimulation())
385 {
387 {
388 EqNP.setState(IPS_ALERT);
389 LOG_ERROR("Error setting RA/DEC.");
390 EqNP.apply();
391 return false;
392 }
393
394 int err = 0;
395
396 /* Slew reads the '0', that is not the end of the slew */
397 if ((err = Slew(PortFD)))
398 {
399 LOGF_ERROR("Error Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
400 slewError(err);
401 return false;
402 }
403 }
404
406 //EqNP.s = IPS_BUSY;
407
408 LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
409
410 return true;
411}
412
413bool LX200Telescope::Sync(double ra, double dec)
414{
415 char syncString[256] = {0};
416
417 if (!isSimulation() && (setObjectRA(PortFD, ra) < 0 || (setObjectDEC(PortFD, dec)) < 0))
418 {
419 EqNP.setState(IPS_ALERT);
420 LOG_ERROR("Error setting RA/DEC. Unable to Sync.");
421 EqNP.apply();
422 return false;
423 }
424
425 if (!isSimulation() && ::Sync(PortFD, syncString) < 0)
426 {
427 EqNP.setState(IPS_ALERT);
428 LOG_ERROR("Synchronization failed.");
429 EqNP.apply();
430 return false;
431 }
432
433 currentRA = ra;
434 currentDEC = dec;
435
436 LOG_INFO("Synchronization successful.");
437
438 EqNP.setState(IPS_OK);
439
441
442 return true;
443}
444
446{
447 const struct timespec timeout = {0, 100000000L};
448 if (!isSimulation())
449 {
450 // If scope is moving, let's stop it first.
451 if (EqNP.getState() == IPS_BUSY)
452 {
453 if (!isSimulation() && abortSlew(PortFD) < 0)
454 {
455 AbortSP.setState(IPS_ALERT);
456 LOG_ERROR("Abort slew failed");
457 AbortSP.apply();
458 return false;
459 }
460
461 AbortSP.setState(IPS_OK);
462 EqNP.setState(IPS_IDLE);
463 LOG_ERROR("Slew aborted.");
464 AbortSP.apply();
465 EqNP.apply();
466
467 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
468 {
469 MovementNSSP.setState(IPS_IDLE);
470 MovementWESP.setState(IPS_IDLE);
471 EqNP.setState(IPS_IDLE);
472 MovementNSSP.reset();
473 MovementWESP.reset();
474
475 MovementNSSP.apply();
476 MovementWESP.apply();
477 }
478
479 // sleep for 100 msec
480 nanosleep(&timeout, nullptr);
481 }
482
483 if (!isSimulation() && slewToPark(PortFD) < 0)
484 {
485 ParkSP.setState(IPS_ALERT);
486 LOG_ERROR("Parking Failed.");
487 ParkSP.apply();
488 return false;
489 }
490 }
491
493 LOG_INFO("Parking telescope in progress...");
494 return true;
495}
496
498{
499 int current_move = (dir == DIRECTION_NORTH) ? LX200_NORTH : LX200_SOUTH;
500
501 switch (command)
502 {
503 case MOTION_START:
504 if (!isSimulation() && MoveTo(PortFD, current_move) < 0)
505 {
506 LOG_ERROR("Error setting N/S motion direction.");
507 return false;
508 }
509 else
510 LOGF_DEBUG("Moving toward %s.",
511 (current_move == LX200_NORTH) ? "North" : "South");
512 break;
513
514 case MOTION_STOP:
515 if (!isSimulation() && HaltMovement(PortFD, current_move) < 0)
516 {
517 LOG_ERROR("Error stopping N/S motion.");
518 return false;
519 }
520 else
521 LOGF_DEBUG("Movement toward %s halted.",
522 (current_move == LX200_NORTH) ? "North" : "South");
523 break;
524 }
525
526 return true;
527}
528
530{
531 int current_move = (dir == DIRECTION_WEST) ? LX200_WEST : LX200_EAST;
532
533 switch (command)
534 {
535 case MOTION_START:
536 if (!isSimulation() && MoveTo(PortFD, current_move) < 0)
537 {
538 LOG_ERROR("Error setting W/E motion direction.");
539 return false;
540 }
541 else
542 LOGF_DEBUG("Moving toward %s.", (current_move == LX200_WEST) ? "West" : "East");
543 break;
544
545 case MOTION_STOP:
546 if (!isSimulation() && HaltMovement(PortFD, current_move) < 0)
547 {
548 LOG_ERROR("Error stopping W/E motion.");
549 return false;
550 }
551 else
552 LOGF_DEBUG("Movement toward %s halted.",
553 (current_move == LX200_WEST) ? "West" : "East");
554 break;
555 }
556
557 return true;
558}
559
561{
562 if (!isSimulation() && abortSlew(PortFD) < 0)
563 {
564 LOG_ERROR("Failed to abort slew.");
565 return false;
566 }
567
568 if (GuideNSNP.getState() == IPS_BUSY || GuideWENP.getState() == IPS_BUSY)
569 {
570 GuideNSNP.setState(IPS_IDLE);
571 GuideWENP.setState(IPS_IDLE);
572 GuideWENP[AXIS_RA].setValue(0);
573 GuideWENP[AXIS_DE].setValue(0);
574 GuideNSNP[AXIS_RA].setValue(0);
575 GuideNSNP[AXIS_DE].setValue(0);
576
577 if (GuideNSTID)
578 {
580 GuideNSTID = 0;
581 }
582
583 if (GuideWETID)
584 {
586 GuideWETID = 0;
587 }
588
589 LOG_INFO("Guide aborted.");
590 GuideNSNP.apply();
591 GuideWENP.apply();
592
593 return true;
594 }
595
596 return true;
597}
598
599bool LX200Telescope::setLocalDate(uint8_t days, uint8_t months, uint16_t years)
600{
601 return (setCalenderDate(PortFD, days, months, years) == 0);
602}
603
604bool LX200Telescope::setLocalTime24(uint8_t hour, uint8_t minute, uint8_t second)
605{
606 return (setLocalTime(PortFD, hour, minute, second) == 0);
607}
608
610{
611 return (::setUTCOffset(PortFD, (offset * -1.0)) == 0);
612}
613
614bool LX200Telescope::updateTime(ln_date *utc, double utc_offset)
615{
616 struct ln_zonedate ltm;
617
618 if (isSimulation())
619 return true;
620
621 ln_date_to_zonedate(utc, &ltm, utc_offset * 3600.0);
622
623 JD = ln_get_julian_day(utc);
624
625 LOGF_DEBUG("New JD is %.2f", JD);
626
627 // Meade defines UTC Offset as the offset ADDED to local time to yield UTC, which
628 // is the opposite of the standard definition of UTC offset!
629 if (setUTCOffset(utc_offset) == false)
630 {
631 LOG_ERROR("Error setting UTC Offset.");
632 return false;
633 }
634
635 // Set Local Time
636 if (setLocalTime24(ltm.hours, ltm.minutes, ltm.seconds) == false)
637 {
638 LOG_ERROR("Error setting local time.");
639 return false;
640 }
641
642 if (setLocalDate(ltm.days, ltm.months, ltm.years) == false)
643 {
644 LOG_ERROR("Error setting local date.");
645 return false;
646 }
647
648 LOG_INFO("Time updated, updating planetary data...");
649 return true;
650}
651
652bool LX200Telescope::updateLocation(double latitude, double longitude, double elevation)
653{
654 INDI_UNUSED(elevation);
655
656 // JM 2021-04-10: MUST convert from INDI longitude to standard longitude.
657 // DO NOT REMOVE
658 if (longitude > 180)
659 longitude = longitude - 360;
660
661 if (!isSimulation())
662 {
663 if (setSiteLongitude(PortFD, longitude) < 0)
664 {
665 LOG_ERROR("Error setting site longitude coordinates");
666 return false;
667 }
668
669 if (setSiteLatitude(PortFD, latitude) < 0)
670 {
671 LOG_ERROR("Error setting site latitude coordinates");
672 return false;
673 }
674 }
675
676 char l[MAXINDINAME] = {0}, L[MAXINDINAME] = {0};
677 fs_sexa(l, latitude, 2, 36000);
678 fs_sexa(L, longitude, 2, 36000);
679
680 // Choose WGS 84, also known as EPSG:4326 for latitude/longitude ordering
681 LOGF_INFO("Site location in the mount updated to Latitude %.12s (%g) Longitude %.12s (%g) (Longitude sign in carthography format)",
682 l, latitude, L, longitude);
683
684 return true;
685}
686
687bool LX200Telescope::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
688{
689 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
690 {
691 if (!strcmp(name, SiteNameTP.name))
692 {
693 if (!isSimulation() && setSiteName(PortFD, texts[0], currentSiteNum) < 0)
694 {
696 IDSetText(&SiteNameTP, "Setting site name");
697 return false;
698 }
699
700 SiteNameTP.s = IPS_OK;
701 IText *tp = IUFindText(&SiteNameTP, names[0]);
702 IUSaveText(tp, texts[0]);
703 IDSetText(&SiteNameTP, "Site name updated");
704 return true;
705 }
706 }
707
708 return INDI::Telescope::ISNewText(dev, name, texts, names, n);
709}
710
711bool LX200Telescope::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
712{
713 // Check focuser interface
714 if (FI::processNumber(dev, name, values, names, n))
715 return true;
716 // Check guider interface
717 if (GI::processNumber(dev, name, values, names, n))
718 return true;
719
720 // Check rest of LX200Telescope properties
721 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
722 {
723 // Update Frequency
724 if (!strcmp(name, TrackFreqNP.name))
725 {
726 LOGF_DEBUG("Trying to set track freq of: %04.1f", values[0]);
728 {
729 if (!isSimulation() && setPreciseTrackFreq(PortFD, values[0]) < 0)
730 {
732 IDSetNumber(&TrackFreqNP, "Error setting tracking frequency");
733 return false;
734 }
736 TrackFreqNP.np[0].value = values[0];
737 IDSetNumber(&TrackFreqNP, "Tracking frequency set to %8.5f", values[0]);
738 }
739 else
740 {
741 //Normal Tracking Frequency
742 if (!isSimulation() && setTrackFreq(PortFD, values[0]) < 0)
743
744 LOGF_DEBUG("Trying to set track freq of: %f\n", values[0]);
745 if (!isSimulation() && setTrackFreq(PortFD, values[0]) < 0)
746 {
747 LOGF_DEBUG("Trying to set track freq of: %f\n", values[0]);
748 if (!isSimulation() && setTrackFreq(PortFD, values[0]) < 0)
749 {
751 IDSetNumber(&TrackFreqNP, "Error setting tracking frequency");
752 return false;
753 }
755 IDSetNumber(&TrackFreqNP, "Error setting tracking frequency");
756 return false;
757 }
758
760 TrackFreqNP.np[0].value = values[0];
761 IDSetNumber(&TrackFreqNP, "Tracking frequency set to %04.1f", values[0]);
762 }
763
765 {
767 TrackModeSP[0].setState(ISS_OFF);
768 TrackModeSP[1].setState(ISS_OFF);
769 TrackModeSP[2].setState(ISS_OFF);
770 TrackModeSP[3].setState(ISS_ON);
771 TrackModeSP.setState(IPS_OK);
773 TrackModeSP.apply();
774 }
775
776 return true;
777 }
778 }
779
780 // if we didn't process it, continue up the chain, let somebody else
781 // give it a shot
782 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
783}
784
785bool LX200Telescope::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
786{
787 // Focuser Interface
788 if (FI::processSwitch(dev, name, states, names, n))
789 return true;
790
791 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
792 {
793 // Alignment
794 if (!strcmp(name, AlignmentSP.name))
795 {
796 if (IUUpdateSwitch(&AlignmentSP, states, names, n) < 0)
797 return false;
798
799 int index = IUFindOnSwitchIndex(&AlignmentSP);
800
801 if (!isSimulation() && setAlignmentMode(PortFD, index) < 0)
802 {
804 IDSetSwitch(&AlignmentSP, "Error setting alignment mode.");
805 return false;
806 }
807
809 IDSetSwitch(&AlignmentSP, nullptr);
811 return true;
812 }
813
814 // Sites
815 if (!strcmp(name, SiteSP.name))
816 {
817 if (IUUpdateSwitch(&SiteSP, states, names, n) < 0)
818 return false;
819
821
823 {
824 SiteSP.s = IPS_ALERT;
825 IDSetSwitch(&SiteSP, "Error selecting sites.");
826 return false;
827 }
828 char siteName[64] = {0};
829 if (isSimulation())
830 {
831 IUSaveText(&SiteNameTP.tp[0], "Sample Site");
832 }
833 else
834 {
836 IUSaveText(&SiteNameT[0], siteName);
837 }
840
841 SiteNameTP.s = IPS_OK;
842 SiteSP.s = IPS_OK;
843
844 IDSetText(&SiteNameTP, nullptr);
845 IDSetSwitch(&SiteSP, nullptr);
846
847 return false;
848 }
849
850 // Pulse-Guide command support
851 if (!strcmp(name, UsePulseCmdSP.name))
852 {
854 IUUpdateSwitch(&UsePulseCmdSP, states, names, n);
855
857 IDSetSwitch(&UsePulseCmdSP, nullptr);
859 LOGF_INFO("Pulse guiding is %s.", usePulseCommand ? "enabled" : "disabled");
860 return true;
861 }
862 }
863
864 // Nobody has claimed this, so pass it to the parent
865 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
866}
867
869{
870 if (isSimulation())
871 return true;
872
873 bool rc = (selectTrackingMode(PortFD, mode) == 0);
874
875 // Only update tracking frequency if it is defined and not deleted by child classes
876 // Note, that LX200_HAS_PRECISE_TRACKING_FREQ can use the same get function
878 {
879 getTrackFreq(PortFD, &TrackFreqN[0].value);
880 IDSetNumber(&TrackFreqNP, nullptr);
881 }
882 return rc;
883}
884
886{
887 // Convert index to Meade format
888 index = 3 - index;
889
890 if (!isSimulation() && setSlewMode(PortFD, index) < 0)
891 {
892 LOG_ERROR("Error setting slew mode.");
893 return false;
894 }
895
896 return true;
897}
898
900{
901 if (SlewRateSP.findOnSwitchIndex() == index)
902 return true;
903
904 if (!isSimulation() && setSlewMode(PortFD, 3 - index) < 0)
905 {
906 SlewRateSP.setState(IPS_ALERT);
907 LOG_ERROR("Error setting slew mode.");
908 SlewRateSP.apply();
909 return false;
910 }
911
912 SlewRateSP.reset();
913 SlewRateSP[index].setState(ISS_ON);
914 SlewRateSP.setState(IPS_OK);
915 SlewRateSP.apply();
916 return true;
917}
918
920{
921 static_cast<LX200Telescope *>(p)->updateFocusTimer();
922}
923
925{
926 // switch (FocusTimerNP.s)
927 // {
928 // case IPS_IDLE:
929 // break;
930
931 // case IPS_BUSY:
932 // //if (isDebug())
933 // //IDLog("Focus Timer Value is %g\n", FocusTimerN[0].value);
934
935 // FocusTimerN[0].value -= 50;
936
937 // if (FocusTimerN[0].value <= 0)
938 // {
939 // //if (isDebug())
940 // //IDLog("Focus Timer Expired\n");
941
942 // if (!isSimulation() && setFocuserSpeedMode(PortFD, 0) < 0)
943 // {
944 // FocusModeSP.s = IPS_ALERT;
945 // IDSetSwitch(&FocusModeSP, "Error setting focuser mode.");
946
947 // //if (isDebug())
948 // //IDLog("Error setting focuser mode\n");
949
950 // return;
951 // }
952
953 // FocusMotionSP.setState(IPS_IDLE);
954 // FocusTimerNP.s = IPS_OK;
955 // FocusModeSP.s = IPS_OK;
956
957 // FocusMotionSP.reset();
958 // IUResetSwitch(&FocusModeSP);
959 // FocusModeS[0].s = ISS_ON;
960
961 // IDSetSwitch(&FocusModeSP, nullptr);
962 // FocusMotionSP.apply();
963 // }
964
965 // FocusTimerNP.apply();
966
967 // if (FocusTimerN[0].value > 0)
968 // IEAddTimer(50, LX200Telescope::updateFocusHelper, this);
969 // break;
970
971 // case IPS_OK:
972 // break;
973
974 // case IPS_ALERT:
975 // break;
976 // }
977
978 AbortFocuser();
979 FocusTimerNP.setState(IPS_OK);
980 FocusTimerNP[0].setValue(0);
981 FocusTimerNP.apply();
982}
983
985{
986 static struct timeval ltv;
987 struct timeval tv;
988 double dt = 0, da = 0, dx = 0;
989 int nlocked = 0;
990
991 /* update elapsed time since last poll, don't presume exactly POLLMS */
992 gettimeofday(&tv, nullptr);
993
994 if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
995 ltv = tv;
996
997 dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
998 ltv = tv;
999 da = LX200_GENERIC_SLEWRATE * dt;
1000
1001 /* Process per current state. We check the state of EQUATORIAL_COORDS and act accordingly */
1002 switch (TrackState)
1003 {
1004
1005 case SCOPE_IDLE:
1006 currentRA += (TRACKRATE_SIDEREAL / 3600.0 * dt / 15.);
1007 break;
1008
1009 case SCOPE_TRACKING:
1010 switch (TrackModeSP.findOnSwitchIndex())
1011 {
1012 case TRACK_SIDEREAL:
1013 da = 0;
1014 dx = 0;
1015 break;
1016
1017 case TRACK_LUNAR:
1018 da = ((TRACKRATE_LUNAR - TRACKRATE_SIDEREAL) / 3600.0 * dt / 15.);
1019 dx = 0;
1020 break;
1021
1022 case TRACK_SOLAR:
1023 da = ((TRACKRATE_SOLAR - TRACKRATE_SIDEREAL) / 3600.0 * dt / 15.);
1024 dx = 0;
1025 break;
1026
1027 case TRACK_CUSTOM:
1028 da = ((TrackRateNP[AXIS_RA].getValue() - TRACKRATE_SIDEREAL) / 3600.0 * dt / 15.);
1029 dx = (TrackRateNP[AXIS_DE].getValue() / 3600.0 * dt);
1030 break;
1031
1032 }
1033
1034 currentRA += da;
1035 currentDEC += dx;
1036 break;
1037
1038 case SCOPE_SLEWING:
1039 case SCOPE_PARKING:
1040 /* slewing - nail it when both within one pulse @ LX200_GENERIC_SLEWRATE */
1041 nlocked = 0;
1042
1043 dx = targetRA - currentRA;
1044
1045 if (fabs(dx) <= da)
1046 {
1048 nlocked++;
1049 }
1050 else if (dx > 0)
1051 currentRA += da / 15.;
1052 else
1053 currentRA -= da / 15.;
1054
1055 dx = targetDEC - currentDEC;
1056 if (fabs(dx) <= da)
1057 {
1059 nlocked++;
1060 }
1061 else if (dx > 0)
1062 currentDEC += da;
1063 else
1064 currentDEC -= da;
1065
1066 if (nlocked == 2)
1067 {
1070 else
1071 SetParked(true);
1072 }
1073
1074 break;
1075
1076 default:
1077 break;
1078 }
1079
1081}
1082
1084{
1085 if (!isSimulation())
1086 {
1088
1090 getAlignment();
1091
1092 // Only check time format if it is not already initialized by the class
1094 {
1095 if (getTimeFormat(PortFD, &timeFormat) < 0)
1096 LOG_ERROR("Failed to retrieve time format from device.");
1097 else
1098 {
1099 timeFormat = (timeFormat == 24) ? LX200_24 : LX200_AM;
1100 // We always do 24 hours
1101 if (timeFormat != LX200_24)
1102 {
1103 // Toggle format and suppress gcc warning
1104 int rc = toggleTimeFormat(PortFD);
1105 INDI_UNUSED(rc);
1106 }
1107 }
1108 }
1109
1111 {
1112 char siteName[64] = {0};
1113 if (getSiteName(PortFD, siteName, currentSiteNum) < 0)
1114 {
1115 LOG_ERROR("Failed to get site name from device");
1116 }
1117 else
1118 {
1119 IUSaveText(&SiteNameT[0], siteName);
1120 IDSetText(&SiteNameTP, nullptr);
1121 }
1122 }
1123
1124
1126 {
1127 if (getTrackFreq(PortFD, &TrackFreqN[0].value) < 0)
1128 LOG_ERROR("Failed to get tracking frequency from device.");
1129 else
1130 IDSetNumber(&TrackFreqNP, nullptr);
1131 }
1132
1133 }
1134
1138 sendScopeTime();
1139}
1140
1142{
1143 if (slewCode == 1)
1144 LOG_ERROR("Object below horizon.");
1145 else if (slewCode == 2)
1146 LOG_ERROR("Object below the minimum elevation limit.");
1147 else
1148 LOGF_ERROR("Slew failed (%d).", slewCode);
1149
1150 EqNP.setState(IPS_ALERT);
1151 EqNP.apply();
1152}
1153
1155{
1156 signed char align = ACK(PortFD);
1157 if (align < 0)
1158 {
1159 IDSetSwitch(&AlignmentSP, "Failed to get telescope alignment.");
1160 return;
1161 }
1162
1163 AlignmentS[0].s = ISS_OFF;
1164 AlignmentS[1].s = ISS_OFF;
1165 AlignmentS[2].s = ISS_OFF;
1166
1167 switch (align)
1168 {
1169 case 'P':
1170 AlignmentS[0].s = ISS_ON;
1171 break;
1172 case 'A':
1173 AlignmentS[1].s = ISS_ON;
1174 break;
1175 case 'L':
1176 AlignmentS[2].s = ISS_ON;
1177 break;
1178 case 'G':
1179 // German equatorial: no matching Alignment switch
1181 break;
1182 }
1183
1184 AlignmentSP.s = IPS_OK;
1185 IDSetSwitch(&AlignmentSP, nullptr);
1186
1187 int index = IUFindOnSwitchIndex(&AlignmentSP);
1188 if (index >= 0)
1190}
1191
1193{
1194 switch (index)
1195 {
1196 // Polar: a fork on a wedge, unless the driver already reports an equatorial type (e.g. GEM)
1197 case 0:
1198 if (getMountType() == MOUNT_ALTAZ)
1200 break;
1201 // AltAz or Land
1202 case 1:
1203 case 2:
1205 break;
1206 }
1207}
1208
1209bool LX200Telescope::getLocalTime(char *timeString)
1210{
1211 if (isSimulation())
1212 {
1213 time_t now = time (nullptr);
1214 strftime(timeString, MAXINDINAME, "%T", localtime(&now));
1215 }
1216 else
1217 {
1218 double ctime = 0;
1219 int h, m, s;
1220 if (getLocalTime24(PortFD, &ctime) < 0)
1221 return false;
1222 getSexComponents(ctime, &h, &m, &s);
1223 snprintf(timeString, MAXINDINAME, "%02d:%02d:%02d", h, m, s);
1224 }
1225
1226 return true;
1227}
1228
1229bool LX200Telescope::getLocalDate(char *dateString)
1230{
1231 if (isSimulation())
1232 {
1233 time_t now = time (nullptr);
1234 strftime(dateString, MAXINDINAME, "%F", localtime(&now));
1235 }
1236 else
1237 {
1238 if (getCalendarDate(PortFD, dateString) < 0)
1239 return false;
1240 }
1241
1242 return true;
1243}
1244
1246{
1247 if (isSimulation())
1248 {
1249 *offset = 3;
1250 return true;
1251 }
1252
1253 int lx200_utc_offset = 0;
1254 if (getUTCOffset(PortFD, &lx200_utc_offset) < 0)
1255 return false;
1256 // LX200 TimeT Offset is defined at the number of hours added to LOCAL TIME to get TimeT. This is contrary to the normal definition.
1257 *offset = lx200_utc_offset * -1;
1258 return true;
1259}
1260
1262{
1263 char cdate[MAXINDINAME] = {0};
1264 char ctime[MAXINDINAME] = {0};
1265 struct tm ltm;
1266 struct tm utm;
1267
1268 memset(&ltm, 0, sizeof(ltm));
1269 memset(&utm, 0, sizeof(utm));
1270
1271 time_t time_epoch;
1272
1273 double offset = 0;
1274 if (getUTFOffset(&offset) == false)
1275 {
1276 LOG_WARN("Could not obtain UTC offset from mount!");
1277 return false;
1278 }
1279
1280 if (getLocalTime(ctime) == false)
1281 {
1282 LOG_WARN("Could not obtain local time from mount!");
1283 return false;
1284 }
1285
1286 if (getLocalDate(cdate) == false)
1287 {
1288 LOG_WARN("Could not obtain local date from mount!");
1289 return false;
1290 }
1291
1292 // To ISO 8601 format in LOCAL TIME!
1293 char datetime[MAXINDINAME] = {0};
1294 snprintf(datetime, MAXINDINAME, "%sT%s", cdate, ctime);
1295
1296 // Now that date+time are combined, let's get tm representation of it.
1297 if (strptime(datetime, "%FT%T", &ltm) == nullptr)
1298 {
1299 LOGF_WARN("Could not process mount date and time: %s", datetime);
1300 return false;
1301 }
1302
1303 // Assume no daylight savings always
1304 int isdst = 0;
1305
1306 // Try to get whether daylight saving time is toggled.
1307 // By default we assume it's inactive.
1308 // N.B. This only works for LX200 Autostar II so shouldn't be used in base class.
1309 //getDaylightSaving(PortFD, &isdst);
1310
1311 ltm.tm_isdst = isdst;
1312
1313 // A mount without a battery backed clock boots with a placeholder date (e.g. 2000-01-01).
1314 // Do not advertise it as valid time, otherwise clients may adopt it. Leave TIME_UTC idle
1315 // until a client sets the time.
1316 if (ltm.tm_year + 1900 < MIN_VALID_MOUNT_YEAR)
1317 {
1318 LOGF_WARN("Mount clock is not set (%s local). Waiting for time to be set by the client.", datetime);
1319 TimeTP.setState(IPS_IDLE);
1320 TimeTP.apply();
1321 return false;
1322 }
1323
1324 // Get local time epoch in UNIX seconds
1325 time_epoch = mktime(&ltm);
1326
1327 // LOCAL to UTC by subtracting offset.
1328 time_epoch -= static_cast<int>(offset * 3600.0);
1329
1330 // Get UTC (we're using localtime_r, but since we shifted time_epoch above by UTCOffset, we should be getting the real UTC time)
1331 localtime_r(&time_epoch, &utm);
1332
1333 // Format it into the final UTC ISO 8601
1334 strftime(cdate, MAXINDINAME, "%Y-%m-%dT%H:%M:%S", &utm);
1335 TimeTP[UTC].setText(cdate);
1336
1337 char utcStr[8] = {0};
1338 snprintf(utcStr, 8, "%.2f", offset);
1339 TimeTP[OFFSET].setText(utcStr);
1340
1341 LOGF_DEBUG("Mount controller UTC Time: %s", TimeTP[UTC].getText());
1342 LOGF_DEBUG("Mount controller UTC Offset: %s", TimeTP[OFFSET].getText());
1343
1344 // Let's send everything to the client
1345 TimeTP.setState(IPS_OK);
1346 TimeTP.apply();
1347
1348 return true;
1349}
1350
1352{
1353 int lat_dd = 0, lat_mm = 0, long_dd = 0, long_mm = 0;
1354 double lat_ssf = 0.0, long_ssf = 0.0;
1355 char lat_sexagesimal[MAXINDIFORMAT];
1356 char lng_sexagesimal[MAXINDIFORMAT];
1357
1358 if (isSimulation())
1359 {
1360 LocationNP[LOCATION_LATITUDE].setValue(29.5);
1361 LocationNP[LOCATION_LONGITUDE].setValue(48.0);
1362 LocationNP[LOCATION_ELEVATION].setValue(10);
1363 LocationNP.setState(IPS_OK);
1364 LocationNP.apply( );
1365 return true;
1366 }
1367
1368 if (getSiteLatitude(PortFD, &lat_dd, &lat_mm, &lat_ssf) < 0)
1369 {
1370 LOG_WARN("Failed to get site latitude from device.");
1371 return false;
1372 }
1373 else
1374 {
1375 double value = 0;
1376 snprintf(lat_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", lat_dd, lat_mm, lat_ssf);
1377 f_scansexa(lat_sexagesimal, &value);
1378 LocationNP[LOCATION_LATITUDE].setValue(value);
1379 }
1380
1381 if (getSiteLongitude(PortFD, &long_dd, &long_mm, &long_ssf) < 0)
1382 {
1383 LOG_WARN("Failed to get site longitude from device.");
1384 return false;
1385 }
1386 else
1387 {
1388 double value = 0;
1389 snprintf(lng_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", long_dd, long_mm, long_ssf);
1390 f_scansexa(lng_sexagesimal, &value);
1391 value = range360(value);
1392 LocationNP[LOCATION_LONGITUDE].setValue(value);
1393 fs_sexa(lng_sexagesimal, LocationNP[LOCATION_LONGITUDE].getValue(), 2, 36000);
1394 }
1395
1396 LOGF_INFO("Mount has Latitude %s (%g) Longitude (0 to +360 Eastwards) %s (%g)",
1397 lat_sexagesimal,
1398 LocationNP[LOCATION_LATITUDE].getValue(),
1399 lng_sexagesimal,
1400 LocationNP[LOCATION_LONGITUDE].getValue());
1401
1402 LocationNP.apply();
1403
1404 saveConfig(true, "GEOGRAPHIC_COORD");
1405
1406 return true;
1407}
1408
1410{
1412 {
1413 LOG_ERROR("Cannot guide while slewing or parking in progress. Stop first.");
1414 return IPS_ALERT;
1415 }
1416
1417 // If we're using pulse command, then MovementXXX should NOT be active at all.
1418 if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY))
1419 {
1420 LOG_ERROR("Cannot pulse guide while manually in motion. Stop first.");
1421 return IPS_ALERT;
1422 }
1423
1424 if (GuideNSTID)
1425 {
1427 GuideNSTID = 0;
1428 }
1429
1430 if (usePulseCommand)
1431 {
1433 }
1434 else
1435 {
1437
1438 ISState states[] = { ISS_ON, ISS_OFF };
1439 const char *names[] = { MovementNSSP[DIRECTION_NORTH].getName(), MovementNSSP[DIRECTION_SOUTH].getName()};
1440 ISNewSwitch(MovementNSSP.getDeviceName(), MovementNSSP.getName(), states, const_cast<char **>(names), 2);
1441 }
1442
1444 GuideNSTID = IEAddTimer(static_cast<int>(ms), guideTimeoutHelperNS, this);
1445 return IPS_BUSY;
1446}
1447
1449{
1451 {
1452 LOG_ERROR("Cannot guide while slewing or parking in progress. Stop first.");
1453 return IPS_ALERT;
1454 }
1455
1456 // If we're using pulse command, then MovementXXX should NOT be active at all.
1457 if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY))
1458 {
1459 LOG_ERROR("Cannot pulse guide while manually in motion. Stop first.");
1460 return IPS_ALERT;
1461 }
1462
1463 if (GuideNSTID)
1464 {
1466 GuideNSTID = 0;
1467 }
1468
1469 if (usePulseCommand)
1470 {
1472 }
1473 else
1474 {
1476
1477 ISState states[] = { ISS_OFF, ISS_ON };
1478 const char *names[] = { MovementNSSP[DIRECTION_NORTH].getName(), MovementNSSP[DIRECTION_SOUTH].getName()};
1479 ISNewSwitch(MovementNSSP.getDeviceName(), MovementNSSP.getName(), states, const_cast<char **>(names), 2);
1480 }
1481
1483 GuideNSTID = IEAddTimer(static_cast<int>(ms), guideTimeoutHelperNS, this);
1484 return IPS_BUSY;
1485}
1486
1488{
1490 {
1491 LOG_ERROR("Cannot guide while slewing or parking in progress. Stop first.");
1492 return IPS_ALERT;
1493 }
1494
1495 // If we're using pulse command, then MovementXXX should NOT be active at all.
1496 if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY))
1497 {
1498 LOG_ERROR("Cannot pulse guide while manually in motion. Stop first.");
1499 return IPS_ALERT;
1500 }
1501
1502 if (GuideWETID)
1503 {
1505 GuideWETID = 0;
1506 }
1507
1508 if (usePulseCommand)
1509 {
1511 }
1512 else
1513 {
1515
1516 ISState states[] = { ISS_OFF, ISS_ON };
1517 const char *names[] = { MovementWESP[DIRECTION_WEST].getName(), MovementWESP[DIRECTION_EAST].getName()};
1518 ISNewSwitch(MovementWESP.getDeviceName(), MovementWESP.getName(), states, const_cast<char **>(names), 2);
1519 }
1520
1522 GuideWETID = IEAddTimer(static_cast<int>(ms), guideTimeoutHelperWE, this);
1523 return IPS_BUSY;
1524}
1525
1527{
1529 {
1530 LOG_ERROR("Cannot guide while slewing or parking in progress. Stop first.");
1531 return IPS_ALERT;
1532 }
1533
1534 // If we're using pulse command, then MovementXXX should NOT be active at all.
1535 if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY))
1536 {
1537 LOG_ERROR("Cannot pulse guide while manually in motion. Stop first.");
1538 return IPS_ALERT;
1539 }
1540
1541 if (GuideWETID)
1542 {
1544 GuideWETID = 0;
1545 }
1546
1547 if (usePulseCommand)
1548 {
1550 }
1551 else
1552 {
1554
1555 ISState states[] = { ISS_ON, ISS_OFF };
1556 const char *names[] = { MovementWESP[DIRECTION_WEST].getName(), MovementWESP[DIRECTION_EAST].getName()};
1557 ISNewSwitch(MovementWESP.getDeviceName(), MovementWESP.getName(), states, const_cast<char **>(names), 2);
1558 }
1559
1561 GuideWETID = IEAddTimer(static_cast<int>(ms), guideTimeoutHelperWE, this);
1562 return IPS_BUSY;
1563}
1564
1565int LX200Telescope::SendPulseCmd(int8_t direction, uint32_t duration_msec)
1566{
1567 return ::SendPulseCmd(PortFD, direction, duration_msec);
1568}
1569
1571{
1572 static_cast<LX200Telescope *>(p)->guideTimeoutNS();
1573}
1574
1576{
1577 static_cast<LX200Telescope *>(p)->guideTimeoutWE();
1578}
1579
1581{
1582 if (usePulseCommand == false)
1583 {
1584 ISState states[] = { ISS_OFF, ISS_OFF };
1585 const char *names[] = { MovementWESP[DIRECTION_WEST].getName(), MovementWESP[DIRECTION_EAST].getName()};
1586 ISNewSwitch(MovementWESP.getDeviceName(), MovementWESP.getName(), states, const_cast<char **>(names), 2);
1587 }
1588
1589 GuideWENP[DIRECTION_WEST].setValue(0);
1590 GuideWENP[DIRECTION_EAST].setValue(0);
1591 GuideWENP.setState(IPS_IDLE);
1592 GuideWETID = 0;
1593 GuideWENP.apply();
1594}
1595
1597{
1598 if (usePulseCommand == false)
1599 {
1600 ISState states[] = { ISS_OFF, ISS_OFF };
1601 const char *names[] = { MovementNSSP[DIRECTION_NORTH].getName(), MovementNSSP[DIRECTION_SOUTH].getName()};
1602 ISNewSwitch(MovementNSSP.getDeviceName(), MovementNSSP.getName(), states, const_cast<char **>(names), 2);
1603 }
1604
1605 GuideNSNP[0].setValue(0);
1606 GuideNSNP[1].setValue(0);
1607 GuideNSNP.setState(IPS_IDLE);
1608 GuideNSTID = 0;
1609 GuideNSNP.apply();
1610
1611}
1612
1625
1627{
1628 INDI_UNUSED(enabled);
1629 return true;
1630}
1631
1633{
1634 return SetFocuserSpeed(0);
1635}
1636
1637IPState LX200Telescope::MoveFocuser(FocusDirection dir, int speed, uint16_t duration)
1638{
1639 FocusDirection finalDirection = dir;
1640 // Reverse final direction if necessary
1641 if (FocusReverseSP[INDI_ENABLED].getState() == ISS_ON)
1642 finalDirection = (dir == FOCUS_INWARD) ? FOCUS_OUTWARD : FOCUS_INWARD;
1643
1644 SetFocuserSpeed(speed);
1645
1646 setFocuserMotion(PortFD, finalDirection);
1647
1649
1650 return IPS_BUSY;
1651}
1652
1654{
1655 return (setFocuserSpeedMode(PortFD, speed) == 0);
1656}
1657
bool isConnected() const
INDI::PropertyText getText(const char *name) const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
uint32_t getDriverInterface() const
INDI::PropertySwitch FocusReverseSP
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusSpeedNP
INDI::PropertyNumber FocusTimerNP
void initProperties(const char *groupName)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
bool saveConfigItems(FILE *fp)
saveConfigItems save focuser properties defined in the interface in config file
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process focus number properties.
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process focus switch properties.
INDI::PropertyNumber GuideNSNP
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
INDI::PropertyNumber GuideWENP
void initProperties(const char *groupName)
Initialize guider properties. It is recommended to call this function within initProperties() of your...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
TelescopeStatus TrackState
TelescopeMountType getMountType() const
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
IGeographicCoordinates m_Location
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
ISwitch UsePulseCmdS[2]
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
uint32_t genericCapability
int8_t guide_direction_we
static void guideTimeoutHelperNS(void *p)
INumber TrackFreqN[1]
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
void updateMountTypeFromAlignment(int index)
ITextVectorProperty SiteNameTP
virtual void slewError(int slewCode)
bool updateSlewRate(int index)
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
static void updateFocusHelper(void *p)
virtual bool getLocalDate(char *dateString)
virtual bool Park() override
Park the telescope to its home position.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
static constexpr int MIN_VALID_MOUNT_YEAR
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
ISwitchVectorProperty AlignmentSP
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool getUTFOffset(double *offset)
virtual bool sendScopeLocation()
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool isSlewComplete()
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual const char * getDefaultName() override
static void guideTimeoutHelperWE(void *p)
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool getLocalTime(char *timeString)
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
INumberVectorProperty TrackFreqNP
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool checkConnection()
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool sendScopeTime()
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years)
virtual bool setLocalTime24(uint8_t hour, uint8_t minute, uint8_t second)
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual void getBasicData()
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool setUTCOffset(double offset)
ISwitch AlignmentS[3]
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
virtual bool Handshake() override
perform handshake with device to check communication
virtual int SendPulseCmd(int8_t direction, uint32_t duration_msec)
ISwitchVectorProperty SiteSP
virtual const char * getDriverName() override
int8_t guide_direction_ns
@ LX200_HAS_PRECISE_TRACKING_FREQ
ISwitchVectorProperty UsePulseCmdSP
const char * GUIDE_TAB
GUIDE_TAB Where all the properties for guiding are located.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
const char * FOCUS_TAB
FOCUS_TAB Where all the properties for focuser are located.
void IERmTimer(int timerid)
Remove the timer with the given timerid, as returned from IEAddTimer() or IEAddPeriodicTimer().
Definition eventloop.c:606
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
Definition eventloop.c:586
INDI::PropertySwitch ParkSP
INDI::PropertySwitch AbortSP
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertyText TimeTP
INDI::PropertySwitch MovementWESP
INDI::PropertyNumber LocationNP
#define setLocalTime(fd, x, y, z)
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
#define MAXINDIFORMAT
Definition indiapi.h:193
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
#define MAXINDINAME
Definition indiapi.h:189
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_EAST
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_SOUTH
@ DIRECTION_NORTH
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Definition indicom.c:194
void getSexComponents(double value, int *d, int *m, int *s)
Definition indicom.c:243
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition indicom.c:1321
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
Implementations for common driver routines.
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sidereal time given longitude and system clock.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
Definition indidevapi.c:33
IText * IUFindText(const ITextVectorProperty *tvp, const char *name)
Find an IText member in a vector text property.
Definition indidevapi.c:265
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition indidevapi.c:337
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition indidevapi.c:366
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:509
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
Definition indidevapi.c:416
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUGetConfigText(const char *dev, const char *property, const char *member, char *value, int len)
IUGetConfigText Opens configuration file and reads single text property.
Definition indidriver.c:908
int IUGetConfigOnSwitchIndex(const char *dev, const char *property, int *index)
IUGetConfigOnSwitchIndex Opens configuration file and reads single switch property to find ON switch ...
Definition indidriver.c:719
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
INDI::FocuserInterface FI
INDI::GuiderInterface GI
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOGF_WARN(fmt,...)
Definition indilogger.h:81
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#define TRACKRATE_SOLAR
Definition indimacros.h:45
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
#define TRACKRATE_LUNAR
Definition indimacros.h:48
#define getDeviceName
int setFocuserMotion(int fd, int motionType)
int setAlignmentMode(int fd, unsigned int alignMode)
int setSlewMode(int fd, int slewMode)
int getSiteLongitude(int fd, int *ddd, int *mm, double *ssf)
int selectTrackingMode(int fd, int trackMode)
int getSiteName(int fd, char *siteName, int siteNum)
int selectSite(int fd, int siteNum)
int setObjectRA(int fd, double ra, bool addSpace)
int getLX200EquatorialFormat()
int setSiteLongitude(int fd, double CartographicLongitude, bool addSpace)
int setObjectDEC(int fd, double dec, bool addSpace)
int checkLX200EquatorialFormat(int fd)
int abortSlew(int fd)
int setSiteLatitude(int fd, double Lat, bool addSpace)
int setTrackFreq(int fd, double trackF)
int setFocuserSpeedMode(int fd, int speedMode)
int setCalenderDate(int fd, int dd, int mm, int yy, bool addSpace)
int getCalendarDate(int fd, char *date)
int Slew(int fd)
int MoveTo(int fd, int direction)
int getTimeFormat(int fd, int *format)
int getTrackFreq(int fd, double *value)
int setPreciseTrackFreq(int fd, double trackF)
int setSiteName(int fd, char *siteName, int siteNum)
void setLX200Debug(const char *deviceName, unsigned int debug_level)
int check_lx200_connection(int in_fd)
int HaltMovement(int fd, int direction)
int getSiteLatitude(int fd, int *dd, int *mm, double *ssf)
#define getUTCOffset(fd, x)
#define getLX200DEC(fd, x)
@ LX200_AM
Definition lx200driver.h:65
@ LX200_24
Definition lx200driver.h:64
#define getLX200RA(fd, x)
@ LX200_TRACK_MANUAL
@ LX200_WEST
Definition lx200driver.h:42
@ LX200_SOUTH
Definition lx200driver.h:44
@ LX200_NORTH
Definition lx200driver.h:41
@ LX200_EAST
Definition lx200driver.h:43
@ LX200_EQ_LONGER_FORMAT
Definition lx200driver.h:52
@ LX200_EQ_SHORT_FORMAT
Definition lx200driver.h:50
@ LX200_EQ_LONG_FORMAT
Definition lx200driver.h:51
#define getLocalTime24(fd, x)
#define toggleTimeFormat(fd)
#define slewToPark(fd)
#define LX200_GENERIC_SLEWRATE
One text descriptor.
#define ACK
Definition stvdriver.h:35