Instrument Neutral Distributed Interface INDI 2.2.5
inditelescope.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2011 Gerry Rozema, Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include "inditelescope.h"
20
21#include "indicom.h"
22#include "indicontroller.h"
25
26#include <libnova/sidereal_time.h>
27#include <libnova/transform.h>
28
29#include <cmath>
30#include <cerrno>
31#include <pwd.h>
32#include <cstdlib>
33#include <cstring>
34#include <ctime>
35#include <unistd.h>
36#include <wordexp.h>
37#include <limits>
38
39namespace INDI
40{
41
43 : DefaultDevice(), ParkDataFileName(GetHomeDirectory() + "/.indi/ParkData.xml")
44{
45 controller = new Controller(this);
46 controller->setJoystickCallback(joystickHelper);
47 controller->setAxisCallback(axisHelper);
48 controller->setButtonCallback(buttonHelper);
49
52
55}
56
58{
59 if (ParkdataXmlRoot)
60 delXMLEle(ParkdataXmlRoot);
61
62 delete (controller);
63}
64
66{
68
69 // Since this property was created in setTelescopeCapability before a device name is defined.
70 // Then we need to set the device name here
71 HomeSP.setDeviceName(getDeviceName());
72
73 // Active Devices
74 // @INDI_STANDARD_PROPERTY@
75 ActiveDeviceTP[ACTIVE_GPS].fill("ACTIVE_GPS", "GPS", "GPS Simulator");
76 ActiveDeviceTP[ACTIVE_DOME].fill("ACTIVE_DOME", "DOME", "Dome Simulator");
77 ActiveDeviceTP.fill(getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);
78 ActiveDeviceTP.load();
79
80 // Use locking if dome is closed (and or) park scope if dome is closing
81 // @INDI_STANDARD_PROPERTY@
82 DomePolicySP[DOME_IGNORED].fill("DOME_IGNORED", "Dome ignored", ISS_ON);
83 DomePolicySP[DOME_LOCKS].fill("DOME_LOCKS", "Dome locks", ISS_OFF);
84 DomePolicySP.fill(getDeviceName(), "DOME_POLICY", "Dome Policy", OPTIONS_TAB, IP_RW,
86
87 // @INDI_STANDARD_PROPERTY@
88 EqNP[AXIS_RA].fill("RA", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
89 EqNP[AXIS_DE].fill("DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
90 EqNP.fill(getDeviceName(), "EQUATORIAL_EOD_COORD", "Eq. Coordinates", MAIN_CONTROL_TAB,
91 IP_RW, 60, IPS_IDLE);
92 lastEqState = IPS_IDLE;
93
94 // @INDI_STANDARD_PROPERTY@
95 TargetNP[AXIS_RA].fill("RA", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
96 TargetNP[AXIS_DE].fill("DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
97 TargetNP.fill(getDeviceName(), "TARGET_EOD_COORD", "Slew Target", MOTION_TAB, IP_RO, 60,
98 IPS_IDLE);
99
100 // @INDI_STANDARD_PROPERTY@
101 ParkOptionSP[PARK_CURRENT].fill("PARK_CURRENT", "Current", ISS_OFF);
102 ParkOptionSP[PARK_DEFAULT].fill("PARK_DEFAULT", "Default", ISS_OFF);
103 ParkOptionSP[PARK_WRITE_DATA].fill("PARK_WRITE_DATA", "Write Data", ISS_OFF);
104 ParkOptionSP[PARK_PURGE_DATA].fill("PARK_PURGE_DATA", "Purge Data", ISS_OFF);
105 ParkOptionSP.fill(getDeviceName(), "TELESCOPE_PARK_OPTION", "Park Options", SITE_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
106
107 // @INDI_STANDARD_PROPERTY@
108 TimeTP[UTC].fill("UTC", "UTC Time", nullptr);
109 TimeTP[OFFSET].fill("OFFSET", "UTC Offset", nullptr);
110 TimeTP.fill(getDeviceName(), "TIME_UTC", "UTC", SITE_TAB, IP_RW, 60, IPS_IDLE);
111
112 // @INDI_STANDARD_PROPERTY@
113 LocationNP[LOCATION_LATITUDE].fill("LAT", "Lat (dd:mm:ss.s)", "%012.8m", -90, 90, 0, 0.0);
114 LocationNP[LOCATION_LONGITUDE].fill("LONG", "Lon (dd:mm:ss.s)", "%012.8m", 0, 360, 0, 0.0);
115 LocationNP[LOCATION_ELEVATION].fill("ELEV", "Elevation (m)", "%g", -200, 10000, 0, 0);
116 LocationNP.fill(getDeviceName(), "GEOGRAPHIC_COORD", "Scope Location", SITE_TAB,
117 IP_RW, 60, IPS_IDLE);
118
119 // Pier Side
120 // @INDI_STANDARD_PROPERTY@
121 PierSideSP[PIER_WEST].fill("PIER_WEST", "West (pointing east)", ISS_OFF);
122 PierSideSP[PIER_EAST].fill("PIER_EAST", "East (pointing west)", ISS_OFF);
123 PierSideSP.fill(getDeviceName(), "TELESCOPE_PIER_SIDE", "Pier Side", MAIN_CONTROL_TAB,
125
126 // Pier Side Simulation
127 // @INDI_STANDARD_PROPERTY@
128 SimulatePierSideSP[SIMULATE_YES].fill("SIMULATE_YES", "Yes", ISS_OFF);
129 SimulatePierSideSP[SIMULATE_NO].fill("SIMULATE_NO", "No", ISS_ON);
130 SimulatePierSideSP.fill(getDeviceName(), "SIMULATE_PIER_SIDE", "Simulate Pier Side",
133
134 // PEC State
135 // @INDI_STANDARD_PROPERTY@
136 PECStateSP[PEC_OFF].fill("PEC OFF", "PEC OFF", ISS_ON);
137 PECStateSP[PEC_ON].fill("PEC ON", "PEC ON", ISS_OFF);
138 PECStateSP.fill(getDeviceName(), "PEC", "PEC Playback", MOTION_TAB, IP_RW, ISR_1OFMANY, 0,
139 IPS_IDLE);
140
141 // Mount Type
142 // @INDI_STANDARD_PROPERTY@
143 MountTypeSP[MOUNT_ALTAZ].fill("ALTAZ", "ALTAZ", ISS_OFF);
144 MountTypeSP[MOUNT_EQ_FORK].fill("EQ_FORK", "Fork (Eq)", ISS_OFF);
145 MountTypeSP[MOUNT_EQ_GEM].fill("EQ_GEM", "GEM", ISS_ON);
146 MountTypeSP.fill(getDeviceName(), "TELESCOPE_MOUNT_TYPE", "Mount Type", MOTION_TAB,
148
149 // Track Mode. Child class must call AddTrackMode to add members
150 // @INDI_STANDARD_PROPERTY@
151 TrackModeSP.fill(getDeviceName(), "TELESCOPE_TRACK_MODE", "Track Mode", MAIN_CONTROL_TAB,
153
154 // Track State
155 // @INDI_STANDARD_PROPERTY@
156 TrackStateSP[TRACK_ON].fill("TRACK_ON", "On", ISS_OFF);
157 TrackStateSP[TRACK_OFF].fill("TRACK_OFF", "Off", ISS_ON);
158 TrackStateSP.fill(getDeviceName(), "TELESCOPE_TRACK_STATE", "Tracking", MAIN_CONTROL_TAB,
159 IP_RW, ISR_1OFMANY, 0,
160 IPS_IDLE);
161
162 // Track Rate
163 // @INDI_STANDARD_PROPERTY@
164 TrackRateNP[AXIS_RA].fill("TRACK_RATE_RA", "RA (arcsecs/s)", "%.6f", -16384.0, 16384.0, 0.000001,
166 TrackRateNP[AXIS_DE].fill("TRACK_RATE_DE", "DE (arcsecs/s)", "%.6f", -16384.0, 16384.0, 0.000001, 0.0);
167 TrackRateNP.fill(getDeviceName(), "TELESCOPE_TRACK_RATE", "Track Rates", MAIN_CONTROL_TAB,
168 IP_RW, 60, IPS_IDLE);
169
170 // On Coord Set
171 // @INDI_STANDARD_PROPERTY@
172 // Note: Member elements can be TRACK, SLEW, SYNC, and FLIP
173 CoordSP.fill(getDeviceName(), "ON_COORD_SET", "On Set", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
174 generateCoordSet();
175
176 // @INDI_STANDARD_PROPERTY@
177 if (nSlewRate >= 4)
178 SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate",
180
181 if (CanTrackSatellite())
182 {
183 // @INDI_STANDARD_PROPERTY@
184 TLEtoTrackTP[0].fill("TLE", "TLE", "");
185 TLEtoTrackTP.fill(getDeviceName(), "SAT_TLE_TEXT", "Orbit Params", SATELLITE_TAB,
186 IP_RW, 60, IPS_IDLE);
187
188 char curTime[32] = {0};
189 std::time_t t = std::time(nullptr);
190 struct std::tm *utctimeinfo = std::gmtime(&t);
191 strftime(curTime, sizeof(curTime), "%Y-%m-%dT%H:%M:%S", utctimeinfo);
192
193 // @INDI_STANDARD_PROPERTY@
194 SatPassWindowTP[SAT_PASS_WINDOW_END].fill("SAT_PASS_WINDOW_END", "End UTC", curTime);
195 SatPassWindowTP[SAT_PASS_WINDOW_START].fill("SAT_PASS_WINDOW_START", "Start UTC", curTime);
196 SatPassWindowTP.fill(getDeviceName(), "SAT_PASS_WINDOW", "Pass Window", SATELLITE_TAB, IP_RW, 60, IPS_IDLE);
197
198 // @INDI_STANDARD_PROPERTY@
199 TrackSatSP[SAT_TRACK].fill("SAT_TRACK", "Track", ISS_OFF);
200 TrackSatSP[SAT_HALT].fill("SAT_HALT", "Halt", ISS_ON);
201 TrackSatSP.fill(getDeviceName(), "SAT_TRACKING_STAT",
202 "Sat tracking", SATELLITE_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
203 }
204
205 // @INDI_STANDARD_PROPERTY@
206 ParkSP[PARK].fill("PARK", "Park(ed)", ISS_OFF);
207 ParkSP[UNPARK].fill("UNPARK", "UnPark(ed)", ISS_OFF);
208 ParkSP.fill(getDeviceName(), "TELESCOPE_PARK", "Parking", MAIN_CONTROL_TAB, IP_RW,
209 ISR_1OFMANY, 60, IPS_IDLE);
210
211 // @INDI_STANDARD_PROPERTY@
212 AbortSP[0].fill("ABORT", "Abort", ISS_OFF);
213 AbortSP.fill(getDeviceName(), "TELESCOPE_ABORT_MOTION", "Abort Motion", MAIN_CONTROL_TAB,
215
216 // @INDI_STANDARD_PROPERTY@
217 MovementNSSP[DIRECTION_NORTH].fill("MOTION_NORTH", "North", ISS_OFF);
218 MovementNSSP[DIRECTION_SOUTH].fill("MOTION_SOUTH", "South", ISS_OFF);
219 MovementNSSP.fill(getDeviceName(), "TELESCOPE_MOTION_NS", "Motion N/S", MOTION_TAB,
221
222 // @INDI_STANDARD_PROPERTY@
223 MovementWESP[DIRECTION_WEST].fill("MOTION_WEST", "West", ISS_OFF);
224 MovementWESP[DIRECTION_EAST].fill("MOTION_EAST", "East", ISS_OFF);
225 MovementWESP.fill(getDeviceName(), "TELESCOPE_MOTION_WE", "Motion W/E", MOTION_TAB,
227
228 // Reverse NS or WE
229 // @INDI_STANDARD_PROPERTY@
230 ReverseMovementSP[REVERSE_NS].fill("REVERSE_NS", "North/South", ISS_OFF);
231 ReverseMovementSP[REVERSE_WE].fill("REVERSE_WE", "West/East", ISS_OFF);
232 ReverseMovementSP.fill(getDeviceName(), "TELESCOPE_REVERSE_MOTION", "Reverse", MOTION_TAB, IP_RW, ISR_NOFMANY, 60,
233 IPS_IDLE);
234
235 controller->initProperties();
236
237 // Joystick motion control
238 // @INDI_STANDARD_PROPERTY@
239 MotionControlModeTP[MOTION_CONTROL_MODE_JOYSTICK].fill("MOTION_CONTROL_MODE_JOYSTICK", "4-Way Joystick", ISS_ON);
240 MotionControlModeTP[MOTION_CONTROL_MODE_AXES].fill("MOTION_CONTROL_MODE_AXES", "Two Separate Axes", ISS_OFF);
241 MotionControlModeTP.fill(getDeviceName(), "MOTION_CONTROL_MODE", "Motion Control",
242 "Joystick", IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
243
244 // Lock Axis
245 // @INDI_STANDARD_PROPERTY@
246 LockAxisSP[LOCK_AXIS_1].fill("LOCK_AXIS_1", "West/East", ISS_OFF);
247 LockAxisSP[LOCK_AXIS_2].fill("LOCK_AXIS_2", "North/South", ISS_OFF);
248 LockAxisSP.fill(getDeviceName(), "JOYSTICK_LOCK_AXIS", "Lock Axis", "Joystick", IP_RW,
249 ISR_ATMOST1, 60, IPS_IDLE);
250
251 // Joystick reverse motion and swapping (joystick only)
252 JoystickReverseSP[JOYSTICK_REVERSE_NS].fill("JOYSTICK_REVERSE_NS", "N/S", ISS_OFF);
253 JoystickReverseSP[JOYSTICK_REVERSE_WE].fill("JOYSTICK_REVERSE_WE", "W/E", ISS_OFF);
254 JoystickReverseSP[JOYSTICK_REVERSE_SWAP].fill("JOYSTICK_REVERSE_SWAP", "Swap N/S<->W/E", ISS_OFF);
255 JoystickReverseSP.fill(getDeviceName(), "TELESCOPE_JOYSTICK_REVERSE", "Axis Reverse", "Joystick", IP_RW, ISR_NOFMANY, 60,
256 IPS_IDLE);
257
259
261
262 if (telescopeConnection & CONNECTION_SERIAL)
263 {
265 serialConnection->registerHandshake([&]()
266 {
267 return callHandshake();
268 });
270 }
271
272 if (telescopeConnection & CONNECTION_TCP)
273 {
274 tcpConnection = new Connection::TCP(this);
275 tcpConnection->registerHandshake([&]()
276 {
277 return callHandshake();
278 });
279
281 }
282
283 IDSnoopDevice(ActiveDeviceTP[ACTIVE_GPS].getText(), "GEOGRAPHIC_COORD");
285
288
290
291 double longitude = 0, latitude = 0, elevation = 0;
292 // Get value from config file if it exists.
293 if (IUGetConfigNumber(getDeviceName(), LocationNP.getName(), LocationNP[LOCATION_LONGITUDE].getName(), &longitude) == 0)
294 {
295 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
296 m_Location.longitude = longitude;
297 }
298 if (IUGetConfigNumber(getDeviceName(), LocationNP.getName(), LocationNP[LOCATION_LATITUDE].getName(), &latitude) == 0)
299 {
300 LocationNP[LOCATION_LATITUDE].setValue(latitude);
301 m_Location.latitude = latitude;
302 }
303 if (IUGetConfigNumber(getDeviceName(), LocationNP.getName(), LocationNP[LOCATION_ELEVATION].getName(), &elevation) == 0)
304 {
305 LocationNP[LOCATION_ELEVATION].setValue(elevation);
306 m_Location.elevation = elevation;
307 }
308
309 return true;
310}
311
312void Telescope::ISGetProperties(const char *dev)
313{
315
316 if (CanGOTO())
317 {
319
320 ISState isDomeIgnored = ISS_OFF;
321 if (IUGetConfigSwitch(getDeviceName(), DomePolicySP.getName(), DomePolicySP[DOME_IGNORED].getName(), &isDomeIgnored) == 0)
322 {
323 DomePolicySP[DOME_IGNORED].setState(isDomeIgnored);
324 DomePolicySP[DOME_LOCKS].setState((isDomeIgnored == ISS_ON) ? ISS_OFF : ISS_ON);
325 }
327 }
328
329 if (CanGOTO())
330 controller->ISGetProperties(dev);
331}
332
334{
335 if (isConnected())
336 {
337 controller->mapController("MOTIONDIR", "N/S/W/E Control", Controller::CONTROLLER_JOYSTICK, "JOYSTICK_1");
338 controller->mapController("MOTIONDIRNS", "N/S Control", Controller::CONTROLLER_AXIS, "AXIS_8");
339 controller->mapController("MOTIONDIRWE", "W/E Control", Controller::CONTROLLER_AXIS, "AXIS_7");
340
341 if (nSlewRate >= 4)
342 {
343 controller->mapController("SLEWPRESET", "Slew Rate", Controller::CONTROLLER_JOYSTICK, "JOYSTICK_2");
344 controller->mapController("SLEWPRESETUP", "Slew Rate Up", Controller::CONTROLLER_BUTTON, "BUTTON_5");
345 controller->mapController("SLEWPRESETDOWN", "Slew Rate Down", Controller::CONTROLLER_BUTTON,
346 "BUTTON_6");
347 }
348 if (CanAbort())
349 controller->mapController("ABORTBUTTON", "Abort", Controller::CONTROLLER_BUTTON, "BUTTON_1");
350 if (CanPark())
351 {
352 controller->mapController("PARKBUTTON", "Park", Controller::CONTROLLER_BUTTON, "BUTTON_2");
353 controller->mapController("UNPARKBUTTON", "UnPark", Controller::CONTROLLER_BUTTON, "BUTTON_3");
354 }
355
356 // Now we add our telescope specific stuff
357 if (CanGOTO() || CanSync())
360 if (CanAbort())
362
363 if (HasTrackMode() && TrackModeSP)
365 if (CanControlTrack())
367 if (HasTrackRate())
369 if (CanHomeFind() || CanHomeSet() || CanHomeGo())
371
372 if (CanGOTO())
373 {
377 if (nSlewRate >= 4)
380 }
381
383
384 if (HasTime())
386 if (HasLocation())
388 if (CanPark())
389 {
391 if (parkDataType != PARK_NONE)
392 {
393 // PARK_SIMPLE has no park position, its property is never filled.
397 }
398 }
399
400 if (HasPierSide())
402
404 {
406 ISState value;
407 if (IUGetConfigSwitch(getDefaultName(), "SIMULATE_PIER_SIDE", "SIMULATE_YES", &value) )
408 setSimulatePierSide(value == ISS_ON);
409 }
410
411 if (CanTrackSatellite())
412 {
416 }
417
418 if (HasPECState())
420 }
421 else
422 {
423 if (CanGOTO() || CanSync())
426 if (CanAbort())
428 if (HasTrackMode() && TrackModeSP)
430 if (HasTrackRate())
432 if (CanControlTrack())
434 if (CanHomeFind() || CanHomeSet() || CanHomeGo())
436
437 if (CanGOTO())
438 {
442 if (nSlewRate >= 4)
445 }
446
448
449 if (HasTime())
451 if (HasLocation())
453
454 if (CanPark())
455 {
457 if (parkDataType != PARK_NONE)
458 {
462 }
463 }
464
465 if (HasPierSide())
467
469 {
471 if (getSimulatePierSide() == true)
473 }
474
475 if (CanTrackSatellite())
476 {
480 }
481
482 if (HasPECState())
484 }
485
486 if (CanGOTO())
487 {
488 controller->updateProperties();
489
490 auto useJoystick = getSwitch("USEJOYSTICK");
491 if (useJoystick)
492 {
493 if (isConnected())
494 {
495 if (useJoystick[0].getState() == ISS_ON)
496 {
500
501 LockAxisSP.load();
502 MotionControlModeTP.load();
503 JoystickReverseSP.load();
504 }
505 else
506 {
510 }
511 }
512 else
513 {
517 }
518 }
519 }
520
521 return true;
522}
523
525{
526 controller->ISSnoopDevice(root);
527
528 XMLEle *ep = nullptr;
529 const char *propName = findXMLAttValu(root, "name");
530 auto deviceName = std::string(findXMLAttValu(root, "device"));
531
532 if (isConnected())
533 {
534 if (HasLocation() && !strcmp(propName, "GEOGRAPHIC_COORD") && deviceName == ActiveDeviceTP[ACTIVE_GPS].getText())
535 {
536 // Only accept IPS_OK state
537 if (strcmp(findXMLAttValu(root, "state"), "Ok"))
538 return false;
539
540 double longitude = -1, latitude = -1, elevation = -1;
541
542 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
543 {
544 const char *elemName = findXMLAttValu(ep, "name");
545
546 if (!strcmp(elemName, "LAT"))
547 latitude = atof(pcdataXMLEle(ep));
548 else if (!strcmp(elemName, "LONG"))
549 longitude = atof(pcdataXMLEle(ep));
550 else if (!strcmp(elemName, "ELEV"))
551 elevation = atof(pcdataXMLEle(ep));
552 }
553
554 return processLocationInfo(latitude, longitude, elevation);
555 }
556 else if (HasTime() && !strcmp(propName, "TIME_UTC") && deviceName == ActiveDeviceTP[ACTIVE_GPS].getText())
557 {
558 // Only accept IPS_OK state
559 if (strcmp(findXMLAttValu(root, "state"), "Ok"))
560 return false;
561
562 char utc[MAXINDITSTAMP], offset[MAXINDITSTAMP];
563
564 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
565 {
566 const char *elemName = findXMLAttValu(ep, "name");
567
568 if (!strcmp(elemName, "UTC"))
569 snprintf(utc, MAXINDITSTAMP, "%s", pcdataXMLEle(ep));
570 else if (!strcmp(elemName, "OFFSET"))
571 snprintf(offset, MAXINDITSTAMP, "%s", pcdataXMLEle(ep));
572 }
573
574 return processTimeInfo(utc, offset);
575 }
576 else if (!strcmp(propName, "DOME_PARK") && deviceName == ActiveDeviceTP[ACTIVE_DOME].getText())
577 {
578 // This is handled by Watchdog driver.
579 // Mount shouldn't park due to dome closing in INDI::Telescope
580#if 0
581 if (strcmp(findXMLAttValu(root, "state"), "Ok"))
582 {
583 // Dome options is dome parks or both and dome is parking.
584 if ((DomeClosedLockT[2].s == ISS_ON || DomeClosedLockT[3].s == ISS_ON) && !IsLocked && !IsParked)
585 {
586 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
587 {
588 const char * elemName = findXMLAttValu(ep, "name");
589 if (( (!strcmp(elemName, "SHUTTER_CLOSE") || !strcmp(elemName, "PARK"))
590 && !strcmp(pcdataXMLEle(ep), "On")))
591 {
593 Park();
594 LOG_INFO("Dome is closing, parking mount...");
595 }
596 }
597 }
598 } // Dome is changing state and Dome options is lock or both. d
599 else
600#endif
601 if (!strcmp(findXMLAttValu(root, "state"), "Ok"))
602 {
603 bool prevState = IsLocked;
604 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
605 {
606 const char *elemName = findXMLAttValu(ep, "name");
607
608 if (!IsLocked && (!strcmp(elemName, "PARK")) && !strcmp(pcdataXMLEle(ep), "On"))
609 IsLocked = true;
610 else if (IsLocked && (!strcmp(elemName, "UNPARK")) && !strcmp(pcdataXMLEle(ep), "On"))
611 IsLocked = false;
612 }
613 if (prevState != IsLocked && (DomePolicySP[DOME_LOCKS].getState() == ISS_ON))
614 LOGF_INFO("Dome status changed. Lock is set to: %s", IsLocked ? "locked" : "unlock");
615 }
616 return true;
617 }
618 }
619
620 return DefaultDevice::ISSnoopDevice(root);
621}
622
623void Telescope::triggerSnoop(const char *driverName, const char *snoopedProp)
624{
625 LOGF_DEBUG("Active Snoop, driver: %s, property: %s", driverName, snoopedProp);
626 IDSnoopDevice(driverName, snoopedProp);
627}
628
630{
631 return telescopeConnection;
632}
633
634void Telescope::setTelescopeConnection(const uint8_t &value)
635{
637
638 if (value == 0 || (mask & value) == 0)
639 {
640 DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
641 return;
642 }
643
644 telescopeConnection = value;
645}
646
648{
650
651 ActiveDeviceTP.save(fp);
652 DomePolicySP.save(fp);
653
654 // Ensure that we only save valid locations
655 if (HasLocation() && (LocationNP[LOCATION_LONGITUDE].getValue() != 0 || LocationNP[LOCATION_LATITUDE].getValue() != 0))
656 LocationNP.save(fp);
657
658 if (CanGOTO())
659 ReverseMovementSP.save(fp);
660
661 if (SlewRateSP.isValid())
662 SlewRateSP.save(fp);
663 if (HasPECState())
664 PECStateSP.save(fp);
665 if (HasTrackMode())
666 TrackModeSP.save(fp);
667 if (HasTrackRate())
668 TrackRateNP.save(fp);
669 if (CanSetMountType())
670 MountTypeSP.save(fp);
671
672 controller->saveConfigItems(fp);
673 MotionControlModeTP.save(fp);
674 LockAxisSP.save(fp);
675 JoystickReverseSP.save(fp);
676 SimulatePierSideSP.save(fp);
677
678 return true;
679}
680
681void Telescope::NewRaDec(double ra, double dec)
682{
683 switch (TrackState)
684 {
685 case SCOPE_PARKED:
686 case SCOPE_IDLE:
687 EqNP.setState(IPS_IDLE);
688 break;
689
690 case SCOPE_SLEWING:
691 case SCOPE_PARKING:
692 EqNP.setState(IPS_BUSY);
693 break;
694
695 case SCOPE_TRACKING:
696 EqNP.setState(IPS_OK);
697 break;
698 }
699
701 {
702 TrackStateSP.setState(IPS_IDLE);
703 TrackStateSP[TRACK_ON].setState(ISS_OFF);
704 TrackStateSP[TRACK_OFF].setState(ISS_ON);
705 TrackStateSP.apply();
706 }
707 else if (TrackState == SCOPE_TRACKING && CanControlTrack() && TrackStateSP[TRACK_OFF].getState() == ISS_ON)
708 {
709 TrackStateSP.setState(IPS_BUSY);
710 TrackStateSP[TRACK_ON].setState(ISS_ON);
711 TrackStateSP[TRACK_OFF].setState(ISS_OFF);
712 TrackStateSP.apply();
713 }
714
715 // RA is in hours, so change the arc-second threshold accordingly.
716 constexpr double RA_NOTIFY_THRESHOLD = EQ_NOTIFY_THRESHOLD / 15.0;
717 if (std::abs(EqNP[AXIS_RA].getValue() - ra) > RA_NOTIFY_THRESHOLD ||
718 std::abs(EqNP[AXIS_DE].getValue() - dec) > EQ_NOTIFY_THRESHOLD ||
719 EqNP.getState() != lastEqState)
720 {
721 EqNP[AXIS_RA].setValue(ra);
722 EqNP[AXIS_DE].setValue(dec);
723 lastEqState = EqNP.getState();
724 EqNP.apply();
725 }
726}
727
728bool Telescope::Sync(double ra, double dec)
729{
732 // if we get here, our mount doesn't support sync
733 DEBUG(Logger::DBG_ERROR, "Telescope does not support Sync.");
734 return false;
735}
736
738{
739 INDI_UNUSED(dir);
740 INDI_UNUSED(command);
741 DEBUG(Logger::DBG_ERROR, "Telescope does not support North/South motion.");
742 MovementNSSP.reset();
743 MovementNSSP.setState(IPS_IDLE);
744 MovementNSSP.apply();
745 return false;
746}
747
749{
750 INDI_UNUSED(dir);
751 INDI_UNUSED(command);
752 DEBUG(Logger::DBG_ERROR, "Telescope does not support West/East motion.");
753 MovementWESP.reset();
754 MovementWESP.setState(IPS_IDLE);
755 MovementWESP.apply();
756 return false;
757}
758
759/**************************************************************************************
760** Process Text properties
761***************************************************************************************/
762bool Telescope::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
763{
764 // first check if it's for our device
765 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
766 {
767 if (TimeTP.isNameMatch(name))
768 {
769 int utcindex = IUFindIndex("UTC", names, n);
770 int offsetindex = IUFindIndex("OFFSET", names, n);
771
772 return processTimeInfo(texts[utcindex], texts[offsetindex]);
773 }
774
775 if (ActiveDeviceTP.isNameMatch(name))
776 {
777 ActiveDeviceTP.setState(IPS_OK);
778 ActiveDeviceTP.update(texts, names, n);
779 // Update client display
780 ActiveDeviceTP.apply();
781
782 IDSnoopDevice(ActiveDeviceTP[ACTIVE_GPS].getText(), "GEOGRAPHIC_COORD");
784
787
789 return true;
790 }
791 }
792
793 controller->ISNewText(dev, name, texts, names, n);
794
795 return DefaultDevice::ISNewText(dev, name, texts, names, n);
796}
797
798/**************************************************************************************
799**
800***************************************************************************************/
801bool Telescope::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
802{
803 // first check if it's for our device
804 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
805 {
807 // Goto & Sync for Equatorial Coords
809 if (strcmp(name, "EQUATORIAL_EOD_COORD") == 0)
810 {
811 // this is for us, and it is a goto
812 bool rc = false;
813 double ra = -1;
814 double dec = -100;
815
816 for (int x = 0; x < n; x++)
817 {
818 if (EqNP[AXIS_RA].isNameMatch(names[x]))
819 ra = values[x];
820 else if (EqNP[AXIS_DE].isNameMatch(names[x]))
821 dec = values[x];
822 }
823 if ((ra >= 0) && (ra <= 24) && (dec >= -90) && (dec <= 90))
824 {
825 // Check if it is already parked.
826 if (CanPark())
827 {
828 if (isParked())
829 {
831 "Please unpark the mount before issuing any motion/sync commands.");
832 EqNP.setState(lastEqState = IPS_IDLE);
833 EqNP.apply();
834 return false;
835 }
836 }
837
838 // Check if it can sync
839 if (CanSync())
840 {
841 if (CoordSP.isSwitchOn("SYNC"))
842 {
843 rc = Sync(ra, dec);
844 if (rc)
845 EqNP.setState(lastEqState = IPS_OK);
846 else
847 EqNP.setState(lastEqState = IPS_ALERT);
848 EqNP.apply();
849 return rc;
850 }
851 }
852
853 bool doFlip = false;
854 if (CanFlip())
855 {
856 doFlip = CoordSP.isSwitchOn("FLIP");
857 }
858
859 // Remember Track State
861 // Issue GOTO/Flip
862 if(doFlip)
863 {
864 rc = Flip(ra, dec);
865 }
866 else
867 {
868 rc = Goto(ra, dec);
869 }
870 if (rc)
871 {
872 EqNP.setState(lastEqState = IPS_BUSY);
873 // Now fill in target co-ords, so domes can start turning
874 TargetNP[AXIS_RA].setValue(ra);
875 TargetNP[AXIS_DE].setValue(dec);
876 TargetNP.apply();
877 }
878 else
879 {
880 EqNP.setState(lastEqState = IPS_ALERT);
881 }
882 EqNP.apply();
883 }
884 return rc;
885 }
886
888 // Geographic Coords
890 if (LocationNP.isNameMatch(name))
891 {
892 int latindex = IUFindIndex("LAT", names, n);
893 int longindex = IUFindIndex("LONG", names, n);
894 int elevationindex = IUFindIndex("ELEV", names, n);
895
896 if (latindex == -1 || longindex == -1 || elevationindex == -1)
897 {
898 LocationNP.setState(IPS_ALERT);
899 LOG_ERROR("Location data missing or corrupted.");
900 LocationNP.apply();
901 }
902
903 double targetLat = values[latindex];
904 double targetLong = values[longindex];
905 double targetElev = values[elevationindex];
906
907 return processLocationInfo(targetLat, targetLong, targetElev);
908 }
909
911 // Park Position
913 if (ParkPositionNP.isNameMatch(name))
914 {
915 double axis1 = std::numeric_limits<double>::quiet_NaN(), axis2 = std::numeric_limits<double>::quiet_NaN();
916 for (int x = 0; x < n; x++)
917 {
918 if (ParkPositionNP[AXIS_RA].isNameMatch(names[x]))
919 {
920 axis1 = values[x];
921 }
922 else if (ParkPositionNP[AXIS_DE].isNameMatch(names[x]))
923 {
924 axis2 = values[x];
925 }
926 }
927
928 if (std::isnan(axis1) == false && std::isnan(axis2) == false)
929 {
930 bool rc = false;
931
932 rc = SetParkPosition(axis1, axis2);
933
934 if (rc)
935 {
936 ParkPositionNP.update(values, names, n);
937 Axis1ParkPosition = ParkPositionNP[AXIS_RA].getValue();
938 Axis2ParkPosition = ParkPositionNP[AXIS_DE].getValue();
939 }
940
941 ParkPositionNP.setState(rc ? IPS_OK : IPS_ALERT);
942 }
943 else
944 ParkPositionNP.setState(IPS_ALERT);
945
946 ParkPositionNP.apply();
947 return true;
948 }
949
951 // Track Rate
953 if (TrackRateNP.isNameMatch(name))
954 {
955 double preAxis1 = TrackRateNP[AXIS_RA].getValue(), preAxis2 = TrackRateNP[AXIS_DE].getValue();
956 auto currentTrackingMode = TrackModeSP.findOnSwitch();
957 if (TrackRateNP.update(values, names, n) == false || currentTrackingMode == nullptr)
958 {
959 TrackRateNP.setState(IPS_ALERT);
960 TrackRateNP.apply();
961 return false;
962 }
963
964 if (TrackState == SCOPE_TRACKING && currentTrackingMode->isNameMatch("TRACK_CUSTOM"))
965 {
966 // Check that we do not abruptly change positive tracking rates to negative ones.
967 // tracking must be stopped first.
968 // Give warning is tracking sign would cause a reverse in direction
969 if ( (preAxis1 * TrackRateNP[AXIS_RA].getValue() < 0) || (preAxis2 * TrackRateNP[AXIS_DE].getValue() < 0) )
970 {
971 LOG_ERROR("Cannot reverse tracking while tracking is engaged. Disengage tracking then try again.");
972 return false;
973 }
974
975 // All is fine, ask mount to change tracking rate
976 if (SetTrackRate(TrackRateNP[AXIS_RA].getValue(), TrackRateNP[AXIS_DE].getValue()) == false)
977 {
978 TrackRateNP[AXIS_RA].setValue(preAxis1);
979 TrackRateNP[AXIS_DE].setValue(preAxis2);
980 TrackRateNP.setState(IPS_ALERT);
981 }
982 else
983 TrackRateNP.setState(IPS_OK);
984 }
985
986 // If we are already tracking but tracking mode is NOT custom
987 // We just inform the user that it must be set to custom for these values to take
988 // effect.
989 if (TrackState == SCOPE_TRACKING && !currentTrackingMode->isNameMatch("TRACK_CUSTOM"))
990 {
991 LOG_INFO("Custom tracking rates set. Tracking mode must be set to Custom for these rates to take effect.");
992 }
993
994 // If mount is NOT tracking, we simply accept whatever valid values for use when mount tracking is engaged.
995 TrackRateNP.apply();
996 return true;
997 }
998 }
999
1000 return DefaultDevice::ISNewNumber(dev, name, values, names, n);
1001}
1002
1003/**************************************************************************************
1004**
1005***************************************************************************************/
1006bool Telescope::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
1007{
1008 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
1009 {
1010 // This one is for us
1011 if (CoordSP.isNameMatch(name))
1012 {
1013 // client is telling us what to do with co-ordinate requests
1014 CoordSP.setState(IPS_OK);
1015 CoordSP.update(states, names, n);
1016 // Update client display
1017 CoordSP.apply();
1018 return true;
1019 }
1020
1022 // Slew Rate
1024 if (SlewRateSP.isNameMatch(name))
1025 {
1026 int preIndex = SlewRateSP.findOnSwitchIndex();
1027 SlewRateSP.update(states, names, n);
1028 int nowIndex = SlewRateSP.findOnSwitchIndex();
1029 if (SetSlewRate(nowIndex) == false)
1030 {
1031 SlewRateSP.reset();
1032 SlewRateSP[preIndex].setState(ISS_ON);
1033 SlewRateSP.setState(IPS_ALERT);
1034 }
1035 else
1036 SlewRateSP.setState(IPS_OK);
1037 SlewRateSP.apply();
1038 return true;
1039 }
1040
1042 // Parking
1044 if (ParkSP.isNameMatch(name))
1045 {
1047 {
1048 ParkSP.reset();
1049 ParkSP.setState(IPS_ALERT);
1050 Abort();
1051 LOG_INFO("Parking/Unparking aborted.");
1052 ParkSP.apply();
1053 return true;
1054 }
1055
1056 int preIndex = ParkSP.findOnSwitchIndex();
1057 ParkSP.update(states, names, n);
1058
1059 bool toPark = (ParkSP[PARK].getState() == ISS_ON);
1060
1061 if (toPark == false && TrackState != SCOPE_PARKED)
1062 {
1063 ParkSP.reset();
1064 ParkSP[UNPARK].setState(ISS_ON);
1065 ParkSP.setState(IPS_IDLE);
1066 LOG_INFO("Telescope already unparked.");
1067 IsParked = false;
1068 ParkSP.apply();
1069 return true;
1070 }
1071
1072 if (toPark == false && isLocked())
1073 {
1074 ParkSP.reset();
1075 ParkSP[PARK].setState(ISS_ON);
1076 ParkSP.setState(IPS_ALERT);
1077 LOG_WARN("Cannot unpark mount when dome is locking. See: Dome Policy in options tab.");
1078 IsParked = true;
1079 ParkSP.apply();
1080 return true;
1081 }
1082
1083 if (toPark && TrackState == SCOPE_PARKED)
1084 {
1085 ParkSP.reset();
1086 ParkSP[PARK].setState(ISS_ON);
1087 ParkSP.setState(IPS_IDLE);
1088 LOG_INFO("Telescope already parked.");
1089 ParkSP.apply();
1090 return true;
1091 }
1092
1094
1095 ParkSP.reset();
1096 bool rc = toPark ? Park() : UnPark();
1097 if (rc)
1098 {
1100 {
1101 ParkSP[PARK].setState(toPark ? ISS_ON : ISS_OFF);
1102 ParkSP[UNPARK].setState(toPark ? ISS_OFF : ISS_ON);
1103 ParkSP.setState(IPS_BUSY);
1104 }
1105 else
1106 {
1107 ParkSP[PARK].setState(toPark ? ISS_ON : ISS_OFF);
1108 ParkSP[UNPARK].setState(toPark ? ISS_OFF : ISS_ON);
1109 ParkSP.setState(IPS_OK);
1110 }
1111 }
1112 else
1113 {
1114 ParkSP[preIndex].setState(ISS_ON);
1115 ParkSP.setState(IPS_ALERT);
1116 }
1117
1118 ParkSP.apply();
1119 return true;
1120 }
1121
1123 // NS Motion
1125 if (MovementNSSP.isNameMatch(name))
1126 {
1127 // Check if it is already parked.
1128 if (CanPark())
1129 {
1130 if (isParked())
1131 {
1133 "Please unpark the mount before issuing any motion/sync commands.");
1134 MovementNSSP.setState(IPS_IDLE);
1135 MovementNSSP.apply();
1136 return false;
1137 }
1138 }
1139
1140 MovementNSSP.update(states, names, n);
1141
1142 int current_motion = MovementNSSP.findOnSwitchIndex();
1143
1144 // if same move requested, return
1145 if (MovementNSSP.getState() == IPS_BUSY && current_motion == last_ns_motion)
1146 return true;
1147
1148 // Time to stop motion
1149 if (current_motion == -1 || (last_ns_motion != -1 && current_motion != last_ns_motion))
1150 {
1151 auto targetDirection = last_ns_motion == 0 ? DIRECTION_NORTH : DIRECTION_SOUTH;
1152 if (ReverseMovementSP[REVERSE_NS].getState() == ISS_ON)
1153 targetDirection = targetDirection == DIRECTION_NORTH ? DIRECTION_SOUTH : DIRECTION_NORTH;
1154
1155 if (MoveNS(targetDirection, MOTION_STOP))
1156 {
1157 MovementNSSP.reset();
1158 MovementNSSP.setState(IPS_IDLE);
1159 last_ns_motion = -1;
1160 // Update Target when stopped so that domes can track
1161 TargetNP[AXIS_RA].setValue(EqNP[AXIS_RA].getValue());
1162 TargetNP[AXIS_DE].setValue(EqNP[AXIS_DE].getValue());
1163 TargetNP.apply();
1164 }
1165 else
1166 MovementNSSP.setState(IPS_ALERT);
1167 }
1168 else
1169 {
1172
1173 auto targetDirection = current_motion == 0 ? DIRECTION_NORTH : DIRECTION_SOUTH;
1174 if (ReverseMovementSP[REVERSE_NS].getState() == ISS_ON)
1175 targetDirection = targetDirection == DIRECTION_NORTH ? DIRECTION_SOUTH : DIRECTION_NORTH;
1176
1177 if (MoveNS(targetDirection, MOTION_START))
1178 {
1179 MovementNSSP.setState(IPS_BUSY);
1180 last_ns_motion = targetDirection;
1181 }
1182 else
1183 {
1184 MovementNSSP.reset();
1185 MovementNSSP.setState(IPS_ALERT);
1186 last_ns_motion = -1;
1187 }
1188 }
1189
1190 MovementNSSP.apply();
1191
1192 return true;
1193 }
1194
1196 // WE Motion
1198 if (MovementWESP.isNameMatch(name))
1199 {
1200 // Check if it is already parked.
1201 if (CanPark())
1202 {
1203 if (isParked())
1204 {
1206 "Please unpark the mount before issuing any motion/sync commands.");
1207 MovementWESP.setState(IPS_IDLE);
1208 MovementWESP.apply();
1209 return false;
1210 }
1211 }
1212
1213 MovementWESP.update(states, names, n);
1214
1215 int current_motion = MovementWESP.findOnSwitchIndex();
1216
1217 // if same move requested, return
1218 if (MovementWESP.getState() == IPS_BUSY && current_motion == last_we_motion)
1219 return true;
1220
1221 // Time to stop motion
1222 if (current_motion == -1 || (last_we_motion != -1 && current_motion != last_we_motion))
1223 {
1224 auto targetDirection = last_we_motion == 0 ? DIRECTION_WEST : DIRECTION_EAST;
1225 if (ReverseMovementSP[REVERSE_WE].getState() == ISS_ON)
1226 targetDirection = targetDirection == DIRECTION_EAST ? DIRECTION_WEST : DIRECTION_EAST;
1227 if (MoveWE(targetDirection, MOTION_STOP))
1228 {
1229 MovementWESP.reset();
1230 MovementWESP.setState(IPS_IDLE);
1231 last_we_motion = -1;
1232 // Update Target when stopped so that domes can track
1233 TargetNP[AXIS_RA].setValue(EqNP[AXIS_RA].getValue());
1234 TargetNP[AXIS_DE].setValue(EqNP[AXIS_DE].getValue());
1235 TargetNP.apply();
1236 }
1237 else
1238 MovementWESP.setState(IPS_ALERT);
1239 }
1240 else
1241 {
1244
1245 auto targetDirection = current_motion == 0 ? DIRECTION_WEST : DIRECTION_EAST;
1246 if (ReverseMovementSP[REVERSE_WE].getState() == ISS_ON)
1247 targetDirection = targetDirection == DIRECTION_EAST ? DIRECTION_WEST : DIRECTION_EAST;
1248
1249 if (MoveWE(targetDirection, MOTION_START))
1250 {
1251 MovementWESP.setState(IPS_BUSY);
1252 last_we_motion = targetDirection;
1253 }
1254 else
1255 {
1256 MovementWESP.reset();
1257 MovementWESP.setState(IPS_ALERT);
1258 last_we_motion = -1;
1259 }
1260 }
1261
1262 MovementWESP.apply();
1263
1264 return true;
1265 }
1266
1268 // WE or NS Reverse Motion
1270 if (ReverseMovementSP.isNameMatch(name))
1271 {
1272 ReverseMovementSP.update(states, names, n);
1273 ReverseMovementSP.setState(IPS_OK);
1274 ReverseMovementSP.apply();
1275 saveConfig(true, ReverseMovementSP.getName());
1276 return true;
1277 }
1278
1280 // Homing
1282 if (HomeSP.isNameMatch(name))
1283 {
1284 auto onSwitchName = IUFindOnSwitchName(states, names, n);
1285 // No switch selected. Cancel whatever action if any and return
1286 if (onSwitchName == NULL)
1287 {
1288 if (HomeSP.getState() == IPS_BUSY)
1289 Abort();
1290 HomeSP.reset();
1291 HomeSP.setState(IPS_IDLE);
1292 HomeSP.apply();
1293 return true;
1294 }
1295 auto actionString = std::string(onSwitchName);
1296 auto action = HOME_FIND;
1297 if (actionString == "SET")
1298 action = HOME_SET;
1299 else if (actionString == "GO")
1300 action = HOME_GO;
1301
1302 if (isParked())
1303 {
1304 HomeSP.setState(IPS_ALERT);
1305 HomeSP.reset();
1306 HomeSP.apply();
1307 LOG_ERROR("Cannot home while parked.");
1308 return true;
1309 }
1310
1311 auto state = ExecuteHomeAction(action);
1312 HomeSP.setState(state);
1313 if (state == IPS_BUSY)
1314 HomeSP.update(states, names, n);
1315 HomeSP.apply();
1316 return true;
1317 }
1318
1320 // Abort Motion
1322 if (AbortSP.isNameMatch(name))
1323 {
1324 AbortSP.reset();
1325
1326 if (Abort())
1327 {
1328 AbortSP.setState(IPS_OK);
1329
1330 if (ParkSP.getState() == IPS_BUSY)
1331 {
1332 ParkSP.reset();
1333 ParkSP.setState(IPS_ALERT);
1334 ParkSP.apply();
1335
1336 LOG_INFO("Parking aborted.");
1337 }
1338 if (EqNP.getState() == IPS_BUSY)
1339 {
1340 EqNP.setState(lastEqState = IPS_IDLE);
1341 EqNP.apply();
1342 LOG_INFO("Slew/Track aborted.");
1343 }
1344 if (MovementWESP.getState() == IPS_BUSY)
1345 {
1346 MovementWESP.reset();
1347 MovementWESP.setState(IPS_IDLE);
1348 MovementWESP.apply();
1349 }
1350 if (MovementNSSP.getState() == IPS_BUSY)
1351 {
1352 MovementNSSP.reset();
1353 MovementNSSP.setState(IPS_IDLE);
1354 MovementNSSP.apply();
1355 }
1356
1358
1359 // JM 2017-07-28: Abort shouldn't affect tracking state. It should affect motion and that's it.
1360 //if (TrackState != SCOPE_PARKED)
1361 //TrackState = SCOPE_IDLE;
1362 // For Idle, Tracking, Parked state, we do not change its status, it should remain as is.
1363 // For Slewing & Parking, state should go back to last remembered state.
1365 {
1367 }
1368 }
1369 else
1370 AbortSP.setState(IPS_ALERT);
1371
1372 AbortSP.apply();
1373
1374 return true;
1375 }
1376
1378 // Mount Type
1380 if (MountTypeSP.isNameMatch(name))
1381 {
1382 if (!CanSetMountType())
1383 {
1384 LOG_WARN("The mount type is reported by the driver and cannot be changed.");
1385 MountTypeSP.apply();
1386 return true;
1387 }
1388
1389 const auto previousType = getMountType();
1390 if (!MountTypeSP.update(states, names, n))
1391 {
1392 MountTypeSP.setState(IPS_ALERT);
1393 MountTypeSP.apply();
1394 return false;
1395 }
1396
1397 const auto requestedIndex = MountTypeSP.findOnSwitchIndex();
1398 if (requestedIndex < 0)
1399 {
1400 setMountType(previousType);
1401 return false;
1402 }
1403
1404 const auto requestedType = static_cast<TelescopeMountType>(requestedIndex);
1405 if (requestedType == previousType)
1406 {
1407 MountTypeSP.setState(IPS_OK);
1408 MountTypeSP.apply();
1409 return true;
1410 }
1411
1412 if (SetMountType(requestedType))
1413 {
1414 MountTypeSP.setState(IPS_OK);
1415 MountTypeSP.apply();
1417 }
1418 else
1419 {
1420 MountTypeSP.reset();
1421 MountTypeSP[previousType].setState(ISS_ON);
1422 MountTypeSP.setState(IPS_ALERT);
1423 MountTypeSP.apply();
1424 }
1425 return true;
1426 }
1427
1429 // Track Mode
1431 if (TrackModeSP.isNameMatch(name))
1432 {
1433 int prevIndex = TrackModeSP.findOnSwitchIndex();
1434 TrackModeSP.update(states, names, n);
1435 int currIndex = TrackModeSP.findOnSwitchIndex();
1436 // If same as previous index, or if scope is already idle, then just update switch and return. No commands are sent to the mount.
1437 if (prevIndex == currIndex || TrackState == SCOPE_IDLE)
1438 {
1439 TrackModeSP.setState(IPS_OK);
1440 TrackModeSP.apply(nullptr);
1441 return true;
1442 }
1443
1444 if (TrackState == SCOPE_PARKED)
1445 {
1446 DEBUG(Logger::DBG_WARNING, "Telescope is Parked, Unpark before changing track mode.");
1447 return false;
1448 }
1449
1450 if (SetTrackMode(currIndex))
1451 TrackModeSP.setState(IPS_OK);
1452 else
1453 {
1454 TrackModeSP.reset();
1455 TrackModeSP[prevIndex].setState(ISS_ON);
1456 TrackModeSP.setState(IPS_ALERT);
1457 }
1458 TrackModeSP.apply();
1459 return false;
1460 }
1461
1463 // Track State
1465 if (TrackStateSP.isNameMatch(name))
1466 {
1467 int previousState = TrackStateSP.findOnSwitchIndex();
1468 TrackStateSP.update(states, names, n);
1469 int targetState = TrackStateSP.findOnSwitchIndex();
1470
1471 if (previousState == targetState)
1472 {
1473 TrackStateSP.apply();
1474 return true;
1475 }
1476
1477 if (TrackState == SCOPE_PARKED)
1478 {
1479 DEBUG(Logger::DBG_WARNING, "Telescope is Parked, Unpark before tracking.");
1480 return false;
1481 }
1482
1483 if (SetTrackEnabled((targetState == TRACK_ON) ? true : false))
1484 {
1485 TrackState = (targetState == TRACK_ON) ? SCOPE_TRACKING : SCOPE_IDLE;
1486 TrackStateSP.setState((targetState == TRACK_ON) ? IPS_BUSY : IPS_IDLE);
1487 TrackStateSP[TRACK_ON].setState((targetState == TRACK_ON) ? ISS_ON : ISS_OFF);
1488 TrackStateSP[TRACK_OFF].setState((targetState == TRACK_ON) ? ISS_OFF : ISS_ON);
1489 }
1490 else
1491 {
1492 TrackStateSP.setState(IPS_ALERT);
1493 TrackStateSP.reset();
1494 TrackStateSP[previousState].setState(ISS_ON);
1495 }
1496
1497 TrackStateSP.apply();
1498 return true;
1499 }
1500
1502 // Park Options
1504 if (ParkOptionSP.isNameMatch(name))
1505 {
1506 ParkOptionSP.update(states, names, n);
1507 auto index = ParkOptionSP.findOnSwitchIndex();
1508 if (index == -1)
1509 return false;
1510
1511 ParkOptionSP.reset();
1512
1513 bool rc = false;
1514
1515 if ((TrackState != SCOPE_IDLE && TrackState != SCOPE_TRACKING) || MovementNSSP.getState() == IPS_BUSY ||
1516 MovementWESP.getState() == IPS_BUSY)
1517 {
1518 LOG_INFO("Can not change park position while slewing or already parked.");
1519 ParkOptionSP.setState(IPS_ALERT);
1520 ParkOptionSP.apply();
1521 return false;
1522 }
1523
1524 switch (index)
1525 {
1526 case PARK_CURRENT:
1527 rc = SetCurrentPark();
1528 break;
1529 case PARK_DEFAULT:
1530 rc = SetDefaultPark();
1531 break;
1532 case PARK_WRITE_DATA:
1533 rc = WriteParkData();
1534 if (rc)
1535 LOG_INFO("Saved Park Status/Position.");
1536 else
1537 DEBUG(Logger::DBG_WARNING, "Can not save Park Status/Position.");
1538 break;
1539 case PARK_PURGE_DATA:
1540 rc = PurgeParkData();
1541 if (rc)
1542 LOG_INFO("Park data purged.");
1543 else
1544 DEBUG(Logger::DBG_WARNING, "Can not purge Park Status/Position.");
1545 break;
1546 }
1547
1548 ParkOptionSP.setState(rc ? IPS_OK : IPS_ALERT);
1549 ParkOptionSP.apply();
1550 return true;
1551 }
1552
1554 // Parking Dome Policy
1556 if (DomePolicySP.isNameMatch(name))
1557 {
1558 DomePolicySP.update(states, names, n);
1559 if (DomePolicySP[DOME_IGNORED].getState() == ISS_ON)
1560 LOG_INFO("Dome Policy set to: Dome ignored. Mount can park or unpark regardless of dome parking state.");
1561 else
1562 LOG_WARN("Dome Policy set to: Dome locks. This prevents the mount from unparking when dome is parked.");
1563#if 0
1564 else if (!strcmp(names[0], DomeClosedLockT[2].name))
1565 LOG_INFO("Warning: Dome parking policy set to: Dome parks. This tells "
1566 "scope to park if dome is parking. This will disable the locking "
1567 "for dome parking, EVEN IF MOUNT PARKING FAILS");
1568 else if (!strcmp(names[0], DomeClosedLockT[3].name))
1569 LOG_INFO("Warning: Dome parking policy set to: Both. This disallows the "
1570 "scope from unparking when dome is parked, and tells scope to "
1571 "park if dome is parking. This will disable the locking for dome "
1572 "parking, EVEN IF MOUNT PARKING FAILS.");
1573#endif
1574 DomePolicySP.setState(IPS_OK);
1575 DomePolicySP.apply( );
1576 triggerSnoop(ActiveDeviceTP[ACTIVE_DOME].getText(), "DOME_PARK");
1577 return true;
1578 }
1579
1581 // Simulate Pier Side
1582 // This ia a major change to the design of the simulated scope, it might not handle changes on the fly
1584 if (SimulatePierSideSP.isNameMatch(name))
1585 {
1586 SimulatePierSideSP.update(states, names, n);
1587 int index = SimulatePierSideSP.findOnSwitchIndex();
1588 if (index == -1)
1589 {
1590 SimulatePierSideSP.setState(IPS_ALERT);
1591 LOG_INFO("Cannot determine whether pier side simulation should be switched on or off.");
1592 SimulatePierSideSP.apply();
1593 return false;
1594 }
1595
1596 bool pierSideEnabled = index == 0;
1597
1598 LOGF_INFO("Simulating Pier Side %s.", (pierSideEnabled ? "enabled" : "disabled"));
1599
1600 setSimulatePierSide(pierSideEnabled);
1601 if (pierSideEnabled)
1602 {
1603 // set the pier side from the current Ra
1604 // assumes we haven't tracked across the meridian
1606 }
1607 return true;
1608 }
1609
1611 // Joystick Motion Control Mode
1613 if (MotionControlModeTP.isNameMatch(name))
1614 {
1615 MotionControlModeTP.update(states, names, n);
1616 MotionControlModeTP.setState(IPS_OK);
1617 MotionControlModeTP.apply();
1619 LOG_INFO("Motion control is set to 4-way joystick.");
1620 else if (MotionControlModeTP[MOTION_CONTROL_MODE_AXES].getState() == ISS_ON)
1621 LOG_INFO("Motion control is set to 2 separate axes.");
1622 else
1623 DEBUGF(Logger::DBG_WARNING, "Motion control is set to unknown value %d!", n);
1624 return true;
1625 }
1626
1628 // Joystick Lock Axis
1630 if (LockAxisSP.isNameMatch(name))
1631 {
1632 LockAxisSP.update(states, names, n);
1633 LockAxisSP.setState(IPS_OK);
1634 LockAxisSP.apply();
1635 if (LockAxisSP[AXIS_RA].getState() == ISS_ON)
1636 LOG_INFO("Joystick motion is locked to West/East axis only.");
1637 else if (LockAxisSP[AXIS_DE].getState() == ISS_ON)
1638 LOG_INFO("Joystick motion is locked to North/South axis only.");
1639 else
1640 LOG_INFO("Joystick motion is unlocked.");
1641 return true;
1642 }
1643
1645 // Joystick Reverse/Swap Motion
1647 if (JoystickReverseSP.isNameMatch(name))
1648 {
1649 JoystickReverseSP.update(states, names, n);
1650 JoystickReverseSP.setState(IPS_OK);
1651 JoystickReverseSP.apply();
1653 return true;
1654 }
1655 }
1656
1657 bool rc = controller->ISNewSwitch(dev, name, states, names, n);
1658 if (rc)
1659 {
1660 auto useJoystick = getSwitch("USEJOYSTICK");
1661 if (useJoystick && useJoystick[0].getState() == ISS_ON)
1662 {
1666
1667 LockAxisSP.load();
1668 MotionControlModeTP.load();
1669 JoystickReverseSP.load();
1670 }
1671 else
1672 {
1676 }
1677
1678 }
1679
1680 // Nobody has claimed this, so, ignore it
1681 return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
1682}
1683
1685{
1686 if (telescopeConnection > 0)
1687 {
1689 PortFD = serialConnection->getPortFD();
1690 else if (getActiveConnection() == tcpConnection)
1691 PortFD = tcpConnection->getPortFD();
1692 }
1693
1694 return Handshake();
1695}
1696
1698{
1699 /* Test connection */
1700 return ReadScopeStatus();
1701}
1702
1704{
1705 if (isConnected())
1706 {
1707 bool rc;
1708
1709 rc = ReadScopeStatus();
1710
1711 if (!rc)
1712 {
1713 // read was not good
1714 EqNP.setState(lastEqState = IPS_ALERT);
1715 EqNP.apply();
1716 }
1717
1719 }
1720}
1721
1722bool Telescope::Flip(double ra, double dec)
1723{
1724 INDI_UNUSED(ra);
1726
1727 DEBUG(Logger::DBG_WARNING, "Flip is not supported.");
1728 return false;
1729}
1730
1731bool Telescope::Goto(double ra, double dec)
1732{
1733 INDI_UNUSED(ra);
1735
1736 DEBUG(Logger::DBG_WARNING, "GOTO is not supported.");
1737 return false;
1738}
1739
1741{
1742 DEBUG(Logger::DBG_WARNING, "Abort is not supported.");
1743 return false;
1744}
1745
1747{
1748 DEBUG(Logger::DBG_WARNING, "Parking is not supported.");
1749 return false;
1750}
1751
1753{
1754 DEBUG(Logger::DBG_WARNING, "UnParking is not supported.");
1755 return false;
1756}
1757
1759{
1761 return true;
1762}
1763
1764bool Telescope::SetTrackMode(uint8_t mode)
1765{
1766 INDI_UNUSED(mode);
1767 DEBUG(Logger::DBG_WARNING, "Tracking mode is not supported.");
1768 return false;
1769}
1770
1771bool Telescope::SetTrackRate(double raRate, double deRate)
1772{
1773 INDI_UNUSED(raRate);
1774 INDI_UNUSED(deRate);
1775 DEBUG(Logger::DBG_WARNING, "Custom tracking rates is not supported.");
1776 return false;
1777}
1778
1780{
1781 INDI_UNUSED(enabled);
1782 DEBUG(Logger::DBG_WARNING, "Tracking state is not supported.");
1783 return false;
1784}
1785
1786int Telescope::AddTrackMode(const char *name, const char *label, bool isDefault)
1787{
1788 INDI::WidgetSwitch node;
1789 node.fill(name, label, isDefault ? ISS_ON : ISS_OFF);
1790 TrackModeSP.push(std::move(node));
1791 return (TrackModeSP.count() - 1);
1792}
1793
1795{
1796 DEBUG(Logger::DBG_WARNING, "Parking is not supported.");
1797 return false;
1798}
1799
1801{
1802 DEBUG(Logger::DBG_WARNING, "Parking is not supported.");
1803 return false;
1804}
1805
1806bool Telescope::processTimeInfo(const char *utc, const char *offset)
1807{
1808 struct ln_date utc_date;
1809 double utc_offset = 0;
1810
1811 if (extractISOTime(utc, &utc_date) == -1)
1812 {
1814 LOGF_ERROR("Date/Time is invalid: %s.", utc);
1815 TimeTP.apply();
1816 return false;
1817 }
1818
1819 utc_offset = atof(offset);
1820
1821 if (updateTime(&utc_date, utc_offset))
1822 {
1823 TimeTP[UTC].setText(utc);
1824 TimeTP[OFFSET].setText(offset);
1826 TimeTP.apply();
1827 return true;
1828 }
1829 else
1830 {
1831 TimeTP.setState(IPS_ALERT);
1832 TimeTP.apply();
1833 return false;
1834 }
1835}
1836
1837bool Telescope::processLocationInfo(double latitude, double longitude, double elevation)
1838{
1839 // Do not update if not necessary
1840 // JM 2021-05-26: This can sometimes be problematic. Let child driver deals with duplicate requests.
1841#if 0
1842 if (latitude == LocationN[LOCATION_LATITUDE].value && longitude == LocationN[LOCATION_LONGITUDE].value &&
1843 elevation == LocationN[LOCATION_ELEVATION].value)
1844 {
1845 LocationNP.s = IPS_OK;
1846 IDSetNumber(&LocationNP, nullptr);
1847 return true;
1848 }
1849 else
1850#endif
1851 if (latitude == 0 && longitude == 0)
1852 {
1853 LOG_DEBUG("Silently ignoring invalid latitude and longitude.");
1854 LocationNP.setState(IPS_IDLE);
1855 LocationNP.apply();
1856 return false;
1857 }
1858
1859 if (updateLocation(latitude, longitude, elevation))
1860 {
1861 LocationNP.setState(IPS_OK);
1862 LocationNP[LOCATION_LATITUDE].setValue(latitude);
1863 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
1864 LocationNP[LOCATION_ELEVATION].setValue(elevation);
1865 // Update client display
1866 LocationNP.apply();
1867
1868 // Always save geographic coord config immediately.
1869 saveConfig(true, "GEOGRAPHIC_COORD");
1870
1871 updateObserverLocation(latitude, longitude, elevation);
1872
1873 return true;
1874 }
1875 else
1876 {
1877 LocationNP.setState(IPS_ALERT);
1878 // Update client display
1879 LocationNP.apply();
1880
1881 return false;
1882 }
1883}
1884
1885bool Telescope::updateTime(ln_date *utc, double utc_offset)
1886{
1887 INDI_UNUSED(utc);
1888 INDI_UNUSED(utc_offset);
1889 return true;
1890}
1891
1892bool Telescope::updateLocation(double latitude, double longitude, double elevation)
1893{
1894 INDI_UNUSED(latitude);
1895 INDI_UNUSED(longitude);
1896 INDI_UNUSED(elevation);
1897 return true;
1898}
1899
1905
1906void Telescope::updateObserverLocation(double latitude, double longitude, double elevation)
1907{
1908 m_Location.longitude = longitude;
1909 m_Location.latitude = latitude;
1910 m_Location.elevation = elevation;
1911 char lat_str[MAXINDIFORMAT] = {0}, lng_str[MAXINDIFORMAT] = {0};
1912
1913 // Make display longitude to be in the standard 0 to +180 East, and 0 to -180 West.
1914 // No need to confuse new users with INDI format.
1915 double display_longitude = longitude > 180 ? longitude - 360 : longitude;
1916 fs_sexa(lat_str, m_Location.latitude, 2, 36000);
1917 fs_sexa(lng_str, display_longitude, 2, 36000);
1918 // Choose WGS 84, also known as EPSG:4326 for latitude/longitude ordering
1919 LOGF_INFO("Observer location updated: Latitude %.12s (%.2f) Longitude %.12s (%.2f)", lat_str, m_Location.latitude, lng_str,
1920 display_longitude);
1921}
1922
1923bool Telescope::SetParkPosition(double Axis1Value, double Axis2Value)
1924{
1925 INDI_UNUSED(Axis1Value);
1926 INDI_UNUSED(Axis2Value);
1927 return true;
1928}
1929
1930void Telescope::generateCoordSet()
1931{
1932 CoordSP.resize(0);
1933
1934 INDI::WidgetSwitch node;
1935 node.fill("TRACK", "Track", ISS_ON);
1936 CoordSP.push(std::move(node));
1937
1938 if(CanGOTO())
1939 {
1940 INDI::WidgetSwitch node;
1941 node.fill("SLEW", "Slew", ISS_OFF);
1942 CoordSP.push(std::move(node));
1943 }
1944
1945 if(CanSync())
1946 {
1947 INDI::WidgetSwitch node;
1948 node.fill("SYNC", "Sync", ISS_OFF);
1949 CoordSP.push(std::move(node));
1950
1951 }
1952
1953 if(CanFlip())
1954 {
1955 INDI::WidgetSwitch node;
1956 node.fill("FLIP", "Flip", ISS_OFF);
1957 CoordSP.push(std::move(node));
1958 }
1959}
1960
1961void Telescope::SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
1962{
1963 capability = cap;
1964 nSlewRate = slewRateCount;
1965
1966 MountTypeSP.setPermission(CanSetMountType() ? IP_RW : IP_RO);
1967
1968 generateCoordSet();
1969
1970 if (nSlewRate >= 4)
1971 {
1972 SlewRateSP.resize(0);
1973 INDI::WidgetSwitch node;
1974 //int step = nSlewRate / 4;
1975 for (int i = 0; i < nSlewRate; i++)
1976 {
1977 // char name[4];
1978 auto name = std::to_string(i + 1) + "x";
1979 // snprintf(name, 4, "%dx", i + 1);
1980 // IUFillSwitch(SlewRateS + i, name, name, ISS_OFF);
1981 node.fill(name, name, ISS_OFF);
1982 SlewRateSP.push(std::move(node));
1983 }
1984
1985 // If number of slew rate is EXACTLY 4, then let's use common labels
1986 if (nSlewRate == 4)
1987 {
1988 // strncpy((SlewRateS + (0))->label, "Guide", MAXINDILABEL);
1989 SlewRateSP[0].setLabel("Guide");
1990 SlewRateSP[1].setLabel("Centering");
1991 SlewRateSP[2].setLabel("Find");
1992 SlewRateSP[3].setLabel("Max");
1993 }
1994
1995 // By Default we set current Slew Rate to 0.5 of max
1996 SlewRateSP[nSlewRate / 2].setState(ISS_ON);
1997
1998 SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate",
2000 }
2001
2002 if (CanHomeFind() || CanHomeSet() || CanHomeGo())
2003 {
2004 HomeSP.resize(0);
2005 if (CanHomeFind())
2006 {
2007 INDI::WidgetSwitch node;
2008 node.fill("FIND", "Find", ISS_OFF);
2009 HomeSP.push(std::move(node));
2010 }
2011
2012 if (CanHomeSet())
2013 {
2014 INDI::WidgetSwitch node;
2015 node.fill("SET", "Set", ISS_OFF);
2016 HomeSP.push(std::move(node));
2017 }
2018
2019 if (CanHomeGo())
2020 {
2021 INDI::WidgetSwitch node;
2022 node.fill("GO", "Go", ISS_OFF);
2023 HomeSP.push(std::move(node));
2024 }
2025
2026 HomeSP.shrink_to_fit();
2027 HomeSP.fill(getDeviceName(), "TELESCOPE_HOME", "Home", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
2028 }
2029}
2030
2032{
2034
2036 {
2037 switch (parkDataType)
2038 {
2039 case PARK_RA_DEC:
2040 ParkPositionNP[AXIS_RA].fill("PARK_RA", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
2041 ParkPositionNP[AXIS_DE].fill("PARK_DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
2042 break;
2043
2044 case PARK_HA_DEC:
2045 ParkPositionNP[AXIS_RA].fill("PARK_HA", "HA (hh:mm:ss)", "%010.6m", -12, 12, 0, 0);
2046 ParkPositionNP[AXIS_DE].fill("PARK_DEC", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
2047 break;
2048
2049 case PARK_AZ_ALT:
2050 ParkPositionNP[AXIS_AZ].fill("PARK_AZ", "AZ D:M:S", "%10.6m", 0.0, 360.0, 0.0, 0);
2051 ParkPositionNP[AXIS_ALT].fill("PARK_ALT", "Alt D:M:S", "%10.6m", -90., 90.0, 0.0, 0);
2052 break;
2053
2055 ParkPositionNP[AXIS_RA].fill("PARK_RA", "RA Encoder", "%.0f", 0, 16777215, 1, 0);
2056 ParkPositionNP[AXIS_DE].fill("PARK_DEC", "DEC Encoder", "%.0f", 0, 16777215, 1, 0);
2057 break;
2058
2060 ParkPositionNP[AXIS_RA].fill("PARK_AZ", "AZ Encoder", "%.0f", 0, 16777215, 1, 0);
2061 ParkPositionNP[AXIS_DE].fill("PARK_ALT", "ALT Encoder", "%.0f", 0, 16777215, 1, 0);
2062 break;
2063
2064 default:
2065 break;
2066 }
2067
2068 ParkPositionNP.fill(getDeviceName(), "TELESCOPE_PARK_POSITION", "Park Position", SITE_TAB, IP_RW, 60, IPS_IDLE);
2069 }
2070}
2071
2072void Telescope::SyncParkStatus(bool isparked)
2073{
2074 IsParked = isparked;
2075 ParkSP.reset();
2076 ParkSP.setState(IPS_OK);
2077
2078 if (IsParked)
2079 {
2080 ParkSP[PARK].setState(ISS_ON);
2082 LOG_INFO("Mount is parked.");
2083 }
2084 else
2085 {
2086 ParkSP[UNPARK].setState(ISS_ON);
2088 LOG_INFO("Mount is unparked.");
2089 }
2090
2091 ParkSP.apply();
2092}
2093
2094void Telescope::SetParked(bool isparked)
2095{
2096 SyncParkStatus(isparked);
2097
2098 if (parkDataType != PARK_NONE)
2099 WriteParkData();
2100}
2101
2103{
2104 return IsParked;
2105}
2106
2108{
2109 const char *loadres = LoadParkData();
2110 if (loadres)
2111 {
2112 LOGF_INFO("InitPark: No Park data in file %s: %s", ParkDataFileName.c_str(), loadres);
2113 SyncParkStatus(false);
2114 return false;
2115 }
2116
2118
2120 {
2121 LOGF_DEBUG("InitPark Axis1 %.2f Axis2 %.2f", Axis1ParkPosition, Axis2ParkPosition);
2122 ParkPositionNP[AXIS_RA].setValue(Axis1ParkPosition);
2123 ParkPositionNP[AXIS_DE].setValue(Axis2ParkPosition);
2124 ParkPositionNP.apply();
2125 }
2126
2127 return true;
2128}
2129
2130const char *Telescope::LoadParkXML()
2131{
2132 wordexp_t wexp;
2133 FILE *fp = nullptr;
2134 LilXML *lp = nullptr;
2135 static char errmsg[XML_ERROR_SIZE];
2136
2137 XMLEle *parkxml = nullptr;
2138 XMLAtt *ap = nullptr;
2139 bool devicefound = false;
2140
2141 ParkDeviceName = getDeviceName();
2142 ParkstatusXml = nullptr;
2143 ParkdeviceXml = nullptr;
2144 ParkpositionXml = nullptr;
2145 ParkpositionAxis1Xml = nullptr;
2146 ParkpositionAxis2Xml = nullptr;
2147
2148 if (wordexp(ParkDataFileName.c_str(), &wexp, 0))
2149 {
2150 wordfree(&wexp);
2151 return "Badly formed filename.";
2152 }
2153
2154 if (!(fp = fopen(wexp.we_wordv[0], "r")))
2155 {
2156 wordfree(&wexp);
2157 return strerror(errno);
2158 }
2159 wordfree(&wexp);
2160
2161 lp = newLilXML();
2162
2163 if (ParkdataXmlRoot)
2164 delXMLEle(ParkdataXmlRoot);
2165
2166 ParkdataXmlRoot = readXMLFile(fp, lp, errmsg);
2167 fclose(fp);
2168
2169 delLilXML(lp);
2170 if (!ParkdataXmlRoot)
2171 return errmsg;
2172
2173 parkxml = nextXMLEle(ParkdataXmlRoot, 1);
2174
2175 if (!parkxml)
2176 return "Empty park file.";
2177
2178 if (!strcmp(tagXMLEle(parkxml), "parkdata"))
2179 {
2180 delXMLEle(parkxml);
2181 return "Not a park data file";
2182 }
2183
2184 while (parkxml)
2185 {
2186 if (strcmp(tagXMLEle(parkxml), "device"))
2187 {
2188 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
2189 continue;
2190 }
2191 ap = findXMLAtt(parkxml, "name");
2192 if (ap && (!strcmp(valuXMLAtt(ap), ParkDeviceName)))
2193 {
2194 devicefound = true;
2195 break;
2196 }
2197 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
2198 }
2199
2200 if (!devicefound)
2201 {
2202 delXMLEle(parkxml);
2203 return "No park data found for this device";
2204 }
2205
2206 ParkdeviceXml = parkxml;
2207 ParkstatusXml = findXMLEle(parkxml, "parkstatus");
2208
2210 {
2211 ParkpositionXml = findXMLEle(parkxml, "parkposition");
2212 if (ParkpositionXml)
2213 ParkpositionAxis1Xml = findXMLEle(ParkpositionXml, "axis1position");
2214 if (ParkpositionXml)
2215 ParkpositionAxis2Xml = findXMLEle(ParkpositionXml, "axis2position");
2216
2217 if (ParkstatusXml == nullptr || ParkpositionAxis1Xml == nullptr || ParkpositionAxis2Xml == nullptr)
2218 {
2219 return "Park data invalid or missing.";
2220 }
2221 }
2222 else if (ParkstatusXml == nullptr)
2223 {
2224 return "Park data invalid or missing.";
2225 }
2226
2227 return nullptr;
2228}
2229
2231{
2232 IsParked = false;
2233
2234 const char *result = LoadParkXML();
2235 if (result != nullptr)
2236 return result;
2237
2238 if (!strcmp(pcdataXMLEle(ParkstatusXml), "true"))
2239 IsParked = true;
2240
2242 {
2243 double axis1Pos = std::numeric_limits<double>::quiet_NaN();
2244 double axis2Pos = std::numeric_limits<double>::quiet_NaN();
2245
2246 int rc = sscanf(pcdataXMLEle(ParkpositionAxis1Xml), "%lf", &axis1Pos);
2247 if (rc != 1)
2248 {
2249 return "Unable to parse Park Position Axis 1.";
2250 }
2251 rc = sscanf(pcdataXMLEle(ParkpositionAxis2Xml), "%lf", &axis2Pos);
2252 if (rc != 1)
2253 {
2254 return "Unable to parse Park Position Axis 2.";
2255 }
2256
2257 if (std::isnan(axis1Pos) == false && std::isnan(axis2Pos) == false)
2258 {
2259 Axis1ParkPosition = axis1Pos;
2260 Axis2ParkPosition = axis2Pos;
2261 return nullptr;
2262 }
2263
2264 return "Failed to parse Park Position.";
2265 }
2266
2267 return nullptr;
2268}
2269
2271{
2272 // We need to refresh parking data in case other devices parking states were updated since we
2273 // read the data the first time.
2274 if (LoadParkXML() != nullptr)
2275 LOG_DEBUG("Failed to refresh parking data.");
2276
2277 wordexp_t wexp;
2278 FILE *fp = nullptr;
2279 LilXML *lp = nullptr;
2280 static char errmsg[XML_ERROR_SIZE];
2281
2282 XMLEle *parkxml = nullptr;
2283 XMLAtt *ap = nullptr;
2284 bool devicefound = false;
2285
2286 ParkDeviceName = getDeviceName();
2287
2288 if (wordexp(ParkDataFileName.c_str(), &wexp, 0))
2289 {
2290 wordfree(&wexp);
2291 return false;
2292 }
2293
2294 if (!(fp = fopen(wexp.we_wordv[0], "r")))
2295 {
2296 wordfree(&wexp);
2297 LOGF_ERROR("Failed to purge park data: %s", strerror(errno));
2298 return false;
2299 }
2300 wordfree(&wexp);
2301
2302 lp = newLilXML();
2303
2304 if (ParkdataXmlRoot)
2305 delXMLEle(ParkdataXmlRoot);
2306
2307 ParkdataXmlRoot = readXMLFile(fp, lp, errmsg);
2308 fclose(fp);
2309
2310 delLilXML(lp);
2311 if (!ParkdataXmlRoot)
2312 return false;
2313
2314 parkxml = nextXMLEle(ParkdataXmlRoot, 1);
2315
2316 if (!parkxml)
2317 return false;
2318
2319 if (!strcmp(tagXMLEle(parkxml), "parkdata"))
2320 {
2321 delXMLEle(parkxml);
2322 return false;
2323 }
2324
2325 while (parkxml)
2326 {
2327 if (strcmp(tagXMLEle(parkxml), "device"))
2328 {
2329 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
2330 continue;
2331 }
2332 ap = findXMLAtt(parkxml, "name");
2333 if (ap && (!strcmp(valuXMLAtt(ap), ParkDeviceName)))
2334 {
2335 devicefound = true;
2336 break;
2337 }
2338 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
2339 }
2340
2341 if (!devicefound)
2342 return false;
2343
2344 delXMLEle(parkxml);
2345
2346 ParkstatusXml = nullptr;
2347 ParkdeviceXml = nullptr;
2348 ParkpositionXml = nullptr;
2349 ParkpositionAxis1Xml = nullptr;
2350 ParkpositionAxis2Xml = nullptr;
2351
2352 wordexp(ParkDataFileName.c_str(), &wexp, 0);
2353 if (!(fp = fopen(wexp.we_wordv[0], "w")))
2354 {
2355 wordfree(&wexp);
2356 LOGF_INFO("WriteParkData: can not write file %s: %s", ParkDataFileName.c_str(), strerror(errno));
2357 return false;
2358 }
2359 prXMLEle(fp, ParkdataXmlRoot, 0);
2360 fclose(fp);
2361 wordfree(&wexp);
2362
2363 return true;
2364}
2365
2367{
2368 // We need to refresh parking data in case other devices parking states were updated since we
2369 // read the data the first time.
2370 if (LoadParkXML() != nullptr)
2371 LOG_DEBUG("Failed to refresh parking data.");
2372
2373 wordexp_t wexp;
2374 FILE *fp;
2375 char pcdata[30];
2376 ParkDeviceName = getDeviceName();
2377
2378 if (wordexp(ParkDataFileName.c_str(), &wexp, 0))
2379 {
2380 wordfree(&wexp);
2381 LOGF_INFO("WriteParkData: can not write file %s: Badly formed filename.",
2382 ParkDataFileName.c_str());
2383 return false;
2384 }
2385
2386 if (!(fp = fopen(wexp.we_wordv[0], "w")))
2387 {
2388 wordfree(&wexp);
2389 LOGF_INFO("WriteParkData: can not write file %s: %s", ParkDataFileName.c_str(),
2390 strerror(errno));
2391 return false;
2392 }
2393
2394 if (!ParkdataXmlRoot)
2395 ParkdataXmlRoot = addXMLEle(nullptr, "parkdata");
2396
2397 if (!ParkdeviceXml)
2398 {
2399 ParkdeviceXml = addXMLEle(ParkdataXmlRoot, "device");
2400 addXMLAtt(ParkdeviceXml, "name", ParkDeviceName);
2401 }
2402
2403 if (!ParkstatusXml)
2404 ParkstatusXml = addXMLEle(ParkdeviceXml, "parkstatus");
2405 editXMLEle(ParkstatusXml, (IsParked ? "true" : "false"));
2406
2408 {
2409 if (!ParkpositionXml)
2410 ParkpositionXml = addXMLEle(ParkdeviceXml, "parkposition");
2411 if (!ParkpositionAxis1Xml)
2412 ParkpositionAxis1Xml = addXMLEle(ParkpositionXml, "axis1position");
2413 if (!ParkpositionAxis2Xml)
2414 ParkpositionAxis2Xml = addXMLEle(ParkpositionXml, "axis2position");
2415
2416 snprintf(pcdata, sizeof(pcdata), "%lf", Axis1ParkPosition);
2417 editXMLEle(ParkpositionAxis1Xml, pcdata);
2418 snprintf(pcdata, sizeof(pcdata), "%lf", Axis2ParkPosition);
2419 editXMLEle(ParkpositionAxis2Xml, pcdata);
2420 }
2421
2422 prXMLEle(fp, ParkdataXmlRoot, 0);
2423 fclose(fp);
2424 wordfree(&wexp);
2425
2426 return true;
2427}
2428
2430{
2431 return Axis1ParkPosition;
2432}
2434{
2435 return Axis1DefaultParkPosition;
2436}
2438{
2439 return Axis2ParkPosition;
2440}
2442{
2443 return Axis2DefaultParkPosition;
2444}
2445
2446void Telescope::SetAxis1Park(double value)
2447{
2448 LOGF_DEBUG("Setting Park Axis1 to %.2f", value);
2449 Axis1ParkPosition = value;
2450 ParkPositionNP[AXIS_RA].setValue(value);
2451 ParkPositionNP.apply();
2452}
2453
2455{
2456 LOGF_DEBUG("Setting Default Park Axis1 to %.2f", value);
2457 Axis1DefaultParkPosition = value;
2458}
2459
2460void Telescope::SetAxis2Park(double value)
2461{
2462 LOGF_DEBUG("Setting Park Axis2 to %.2f", value);
2463 Axis2ParkPosition = value;
2464 ParkPositionNP[AXIS_DE].setValue(value);
2465 ParkPositionNP.apply();
2466}
2467
2469{
2470 LOGF_DEBUG("Setting Default Park Axis2 to %.2f", value);
2471 Axis2DefaultParkPosition = value;
2472}
2473
2475{
2476 return DomePolicySP[DOME_LOCKS].getState() == ISS_ON && IsLocked;
2477}
2478
2480{
2481 INDI_UNUSED(index);
2482 return true;
2483}
2484
2485void Telescope::processButton(const char *button_n, ISState state)
2486{
2487 //ignore OFF
2488 if (state == ISS_OFF)
2489 return;
2490
2491 if (!strcmp(button_n, "ABORTBUTTON"))
2492 {
2493 auto trackSW = getSwitch("TELESCOPE_TRACK_MODE");
2494 // Only abort if we have some sort of motion going on
2495 if (ParkSP.getState() == IPS_BUSY || MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY
2496 || EqNP.getState() == IPS_BUSY ||
2497 (trackSW && trackSW.getState() == IPS_BUSY))
2498 {
2499 // Invoke parent processing so that Telescope takes care of abort cross-check
2500 ISState states[1] = { ISS_ON };
2501 const char *names[1] = { AbortSP[0].getName() };
2502 ISNewSwitch(getDeviceName(), AbortSP.getName(), states, const_cast<char **>(names), 1);
2503 }
2504 }
2505 else if (!strcmp(button_n, "PARKBUTTON"))
2506 {
2507 ISState states[2] = { ISS_ON, ISS_OFF };
2508 const char *names[2] = { ParkSP[PARK].getName(), ParkSP[UNPARK].getName() };
2509 ISNewSwitch(getDeviceName(), ParkSP.getName(), states, const_cast<char **>(names), 2);
2510 }
2511 else if (!strcmp(button_n, "UNPARKBUTTON"))
2512 {
2513 ISState states[2] = { ISS_OFF, ISS_ON };
2514 const char *names[2] = { ParkSP[PARK].getName(), ParkSP[UNPARK].getName() };
2515 ISNewSwitch(getDeviceName(), ParkSP.getName(), states, const_cast<char **>(names), 2);
2516 }
2517 else if (!strcmp(button_n, "SLEWPRESETUP"))
2518 {
2519 // Re-arm the one-shot gate — button events don't pass through the
2520 // mag < 0.5 re-arm path that analog joystick pairs use.
2521 m_slewPresetArmed = true;
2522 // angle=90 (RIGHT) falls in the (45°,225°] "increase-index" branch
2523 processSlewPresets(1, 90);
2524 }
2525 else if (!strcmp(button_n, "SLEWPRESETDOWN"))
2526 {
2527 // Re-arm the one-shot gate — same reason as above.
2528 m_slewPresetArmed = true;
2529 // angle=270 (LEFT) falls in the "decrease-index" branch
2530 processSlewPresets(1, 270);
2531 }
2532}
2533
2534void Telescope::processJoystick(const char *joystick_n, double mag, double angle)
2535{
2536 if (MotionControlModeTP[MOTION_CONTROL_MODE_JOYSTICK].getState() == ISS_ON && !strcmp(joystick_n, "MOTIONDIR"))
2537 {
2539 {
2540 DEBUG(Logger::DBG_WARNING, "Can not slew while mount is parking/parked.");
2541 return;
2542 }
2543
2544 processNSWE(mag, angle);
2545 }
2546 else if (!strcmp(joystick_n, "SLEWPRESET"))
2547 processSlewPresets(mag, angle);
2548}
2549
2550void Telescope::processAxis(const char *axis_n, double value)
2551{
2553 {
2554 if (!strcmp(axis_n, "MOTIONDIRNS") || !strcmp(axis_n, "MOTIONDIRWE"))
2555 {
2557 {
2558 LOG_WARN("Cannot slew while mount is parking/parked.");
2559 return;
2560 }
2561
2562 if (!strcmp(axis_n, "MOTIONDIRNS"))
2563 {
2564 // South
2565 if (value > 0)
2566 {
2567 motionDirNSValue = -1;
2568 }
2569 // North
2570 else if (value < 0)
2571 {
2572 motionDirNSValue = 1;
2573 }
2574 else
2575 {
2576 motionDirNSValue = 0;
2577 }
2578 }
2579 else if (!strcmp(axis_n, "MOTIONDIRWE"))
2580 {
2581 // East
2582 if (value > 0)
2583 {
2584 motionDirWEValue = 1;
2585 }
2586 // West
2587 else if (value < 0)
2588 {
2589 motionDirWEValue = -1;
2590 }
2591 else
2592 {
2593 motionDirWEValue = 0;
2594 }
2595 }
2596
2597 float x = motionDirWEValue * sqrt(1 - pow(motionDirNSValue, 2) / 2.0f);
2598 float y = motionDirNSValue * sqrt(1 - pow(motionDirWEValue, 2) / 2.0f);
2599 float angle = atan2(y, x) * (180.0 / 3.141592653589);
2600 float mag = sqrt(pow(y, 2) + pow(x, 2));
2601 while (angle < 0)
2602 {
2603 angle += 360;
2604 }
2605 if (mag == 0)
2606 {
2607 angle = 0;
2608 }
2609
2610 processNSWE(mag, angle);
2611 }
2612 }
2613}
2614
2615void Telescope::processNSWE(double mag, double angle)
2616{
2617 if (mag < 0.5)
2618 {
2619 // Moving in the same direction will make it stop
2620 if (MovementNSSP.getState() == IPS_BUSY)
2621 {
2623 {
2624 MovementNSSP.reset();
2625 MovementNSSP.setState(IPS_IDLE);
2626 MovementNSSP.apply();
2627 }
2628 else
2629 {
2630 MovementNSSP.setState(IPS_ALERT);
2631 MovementNSSP.apply();
2632 }
2633 }
2634
2635 if (MovementWESP.getState() == IPS_BUSY)
2636 {
2638 {
2639 MovementWESP.reset();
2640 MovementWESP.setState(IPS_IDLE);
2641 MovementWESP.apply();
2642 }
2643 else
2644 {
2645 MovementWESP.setState(IPS_ALERT);
2646 MovementWESP.apply();
2647 }
2648 }
2649 }
2650 // Put high threshold
2651 else if (mag > 0.9)
2652 {
2653 // Only one axis can move at a time
2654 if (LockAxisSP[AXIS_RA].getState() == ISS_ON)
2655 {
2656 // West
2657 if (angle >= 90 && angle <= 270)
2658 angle = 180;
2659 // East
2660 else
2661 angle = 0;
2662 }
2663 else if (LockAxisSP[AXIS_DE].getState() == ISS_ON)
2664 {
2665 // North
2666 if (angle >= 0 && angle <= 180)
2667 angle = 90;
2668 // South
2669 else
2670 angle = 270;
2671 }
2672
2673 // Snap angle to x or y direction if close to corresponding axis (i.e. deviation < 15°)
2674 if (angle > 75 && angle < 105)
2675 {
2676 angle = 90;
2677 }
2678 if (angle > 165 && angle < 195)
2679 {
2680 angle = 180;
2681 }
2682 if (angle > 255 && angle < 285)
2683 {
2684 angle = 270;
2685 }
2686 if (angle > 345 || angle < 15)
2687 {
2688 angle = 0;
2689 }
2690
2691 // Apply joystick reverse/swap transforms
2693 angle = fmod(angle + 90.0, 360.0);
2694 if (JoystickReverseSP[JOYSTICK_REVERSE_NS].getState() == ISS_ON)
2695 angle = fmod(360.0 - angle, 360.0);
2696 if (JoystickReverseSP[JOYSTICK_REVERSE_WE].getState() == ISS_ON)
2697 angle = fmod(540.0 - angle, 360.0);
2698
2699 // North
2700 if (angle > 0 && angle < 180)
2701 {
2702 // Don't try to move if you're busy and moving in the same direction
2703 if (MovementNSSP.getState() != IPS_BUSY || MovementNSSP[DIRECTION_NORTH].getState() != ISS_ON)
2705
2706 MovementNSSP.setState(IPS_BUSY);
2709 MovementNSSP.apply();
2710 }
2711 // South
2712 if (angle > 180 && angle < 360)
2713 {
2714 // Don't try to move if you're busy and moving in the same direction
2715 if (MovementNSSP.getState() != IPS_BUSY || MovementNSSP[DIRECTION_SOUTH].getState() != ISS_ON)
2717
2718 MovementNSSP.setState(IPS_BUSY);
2721 MovementNSSP.apply();
2722 }
2723 // East
2724 if (angle < 90 || angle > 270)
2725 {
2726 // Don't try to move if you're busy and moving in the same direction
2727 if (MovementWESP.getState() != IPS_BUSY || MovementWESP[DIRECTION_EAST].getState() != ISS_ON)
2729
2730 MovementWESP.setState(IPS_BUSY);
2733 MovementWESP.apply();
2734 }
2735
2736 // West
2737 if (angle > 90 && angle < 270)
2738 {
2739 // Don't try to move if you're busy and moving in the same direction
2740 if (MovementWESP.getState() != IPS_BUSY || MovementWESP[DIRECTION_WEST].getState() != ISS_ON)
2742
2743 MovementWESP.setState(IPS_BUSY);
2746 MovementWESP.apply();
2747 }
2748 }
2749}
2750
2751void Telescope::processSlewPresets(double mag, double angle)
2752{
2753 // mag >= 0.9 → joystick fully deflected → eligible to fire once
2754 // mag < 0.5 → joystick near centre → re-arm for next press
2755 // 0.5 ≤ mag < 0.9 → transitional zone → do nothing
2756 if (mag < 0.9)
2757 {
2758 if (mag < 0.5 && !m_slewPresetArmed)
2759 m_slewPresetArmed = true;
2760 return;
2761 }
2762
2763 // Already fired once for this press – ignore jitter until released.
2764 if (!m_slewPresetArmed)
2765 return;
2766
2767 m_slewPresetArmed = false;
2768
2769 size_t currentIndex = SlewRateSP.findOnSwitchIndex();
2770
2771 // Direction convention (compass angles, N=0°):
2772 // RIGHT (90°) / DOWN (180°) → angle in (45°, 225°] → increase index
2773 // UP (0°) / LEFT (270°) → angle outside that range → decrease index
2774 //
2775 // This matches the standard GUI list convention where RIGHT/DOWN moves to
2776 // the next (higher-index) item and UP/LEFT moves to the previous item.
2777 if (angle > 45 && angle <= 225)
2778 {
2779 // Increase index → next (faster) slew rate
2780 if (currentIndex >= SlewRateSP.count() - 1)
2781 return;
2782 SlewRateSP.reset();
2783 SlewRateSP[currentIndex + 1].setState(ISS_ON);
2784 SetSlewRate(currentIndex + 1);
2785 }
2786 else
2787 {
2788 // Decrease index → previous (slower) slew rate
2789 if (currentIndex <= 0)
2790 return;
2791 SlewRateSP.reset();
2792 SlewRateSP[currentIndex - 1].setState(ISS_ON);
2793 SetSlewRate(currentIndex - 1);
2794 }
2795
2796 SlewRateSP.apply();
2797}
2798
2799void Telescope::joystickHelper(const char *joystick_n, double mag, double angle, void *context)
2800{
2801 static_cast<Telescope *>(context)->processJoystick(joystick_n, mag, angle);
2802}
2803
2804void Telescope::axisHelper(const char *axis_n, double value, void *context)
2805{
2806 static_cast<Telescope *>(context)->processAxis(axis_n, value);
2807}
2808
2809void Telescope::buttonHelper(const char *button_n, ISState state, void *context)
2810{
2811 static_cast<Telescope *>(context)->processButton(button_n, state);
2812}
2813
2815{
2816 // ensure that the scope knows it's pier side or the pier side is simulated
2817 if (HasPierSide() == false && getSimulatePierSide() == false)
2818 return;
2819
2820 currentPierSide = side;
2821
2823 {
2824 PierSideSP[PIER_WEST].setState((side == PIER_WEST) ? ISS_ON : ISS_OFF);
2825 PierSideSP[PIER_EAST].setState((side == PIER_EAST) ? ISS_ON : ISS_OFF);
2826 PierSideSP.setState(IPS_OK);
2827 PierSideSP.apply();
2828
2830 }
2831}
2832
2839{
2840 // return unknown if the mount does not have pier side, this will be the case for a fork mount
2841 // where a pier flip is not required.
2844
2845 // calculate the hour angle and derive the pier side
2846 double lst = get_local_sidereal_time(m_Location.longitude);
2847 double hourAngle = get_local_hour_angle(lst, ra);
2848
2850}
2851
2853{
2855 return;
2856
2857 if (MountTypeSP[type].getState() == ISS_ON && MountTypeSP.getState() == IPS_OK)
2858 return;
2859
2860 MountTypeSP.reset();
2861 MountTypeSP[type].setState(ISS_ON);
2862 MountTypeSP.setState(IPS_OK);
2863 // The property is only defined while connected.
2864 if (isConnected())
2865 MountTypeSP.apply();
2866}
2867
2869{
2870 const auto index = MountTypeSP.findOnSwitchIndex();
2871 return index < 0 ? MOUNT_EQ_GEM : static_cast<TelescopeMountType>(index);
2872}
2873
2875{
2876 currentPECState = state;
2877
2879 {
2880
2881 PECStateSP[PEC_OFF].setState((state == PEC_ON) ? ISS_OFF : ISS_ON);
2882 PECStateSP[PEC_ON].setState((state == PEC_ON) ? ISS_ON : ISS_OFF);
2883 PECStateSP.setState(IPS_OK);
2884 PECStateSP.apply();
2885
2887 }
2888}
2889
2891{
2892 // Check first the HOME environmental variable
2893 const char *HomeDir = getenv("HOME");
2894
2895 // ...otherwise get the home directory of the current user.
2896 if (!HomeDir)
2897 {
2898 HomeDir = getpwuid(getuid())->pw_dir;
2899 }
2900 return (HomeDir ? std::string(HomeDir) : "");
2901}
2902
2903bool Telescope::CheckFile(const std::string &file_name, bool writable) const
2904{
2905 FILE *FilePtr = fopen(file_name.c_str(), (writable ? "a" : "r"));
2906
2907 if (FilePtr)
2908 {
2909 fclose(FilePtr);
2910 return true;
2911 }
2912 return false;
2913}
2914
2916{
2917 char ts[32] = {0};
2918
2919 std::time_t t = std::time(nullptr);
2920 struct std::tm *utctimeinfo = std::gmtime(&t);
2921
2922 strftime(ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", utctimeinfo);
2923 TimeTP[UTC].setText(ts);
2924
2925 struct std::tm *localtimeinfo = std::localtime(&t);
2926 snprintf(ts, sizeof(ts), "%4.2f", (localtimeinfo->tm_gmtoff / 3600.0));
2927 TimeTP[OFFSET].setText(ts);
2928
2929 TimeTP.setState(IPS_OK);
2930
2931 TimeTP.apply();
2932}
2933
2935{
2936 return m_simulatePierSide;
2937}
2938
2940{
2941 switch (ps)
2942 {
2943 case PIER_WEST:
2944 return "PIER_WEST";
2945 case PIER_EAST:
2946 return "PIER_EAST";
2947 default:
2948 return "PIER_UNKNOWN";
2949 }
2950}
2951
2953{
2954 SimulatePierSideSP.reset();
2955 SimulatePierSideSP[SIMULATE_YES].setState(simulate ? ISS_ON : ISS_OFF);
2956 SimulatePierSideSP[SIMULATE_NO].setState(simulate ? ISS_OFF : ISS_ON);
2957 SimulatePierSideSP.setState(IPS_OK);
2958 SimulatePierSideSP.apply();
2959
2960 if (simulate)
2961 {
2964 }
2965 else
2966 {
2967 capability &= static_cast<uint32_t>(~TELESCOPE_HAS_PIER_SIDE);
2969 }
2970
2971 m_simulatePierSide = simulate;
2972}
2973
2974}
int SetSlewRate(void)
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
bool isConnected() const
const char * getDeviceName() const
INDI::PropertySwitch getSwitch(const char *name) const
INDI::PropertyText getText(const char *name) const
The Controller class provides functionality to access a controller (e.g. joystick) input and send it ...
void addPollPeriodControl()
Add Polling period control to the driver.
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
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)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual const char * getDefaultName()=0
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Connection::Interface * getActiveConnection()
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
void push(WidgetView< T > &&item)
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void resize(size_t size)
TelescopeStatus TrackState
bool isLocked() const
isLocked is mount currently locked?
virtual bool SetTrackMode(uint8_t mode)
SetTrackMode Set active tracking mode. Do not change track state.
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
bool HasPierSideSimulation()
virtual bool Goto(double ra, double dec)
Move the scope to the supplied RA and DEC coordinates.
TelescopeMountType getMountType() const
void processButton(const char *button_n, ISState state)
static void axisHelper(const char *axis_n, double value, void *context)
void processAxis(const char *axis_n, double value)
bool CheckFile(const std::string &file_name, bool writable) const
Check if a file exists and it is readable.
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
virtual bool ReadScopeStatus()=0
Read telescope status.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool Park()
Park the telescope to its home position.
virtual bool SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
TelescopeParkData parkDataType
std::string GetHomeDirectory() const
Validate a file name.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual void TimerHit() override
Called when setTimer() time is up.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool SetTrackRate(double raRate, double deRate)
SetTrackRate Set custom tracking rates.
double GetAxis1Park() const
virtual bool UnPark()
Unpark the telescope if already parked.
virtual bool SetSlewRate(int index)
SetSlewRate Set desired slew rate index.
virtual bool SetDefaultPark()
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
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...
void setTelescopeConnection(const uint8_t &value)
setTelescopeConnection Set telescope connection mode. Child class should call this in the constructor...
double GetAxis2Park() const
bool isParked()
isParked is mount currently parked?
void processNSWE(double mag, double angle)
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
Connection::Serial * serialConnection
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
static void joystickHelper(const char *joystick_n, double mag, double angle, void *context)
void updateObserverLocation(double latitude, double longitude, double elevation)
Update location settings of the observer.
double GetAxis1ParkDefault() const
virtual bool Handshake()
perform handshake with device to check communication
virtual bool SetMountType(TelescopeMountType type)
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
virtual bool SetTrackEnabled(bool enabled)
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
virtual bool updateTime(ln_date *utc, double utc_offset)
Update telescope time, date, and UTC offset.
Connection::TCP * tcpConnection
static void buttonHelper(const char *button_n, ISState state, void *context)
uint8_t getTelescopeConnection() const
const char * LoadParkData()
void setPECState(TelescopePECState state)
virtual IPState ExecuteHomeAction(TelescopeHomeAction action)
Execute a homing action.
TelescopeMountType
Mount geometry reported in the standard TELESCOPE_MOUNT_TYPE property. The values are the indices of ...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateLocation(double latitude, double longitude, double elevation)
Update telescope location settings.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool SetParkPosition(double Axis1Value, double Axis2Value)
SetParkPosition Set desired parking position to the supplied value. This ONLY sets the desired park p...
IGeographicCoordinates m_Location
void processJoystick(const char *joystick_n, double mag, double angle)
bool callHandshake()
callHandshake Helper function that sets the port file descriptor before calling the actual Handshake ...
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
virtual void SyncParkStatus(bool isparked)
SyncParkStatus Update the state and switches for parking.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
Move the telescope in the direction dir.
TelescopeStatus RememberTrackState
RememberTrackState Remember last state of Track State to fall back to in case of errors or aborts.
virtual bool Abort()
Abort any telescope motion including tracking if possible.
double GetAxis2ParkDefault() const
TelescopePECState currentPECState
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 MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
Start or Stop the telescope motion in the direction dir.
virtual bool Flip(double ra, double dec)
Move and flip the scope to the supplied RA and DEC coordinates.
void processSlewPresets(double mag, double angle)
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.
TelescopePECState lastPECState
TelescopePierSide expectedPierSide(double ra)
Calculate the expected pier side for scopes that do not report this property themselves.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
virtual bool Sync(double ra, double dec)
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * SATELLITE_TAB
SATELLITE_TAB.
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 * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int errno
INDI::PropertySwitch ParkSP
INDI::PropertySwitch SimulatePierSideSP
TelescopePierSide currentPierSide
INDI::PropertySwitch AbortSP
INDI::PropertySwitch DomePolicySP
INDI::PropertyText ActiveDeviceTP
INDI::PropertyText TLEtoTrackTP
Text Vector property defining the orbital elements of an artificial satellite (TLE)....
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch MovementNSSP
INDI::PropertyText SatPassWindowTP
Text Vector property defining the start and end of a satellite pass (window contains pass)....
TelescopePierSide lastPierSide
INDI::PropertyNumber EqNP
INDI::PropertySwitch TrackStateSP
bool getSimulatePierSide() const
INDI::PropertySwitch PECStateSP
INDI::PropertySwitch HomeSP
INDI::PropertySwitch MotionControlModeTP
INDI::PropertySwitch TrackSatSP
Switch Vector property defining the state of the satellite tracking of the mount. Example implementat...
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertyText TimeTP
INDI::PropertySwitch MountTypeSP
Standard TELESCOPE_MOUNT_TYPE property, indexed by TelescopeMountType. Writable if the driver sets TE...
INDI::PropertySwitch PierSideSP
INDI::PropertySwitch LockAxisSP
INDI::PropertySwitch ReverseMovementSP
INDI::PropertySwitch MovementWESP
INDI::PropertySwitch JoystickReverseSP
INDI::PropertySwitch ParkOptionSP
INDI::PropertySwitch CoordSP
void setSimulatePierSide(bool value)
INDI::PropertyNumber LocationNP
INDI::PropertyNumber ParkPositionNP
const char * getPierSideStr(TelescopePierSide ps)
INDI::PropertyNumber TargetNP
@ SAT_TRACK
Track signal.
@ SAT_HALT
Halt signal (abort).
@ SAT_PASS_WINDOW_END
Index for end of the window.
@ SAT_PASS_WINDOW_START
Index for start of the window.
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
#define MAXINDITSTAMP
Definition indiapi.h:195
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
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
@ AXIS_AZ
@ AXIS_ALT
INDI_DIR_WE
@ DIRECTION_EAST
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_SOUTH
@ DIRECTION_NORTH
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
double get_local_hour_angle(double sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
Definition indicom.c:1379
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.
int extractISOTime(const char *timestr, struct ln_date *iso_date)
Extract ISO 8601 time and store it in a tm struct.
int IUFindIndex(const char *needle, char **hay, unsigned int n)
Returns the index of the string in a string array.
Definition indidevapi.c:326
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
Definition indidevapi.c:355
#define INDI_UNUSED(x)
Definition indidevapi.h:132
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
Definition indidriver.c:143
int IUGetConfigNumber(const char *dev, const char *property, const char *member, double *value)
IUGetConfigNumber Opens configuration file and reads single number property.
Definition indidriver.c:846
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
*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 DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
Definition indilogger.h:56
#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 DEBUGF(priority, msg,...)
Definition indilogger.h:57
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
Definition lilxml.cpp:644
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
Definition lilxml.cpp:555
XMLAtt * findXMLAtt(XMLEle *ep, const char *name)
Find an XML attribute within an XML element.
Definition lilxml.cpp:524
LilXML * newLilXML()
Create a new lilxml parser.
Definition lilxml.cpp:150
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
Definition lilxml.cpp:600
XMLEle * addXMLEle(XMLEle *parent, const char *tag)
add an element with the given tag to the given element. parent can be NULL to make a new root.
Definition lilxml.cpp:670
XMLEle * findXMLEle(XMLEle *ep, const char *tag)
Find an XML element within an XML element.
Definition lilxml.cpp:537
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
Definition lilxml.cpp:624
void editXMLEle(XMLEle *ep, const char *pcdata)
set the pcdata of the given element
Definition lilxml.cpp:698
void prXMLEle(FILE *fp, XMLEle *ep, int level)
Print an XML element.
Definition lilxml.cpp:844
void delXMLEle(XMLEle *ep)
delXMLEle Delete XML element.
Definition lilxml.cpp:167
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Definition lilxml.cpp:606
void delLilXML(LilXML *lp)
Delete a lilxml parser.
Definition lilxml.cpp:159
XMLAtt * addXMLAtt(XMLEle *ep, const char *name, const char *valu)
Add an XML attribute to an existing XML element.
Definition lilxml.cpp:706
XMLEle * readXMLFile(FILE *fp, LilXML *lp, char ynot[])
Handy wrapper to read one xml file.
Definition lilxml.cpp:653
struct LilXML_ LilXML
Definition lilxml.h:82
struct xml_att_ XMLAtt
Definition lilxml.h:80
#define XML_ERROR_SIZE
Definition lilxml.h:73
struct xml_ele_ XMLEle
Definition lilxml.h:81
Namespace to encapsulate INDI client, drivers, and mediator classes.
INDI::WidgetViewSwitch WidgetSwitch
uint16_t type
Definition pwc-ioctl.h:0
void fill(const char *name, const char *label, ISState state=ISS_OFF)