Instrument Neutral Distributed Interface INDI 2.2.5
ieqprolegacy.cpp
Go to the documentation of this file.
1/*
2 INDI IEQ Pro driver
3
4 Copyright (C) 2015 Jasem Mutlaq
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "ieqprolegacy.h"
22#include "indicom.h"
24
25#include <libnova/sidereal_time.h>
26#include <libnova/transform.h>
27#include <memory>
28
29#include <cmath>
30#include <cstring>
31
32/* Simulation Parameters */
33#define SLEWRATE 1 /* slew rate, degrees/s */
34
35#define MOUNTINFO_TAB "Mount Info"
36
37// We declare an auto pointer to IEQPro.
38static std::unique_ptr<IEQProLegacy> scope(new IEQProLegacy());
39
40/* Constructor */
42{
43 setVersion(1, 7);
44
45 scopeInfo.gpsStatus = GPS_OFF;
46 scopeInfo.systemStatus = ST_STOPPED;
47 scopeInfo.trackRate = TR_SIDEREAL;
48 scopeInfo.slewRate = SR_1;
49 scopeInfo.timeSource = TS_RS232;
50 scopeInfo.hemisphere = HEMI_NORTH;
51
52 DBG_SCOPE = INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE");
53
57 9);
58}
59
61{
62 return "iEQ";
63}
64
66{
68
69 /* Firmware */
70 IUFillText(&FirmwareT[FW_MODEL], "Model", "", nullptr);
71 IUFillText(&FirmwareT[FW_BOARD], "Board", "", nullptr);
72 IUFillText(&FirmwareT[FW_CONTROLLER], "Controller", "", nullptr);
73 IUFillText(&FirmwareT[FW_RA], "RA", "", nullptr);
74 IUFillText(&FirmwareT[FW_DEC], "DEC", "", nullptr);
75 IUFillTextVector(&FirmwareTP, FirmwareT, 5, getDeviceName(), "Firmware Info", "", MOUNTINFO_TAB, IP_RO, 0,
76 IPS_IDLE);
77
78 /* Tracking Mode */
79 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
80 AddTrackMode("TRACK_SOLAR", "Solar");
81 AddTrackMode("TRACK_LUNAR", "Lunar");
82 AddTrackMode("TRACK_KING", "King");
83 AddTrackMode("TRACK_CUSTOM", "Custom");
84
85 // Slew Rates
86 SlewRateSP[0].setLabel("1x");
87 SlewRateSP[1].setLabel("2x");
88 SlewRateSP[2].setLabel("8x");
89 SlewRateSP[3].setLabel("16x");
90 SlewRateSP[4].setLabel("64x");
91 SlewRateSP[5].setLabel("128x");
92 SlewRateSP[6].setLabel("256x");
93 SlewRateSP[7].setLabel("512x");
94 SlewRateSP[8].setLabel("MAX");
95 SlewRateSP.reset();
96 // 64x is the default
97 SlewRateSP[4].setState(ISS_ON);
98
99 // Set TrackRate limits within +/- 0.0100 of Sidereal rate
100 TrackRateNP[AXIS_RA].setMin(TRACKRATE_SIDEREAL - 0.01);
101 TrackRateNP[AXIS_RA].setMax(TRACKRATE_SIDEREAL + 0.01);
102 TrackRateNP[AXIS_DE].setMin(-0.01);
103 TrackRateNP[AXIS_DE].setMax(0.01);
104
105 /* GPS Status */
106 IUFillSwitch(&GPSStatusS[GPS_OFF], "Off", "", ISS_ON);
107 IUFillSwitch(&GPSStatusS[GPS_ON], "On", "", ISS_OFF);
108 IUFillSwitch(&GPSStatusS[GPS_DATA_OK], "Data OK", "", ISS_OFF);
109 IUFillSwitchVector(&GPSStatusSP, GPSStatusS, 3, getDeviceName(), "GPS_STATUS", "GPS", MOUNTINFO_TAB, IP_RO,
111
112 /* Time Source */
113 IUFillSwitch(&TimeSourceS[TS_RS232], "RS232", "", ISS_ON);
114 IUFillSwitch(&TimeSourceS[TS_CONTROLLER], "Controller", "", ISS_OFF);
115 IUFillSwitch(&TimeSourceS[TS_GPS], "GPS", "", ISS_OFF);
116 IUFillSwitchVector(&TimeSourceSP, TimeSourceS, 3, getDeviceName(), "TIME_SOURCE", "Time Source", MOUNTINFO_TAB,
118
119 /* Hemisphere */
120 IUFillSwitch(&HemisphereS[HEMI_SOUTH], "South", "", ISS_OFF);
121 IUFillSwitch(&HemisphereS[HEMI_NORTH], "North", "", ISS_ON);
122 IUFillSwitchVector(&HemisphereSP, HemisphereS, 2, getDeviceName(), "HEMISPHERE", "Hemisphere", MOUNTINFO_TAB, IP_RO,
124
125 /* Home */
126 IUFillSwitch(&HomeS[IEQ_FIND_HOME], "FindHome", "Find Home", ISS_OFF);
127 IUFillSwitch(&HomeS[IEQ_SET_HOME], "SetCurrentAsHome", "Set current as Home", ISS_OFF);
128 IUFillSwitch(&HomeS[IEQ_GOTO_HOME], "GoToHome", "Go to Home", ISS_OFF);
129 IUFillSwitchVector(&HomeSP, HomeS, 3, getDeviceName(), "HOME", "Home", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 0,
130 IPS_IDLE);
131
132 /* How fast do we guide compared to sidereal rate */
133 IUFillNumber(&GuideRateN[RA_AXIS], "RA_GUIDE_RATE", "x Sidereal", "%.2f", 0.01, 0.9, 0.1, 0.5);
134 IUFillNumber(&GuideRateN[DEC_AXIS], "DE_GUIDE_RATE", "x Sidereal", "%.2f", 0.1, 0.99, 0.1, 0.5);
135 IUFillNumberVector(&GuideRateNP, GuideRateN, 2, getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RW, 0,
136 IPS_IDLE);
137
139
141
143
145
147
149
150 // Only CEM40 and GEM45 have 115200 baud, rest are 9600
151 if (strstr(getDeviceName(), "CEM40") || strstr(getDeviceName(), "GEM45"))
153
155 currentDEC = LocationNP[LOCATION_LATITUDE].getValue() > 0 ? 90 : -90;
156 return true;
157}
158
160{
162
163 if (isConnected())
164 {
165 defineProperty(&HomeSP);
166
167 defineProperty(&GuideRateNP);
168
169 defineProperty(&FirmwareTP);
170 defineProperty(&GPSStatusSP);
171 defineProperty(&TimeSourceSP);
172 defineProperty(&HemisphereSP);
173
174 getStartupData();
175 }
176 else
177 {
178 deleteProperty(HomeSP.name);
179
180 deleteProperty(GuideRateNP.name);
181
182 deleteProperty(FirmwareTP.name);
183 deleteProperty(GPSStatusSP.name);
184 deleteProperty(TimeSourceSP.name);
185 deleteProperty(HemisphereSP.name);
186 }
187
189
190 return true;
191}
192
193void IEQProLegacy::getStartupData()
194{
195 LOG_DEBUG("Getting firmware data...");
196 if (get_ieqpro_firmware(PortFD, &firmwareInfo))
197 {
198 IUSaveText(&FirmwareT[0], firmwareInfo.Model.c_str());
199
200 // Alt-Az models (e.g. "Cube II AA", "AZ Mount Pro") and dual-mode mounts in Alt-Az mode
201 {
202 const std::string &model = firmwareInfo.Model;
203 const bool altAz = (model.size() >= 3 && model.compare(model.size() - 3, 3, " AA") == 0) ||
204 model.find("AZ Mount") != std::string::npos;
206 }
207
208 IUSaveText(&FirmwareT[1], firmwareInfo.MainBoardFirmware.c_str());
209 IUSaveText(&FirmwareT[2], firmwareInfo.ControllerFirmware.c_str());
210 IUSaveText(&FirmwareT[3], firmwareInfo.RAFirmware.c_str());
211 IUSaveText(&FirmwareT[4], firmwareInfo.DEFirmware.c_str());
212
213 FirmwareTP.s = IPS_OK;
214 IDSetText(&FirmwareTP, nullptr);
215 }
216
217 LOG_DEBUG("Getting guiding rate...");
218 double raGuideRate = 0, deGuideRate = 0;
219 if (get_ieqpro_guide_rate(PortFD, &raGuideRate, &deGuideRate))
220 {
221 GuideRateN[RA_AXIS].value = raGuideRate;
222 GuideRateN[DEC_AXIS].value = deGuideRate;
223 IDSetNumber(&GuideRateNP, nullptr);
224 }
225
226 double utc_offset;
227 int yy, dd, mm, hh, minute, ss;
228 if (get_ieqpro_utc_date_time(PortFD, &utc_offset, &yy, &mm, &dd, &hh, &minute, &ss))
229 {
230 char isoDateTime[32] = {0};
231 char utcOffset[8] = {0};
232
233 snprintf(isoDateTime, 32, "%04d-%02d-%02dT%02d:%02d:%02d", yy, mm, dd, hh, minute, ss);
234 snprintf(utcOffset, 8, "%4.2f", utc_offset);
235
236 TimeTP[UTC].setText(isoDateTime);
237 TimeTP[OFFSET].setText(utcOffset);
238
239 LOGF_INFO("Mount UTC offset is %s. UTC time is %s", utcOffset, isoDateTime);
240
241 TimeTP.setState(IPS_OK);
242 TimeTP.apply();
243 }
244
245 // Get Longitude and Latitude from mount
246 double longitude = 0, latitude = 0;
247 if (get_ieqpro_latitude(PortFD, &latitude) && get_ieqpro_longitude(PortFD, &longitude))
248 {
249 // Convert to INDI standard longitude (0 to 360 Eastward)
250 if (longitude < 0)
251 longitude += 360;
252
253 LOGF_INFO("Mount Longitude %g Latitude %g", longitude, latitude);
254
255 LocationNP[LOCATION_LATITUDE].setValue(latitude);
256 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
257 LocationNP.setState(IPS_OK);
258
259 LocationNP.apply(nullptr);
260
261 saveConfig(true, "GEOGRAPHIC_COORD");
262 }
263 else if (IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LONG", &longitude) == 0 &&
264 IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LAT", &latitude) == 0)
265 {
266 LocationNP[LOCATION_LATITUDE].setValue(latitude);
267 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
268 LocationNP.setState(IPS_OK);
269
270 LocationNP.apply();
271 }
272
273 if (InitPark())
274 {
275 // If loading parking data is successful, we just set the default parking values.
276 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
278 }
279 else
280 {
281 // Otherwise, we set all parking data to default in case no parking data is found.
282 SetAxis1Park(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
284 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
286 }
287
288 if (isSimulation())
289 {
290 if (isParked())
292 else
294 }
295}
296
297bool IEQProLegacy::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
298{
299 // Check guider interface
300 if (GI::processNumber(dev, name, values, names, n))
301 return true;
302
303 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
304 {
305 // Guiding Rate
306 if (!strcmp(name, GuideRateNP.name))
307 {
308 IUUpdateNumber(&GuideRateNP, values, names, n);
309
310 if (set_ieqpro_guide_rate(PortFD, GuideRateN[RA_AXIS].value, GuideRateN[DEC_AXIS].value))
311 GuideRateNP.s = IPS_OK;
312 else
313 GuideRateNP.s = IPS_ALERT;
314
315 IDSetNumber(&GuideRateNP, nullptr);
316
317 return true;
318 }
319 }
320
321 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
322}
323
324bool IEQProLegacy::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
325{
326 if (!strcmp(getDeviceName(), dev))
327 {
328 if (!strcmp(name, HomeSP.name))
329 {
330 IUUpdateSwitch(&HomeSP, states, names, n);
331
332 IEQ_HOME_OPERATION operation = static_cast<IEQ_HOME_OPERATION>(IUFindOnSwitchIndex(&HomeSP));
333
334 IUResetSwitch(&HomeSP);
335
336 switch (operation)
337 {
338 case IEQ_FIND_HOME:
339 if (firmwareInfo.Model.find("CEM") == std::string::npos)
340 {
341 HomeSP.s = IPS_IDLE;
342 IDSetSwitch(&HomeSP, nullptr);
343 LOG_WARN("Home search is not supported in this model.");
344 return true;
345 }
346
347 if (find_ieqpro_home(PortFD) == false)
348 {
349 HomeSP.s = IPS_ALERT;
350 IDSetSwitch(&HomeSP, nullptr);
351 return false;
352 }
353
354 HomeSP.s = IPS_OK;
355 IDSetSwitch(&HomeSP, nullptr);
356 LOG_INFO("Searching for home position...");
357 return true;
358
359 case IEQ_SET_HOME:
360 if (set_ieqpro_current_home(PortFD) == false)
361 {
362 HomeSP.s = IPS_ALERT;
363 IDSetSwitch(&HomeSP, nullptr);
364 return false;
365 }
366
367 HomeSP.s = IPS_OK;
368 IDSetSwitch(&HomeSP, nullptr);
369 LOG_INFO("Home position set to current coordinates.");
370 return true;
371
372 case IEQ_GOTO_HOME:
373 if (goto_ieqpro_home(PortFD) == false)
374 {
375 HomeSP.s = IPS_ALERT;
376 IDSetSwitch(&HomeSP, nullptr);
377 return false;
378 }
379
380 HomeSP.s = IPS_OK;
381 IDSetSwitch(&HomeSP, nullptr);
382 LOG_INFO("Slewing to home position...");
383 return true;
384 }
385
386 return true;
387 }
388 }
389
390 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
391}
392
394{
395 bool rc = false;
396
397 IEQInfo newInfo;
398
399 if (isSimulation())
400 mountSim();
401
402 rc = get_ieqpro_status(PortFD, &newInfo);
403
404 if (rc)
405 {
406 IUResetSwitch(&GPSStatusSP);
407 GPSStatusS[newInfo.gpsStatus].s = ISS_ON;
408 IDSetSwitch(&GPSStatusSP, nullptr);
409
410 IUResetSwitch(&TimeSourceSP);
411 TimeSourceS[newInfo.timeSource].s = ISS_ON;
412 IDSetSwitch(&TimeSourceSP, nullptr);
413
414 IUResetSwitch(&HemisphereSP);
415 HemisphereS[newInfo.hemisphere].s = ISS_ON;
416 IDSetSwitch(&HemisphereSP, nullptr);
417
418 /*
419 TelescopeTrackMode trackMode = TRACK_SIDEREAL;
420
421 switch (newInfo.trackRate)
422 {
423 case TR_SIDEREAL:
424 trackMode = TRACK_SIDEREAL;
425 break;
426 case TR_SOLAR:
427 trackMode = TRACK_SOLAR;
428 break;
429 case TR_LUNAR:
430 trackMode = TRACK_LUNAR;
431 break;
432 case TR_KING:
433 trackMode = TRACK_SIDEREAL;
434 break;
435 case TR_CUSTOM:
436 trackMode = TRACK_CUSTOM;
437 break;
438 }*/
439
440 switch (newInfo.systemStatus)
441 {
442 case ST_STOPPED:
443 TrackModeSP.setState(IPS_IDLE);
445 break;
446 case ST_PARKED:
447 TrackModeSP.setState(IPS_IDLE);
449 if (!isParked())
450 SetParked(true);
451 break;
452 case ST_HOME:
453 TrackModeSP.setState(IPS_IDLE);
455 break;
456 case ST_SLEWING:
460 break;
463 case ST_GUIDING:
464 // If slew to parking position is complete, issue park command now.
467 else
468 {
469 TrackModeSP.setState(IPS_BUSY);
471 if (scopeInfo.systemStatus == ST_SLEWING)
472 LOG_INFO("Slew complete, tracking...");
473 else if (scopeInfo.systemStatus == ST_MERIDIAN_FLIPPING)
474 LOG_INFO("Meridian flip complete, tracking...");
475 }
476 break;
477 }
478
479 TrackModeSP.reset();
480 TrackModeSP[newInfo.trackRate].setState(ISS_ON);
481 TrackModeSP.apply();
482
483 scopeInfo = newInfo;
484 }
485
486 rc = get_ieqpro_coords(PortFD, &currentRA, &currentDEC);
487
488 if (rc)
489 NewRaDec(currentRA, currentDEC);
490
491 return rc;
492}
493
494bool IEQProLegacy::Goto(double r, double d)
495{
496 targetRA = r;
497 targetDEC = d;
498 char RAStr[64] = {0}, DecStr[64] = {0};
499
500 fs_sexa(RAStr, targetRA, 2, 3600);
501 fs_sexa(DecStr, targetDEC, 2, 3600);
502
503 if (set_ieqpro_ra(PortFD, r) == false || set_ieqpro_dec(PortFD, d) == false)
504 {
505 LOG_ERROR("Error setting RA/DEC.");
506 return false;
507 }
508
509 if (slew_ieqpro(PortFD) == false)
510 {
511 LOG_ERROR("Failed to slew.");
512 return false;
513 }
514
516
517 LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
518 return true;
519}
520
521bool IEQProLegacy::Sync(double ra, double dec)
522{
523 if (set_ieqpro_ra(PortFD, ra) == false || set_ieqpro_dec(PortFD, dec) == false)
524 {
525 LOG_ERROR("Error setting RA/DEC.");
526 return false;
527 }
528
529 if (sync_ieqpro(PortFD) == false)
530 {
531 LOG_ERROR("Failed to sync.");
532 }
533
534 EqNP.setState(IPS_OK);
535
536 currentRA = ra;
537 currentDEC = dec;
538
539 NewRaDec(currentRA, currentDEC);
540
541 return true;
542}
543
545{
546 return abort_ieqpro(PortFD);
547}
548
550{
551#if 0
552 targetRA = GetAxis1Park();
553 targetDEC = GetAxis2Park();
554
555 if (set_ieqpro_ra(PortFD, targetRA) == false || set_ieqpro_dec(PortFD, targetDEC) == false)
556 {
557 LOG_ERROR("Error setting RA/DEC.");
558 return false;
559 }
560
561 if (slew_ieqpro(PortFD) == false)
562 {
563 LOG_ERROR("Failed to slew tp parking position.");
564 return false;
565 }
566
567 char RAStr[64] = {0}, DecStr[64] = {0};
568 fs_sexa(RAStr, targetRA, 2, 3600);
569 fs_sexa(DecStr, targetDEC, 2, 3600);
570
572 LOGF_INFO("Telescope parking in progress to RA: %s DEC: %s", RAStr, DecStr);
573
574 return true;
575#endif
576
577 double parkAz = GetAxis1Park();
578 double parkAlt = GetAxis2Park();
579
580 char AzStr[16], AltStr[16];
581 fs_sexa(AzStr, parkAz, 2, 3600);
582 fs_sexa(AltStr, parkAlt, 2, 3600);
583 LOGF_DEBUG("Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
584
585 INDI::IEquatorialCoordinates equatorialCoords {0, 0};
586 INDI::IHorizontalCoordinates horizontalCoords {parkAz, parkAlt};
587 INDI::HorizontalToEquatorial(&horizontalCoords, &m_Location, ln_get_julian_from_sys(), &equatorialCoords);
588
589 if (Goto(equatorialCoords.rightascension, equatorialCoords.declination))
590 {
592 LOG_INFO("Parking is in progress...");
593
594 return true;
595 }
596 else
597 return false;
598}
599
601{
603 {
604 SetParked(false);
606 return true;
607 }
608 else
609 return false;
610}
611
613{
614 if (isSimulation())
615 {
622 }
623
624 if (check_ieqpro_connection(PortFD) == false)
625 return false;
626
627 return true;
628}
629
630bool IEQProLegacy::updateTime(ln_date *utc, double utc_offset)
631{
632 struct ln_zonedate ltm;
633
634 ln_date_to_zonedate(utc, &ltm, utc_offset * 3600.0);
635
636 // Set Local Time
637 if (set_ieqpro_local_time(PortFD, ltm.hours, ltm.minutes, ltm.seconds) == false)
638 {
639 LOG_ERROR("Error setting local time.");
640 return false;
641 }
642
643 // Send it as YY (i.e. 2015 --> 15)
644 ltm.years -= 2000;
645
646 // Set Local date
647 if (set_ieqpro_local_date(PortFD, ltm.years, ltm.months, ltm.days) == false)
648 {
649 LOG_ERROR("Error setting local date.");
650 return false;
651 }
652
653 // UTC Offset
654 if (set_ieqpro_utc_offset(PortFD, utc_offset) == false)
655 {
656 LOG_ERROR("Error setting UTC Offset.");
657 return false;
658 }
659
660 LOG_INFO("Time and date updated.");
661
662 return true;
663}
664
665bool IEQProLegacy::updateLocation(double latitude, double longitude, double elevation)
666{
667 INDI_UNUSED(elevation);
668
669 if (longitude > 180)
670 longitude -= 360;
671
672 if (set_ieqpro_longitude(PortFD, longitude) == false)
673 {
674 LOG_ERROR("Failed to set longitude.");
675 return false;
676 }
677
678 if (set_ieqpro_latitude(PortFD, latitude) == false)
679 {
680 LOG_ERROR("Failed to set latitude.");
681 return false;
682 }
683
684 char l[32] = {0}, L[32] = {0};
685 fs_sexa(l, latitude, 3, 3600);
686 fs_sexa(L, longitude, 4, 3600);
687
688 LOGF_INFO("Site location updated to Lat %.32s - Long %.32s", l, L);
689
690 return true;
691}
692
694{
695 set_ieqpro_debug(enable);
696}
697
699{
700 set_ieqpro_simulation(enable);
701}
702
704{
706 {
707 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
708 return false;
709 }
710
711 switch (command)
712 {
713 case MOTION_START:
714 if (start_ieqpro_motion(PortFD, (dir == DIRECTION_NORTH ? IEQ_N : IEQ_S)) == false)
715 {
716 LOG_ERROR("Error setting N/S motion direction.");
717 return false;
718 }
719 else
720 LOGF_INFO("Moving toward %s.", (dir == DIRECTION_NORTH) ? "North" : "South");
721 break;
722
723 case MOTION_STOP:
724 if (stop_ieqpro_motion(PortFD, (dir == DIRECTION_NORTH ? IEQ_N : IEQ_S)) == false)
725 {
726 LOG_ERROR("Error stopping N/S motion.");
727 return false;
728 }
729 else
730 LOGF_INFO("%s motion stopped.", (dir == DIRECTION_NORTH) ? "North" : "South");
731 break;
732 }
733
734 return true;
735}
736
738{
740 {
741 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
742 return false;
743 }
744
745 switch (command)
746 {
747 case MOTION_START:
748 if (start_ieqpro_motion(PortFD, (dir == DIRECTION_WEST ? IEQ_W : IEQ_E)) == false)
749 {
750 LOG_ERROR("Error setting N/S motion direction.");
751 return false;
752 }
753 else
754 LOGF_INFO("Moving toward %s.", (dir == DIRECTION_WEST) ? "West" : "East");
755 break;
756
757 case MOTION_STOP:
758 if (stop_ieqpro_motion(PortFD, (dir == DIRECTION_WEST ? IEQ_W : IEQ_E)) == false)
759 {
760 LOG_ERROR("Error stopping W/E motion.");
761 return false;
762 }
763 else
764 LOGF_INFO("%s motion stopped.", (dir == DIRECTION_WEST) ? "West" : "East");
765 break;
766 }
767
768 return true;
769}
770
772{
773 bool rc = start_ieqpro_guide(PortFD, IEQ_N, ms);
774 return (rc ? IPS_OK : IPS_ALERT);
775}
776
778{
779 bool rc = start_ieqpro_guide(PortFD, IEQ_S, ms);
780 return (rc ? IPS_OK : IPS_ALERT);
781}
782
784{
785 bool rc = start_ieqpro_guide(PortFD, IEQ_E, ms);
786 return (rc ? IPS_OK : IPS_ALERT);
787}
788
790{
791 bool rc = start_ieqpro_guide(PortFD, IEQ_W, ms);
792 return (rc ? IPS_OK : IPS_ALERT);
793}
794
796{
797 IEQ_SLEW_RATE rate = static_cast<IEQ_SLEW_RATE>(index);
798 return set_ieqpro_slew_rate(PortFD, rate);
799}
800
802{
804
805 return true;
806}
807
809{
810 static struct timeval ltv;
811 struct timeval tv;
812 double dt, da, dx;
813 int nlocked;
814
815 /* update elapsed time since last poll, don't presume exactly POLLMS */
816 gettimeofday(&tv, nullptr);
817
818 if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
819 ltv = tv;
820
821 dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
822 ltv = tv;
823 da = SLEWRATE * dt;
824
825 /* Process per current state. We check the state of EQUATORIAL_COORDS and act accordingly */
826 switch (TrackState)
827 {
828 case SCOPE_IDLE:
829 currentRA += (TrackRateNP[AXIS_RA].getValue() / 3600.0 * dt) / 15.0;
830 currentRA = range24(currentRA);
831 break;
832
833 case SCOPE_TRACKING:
834 if (TrackModeSP[1].getState() == ISS_ON)
835 {
836 currentRA += ( ((TRACKRATE_SIDEREAL / 3600.0) - (TrackRateNP[AXIS_RA].getValue() / 3600.0)) * dt) / 15.0;
837 currentDEC += ( (TrackRateNP[AXIS_DE].getValue() / 3600.0) * dt);
838 }
839 break;
840
841 case SCOPE_SLEWING:
842 case SCOPE_PARKING:
843 /* slewing - nail it when both within one pulse @ SLEWRATE */
844 nlocked = 0;
845
846 dx = targetRA - currentRA;
847
848 // Take shortest path
849 if (fabs(dx) > 12)
850 dx *= -1;
851
852 if (fabs(dx) <= da)
853 {
854 currentRA = targetRA;
855 nlocked++;
856 }
857 else if (dx > 0)
858 currentRA += da / 15.;
859 else
860 currentRA -= da / 15.;
861
862 if (currentRA < 0)
863 currentRA += 24;
864 else if (currentRA > 24)
865 currentRA -= 24;
866
867 dx = targetDEC - currentDEC;
868 if (fabs(dx) <= da)
869 {
870 currentDEC = targetDEC;
871 nlocked++;
872 }
873 else if (dx > 0)
874 currentDEC += da;
875 else
876 currentDEC -= da;
877
878 if (nlocked == 2)
879 {
882 else
884 }
885
886 break;
887
888 default:
889 break;
890 }
891
892 set_sim_ra(currentRA);
893 set_sim_dec(currentDEC);
894}
895
897{
898 INDI::IEquatorialCoordinates equatorialCoords {currentRA, currentDEC};
899 INDI::IHorizontalCoordinates horizontalCoords {0, 0};
900 INDI::EquatorialToHorizontal(&equatorialCoords, &m_Location, ln_get_julian_from_sys(), &horizontalCoords);
901 double parkAZ = horizontalCoords.azimuth;
902 double parkAlt = horizontalCoords.altitude;
903
904 char AzStr[16], AltStr[16];
905 fs_sexa(AzStr, parkAZ, 2, 3600);
906 fs_sexa(AltStr, parkAlt, 2, 3600);
907
908 LOGF_DEBUG("Setting current parking position to coordinates Az (%s) Alt (%s)...", AzStr,
909 AltStr);
910
911 SetAxis1Park(parkAZ);
912 SetAxis2Park(parkAlt);
913
914 return true;
915}
916
918{
919 // By default azimuth 0
920 SetAxis1Park(0);
921
922 // Altitude = latitude of observer
924
925 return true;
926}
927
929{
930 IEQ_TRACK_RATE rate = static_cast<IEQ_TRACK_RATE>(mode);
931
932 if (set_ieqpro_track_mode(PortFD, rate))
933 return true;
934
935 return false;
936}
937
938bool IEQProLegacy::SetTrackRate(double raRate, double deRate)
939{
940 static bool deRateWarning = true;
941
942 // Convert to arcsecs/s to +/- 0.0100 accepted by
943 double ieqRARate = raRate - TRACKRATE_SIDEREAL;
944 if (deRate != 0 && deRateWarning)
945 {
946 // Only send warning once per session
947 deRateWarning = false;
948 LOG_WARN("Custom Declination tracking rate is not implemented yet.");
949 }
950
952 return true;
953
954 return false;
955}
956
958{
959 if (enabled)
960 {
961 // If we are engaging tracking, let us first set tracking mode, and if we have custom mode, then tracking rate.
962 // NOTE: Is this the correct order? or should tracking be switched on first before making these changes? Need to test.
963 SetTrackMode(TrackModeSP.findOnSwitchIndex());
964 if (TrackModeSP[TR_CUSTOM].getState() == ISS_ON)
965 SetTrackRate(TrackRateNP[AXIS_RA].getValue(), TrackRateNP[AXIS_DE].getValue());
966 }
967
968 return set_ieqpro_track_enabled(PortFD, enabled);
969}
@ FW_MODEL
@ FW_DEC
@ FW_RA
@ SR_1
@ SR_3
@ GPS_OFF
@ GPS_ON
#define MOUNTINFO_TAB
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool Park() override
Park the telescope to its home position.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual const char * getDefaultName() override
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
virtual void simulationTriggered(bool enable) override
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool isConnected() const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
uint32_t getDriverInterface() const
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void initProperties(const char *groupName)
Initialize guider properties. It is recommended to call this function within initProperties() of your...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
double GetAxis1Park() const
double GetAxis2Park() const
bool isParked()
isParked is mount currently parked?
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.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
IGeographicCoordinates m_Location
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
INDI::PropertyNumber TrackRateNP
INDI::PropertyNumber EqNP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertyText TimeTP
INDI::PropertyNumber LocationNP
#define SLEWRATE
Definition ieqpro.cpp:35
bool goto_ieqpro_home(int fd)
bool set_ieqpro_latitude(int fd, double latitude)
bool sync_ieqpro(int fd)
bool set_ieqpro_current_home(int fd)
void set_sim_gps_status(IEQ_GPS_STATUS value)
bool start_ieqpro_guide(int fd, IEQ_DIRECTION dir, uint32_t ms)
void set_sim_dec(double dec)
bool find_ieqpro_home(int fd)
bool slew_ieqpro(int fd)
void set_sim_hemisphere(IEQ_HEMISPHERE value)
bool set_ieqpro_local_date(int fd, int yy, int mm, int dd)
bool get_ieqpro_utc_date_time(int fd, double *utc_hours, int *yy, int *mm, int *dd, int *hh, int *minute, int *ss)
bool get_ieqpro_status(int fd, IEQInfo *info)
bool set_ieqpro_local_time(int fd, int hh, int mm, int ss)
void set_ieqpro_debug(bool enable)
bool get_ieqpro_coords(int fd, double *ra, double *dec)
bool park_ieqpro(int fd)
double ra
void set_ieqpro_device(const char *name)
void set_ieqpro_simulation(bool enable)
bool get_ieqpro_firmware(int fd, FirmwareInfo *info)
bool set_ieqpro_custom_ra_track_rate(int fd, double rate)
bool set_ieqpro_dec(int fd, double dec)
bool set_ieqpro_guide_rate(int fd, double raRate, double deRate)
bool abort_ieqpro(int fd)
bool unpark_ieqpro(int fd)
bool set_ieqpro_track_mode(int fd, IEQ_TRACK_RATE rate)
void set_sim_system_status(IEQ_SYSTEM_STATUS value)
void set_sim_slew_rate(IEQ_SLEW_RATE value)
bool get_ieqpro_latitude(int fd, double *latitude)
bool check_ieqpro_connection(int fd)
double dec
bool set_ieqpro_ra(int fd, double ra)
bool set_ieqpro_slew_rate(int fd, IEQ_SLEW_RATE rate)
bool get_ieqpro_guide_rate(int fd, double *raRate, double *deRate)
bool start_ieqpro_motion(int fd, IEQ_DIRECTION dir)
void set_sim_time_source(IEQ_TIME_SOURCE value)
bool set_ieqpro_utc_offset(int fd, double offset)
bool set_ieqpro_longitude(int fd, double longitude)
bool get_ieqpro_longitude(int fd, double *longitude)
void set_sim_ra(double ra)
bool set_ieqpro_track_enabled(int fd, bool enabled)
bool stop_ieqpro_motion(int fd, IEQ_DIRECTION dir)
void set_sim_track_rate(IEQ_TRACK_RATE value)
IEQ_HOME_OPERATION
@ IEQ_FIND_HOME
@ IEQ_SET_HOME
@ IEQ_GOTO_HOME
IEQ_TRACK_RATE
@ TR_SIDEREAL
@ TR_CUSTOM
@ TS_RS232
@ TS_CONTROLLER
@ HEMI_NORTH
@ HEMI_SOUTH
IEQ_SLEW_RATE
@ FW_CONTROLLER
@ FW_BOARD
@ GPS_DATA_OK
@ ST_STOPPED
@ ST_MERIDIAN_FLIPPING
@ ST_PARKED
@ ST_TRACKING_PEC_ON
@ ST_TRACKING_PEC_OFF
@ ST_SLEWING
@ ST_GUIDING
@ ST_HOME
#define RA_AXIS
#define DEC_AXIS
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
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_ATMOST1
Definition indiapi.h:172
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_NORTH
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition indicom.c:1311
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
Implementations for common driver routines.
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sidereal time given longitude and system clock.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition indidevapi.c:337
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition indidevapi.c:366
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:509
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
Definition indidevapi.c:416
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int 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 IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
INDI::GuiderInterface GI
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define 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 LOG_INFO(txt)
Definition indilogger.h:74
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
#define getDeviceName
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
void HorizontalToEquatorial(IHorizontalCoordinates *object, IGeographicCoordinates *observer, double JD, IEquatorialCoordinates *position)
HorizontalToEquatorial Calculate Equatorial EOD Coordinates from horizontal coordinates.
Definition libastro.cpp:161
std::string Model
IEQ_GPS_STATUS gpsStatus
IEQ_TIME_SOURCE timeSource
IEQ_SYSTEM_STATUS systemStatus
IEQ_TRACK_RATE trackRate
IEQ_HEMISPHERE hemisphere