Instrument Neutral Distributed Interface INDI 2.2.5
celestrongps.cpp
Go to the documentation of this file.
1#if 0
3Copyright (C) 2003 - 2017 Jasem Mutlaq ([email protected])
4
5This library is free software;
6you can redistribute it and / or
7modify it under the terms of the GNU Lesser General Public
8License as published by the Free Software Foundation;
9either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY;
14without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public
19License along with this library;
20if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
22
23Version with experimental pulse guide support. GC 04.12.2015
24
25#endif
26
27#include "celestrongps.h"
28
29#include "indicom.h"
30
31#include <libnova/transform.h>
32
33#include <cmath>
34#include <memory>
35#include <cstring>
36#include <unistd.h>
37
38#include <sys/stat.h>
39
40#include "indilogger.h"
41#include "indiutility.h"
42
43//#include <time.h>
44
45// Simulation Parameters
46#define GOTO_RATE 5 // slew rate, degrees/s
47#define SLEW_RATE 0.5 // slew rate, degrees/s
48#define FINE_SLEW_RATE 0.1 // slew rate, degrees/s
49#define GOTO_LIMIT 5.5 // Move at GOTO_RATE until distance from target is GOTO_LIMIT degrees
50#define SLEW_LIMIT 1 // Move at SLEW_LIMIT until distance from target is SLEW_LIMIT degrees
51#define FINE_SLEW_LIMIT 0.5 // Move at FINE_SLEW_RATE until distance from target is FINE_SLEW_LIMIT degrees
52
53#define MOUNTINFO_TAB "Mount Info"
54
55static std::unique_ptr<CelestronGPS> telescope(new CelestronGPS());
56
58{
59 setVersion(3, 6); // update libindi/drivers.xml as well
60
61
62 fwInfo.Version = "Invalid";
63 fwInfo.controllerVersion = 0;
64 fwInfo.controllerVariant = ISNEXSTAR;
65 fwInfo.isGem = false;
66 fwInfo.hasFocuser = false;
67
68 INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE");
69
70 currentRA = 0;
71 currentDEC = 90;
72 currentAZ = 0;
73 currentALT = 0;
74 targetAZ = 0;
75 targetALT = 0;
76
77 // focuser
79
80 focusTrueMax = 0;
81 focusTrueMin = 0xffffffff;
82
83 // Set minimum properties.
84 // ISGetProperties in INDI::Telescope checks for CanGOTO which must be set.
86}
87
88bool CelestronGPS::checkMinVersion(double minVersion, const char *feature, bool debug)
89{
90 if (((fwInfo.controllerVariant == ISSTARSENSE) &&
91 (fwInfo.controllerVersion < MINSTSENSVER)) ||
92 ((fwInfo.controllerVariant == ISNEXSTAR) &&
93 (fwInfo.controllerVersion < minVersion)))
94 {
95 if (debug)
96 LOGF_DEBUG("Firmware v%3.2f does not support %s. Minimum required version is %3.2f",
97 fwInfo.controllerVersion, feature, minVersion);
98 else
99 LOGF_WARN("Firmware v%3.2f does not support %s. Minimum required version is %3.2f",
100 fwInfo.controllerVersion, feature, minVersion);
101
102 return false;
103 }
104 return true;
105}
106
108{
109 return "Celestron GPS";
110}
111
113{
116
117 // Firmware
118 IUFillText(&FirmwareT[FW_MODEL], "Model", "", nullptr);
119 IUFillText(&FirmwareT[FW_VERSION], "HC Version", "", nullptr);
120 IUFillText(&FirmwareT[FW_RA], "Ra Version", "", nullptr);
121 IUFillText(&FirmwareT[FW_DEC], "Dec Version", "", nullptr);
122 IUFillText(&FirmwareT[FW_ISGEM], "Mount Type", "", nullptr);
123 IUFillText(&FirmwareT[FW_CAN_AUX], "Guide Method", "", nullptr);
124 IUFillText(&FirmwareT[FW_HAS_FOC], "Has Focuser", "", nullptr);
125 IUFillTextVector(&FirmwareTP, FirmwareT, 7, getDeviceName(), "Firmware Info", "", MOUNTINFO_TAB, IP_RO, 0,
126 IPS_IDLE);
127
128 // Celestron Track Modes are Off, AltAz, EQ N, EQ S and Ra and Dec (StarSense only)
129 // off is not provided as these are used to set the track mode when tracking is enabled
130 // may be required for set up, value will be read from the mount if possible
131 IUFillSwitchVector(&CelestronTrackModeSP, CelestronTrackModeS, 4, getDeviceName(), "CELESTRON_TRACK_MODE", "Track Mode",
133 IUFillSwitch(&CelestronTrackModeS[0], "MODE_ALTAZ", "Alt Az", ISS_OFF);
134 IUFillSwitch(&CelestronTrackModeS[1], "MODE_EQ_N", "EQ N", ISS_ON);
135 IUFillSwitch(&CelestronTrackModeS[2], "MODE_EQ_S", "EQ S", ISS_OFF);
136 IUFillSwitch(&CelestronTrackModeS[3], "MODE_RA_DEC", "Ra and Dec", ISS_OFF);
137
138 // INDI track modes are sidereal, solar and lunar
139 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
140 AddTrackMode("TRACK_SOLAR", "Solar");
141 AddTrackMode("TRACK_LUNAR", "Lunar");
142
143 IUFillSwitch(&UseHibernateS[0], "Enable", "", ISS_OFF);
144 IUFillSwitch(&UseHibernateS[1], "Disable", "", ISS_ON);
147
148 //GUIDE Define "Use Pulse Cmd" property (Switch).
149 // IUFillSwitch(&UsePulseCmdS[0], "Off", "", ISS_OFF);
150 // IUFillSwitch(&UsePulseCmdS[1], "On", "", ISS_ON);
151 // IUFillSwitchVector(&UsePulseCmdSP, UsePulseCmdS, 2, getDeviceName(), "Use Pulse Cmd", "", MAIN_CONTROL_TAB, IP_RW,
152 // ISR_1OFMANY, 0, IPS_IDLE);
153
154 // experimental last align control
155 IUFillSwitchVector(&LastAlignSP, LastAlignS, 1, getDeviceName(), "Align", "Align", MAIN_CONTROL_TAB,
157 IUFillSwitch(&LastAlignS[0], "Align", "Align", ISS_OFF);
158 // maybe a second switch which confirms the align
159
161
162 //GUIDE Initialize guiding properties.
164
169 IUFillNumber(&GuideRateN[AXIS_RA], "GUIDE_RATE_WE", "W/E Rate", "%0.2f", 0, 1, 0.1, GuideRateN[AXIS_RA].value);
170 IUFillNumber(&GuideRateN[AXIS_DE], "GUIDE_RATE_NS", "N/S Rate", "%0.2f", 0, 1, 0.1, GuideRateN[AXIS_DE].value);
171 IUFillNumberVector(&GuideRateNP, GuideRateN, 2, getDeviceName(), "GUIDE_RATE", "Guide Rate x sidereal", GUIDE_TAB, IP_RW, 0,
172 IPS_IDLE);
173
177
178 IUFillSwitch(&PecControlS[PEC_Seek], "PEC_SEEK_INDEX", "Seek Index", ISS_OFF);
179 IUFillSwitch(&PecControlS[PEC_Stop], "PEC_STOP", "Stop", ISS_OFF);
180 IUFillSwitch(&PecControlS[PEC_Playback], "PEC_PLAYBACK", "Playback", ISS_OFF);
181 IUFillSwitch(&PecControlS[PEC_Record], "PEC_RECORD", "Record", ISS_OFF);
182 IUFillSwitchVector(&PecControlSP, PecControlS, 4, getDeviceName(), "PEC_CONTROL", "PEC Control", MOTION_TAB, IP_RW,
183 ISR_ATMOST1, 60, IPS_IDLE);
184
185 IUFillText(&PecInfoT[0], "PEC_STATE", "Pec State", "undefined");
186 IUFillText(&PecInfoT[1], "PEC_INDEX", "Pec Index", " ");
187 IUFillTextVector(&PecInfoTP, PecInfoT, 2, getDeviceName(), "PEC_INFO", "Pec Info", MOTION_TAB, IP_RO, 60, IPS_IDLE);
188
189 // load Pec data from file
190 IUFillText(&PecFileNameT[0], "PEC_FILE_NAME", "File Name", "");
191 IUFillTextVector(&PecFileNameTP, PecFileNameT, 1, getDeviceName(), "PEC_LOAD", "Load PEC", MOTION_TAB, IP_WO, 60, IPS_IDLE);
192
196
197 IUFillSwitch(&DSTSettingS[0], "DST_ENABLED", "Enabled", ISS_OFF);
198 IUFillSwitchVector(&DSTSettingSP, DSTSettingS, 1, getDeviceName(), "DST_STATE", "DST", SITE_TAB, IP_RW, ISR_NOFMANY, 60,
199 IPS_IDLE);
200
202
203 //GUIDE Set guider interface.
205
206 //FocuserInterface
207 //Initial, these will be updated later.
208 FocusRelPosNP[0].setMin(0.);
209 FocusRelPosNP[0].setMax(30000.);
210 FocusRelPosNP[0].setValue(0);
211 FocusRelPosNP[0].setStep(1000);
212 FocusAbsPosNP[0].setMin(0.);
213 FocusAbsPosNP[0].setMax(60000.);
214 FocusAbsPosNP[0].setValue(0);
215 FocusAbsPosNP[0].setStep(1000);
216
217 // Maximum Position Settings, will be read from the hardware
218 FocusMaxPosNP[0].setMax(60000);
219 FocusMaxPosNP[0].setMin(1000);
220 FocusMaxPosNP[0].setValue(60000);
221 FocusMaxPosNP.setPermission(IP_RO);
222
223 // Focuser backlash
224 // CR this is a value, positive or negative to define the direction. It is implemented
225 // in the driver.
226
227 FocusBacklashNP[0].setMin(-1000);
228 FocusBacklashNP[0].setMax(1000);
229 FocusBacklashNP[0].setStep(1);
230 FocusBacklashNP[0].setValue(0);
231 // IUFillNumber(&FocusBacklashN[0], "STEPS", "Steps", "%.f", -500., 500, 1., 0.);
232 // IUFillNumberVector(&FocusBacklashNP, FocusBacklashN, 1, getDeviceName(), "FOCUS_BACKLASH", "Backlash",
233 // FOCUS_TAB, IP_RW, 0, IPS_IDLE);
234
235 // Focuser min limit, read from the hardware
236 // IUFillNumber(&FocusMinPosN[0], "FOCUS_MIN_VALUE", "Steps", "%.f", 0, 40000., 1., 0.);
237 // IUFillNumberVector(&FocusMinPosNP, FocusMinPosN, 1, getDeviceName(), "FOCUS_MIN", "Min. Position",
238 // FOCUS_TAB, IP_RO, 0, IPS_IDLE);
239
240 return true;
241}
242
243void CelestronGPS::ISGetProperties(const char *dev)
244{
245 static bool configLoaded = false;
246
247 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
248 return;
249
251
254 if (configLoaded == false)
255 {
256 configLoaded = true;
257 loadConfig(true, "Hibernate");
258 }
259}
260
262{
263 if (isConnected())
264 {
266
267 if (driver.get_firmware(&fwInfo))
268 {
269 IUSaveText(&FirmwareT[FW_MODEL], fwInfo.Model.c_str());
270 IUSaveText(&FirmwareT[FW_VERSION], fwInfo.Version.c_str());
271 IUSaveText(&FirmwareT[FW_RA], fwInfo.RAFirmware.c_str());
272 IUSaveText(&FirmwareT[FW_DEC], fwInfo.DEFirmware.c_str());
273 IUSaveText(&FirmwareT[FW_ISGEM], fwInfo.isGem ? "GEM" : "Fork");
274 canAuxGuide = (atof(fwInfo.RAFirmware.c_str()) >= 6.12 && atof(fwInfo.DEFirmware.c_str()) >= 6.12);
275 IUSaveText(&FirmwareT[FW_CAN_AUX], canAuxGuide ? "Mount" : "Time Guide");
276 IUSaveText(&FirmwareT[FW_HAS_FOC], fwInfo.hasFocuser ? "True" : "False");
277
278 setMountType(fwInfo.isGem ? MOUNT_EQ_GEM : MOUNT_EQ_FORK);
279
280 usePreciseCoords = (checkMinVersion(2.2, "usePreciseCoords"));
281 // set the default switch index, will be updated from the mount if possible
282 fwInfo.celestronTrackMode = static_cast<CELESTRON_TRACK_MODE>(IUFindOnSwitchIndex(&CelestronTrackModeSP) + 1);
283 }
284 else
285 {
286 fwInfo.Version = "Invalid";
287 LOG_WARN("Failed to retrieve firmware information.");
288 }
289
290 // JM 2018-09-28: According to user reports in this thread:
291 // http://www.indilib.org/forum/mounts/2208-celestron-avx-mount-and-starsense.html
292 // Parking is also supported fine with StarSense
293 if (checkMinVersion(2.3, "park"))
294 cap |= TELESCOPE_CAN_PARK;
295
296 if (checkMinVersion(4.1, "sync"))
297 cap |= TELESCOPE_CAN_SYNC;
298
299 if (checkMinVersion(2.3, "updating time and location settings"))
300 {
302 }
303
304 // changing track mode (aka rate) is only available for equatorial mounts
305
306 // StarSense supports track mode
307 if (checkMinVersion(2.3, "track on/off"))
309 else
310 LOG_WARN("Mount firmware does not support track on off.");
311
312 if (fwInfo.isGem && checkMinVersion(4.15, "Pier Side", true))
314 else
315 LOG_WARN("Mount firmware does not support getting pier side.");
316
317 // Track Mode (t) is only supported for 2.3+
319 if (checkMinVersion(2.3, "track mode"))
320 {
321 if (isSimulation())
322 {
323 if (isParked())
324 driver.set_sim_track_mode(CTM_OFF);
325 else
326 driver.set_sim_track_mode(CTM_EQN);
327 }
328 if (driver.get_track_mode(&ctm))
329 {
330 if (ctm != CTM_OFF)
331 {
332 fwInfo.celestronTrackMode = ctm;
334 CelestronTrackModeS[ctm - 1].s = ISS_ON;
336
337 saveConfig(true, "CELESTRON_TRACK_MODE");
338 LOGF_DEBUG("Celestron mount tracking, mode %s", CelestronTrackModeS[ctm - 1].label);
339 }
340 else
341 {
342 LOG_INFO("Mount tracking is off.");
344 }
345 }
346 else
347 {
348 LOG_DEBUG("get_track_mode failed");
350 }
351
353 }
354
355 // JM 2025.09.19: Celestron Track Mode (EQ-N, EQ-S, ALTAZ) is not related
356 // to TELESCOPE_HAS_TRACK_MODE which is about track *rates* like Lunar, Solar, Sidereal..etc
357 // if (fwInfo.celestronTrackMode != CTM_ALTAZ)
358 // cap |= TELESCOPE_HAS_TRACK_MODE;
359 // else
360 // {
361 // TrackModeSP[TRACK_SIDEREAL].setState(ISS_ON);
362 // LOG_WARN("Mount firmware does not support track mode.");
363 // }
364
366
368
369 if (fwInfo.Version != "Invalid")
371
372 if (InitPark())
373 {
374 // If loading parking data is successful, we just set the default parking values.
375 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
377 }
378 else
379 {
380 // Otherwise, we set all parking data to default in case no parking data is found.
381 SetAxis1Park(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
383 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
385 }
386
387 // InitPark sets TrackState to IDLE or PARKED so this is the earliest we can
388 // update TrackState using the current mount properties
389 // Something seems to set IsParked to true, force the correct state if the
390 // mount is tracking
391 if (ctm != CTM_OFF)
392 {
393 SetParked(false);
395 }
396
397 //GUIDE Update properties.
398 // check if the mount type and version supports guiding
399 // Only show the guide information for mounts that
400 // support guiding. That's GEMs and fork mounts in equatorial modes.
401 // well, anything in an equatorial mode
402 if (fwInfo.celestronTrackMode == CELESTRON_TRACK_MODE::CTM_EQN ||
403 fwInfo.celestronTrackMode == CELESTRON_TRACK_MODE::CTM_EQS ||
404 fwInfo.celestronTrackMode == CELESTRON_TRACK_MODE::CTM_RADEC)
405 {
407 uint8_t rate;
408 if (driver.get_guide_rate(CELESTRON_AXIS::RA_AXIS, &rate))
409 {
410 GuideRateN[AXIS_RA].value = std::min(std::max(static_cast<double>(rate) / 255.0, 0.0), 1.0);
411 LOGF_DEBUG("Get Guide Rate: RA %f", GuideRateN[AXIS_RA].value);
412 if (driver.get_guide_rate(CELESTRON_AXIS::DEC_AXIS, &rate))
413 {
414 GuideRateN[AXIS_DE].value = std::min(std::max(static_cast<double>(rate) / 255.0, 0.0), 1.0);
415 IDSetNumber(&GuideRateNP, nullptr);
416 LOGF_DEBUG("Get Guide Rate: Dec %f", GuideRateN[AXIS_DE].value);
417 }
418 }
419 else
420 LOG_DEBUG("Unable to get guide rates from mount.");
421
423
424 LOG_INFO("Mount supports guiding.");
425 }
426 else
427 LOG_INFO("Mount does not support guiding. Tracking mode must be set in handset to either EQ-North or EQ-South.");
428
429
431
432 // JM 2014-04-14: User (davidw) reported AVX mount serial communication times out issuing "h" command with firmware 5.28
433 // JM 2018-09-27: User (suramara) reports that it works with AVX mount with Star Sense firmware version 1.19
434 //if (fwInfo.controllerVersion >= 2.3 && fwInfo.Model != "AVX" && fwInfo.Model != "CGE Pro")
435 if (checkMinVersion(2.3, "date and time setting"))
436 {
437 double utc_offset;
438 int yy, dd, mm, hh, minute, ss;
439 bool dst;
440 // StarSense doesn't seems to handle the precise time commands
441 bool precise = fwInfo.controllerVersion >= 5.28;
442 if (driver.get_utc_date_time(&utc_offset, &yy, &mm, &dd, &hh, &minute, &ss, &dst, precise))
443 {
444 char isoDateTime[32];
445 char utcOffset[8];
446
447 snprintf(isoDateTime, 32, "%04d-%02d-%02dT%02d:%02d:%02d", yy, mm, dd, hh, minute, ss);
448 snprintf(utcOffset, 8, "%4.2f", utc_offset);
449
450 TimeTP[UTC].setText(isoDateTime);
451 TimeTP[OFFSET].setText(utcOffset);
452
453 defineProperty(&DSTSettingSP);
454 DSTSettingS[0].s = dst ? ISS_ON : ISS_OFF;
455
456 LOGF_INFO("Mount UTC offset: %s. UTC time: %s. DST: %s", utcOffset, isoDateTime, dst ? "On" : "Off");
457 //LOGF_DEBUG("Mount UTC offset is %s. UTC time is %s", utcOffset, isoDateTime);
458
459 TimeTP.setState(IPS_OK);
460 TimeTP.apply();
461 IDSetSwitch(&DSTSettingSP, nullptr);
462 }
463 double longitude, latitude;
464 if (driver.get_location(&longitude, &latitude))
465 {
466 LocationNP[LOCATION_LATITUDE].setValue(latitude);
467 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
468 LocationNP[LOCATION_ELEVATION].setValue(0);
469 LocationNP.setState(IPS_OK);
470 LOGF_DEBUG("Mount latitude %8.4f longitude %8.4f", latitude, longitude);
471 }
472 }
473 else
474 LOG_WARN("Mount does not support retrieval of date, time and location.");
475
476 // last align is only available for mounts with switches that define the start index position
477 // At present that is only the CGX and CGX-L mounts so the control is only made available for them
478 // comment out this line and rebuild if you want to run with other mounts - at your own risk!
479 if (fwInfo.hasHomeIndex)
480 {
481 defineProperty(&LastAlignSP);
482 }
483
484 // Sometimes users start their mount when it is NOT yet aligned and then try to proceed to use it
485 // So we check issue and issue error if not aligned.
486 checkAlignment();
487
488 // PEC, must have PEC index and be equatorially mounted
489 if (fwInfo.canPec && CelestronTrackModeS[CTM_ALTAZ].s != ISS_OFF)
490 {
491 driver.pecState = PEC_STATE::PEC_AVAILABLE;
495 }
496
497 // handle the focuser
498 if (fwInfo.hasFocuser)
499 {
500 //defineProperty(&FocusBacklashNP);
501 //defineProperty(&FocusMinPosNP);
502
503 if (focusReadLimits())
504 {
505 FocusAbsPosNP.updateMinMax();
506
507 FocusMaxPosNP.apply();
508 // IDSetNumber(&FocusMinPosNP, nullptr);
509 // focuser move capability is only set if the focus limits are valid
513
514 LOG_INFO("Auxiliary focuser is connected.");
515 }
516 if (!focuserIsCalibrated)
517 {
518 LOG_WARN("Focuser not calibrated, moves will not be allowed");
519 }
521 }
522 }
523 else // not connected
524 {
526
528 //deleteProperty(FocusMinPosNP.name);
529
530 //GUIDE Delete properties.
532
534
535 deleteProperty(LastAlignSP.name);
537
538 deleteProperty(DSTSettingSP.name);
539
543
544 if (fwInfo.Version != "Invalid")
546 }
547
548 return true;
549}
550
551bool CelestronGPS::Goto(double ra, double dec)
552{
553 targetRA = ra;
554 targetDEC = dec;
555
556 if (EqNP.getState() == IPS_BUSY || MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
557 {
558 driver.abort();
559 // sleep for 500 mseconds
560 usleep(500000);
561 }
562
563 if (driver.slew_radec(targetRA + SlewOffsetRa, targetDEC, usePreciseCoords) == false)
564 {
565 LOG_ERROR("Failed to slew telescope in RA/DEC.");
566 return false;
567 }
568
570
571 char RAStr[32], DecStr[32];
572 fs_sexa(RAStr, targetRA, 2, 3600);
573 fs_sexa(DecStr, targetDEC, 2, 3600);
574 LOGF_INFO("Slewing to JNOW RA %s - DEC %s SlewOffsetRa %4.1f arcsec", RAStr, DecStr, SlewOffsetRa * 3600 * 15);
575
576 return true;
577}
578
579bool CelestronGPS::Sync(double ra, double dec)
580{
581 if (!checkMinVersion(4.1, "sync"))
582 return false;
583
584 if (driver.sync(ra, dec, usePreciseCoords) == false)
585 {
586 LOG_ERROR("Sync failed.");
587 return false;
588 }
589
590 currentRA = ra;
591 currentDEC = dec;
592
593 char RAStr[32], DecStr[32];
594 fs_sexa(RAStr, targetRA, 2, 3600);
595 fs_sexa(DecStr, targetDEC, 2, 3600);
596 LOGF_INFO("Sync to %s, %s successful.", RAStr, DecStr);
597
598 return true;
599}
600
601/*
602bool CelestronGPS::GotoAzAlt(double az, double alt)
603{
604 if (isSimulation())
605 {
606 INDI::IHorizontalCoordinates horizontalPos;
607 // Libnova south = 0, west = 90, north = 180, east = 270
608 horizontalPos.az = az + 180;
609 if (horizontalPos.az >= 360)
610 horizontalPos.az -= 360;
611 horizontalPos.alt = alt;
612
613 IGeographicCoordinates observer;
614
615 observer.lat = LocationN[LOCATION_LATITUDE].value;
616 observer.lng = LocationN[LOCATION_LONGITUDE].value;
617
618 if (observer.lng > 180)
619 observer.lng -= 360;
620
621 INDI::IEquatorialCoordinates equatorialPos;
622 ln_get_equ_from_hrz(&horizontalPos, &observer, ln_get_julian_from_sys(), &equatorialPos);
623
624 targetRA = equatorialPos.rightascension/15.0;
625 targetDEC = equatorialPos.dec;
626 }
627
628 if (driver.slew_azalt(LocationN[LOCATION_LATITUDE].value, az, alt) == false)
629 {
630 LOG_ERROR("Failed to slew telescope in Az/Alt.");
631 return false;
632 }
633
634 targetAZ = az;
635 targetALT= alt;
636
637 TrackState = SCOPE_SLEWING;
638
639 HorizontalCoordsNP.s = IPS_BUSY;
640
641 char AZStr[16], ALTStr[16];
642 fs_sexa(AZStr, targetAZ, 3, 3600);
643 fs_sexa(ALTStr, targetALT, 2, 3600);
644 LOGF_INFO("Slewing to Az %s - Alt %s", AZStr, ALTStr);
645
646 return true;
647}
648*/
649
651{
653
655 move = (dir == DIRECTION_NORTH) ? CELESTRON_N : CELESTRON_S;
656 else
657 move = (dir == DIRECTION_NORTH) ? CELESTRON_S : CELESTRON_N;
658
659 CELESTRON_SLEW_RATE rate = static_cast<CELESTRON_SLEW_RATE>(SlewRateSP.findOnSwitchIndex());
660
661 switch (command)
662 {
663 case MOTION_START:
664 if (driver.start_motion(move, rate) == false)
665 {
666 LOG_ERROR("Error setting N/S motion direction.");
667 return false;
668 }
669 else
670 LOGF_INFO("Moving toward %s.", (move == CELESTRON_N) ? "North" : "South");
671 break;
672
673 case MOTION_STOP:
674 if (driver.stop_motion(move) == false)
675 {
676 LOG_ERROR("Error stopping N/S motion.");
677 return false;
678 }
679 else
680 LOGF_INFO("Movement toward %s halted.", (move == CELESTRON_N) ? "North" : "South");
681 break;
682 }
683
684 return true;
685}
686
688{
690 CELESTRON_SLEW_RATE rate = static_cast<CELESTRON_SLEW_RATE>(SlewRateSP.findOnSwitchIndex());
691
692 switch (command)
693 {
694 case MOTION_START:
695 if (driver.start_motion(move, rate) == false)
696 {
697 LOG_ERROR("Error setting W/E motion direction.");
698 return false;
699 }
700 else
701 LOGF_INFO("Moving toward %s.", (move == CELESTRON_W) ? "West" : "East");
702 break;
703
704 case MOTION_STOP:
705 if (driver.stop_motion(move) == false)
706 {
707 LOG_ERROR("Error stopping W/E motion.");
708 return false;
709 }
710 else
711 LOGF_INFO("Movement toward %s halted.", (move == CELESTRON_W) ? "West" : "East");
712 break;
713 }
714
715 return true;
716}
717
719{
721
722 if (isSimulation())
723 mountSim();
724
725 if (driver.get_radec(&currentRA, &currentDEC, usePreciseCoords) == false)
726 {
727 LOG_ERROR("Failed to read RA/DEC values.");
728 return false;
729 }
730
731 if (HasPierSide())
732 {
733 // read the pier side close to reading the Radec so they should match
734 char sop = '?';
735 char psc = 'u';
736 if (driver.get_pier_side(&sop))
737 {
738 // manage version and hemisphere nonsense
739 // HC versions less than 5.24 reverse the side of pier if the mount
740 // is in the Southern hemisphere. StarSense doesn't
741 if (LocationNP[LOCATION_LATITUDE].getValue() < 0)
742 {
743 if (fwInfo.controllerVersion <= 5.24 && fwInfo.controllerVariant != ISSTARSENSE)
744 {
745 // swap the char reported
746 if (sop == 'E')
747 sop = 'W';
748 else if (sop == 'W')
749 sop = 'E';
750 }
751 }
752 // The Celestron and INDI pointing states are opposite
753 if (sop == 'W')
754 {
755 pierSide = PIER_EAST;
756 psc = 'E';
757 }
758 else if (sop == 'E')
759 {
760 pierSide = PIER_WEST;
761 psc = 'W';
762 }
763 // pier side and Ha don't match at +-90 deg dec
764 if (currentDEC > 89.999 || currentDEC < -89.999)
765 {
766 pierSide = PIER_UNKNOWN;
767 psc = 'U';
768 }
769 }
770
771 LOGF_DEBUG("latitude %g, sop %c, PierSide %c",
772 LocationNP[LOCATION_LATITUDE].getValue(),
773 sop, psc);
774 }
775
776
777 // aligning
778 if (slewToIndex)
779 {
780 bool atIndex;
781 if (!driver.indexreached(&atIndex))
782 {
783 LOG_ERROR("IndexReached Failure");
784 slewToIndex = false;
785 return false;
786 }
787 if (atIndex)
788 {
789 slewToIndex = false;
790 // reached the index position.
791
792 // do an alignment
793 if (!fwInfo.hasHomeIndex)
794 {
795 // put another dire warning here
796 LOG_WARN("This mount does not have index switches, the alignment assumes it is at the index position.");
797 }
798
799 if (!driver.lastalign())
800 {
801 LOG_ERROR("LastAlign failed");
802 return false;
803 }
804
805 LastAlignSP.s = IPS_IDLE;
806 IDSetSwitch(&LastAlignSP, "Align finished");
807
808 bool isAligned;
809 if (!driver.check_aligned(&isAligned))
810 {
811 LOG_WARN("get Alignment Failed!");
812 }
813 else
814 {
815 if (isAligned)
816 LOG_INFO("Mount is aligned");
817 else
818 LOG_WARN("Alignment Failed!");
819 }
820
821 return true;
822 }
823 }
824
825 switch (TrackState)
826 {
827 case SCOPE_SLEWING:
828 // are we done?
829 bool slewing;
830 if (driver.is_slewing(&slewing) && !slewing)
831 {
832 LOG_INFO("Slew complete, tracking...");
833 SetTrackEnabled(true);
834 // update ra offset
835 double raoffset = targetRA - currentRA + SlewOffsetRa;
836 if (raoffset > 0.0 || raoffset < 10.0 / 3600.0)
837 {
838 // average last two values
839 SlewOffsetRa = SlewOffsetRa > 0 ? (SlewOffsetRa + raoffset) / 2 : raoffset;
840
841 LOGF_DEBUG("raoffset %4.1f, SlewOffsetRa %4.1f arcsec", raoffset * 3600 * 15, SlewOffsetRa * 3600 * 15);
842 }
843 }
844 break;
845
846 case SCOPE_PARKING:
847 // are we done?
848 if (driver.is_slewing(&slewing) && !slewing)
849 {
850 if (driver.set_track_mode(CTM_OFF))
851 LOG_DEBUG("Mount tracking is off.");
852
853 SetParked(true);
854 saveConfig(true);
855
856 // Check if we need to hibernate
857 if (UseHibernateS[0].s == ISS_ON)
858 {
859 LOG_INFO("Hibernating mount...");
860 if (driver.hibernate())
861 LOG_INFO("Mount hibernated. Please disconnect now and turn off your mount.");
862 else
863 LOG_ERROR("Hibernating mount failed!");
864 }
865 }
866 break;
867
868 default:
869 break;
870 }
871
872 // update pier side and RaDec close together to minimise the possibility of
873 // a mismatch causing an Ha limit error during a pier flip slew.
874 if (HasPierSide())
875 setPierSide(pierSide);
876 NewRaDec(currentRA, currentDEC);
877
878 // is PEC Handling required
879 if (driver.pecState >= PEC_STATE::PEC_AVAILABLE)
880 {
881 static PEC_STATE lastPecState = PEC_STATE::NotKnown;
882 static size_t lastPecIndex = 1000;
883 static size_t numRecordPoints;
884
885 if (driver.pecState >= PEC_STATE::PEC_INDEXED)
886 {
887 if (numPecBins < 88)
888 {
889 numPecBins = driver.getPecNumBins();
890 }
891 // get and show the current PEC index
892 size_t pecIndex = driver.pecIndex();
893
894 if (pecIndex != lastPecIndex)
895 {
896 LOGF_DEBUG("PEC state %s, index %d", driver.PecStateStr(), pecIndex);
897 IUSaveText(&PecInfoT[1], std::to_string(pecIndex).c_str());
898 IDSetText(&PecInfoTP, nullptr);
899 lastPecIndex = pecIndex;
900
901 // count the PEC records
902 if (driver.pecState == PEC_STATE::PEC_RECORDING)
903 numRecordPoints++;
904 else
905 numRecordPoints = 0;
906 }
907 }
908
909 // update the PEC state
910 if (driver.updatePecState() != lastPecState)
911 {
912 // and handle the change, if there was one
913 LOGF_DEBUG("PEC last state %s, new State %s", driver.PecStateStr(lastPecState), driver.PecStateStr());
914
915 // update the state string
916 IUSaveText(&PecInfoT[0], driver.PecStateStr());
917 IDSetText(&PecInfoTP, nullptr);
918
919 // no need to check both current and last because they must be different
920 switch (lastPecState)
921 {
923 // finished seeking
926 IDSetSwitch(&PecControlSP, nullptr);
927 LOG_INFO("PEC index Seek completed.");
928 break;
930 // finished playback
933 IDSetSwitch(&PecControlSP, nullptr);
934 LOG_INFO("PEC playback finished");
935 break;
937 // finished recording
938 LOGF_DEBUG("PEC record stopped, %d records", numRecordPoints);
939
940 if (numRecordPoints >= numPecBins)
941 {
942 savePecData();
943 }
944
947 LOG_INFO("PEC record finished");
948 IDSetSwitch(&PecControlSP, nullptr);
949
950 break;
951 default:
952 break;
953 }
954 lastPecState = driver.pecState;
955 }
956 }
957
958 // focuser
959 if (fwInfo.hasFocuser)
960 {
961 // Check position
962 double lastPosition = FocusAbsPosNP[0].getValue();
963
964 int absPos = focusTrue2Abs(driver.foc_position());
965 if (absPos >= 0)
966 {
967 FocusAbsPosNP[0].setValue(absPos);
968 // Only update if there is actual change
969 if (fabs(lastPosition - FocusAbsPosNP[0].getValue()) > 1)
970 FocusAbsPosNP.apply();
971 }
972
973 if (FocusAbsPosNP.getState() == IPS_BUSY || FocusRelPosNP.getState() == IPS_BUSY)
974 {
975 // The backlash handling is done here, if the move state
976 // shows that a backlash move has been done then the final move needs to be started
977 // and the states left at IPS_BUSY
978
979 if (!driver.foc_moving())
980 {
981 if (focusBacklashMove)
982 {
983 focusBacklashMove = false;
984 if (driver.foc_move(focusAbs2True(focusAbsPosition)))
985 LOGF_INFO("Focus final move %i", focusAbsPosition);
986 else
987 LOG_INFO("Backlash move failed");
988 }
989 else
990 {
991 FocusAbsPosNP.setState(IPS_OK);
992 FocusRelPosNP.setState(IPS_OK);
993 FocusAbsPosNP.apply();
994 FocusRelPosNP.apply();
995 LOG_INFO("Focuser reached requested position.");
996 }
997 }
998 }
999 }
1000
1001 return true;
1002}
1003
1005{
1006 driver.stop_motion(CELESTRON_N);
1007 driver.stop_motion(CELESTRON_S);
1008 driver.stop_motion(CELESTRON_W);
1009 driver.stop_motion(CELESTRON_E);
1010
1011 //GUIDE Abort guide operations.
1012 if (GuideNSNP.getState() == IPS_BUSY || GuideWENP.getState() == IPS_BUSY)
1013 {
1014 GuideNSNP.setState(IPS_IDLE);
1015 GuideWENP.setState(IPS_IDLE);
1016 GuideNSNP[0].setValue(0);
1017 GuideNSNP[1].setValue(0);
1018 GuideWENP[0].setValue(0);
1019 GuideWENP[1].setValue(0);
1020
1021 if (GuideNSTID)
1022 {
1024 GuideNSTID = 0;
1025 }
1026
1027 if (GuideWETID)
1028 {
1030 GuideWETID = 0;
1031 }
1032
1033 LOG_INFO("Guide aborted.");
1034 GuideNSNP.apply();
1035 GuideWENP.apply();
1036
1037 return true;
1038 }
1039
1040 return driver.abort();
1041}
1042
1044{
1045 driver.set_device(getDeviceName());
1046 driver.set_port_fd(PortFD);
1047
1048 if (isSimulation())
1049 {
1050 driver.set_simulation(true);
1051 driver.set_sim_slew_rate(SR_5);
1052 driver.set_sim_ra(0);
1053 driver.set_sim_dec(90);
1054 }
1055
1056 if (driver.check_connection() == false)
1057 {
1058 LOG_ERROR("Failed to communicate with the mount, check the logs for details.");
1059 return false;
1060 }
1061
1062 return true;
1063}
1064
1065bool CelestronGPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
1066{
1067 if (dev && std::string(getDeviceName()) == dev)
1068 {
1069 // Enable/Disable hibernate
1070 if (name && std::string(name) == UseHibernateSP.name)
1071 {
1072 IUUpdateSwitch(&UseHibernateSP, states, names, n);
1073 if (fwInfo.controllerVersion > 0)
1074 {
1075 if (UseHibernateS[0].s == ISS_ON && (checkMinVersion(4.22, "hibernation", true) == false))
1076 {
1077 UseHibernateS[0].s = ISS_OFF;
1078 UseHibernateS[1].s = ISS_ON;
1080 }
1081 else
1083 }
1084 IDSetSwitch(&UseHibernateSP, nullptr);
1085 return true;
1086 }
1087
1088 // start a last align
1089 // the process is:
1090 // start move to switch position
1091 // wait for the move to finish
1092 // set the time from the PC - maybe
1093 // send a Last Align command "Y"
1094
1095
1096 if (name && std::string(name) == LastAlignSP.name)
1097 {
1098 if (!fwInfo.hasHomeIndex)
1099 {
1100 // put the dire warning here
1101 LOG_WARN("This mount does not have index switches, make sure that it is at the index position.");
1102 }
1103 LOG_DEBUG("Start Align");
1104 // start move to switch positions
1105 if (!driver.startmovetoindex())
1106 {
1107 LastAlignSP.s = IPS_ALERT;
1108 return false;
1109 }
1110 // wait for the move to finish
1111 // done in ReadScopeStatus
1112 slewToIndex = true;
1113 LastAlignSP.s = IPS_BUSY;
1114 IDSetSwitch(&LastAlignSP, "Align in progress");
1115 return true;
1116 }
1117
1118 // handle the PEC commands
1119 if (name && std::string(name) == PecControlSP.name)
1120 {
1121 IUUpdateSwitch(&PecControlSP, states, names, n);
1123
1124 switch(idx)
1125 {
1126 case PEC_Stop:
1127 LOG_DEBUG(" stop PEC record or playback");
1128 bool playback;
1129 if ((playback = driver.pecState == PEC_PLAYBACK) || driver.pecState == PEC_RECORDING)
1130 {
1131 if (playback ? driver.PecPlayback(false) : driver.PecRecord(false))
1132 {
1134 }
1135 else
1136 {
1138 }
1139 }
1140 else
1141 {
1142 LOG_WARN("Incorrect state to stop PEC Playback or Record");
1144 }
1146 break;
1147 case PEC_Playback:
1148 LOG_DEBUG("start PEC Playback");
1149 if (driver.pecState == PEC_STATE::PEC_INDEXED)
1150 {
1151 // start playback
1152 if (driver.PecPlayback(true))
1153 {
1155 LOG_INFO("PEC Playback started");
1156 }
1157 else
1158 {
1160 return false;
1161 }
1162 }
1163 else
1164 {
1165 LOG_WARN("Incorrect state to start PEC Playback");
1166 }
1167 break;
1168 case PEC_Record:
1169 LOG_DEBUG("start PEC record");
1171 {
1172 LOG_WARN("Mount must be Tracking to record PEC");
1173 break;
1174 }
1175 if (driver.pecState == PEC_STATE::PEC_INDEXED)
1176 {
1177 if (driver.PecRecord(true))
1178 {
1180 LOG_INFO("PEC Record started");
1181 }
1182 else
1183 {
1185 return false;
1186 }
1187 }
1188 else
1189 {
1190 LOG_WARN("Incorrect state to start PEC Recording");
1191 }
1192 break;
1193 case PEC_Seek:
1194 LOG_DEBUG("Seek PEC Index");
1195 if (driver.isPecAtIndex(true))
1196 {
1197 LOG_INFO("PEC index already found");
1199 }
1200 else if (driver.pecState == PEC_STATE::PEC_AVAILABLE)
1201 {
1202 // start seek, moves up to 2 degrees in Ra
1203 if (driver.PecSeekIndex())
1204 {
1206 LOG_INFO("Seek PEC index started");
1207 }
1208 else
1209 {
1211 return false;
1212 }
1213 }
1214 break;
1215 }
1216 IDSetSwitch(&PecControlSP, nullptr);
1217 return true;
1218 }
1219
1220 // Focuser
1221 if (strstr(name, "FOCUS"))
1222 {
1223 return FI::processSwitch(dev, name, states, names, n);
1224 }
1225 }
1226
1227 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
1228}
1229
1230bool CelestronGPS::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
1231{
1232 // Check focuser interface
1233 if (FI::processNumber(dev, name, values, names, n))
1234 return true;
1235 // Check guider interface
1236 if (GI::processNumber(dev, name, values, names, n))
1237 return true;
1238
1239 if (dev && std::string(dev) == getDeviceName())
1240 {
1241 // Guide Rate
1242 if (strcmp(name, "GUIDE_RATE") == 0)
1243 {
1244 IUUpdateNumber(&GuideRateNP, values, names, n);
1245 GuideRateNP.s = IPS_OK;
1246 IDSetNumber(&GuideRateNP, nullptr);
1247 uint8_t grRa = static_cast<uint8_t>(std::min(GuideRateN[AXIS_RA].value * 256.0, 255.0));
1248 uint8_t grDec = static_cast<uint8_t>(std::min(GuideRateN[AXIS_DE].value * 256.0, 255.0));
1249 //LOGF_DEBUG("Set Guide Rates (0-1x sidereal): Ra %f, Dec %f", GuideRateN[AXIS_RA].value, GuideRateN[AXIS_DE].value);
1250 //LOGF_DEBUG("Set Guide Rates (0-255): Ra %i, Dec %i", grRa, grDec);
1251 LOGF_DEBUG("Set Guide Rates: Ra %f, Dec %f", GuideRateN[AXIS_RA].value, GuideRateN[AXIS_DE].value);
1252 driver.set_guide_rate(CELESTRON_AXIS::RA_AXIS, grRa);
1253 driver.set_guide_rate(CELESTRON_AXIS::DEC_AXIS, grDec);
1254 LOG_WARN("Changing guide rates may require recalibration of guiding.");
1255 return true;
1256 }
1257 }
1258
1259 INDI::Telescope::ISNewNumber(dev, name, values, names, n);
1260 return true;
1261}
1262
1263bool CelestronGPS::ISNewText(const char *dev, const char *name, char **texts, char **names, int n)
1264{
1265 // the idea is that pressing "Set" on the PEC_LOAD text will load the data in the file specified in the text
1266 if (dev && std::string(dev) == getDeviceName())
1267 {
1268 LOGF_DEBUG("ISNewText name %s, text %s, names %s, n %d", name, texts[0], names[0], n);
1269
1270 if (name && std::string(name) == "PEC_LOAD")
1271 {
1272
1273 IUUpdateText(&PecFileNameTP, texts, names, n);
1274 IDSetText(&PecFileNameTP, nullptr);
1275
1276 LOGF_DEBUG("PEC Set %s", PecFileNameT[0].text);
1277
1278 PecData pecData;
1279
1280 // load from file
1281 if (!pecData.Load(PecFileNameT[0].text))
1282 {
1283 LOGF_WARN("File %s load failed", PecFileNameT[0].text);
1284 return false;
1285 }
1286 // save to mount
1287 if (!pecData.Save(&driver))
1288 {
1289 LOGF_WARN("PEC Data file %s save to mount failed", PecFileNameT[0].text);
1290 return false;
1291 }
1292 LOGF_INFO("PEC Data file %s sent to mount", PecFileNameT[0].text);
1293 }
1294 }
1295
1296 INDI::Telescope::ISNewText(dev, name, texts, names, n);
1297 return true;
1298}
1299
1300
1302{
1303 // Just update the number
1304 INDI_UNUSED(steps);
1305 return true;
1306}
1307
1309{
1310 static struct timeval ltv;
1311 struct timeval tv;
1312 double dt, dx, da_ra = 0, da_dec = 0;
1313 int nlocked;
1314
1315 // update elapsed time since last poll, don't presume exactly POLLMS
1316 gettimeofday(&tv, nullptr);
1317
1318 if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
1319 ltv = tv;
1320
1321 dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
1322 ltv = tv;
1323
1324 if (fabs(targetRA - currentRA) * 15. >= GOTO_LIMIT)
1325 da_ra = GOTO_RATE * dt;
1326 else if (fabs(targetRA - currentRA) * 15. >= SLEW_LIMIT)
1327 da_ra = SLEW_RATE * dt;
1328 else
1329 da_ra = FINE_SLEW_RATE * dt;
1330
1331 if (fabs(targetDEC - currentDEC) >= GOTO_LIMIT)
1332 da_dec = GOTO_RATE * dt;
1333 else if (fabs(targetDEC - currentDEC) >= SLEW_LIMIT)
1334 da_dec = SLEW_RATE * dt;
1335 else
1336 da_dec = FINE_SLEW_RATE * dt;
1337
1338 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
1339 {
1340 int rate = SlewRateSP.findOnSwitchIndex();
1341
1342 switch (rate)
1343 {
1344 case SLEW_GUIDE:
1345 da_ra = FINE_SLEW_RATE * dt * 0.05;
1346 da_dec = FINE_SLEW_RATE * dt * 0.05;
1347 break;
1348
1349 case SLEW_CENTERING:
1350 da_ra = FINE_SLEW_RATE * dt * .1;
1351 da_dec = FINE_SLEW_RATE * dt * .1;
1352 break;
1353
1354 case SLEW_FIND:
1355 da_ra = SLEW_RATE * dt;
1356 da_dec = SLEW_RATE * dt;
1357 break;
1358
1359 default:
1360 da_ra = GOTO_RATE * dt;
1361 da_dec = GOTO_RATE * dt;
1362 break;
1363 }
1364
1365 switch (MovementNSSP.getState())
1366 {
1367 case IPS_BUSY:
1368 if (MovementNSSP[DIRECTION_NORTH].getState() == ISS_ON)
1369 currentDEC += da_dec;
1370 else if (MovementNSSP[DIRECTION_SOUTH].getState() == ISS_ON)
1371 currentDEC -= da_dec;
1372 break;
1373
1374 default:
1375 break;
1376 }
1377
1378 switch (MovementWESP.getState())
1379 {
1380 case IPS_BUSY:
1381 if (MovementWESP[DIRECTION_WEST].getState() == ISS_ON)
1382 currentRA += da_ra / 15.;
1383 else if (MovementWESP[DIRECTION_EAST].getState() == ISS_ON)
1384 currentRA -= da_ra / 15.;
1385 break;
1386
1387 default:
1388 break;
1389 }
1390
1391 driver.set_sim_ra(currentRA);
1392 driver.set_sim_dec(currentDEC);
1393
1394 NewRaDec(currentRA, currentDEC);
1395
1396 return;
1397 }
1398
1399 // Process per current state. We check the state of EQUATORIAL_COORDS and act accordingly
1400 switch (TrackState)
1401 {
1402 case SCOPE_IDLE:
1403 currentRA = driver.get_sim_ra() + (TRACKRATE_SIDEREAL / 3600.0 * dt) / 15.0;
1404 currentRA = range24(currentRA);
1405 break;
1406
1407 case SCOPE_SLEWING:
1408 case SCOPE_PARKING:
1409 // slewing - nail it when both within one pulse @ SLEWRATE
1410 nlocked = 0;
1411
1412 dx = targetRA - currentRA;
1413
1414 // Take shortest path
1415 if (fabs(dx) > 12)
1416 dx *= -1;
1417
1418 if (fabs(dx) <= da_ra)
1419 {
1420 currentRA = targetRA;
1421 nlocked++;
1422 }
1423 else if (dx > 0)
1424 currentRA += da_ra / 15.;
1425 else
1426 currentRA -= da_ra / 15.;
1427
1428 if (currentRA < 0)
1429 currentRA += 24;
1430 else if (currentRA > 24)
1431 currentRA -= 24;
1432
1433 dx = targetDEC - currentDEC;
1434 if (fabs(dx) <= da_dec)
1435 {
1436 currentDEC = targetDEC;
1437 nlocked++;
1438 }
1439 else if (dx > 0)
1440 currentDEC += da_dec;
1441 else
1442 currentDEC -= da_dec;
1443
1444 if (nlocked == 2)
1445 {
1446 driver.set_sim_slewing(false);
1447 }
1448
1449 break;
1450
1451 default:
1452 break;
1453 }
1454
1455 driver.set_sim_ra(currentRA);
1456 driver.set_sim_dec(currentDEC);
1457}
1458
1460{
1461 driver.set_simulation(enable);
1462}
1463
1464// Update Location and time are disabled if the mount is aligned. This is because
1465// changing either will change the mount model because at least the local sidereal time
1466// will be changed. StarSense will set the mount to unaligned but it isn't a good idea even
1467// with the NexStar HCs
1468
1469bool CelestronGPS::updateLocation(double latitude, double longitude, double elevation)
1470{
1471 if (!isConnected())
1472 {
1473 LOG_DEBUG("updateLocation called before we are connected");
1474 return false;
1475 }
1476
1477 if (!checkMinVersion(2.3, "updating location"))
1478 return false;
1479
1480 bool isAligned;
1481 if (!driver.check_aligned(&isAligned))
1482 {
1483 LOG_INFO("Update location - check_aligned failed");
1484 return false;
1485 }
1486
1487 if (isAligned)
1488 {
1489 LOG_INFO("Updating location is not necessary since mount is already aligned.");
1490 return false;
1491 }
1492
1493 LOGF_DEBUG("Update location %8.3f, %8.3f, %4.0f", latitude, longitude, elevation);
1494
1495 return driver.set_location(longitude, latitude);
1496}
1497
1498bool CelestronGPS::updateTime(ln_date *utc, double utc_offset)
1499{
1500 if (!isConnected())
1501 {
1502 LOG_DEBUG("updateTime called before we are connected");
1503 return false;
1504 }
1505
1506 if (!checkMinVersion(2.3, "updating time"))
1507 return false;
1508
1509 // setting time on StarSense seems to make it not aligned
1510 bool isAligned;
1511 if (!driver.check_aligned(&isAligned))
1512 {
1513 LOG_INFO("UpdateTime - check_aligned failed");
1514 return false;
1515 }
1516 if (isAligned)
1517 {
1518 LOG_INFO("Updating time is not necessary since mount is already aligned.");
1519 return false;
1520 }
1521
1522 // starsense HC doesn't seem to support the precise time setting
1523 bool precise = fwInfo.controllerVersion >= 5.28;
1524
1525 bool dst = DSTSettingS[0].s == ISS_ON;
1526
1527 LOGF_DEBUG("Update time: offset %f %s UTC %i-%02i-%02iT%02i:%02i:%02.0f", utc_offset, dst ? "DST" : "", utc->years,
1528 utc->months, utc->days,
1529 utc->hours, utc->minutes, utc->seconds);
1530
1531 return (driver.set_datetime(utc, utc_offset, dst, precise));
1532}
1533
1535{
1536 double parkAZ = GetAxis1Park();
1537 double parkAlt = GetAxis2Park();
1538
1539 char AzStr[16], AltStr[16];
1540 fs_sexa(AzStr, parkAZ, 2, 3600);
1541 fs_sexa(AltStr, parkAlt, 2, 3600);
1542
1543 // unsync is only for NS+ 5.29 or more and not StarSense
1544 if (fwInfo.controllerVersion >= 5.29 && !driver.unsync())
1545 return false;
1546
1547 LOGF_DEBUG("Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
1548
1549 if (driver.slew_azalt(parkAZ, parkAlt, usePreciseCoords))
1550 {
1552 LOG_INFO("Parking is in progress...");
1553 return true;
1554 }
1555
1556 return false;
1557}
1558
1560{
1561 bool parkDataValid = (LoadParkData() == nullptr);
1562 // Check if we need to wake up IF:
1563 // 1. Park data exists in ParkData.xml
1564 // 2. Mount is currently parked
1565 // 3. Hibernate option is enabled
1566 if (parkDataValid && isParked() && UseHibernateS[0].s == ISS_ON)
1567 {
1568 LOG_INFO("Waking up mount...");
1569
1570 if (!driver.wakeup())
1571 {
1572 LOG_ERROR("Waking up mount failed! Make sure mount is powered and connected. "
1573 "Hibernate requires firmware version >= 5.21");
1574 return false;
1575 }
1576 }
1577
1578 // Set tracking mode to whatever it was stored before
1579 SetParked(false);
1580
1581 //loadConfig(true, "TELESCOPE_TRACK_MODE");
1582 // Read Saved Track State from config file
1583 for (size_t i = 0; i < TrackStateSP.count(); i++)
1584 IUGetConfigSwitch(getDeviceName(), TrackStateSP.getName(), TrackStateSP[i].getName(), &(TrackStateSP[i].s));
1585
1586 // set the mount tracking state
1587 LOGF_DEBUG("track state %s", TrackStateSP.getLabel());
1588 SetTrackEnabled(TrackStateSP.findOnSwitchIndex() == TRACK_ON);
1589
1590 // reinit PEC
1591 if (driver.pecState >= PEC_STATE::PEC_AVAILABLE)
1592 driver.pecState = PEC_AVAILABLE;
1593
1594 return true;
1595}
1596
1598{
1599 // The Goto Alt-Az and Get Alt-Az menu items have been renamed Goto Axis Postn and Get Axis Postn
1600 // where Postn is an abbreviation for Position. Since this feature doesn't actually refer
1601 // to altitude and azimuth when mounted on a wedge, the new designation is more accurate.
1602 // Source : NexStarHandControlVersion4UsersGuide.pdf
1603
1604 if (driver.get_azalt(&currentAZ, &currentALT, usePreciseCoords) == false)
1605 {
1606 LOG_ERROR("Failed to read AZ/ALT values.");
1607 return false;
1608 }
1609
1610 double parkAZ = currentAZ;
1611 double parkAlt = currentALT;
1612
1613 char AzStr[16], AltStr[16];
1614 fs_sexa(AzStr, parkAZ, 2, 3600);
1615 fs_sexa(AltStr, parkAlt, 2, 3600);
1616
1617 LOGF_DEBUG("Setting current parking position to coordinates Az (%s) Alt (%s)...", AzStr,
1618 AltStr);
1619
1620 SetAxis1Park(parkAZ);
1621 SetAxis2Park(parkAlt);
1622
1623 return true;
1624}
1625
1627{
1628 // The Goto Alt-Az and Get Alt-Az menu items have been renamed Goto Axis Postn and Get Axis Postn
1629 // where Postn is an abbreviation for Position. Since this feature doesn't actually refer
1630 // to altitude and azimuth when mounted on a wedge, the new designation is more accurate.
1631 // Source : NexStarHandControlVersion4UsersGuide.pdf
1632
1633 // By default azimuth 90° ( hemisphere doesn't matter)
1634 SetAxis1Park(90);
1635
1636 // Altitude = 90° (latitude doesn't matter)
1637 SetAxis2Park(90);
1638
1639 return true;
1640}
1641
1643{
1646
1649 IUSaveConfigSwitch(fp, &DSTSettingSP);
1650
1651 // IUSaveConfigNumber(fp, &FocusMinPosNP);
1652
1653 return true;
1654}
1655
1656bool CelestronGPS::setCelestronTrackMode(CELESTRON_TRACK_MODE mode)
1657{
1658 if (driver.set_track_mode(mode))
1659 {
1661 LOGF_DEBUG("Tracking mode set to %i, %s.", mode, CelestronTrackModeS[mode - 1].label);
1662 return true;
1663 }
1664
1665 return false;
1666}
1667
1668//GUIDE Guiding functions.
1669
1670// There have been substantial changes at version 3.3, Nov 2019
1671//
1672// The mount controlled Aux Guide is used if it is available, this is
1673// if the mount firmware version for both axes is 6.12 or better. Other
1674// mounts use a timed guide method.
1675// The mount Aux Guide command has a maximum vulue of 2.55 seconds but if
1676// a longer guide is needed then multiple Aux Guide commands are sent.
1677//
1678// The start guide and stop guide functions use helper functions to avoid
1679// code duplication.
1680
1685
1690
1695
1700
1701// common function to start guiding for all axes.
1703{
1704 // set up direction properties
1705 char dc = 'x';
1706 int* guideTID = &GuideNSTID;
1707 int* ticks = &ticksNS;
1708 uint8_t rate = 50;
1709 int index = 0;
1710
1711 // set up pointers to the various things needed
1712 switch (dirn)
1713 {
1714 case CELESTRON_N:
1715 dc = 'N';
1716 guideTID = &GuideNSTID;
1717 ticks = &ticksNS;
1718 /* Scale guide rates to uint8 in [0..100] for sending to telescopoe, see CelestronDriver::send_pulse() */
1719 rate = guideRateDec = static_cast<uint8_t>(GuideRateN[AXIS_DE].value * 100.0);
1720 break;
1721 case CELESTRON_S:
1722 dc = 'S';
1723 guideTID = &GuideNSTID;
1724 ticks = &ticksNS;
1725 index = 1;
1726 /* Scale guide rates to uint8 in [0..100] for sending to telescopoe, see CelestronDriver::send_pulse() */
1727 rate = guideRateDec = static_cast<uint8_t>(GuideRateN[AXIS_DE].value * 100.0);
1728 break;
1729 case CELESTRON_E:
1730 dc = 'E';
1731 guideTID = &GuideWETID;
1732 ticks = &ticksWE;
1733 /* Scale guide rates to uint8 in [0..100] for sending to telescopoe, see CelestronDriver::send_pulse() */
1734 rate = guideRateRa = static_cast<uint8_t>(GuideRateN[AXIS_RA].value * 100.0);
1735 break;
1736 case CELESTRON_W:
1737 dc = 'W';
1738 guideTID = &GuideWETID;
1739 ticks = &ticksWE;
1740 index = 1;
1741 /* Scale guide rates to uint8 in [0..100] for sending to telescopoe, see CelestronDriver::send_pulse() */
1742 rate = guideRateRa = static_cast<uint8_t>(GuideRateN[AXIS_RA].value * 100.0);
1743 break;
1744 }
1745
1746 LOGF_DEBUG("GUIDE CMD: %c %u ms, %s guide", dc, ms, canAuxGuide ? "Aux" : "Time");
1747
1748 if (!canAuxGuide && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY))
1749 {
1750 LOG_ERROR("Cannot guide while moving.");
1751 return IPS_ALERT;
1752 }
1753
1754 auto directionProperty = dirn > CELESTRON_S ? MovementWESP : MovementNSSP;
1755
1756 // If already moving (no pulse command), then stop movement
1757 if (directionProperty.getState() == IPS_BUSY)
1758 {
1759 LOG_DEBUG("Already moving - stop");
1760 driver.stop_motion(dirn);
1761 }
1762
1763 if (*guideTID)
1764 {
1765 LOGF_DEBUG("Stop timer %c", dc);
1766 IERmTimer(*guideTID);
1767 *guideTID = 0;
1768 }
1769
1770 if (canAuxGuide)
1771 {
1772 // get the number of 10ms hardware ticks
1773 *ticks = ms / 10;
1774
1775 // send the first Aux Guide command,
1776 if (driver.send_pulse(dirn, rate, static_cast<char>(std::min(255, *ticks))) == 0)
1777 {
1778 LOGF_ERROR("send_pulse %c error", dc);
1779 return IPS_ALERT;
1780 }
1781 // decrease ticks and ms values
1782 *ticks -= 255;
1783 ms = ms > 2550 ? 2550 : ms;
1784 }
1785 else
1786 {
1787 directionProperty[index].setState(ISS_ON);
1788 // start movement at HC button rate 1
1789 if (!driver.start_motion(dirn, CELESTRON_SLEW_RATE::SR_1))
1790 {
1791 LOGF_ERROR("StartMotion %c failed", dc);
1792 return IPS_ALERT;
1793 }
1794 *ticks = 0;
1795 }
1796
1797 // Set slew to guiding
1798 SlewRateSP.reset();
1799 SlewRateSP[SLEW_GUIDE].setState(ISS_ON);
1800 SlewRateSP.apply();
1801 // start the guide timeout timer
1802 AddGuideTimer(dirn, static_cast<int>(ms));
1803 return IPS_BUSY;
1804}
1805
1806//GUIDE The timer helper functions.
1808{
1809 static_cast<CelestronGPS *>(p)->guideTimer(CELESTRON_N);
1810}
1811
1813{
1814 static_cast<CelestronGPS *>(p)->guideTimer(CELESTRON_S);
1815}
1816
1818{
1819 static_cast<CelestronGPS *>(p)->guideTimer(CELESTRON_W);
1820}
1821
1823{
1824 static_cast<CelestronGPS *>(p)->guideTimer(CELESTRON_E);
1825}
1826
1827//GUIDE The timer function
1828
1829/* Here I splitted the behaviour depending upon the direction
1830 * of the guide command which generates the timer; this was
1831 * done because the member variable "guide_direction" could
1832 * be modified by a pulse command on the other axis BEFORE
1833 * the calling pulse command is terminated.
1834 */
1835
1837{
1838 int* ticks = &ticksNS;
1839 uint8_t rate = 0;
1840
1841 switch(dirn)
1842 {
1843 case CELESTRON_N:
1844 case CELESTRON_S:
1845 ticks = &ticksNS;
1846 rate = guideRateDec;
1847 break;
1848 case CELESTRON_E:
1849 case CELESTRON_W:
1850 ticks = &ticksWE;
1851 rate = guideRateRa;
1852 break;
1853 }
1854
1855 LOGF_DEBUG("guideTimer dir %c, ticks %i, rate %i", "NSWE"[dirn], *ticks, rate);
1856
1857 if (canAuxGuide)
1858 {
1859 if (driver.get_pulse_status(dirn))
1860 {
1861 // current move not finished, add some more time
1862 AddGuideTimer(dirn, 100);
1863 return;
1864 }
1865 if (*ticks > 0)
1866 {
1867 // do some more guiding and set the timeout
1868 int dt = (*ticks > 255) ? 255 : *ticks;
1869 driver.send_pulse(dirn, rate, static_cast<uint8_t>(dt));
1870 AddGuideTimer(dirn, dt * 10);
1871 *ticks -= 255;
1872 return;
1873 }
1874 // we get here if the axis reports guiding finished and all the ticks have been done
1875 }
1876 else
1877 {
1878 if (!driver.stop_motion(dirn))
1879 LOGF_ERROR("StopMotion failed dir %c", "NSWE"[dirn]);
1880 }
1881
1882 switch(dirn)
1883 {
1884 case CELESTRON_N:
1885 case CELESTRON_S:
1886 MovementNSSP.reset();
1887 MovementNSSP.apply();
1888 GuideNSNP[0].setValue(0);
1889 GuideNSNP[1].setValue(0);
1890 GuideNSNP.setState(IPS_IDLE);
1891 GuideNSTID = 0;
1892 GuideNSNP.apply();
1893 break;
1894 case CELESTRON_E:
1895 case CELESTRON_W:
1896 MovementWESP.reset();
1897 MovementWESP.apply();
1898 GuideWENP[0].setValue(0);
1899 GuideWENP[1].setValue(0);
1900 GuideWENP.setState(IPS_IDLE);
1901 GuideWETID = 0;
1902 GuideWENP.apply();
1903 break;
1904 }
1905 LOGF_DEBUG("Guide %c finished", "NSWE"[dirn]);
1906}
1907
1909{
1910 switch(dirn)
1911 {
1912 case CELESTRON_N:
1914 break;
1915 case CELESTRON_S:
1917 break;
1918 case CELESTRON_E:
1920 break;
1921 case CELESTRON_W:
1923 break;
1924 }
1925}
1926
1927// end of guiding code
1928
1929// the INDI overload, expected to set the track rate
1930// sidereal, solar or lunar and only if the mount is equatorial
1932{
1934
1935 switch (fwInfo.celestronTrackMode)
1936 {
1937 case CTM_OFF:
1938 case CTM_ALTAZ:
1939 case CTM_RADEC:
1940 return false;
1941 case CTM_EQN:
1942 case CTM_EQS:
1943 break;
1944 }
1945
1946 switch (mode)
1947 {
1948 case 0:
1949 rate = CTR_SIDEREAL;
1950 break;
1951 case 1:
1952 rate = CTR_SOLAR;
1953 break;
1954 case 2:
1955 rate = CTR_LUNAR;
1956 break;
1957 default:
1958 return false;
1959 }
1960 return driver.set_track_rate(rate, fwInfo.celestronTrackMode);
1961}
1962
1964{
1965 return setCelestronTrackMode(enabled ? fwInfo.celestronTrackMode : CTM_OFF);
1966 //return setTrackMode(enabled ? static_cast<CELESTRON_TRACK_MODE>(IUFindOnSwitchIndex(&TrackModeSP)+1) : TRACKING_OFF);
1967}
1968
1969void CelestronGPS::checkAlignment()
1970{
1972
1973 bool isAligned;
1974 if (!driver.check_aligned(&isAligned) || !isAligned)
1975 LOG_WARN("Mount is NOT aligned. You must align the mount first before you can use it. Disconnect, align the mount, and reconnect again.");
1976}
1977
1978bool CelestronGPS::savePecData()
1979{
1980 // generate the file name:
1981 // ~/.indi/pec/yyyy-mm-dd/pecData_hh:mm.log
1982
1983 char ts_date[32], ts_time[32];
1984 struct tm *tp;
1985 time_t t;
1986
1987 time(&t);
1988 tp = gmtime(&t);
1989 strftime(ts_date, sizeof(ts_date), "%Y-%m-%d", tp);
1990 strftime(ts_time, sizeof(ts_time), "%H:%M", tp);
1991
1992 char dir[MAXRBUF];
1993 snprintf(dir, MAXRBUF, "%s/PEC_Data/%s", getenv("HOME"), ts_date);
1994
1995 if (INDI::mkpath(dir, 0755) == -1)
1996 {
1997 LOGF_ERROR("Error creating directory %s (%s)", dir, strerror(errno));
1998 return false;
1999 }
2000
2001 char pecFileBuf[MAXRBUF];
2002 snprintf(pecFileBuf, MAXRBUF, "%s/pecData_%s.csv", dir, ts_time);
2003
2004 // show the file name
2005 IUSaveText(&PecFileNameT[0], pecFileBuf);
2006 IDSetText(&PecFileNameTP, nullptr);
2007
2008 // get the PEC data from the mount
2009 PecData pecdata;
2010
2011 if (!pecdata.Load(&driver))
2012 {
2013 LOG_DEBUG("Load PEC from mount failed");
2014 return false;
2015 }
2016 pecdata.RemoveDrift();
2017 // and save it
2018 if (!pecdata.Save(pecFileBuf))
2019 {
2020 LOGF_DEBUG("Save PEC file %s failed", pecFileBuf);
2021 return false;
2022 }
2023 LOGF_INFO("PEC data saved to %s", pecFileBuf);
2024 return true;
2025}
2026
2027// focus control
2029{
2030 uint32_t absPosition = targetTicks;
2031
2032 if (!focuserIsCalibrated)
2033 {
2034 LOG_ERROR("Move is not allowed because the focuser is not calibrated");
2035 return IPS_ALERT;
2036 }
2037
2038 // implement backlash
2039 int delta = static_cast<int>(targetTicks - FocusAbsPosNP[0].getValue());
2040
2041 if ((FocusBacklashNP[0].getValue() < 0 && delta > 0) ||
2042 (FocusBacklashNP[0].getValue() > 0 && delta < 0))
2043 {
2044 focusBacklashMove = true;
2045 focusAbsPosition = absPosition;
2046 absPosition -= FocusBacklashNP[0].getValue();
2047 }
2048
2049 LOGF_INFO("Focus %s move %d", focusBacklashMove ? "backlash" : "direct", absPosition);
2050
2051 if(!driver.foc_move(focusAbs2True(absPosition)))
2052 return IPS_ALERT;
2053
2054 return IPS_BUSY;
2055}
2056
2058{
2059 uint32_t newPosition = 0;
2060
2061 if (dir == FOCUS_INWARD)
2062 newPosition = static_cast<uint32_t>(FocusAbsPosNP[0].getValue()) - ticks;
2063 else
2064 newPosition = static_cast<uint32_t>(FocusAbsPosNP[0].getValue()) + ticks;
2065
2066 // Clamp
2067 newPosition = std::min(static_cast<uint32_t>(FocusAbsPosNP[0].getMax()), newPosition);
2068 return MoveAbsFocuser(newPosition);
2069}
2070
2072{
2073 return driver.foc_abort();
2074}
2075
2076// read the focuser limits from the hardware
2077bool CelestronGPS::focusReadLimits()
2078{
2079 int low = 0, high = 0;
2080 bool valid = driver.foc_limits(&low, &high);
2081
2082 focusTrueMax = high;
2083 focusTrueMin = low;
2084
2085 FocusAbsPosNP[0].setMax(focusTrue2Abs(focusTrueMin));
2086 FocusMaxPosNP[0].setValue(focusTrue2Abs(focusTrueMin));
2089
2092
2093 // FocusMinPosNP[0].setValue(low);
2094 // FocusMinPosNP.s = IPS_OK;
2095 // IDSetNumber(&FocusMinPosNP, nullptr);
2096
2097 focuserIsCalibrated = valid;
2098
2099 LOGF_INFO("Focus Limits: Maximum (%i) Minimum (%i) steps.", high, low);
2100 return valid;
2101}
CELESTRON_DIRECTION
@ CELESTRON_W
@ CELESTRON_N
@ CELESTRON_S
@ CELESTRON_E
@ FW_CAN_AUX
@ FW_MODEL
@ FW_ISGEM
@ FW_VERSION
@ FW_DEC
@ FW_HAS_FOC
@ FW_RA
CELESTRON_SLEW_RATE
@ SR_1
@ SR_5
CELESTRON_TRACK_MODE
@ CTM_EQN
@ CTM_ALTAZ
@ CTM_EQS
@ CTM_OFF
@ CTM_RADEC
#define ISSTARSENSE
#define MINSTSENSVER
CELESTRON_TRACK_RATE
@ CTR_SIDEREAL
@ CTR_SOLAR
@ CTR_LUNAR
PEC_STATE
@ NotKnown
@ PEC_SEEKING
The PEC index is being searched for, goes to PEC_INDEXED when found.
@ PEC_AVAILABLE
PEC is available but inactive, can seek index Seek index is only available command.
@ PEC_PLAYBACK
PEC is being played back, stays in this state until stopped equivalent to TelescopePECState PEC_ON.
@ PEC_RECORDING
PEC is being recorded, goes to PEC_INDEXED when completed.
@ PEC_INDEXED
the PEC index has been found, can go to Playback or Recording this is equivalent to TelescopePECState...
@ DEC_AXIS
@ RA_AXIS
#define ISNEXSTAR
#define SLEW_RATE
#define GOTO_RATE
#define FINE_SLEW_RATE
#define MOUNTINFO_TAB
#define SLEW_LIMIT
#define GOTO_LIMIT
bool check_aligned(bool *isAligned)
bool foc_limits(int *low, int *high)
bool set_track_mode(CELESTRON_TRACK_MODE mode)
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
ITextVectorProperty PecFileNameTP
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
ISwitch UseHibernateS[2]
IText PecInfoT[2]
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
ISwitchVectorProperty PecControlSP
uint8_t guideRateRa
static void guideTimerHelperE(void *p)
static void guideTimerHelperS(void *p)
virtual bool UnPark() override
Unpark the telescope if already parked.
INumber GuideRateN[2]
ISwitch PecControlS[4]
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
ITextVectorProperty FirmwareTP
void guideTimer(CELESTRON_DIRECTION dirn)
static void guideTimerHelperW(void *p)
IPState Guide(CELESTRON_DIRECTION dirn, uint32_t ms)
void AddGuideTimer(CELESTRON_DIRECTION dirn, int ms)
bool AbortFocuser() override
AbortFocuser all focus motion.
IText FirmwareT[7]
IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
INumberVectorProperty GuideRateNP
virtual const char * getDefaultName() override
ITextVectorProperty PecInfoTP
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool Park() override
Park the telescope to its home position.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual void simulationTriggered(bool enable) override
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
ISwitchVectorProperty CelestronTrackModeSP
uint8_t guideRateDec
IText PecFileNameT[1]
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
ISwitchVectorProperty UseHibernateSP
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
static void guideTimerHelperN(void *p)
ISwitch CelestronTrackModeS[4]
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool ISNewText(const char *dev, const char *name, char **texts, char **names, int n) override
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
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...
Class to provide general functionality of a GPS device.
bool isConnected() 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....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
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 syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
uint32_t getDriverInterface() const
INDI::PropertyNumber FocusRelPosNP
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.
void initProperties(const char *groupName)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
INDI::PropertyNumber FocusMaxPosNP
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 FocusBacklashNP
INDI::PropertyNumber FocusAbsPosNP
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....
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
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.
double GetAxis1Park() const
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...
double GetAxis2Park() const
bool isParked()
isParked is mount currently parked?
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....
const char * LoadParkData()
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
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.
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
bool Load(CelestronDriver *driver)
bool Save(const char *filename)
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.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
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
int errno
TelescopePierSide currentPierSide
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch TrackStateSP
INDI::PropertySwitch SlewRateSP
INDI::PropertyText TimeTP
INDI::PropertySwitch MovementWESP
INDI::PropertyNumber LocationNP
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IP_WO
Definition indiapi.h:183
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
@ ISR_NOFMANY
Definition indiapi.h:173
@ ISR_ATMOST1
Definition indiapi.h:172
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_EAST
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_SOUTH
@ DIRECTION_NORTH
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition indicom.c:1311
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.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
Definition indidevapi.c:33
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 IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
#define MAXRBUF
Definition indidriver.c:52
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
int IUGetConfigSwitch(const char *dev, const char *property, const char *member, ISState *value)
IUGetConfigSwitch Opens configuration file and reads single switch property.
Definition indidriver.c:657
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 LOG_DEBUG(txt)
Definition indilogger.h:75
#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_SIDEREAL
Definition indimacros.h:39
#define getDeviceName
int mkpath(std::string s, mode_t mode)
*brief create JSON pointer *sa reference_tokens const string_t & a
double controllerVersion