Instrument Neutral Distributed Interface INDI 2.2.5
ieqpro.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 "ieqpro.h"
22#include "indicom.h"
24
25#include <libnova/sidereal_time.h>
26#include <libnova/transform.h>
27#include <memory>
28#include <thread>
29#include <chrono>
30
31#include <cmath>
32#include <cstring>
33
34/* Simulation Parameters */
35#define SLEWRATE 1 /* slew rate, degrees/s */
36
37#define MOUNTINFO_TAB "Mount Info"
38
39using namespace iEQ;
40
41// We declare an auto pointer to IEQPro.
42static std::unique_ptr<IEQPro> scope(new IEQPro());
43
45{
46 setVersion(1, 11);
47
48 driver.reset(new Base());
49
50 scopeInfo.gpsStatus = GPS_OFF;
51 scopeInfo.systemStatus = ST_STOPPED;
52 scopeInfo.trackRate = TR_SIDEREAL;
53 scopeInfo.slewRate = SR_1;
54 scopeInfo.timeSource = TS_RS232;
55 scopeInfo.hemisphere = HEMI_NORTH;
56
57 DBG_SCOPE = INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE");
58
62 9
63 );
64}
65
67{
68 return "iEQ";
69}
70
72{
74
75 /* Firmware */
76 // Note: the second field of the ':FW1#' reply is the Go2Nova hand controller
77 // firmware, which is distinct from the main board firmware. Element names are
78 // kept for config back-compat; only the display labels are clarified.
79 IUFillText(&FirmwareT[FW_MODEL], "Model", "Model", nullptr);
80 IUFillText(&FirmwareT[FW_BOARD], "Board", "Main Board", nullptr);
81 IUFillText(&FirmwareT[FW_CONTROLLER], "Controller", "Hand Controller", nullptr);
82 IUFillText(&FirmwareT[FW_RA], "RA", "RA", nullptr);
83 IUFillText(&FirmwareT[FW_DEC], "DEC", "DEC", nullptr);
84 IUFillTextVector(&FirmwareTP, FirmwareT, 5, getDeviceName(), "Firmware Info", "", MOUNTINFO_TAB, IP_RO, 0,
85 IPS_IDLE);
86
87 /* Tracking Mode */
88 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
89 AddTrackMode("TRACK_LUNAR", "Lunar");
90 AddTrackMode("TRACK_SOLAR", "Solar");
91 AddTrackMode("TRACK_KING", "King");
92 AddTrackMode("TRACK_CUSTOM", "Custom");
93
94 // Slew Rates
95 SlewRateSP[0].setLabel("1x");
96 SlewRateSP[1].setLabel("2x");
97 SlewRateSP[2].setLabel("8x");
98
99 SlewRateSP[3].setLabel("16x");
100 SlewRateSP[4].setLabel("64x");
101 SlewRateSP[5].setLabel("128x");
102 SlewRateSP[6].setLabel("256x");
103 SlewRateSP[7].setLabel("512x");
104 SlewRateSP[8].setLabel("MAX");
105
106 SlewRateSP.reset();
107 // 64x is the default
108 SlewRateSP[4].setState(ISS_ON);
109
110 // Set TrackRate limits within +/- 0.0100 of Sidereal rate
111 TrackRateNP[AXIS_RA].setMin(TRACKRATE_SIDEREAL - 0.01);
112 TrackRateNP[AXIS_RA].setMax(TRACKRATE_SIDEREAL + 0.01);
113 TrackRateNP[AXIS_DE].setMin(-0.01);
114 TrackRateNP[AXIS_DE].setMax(0.01);
115
116 /* GPS Status */
117 IUFillSwitch(&GPSStatusS[GPS_OFF], "Off", "", ISS_ON);
118 IUFillSwitch(&GPSStatusS[GPS_ON], "On", "", ISS_OFF);
119 IUFillSwitch(&GPSStatusS[GPS_DATA_OK], "Data OK", "", ISS_OFF);
120 IUFillSwitchVector(&GPSStatusSP, GPSStatusS, 3, getDeviceName(), "GPS_STATUS", "GPS", MOUNTINFO_TAB, IP_RO,
122
123 /* Time Source */
124 IUFillSwitch(&TimeSourceS[TS_RS232], "RS232", "", ISS_ON);
125 IUFillSwitch(&TimeSourceS[TS_CONTROLLER], "Controller", "", ISS_OFF);
126 IUFillSwitch(&TimeSourceS[TS_GPS], "GPS", "", ISS_OFF);
127 IUFillSwitchVector(&TimeSourceSP, TimeSourceS, 3, getDeviceName(), "TIME_SOURCE", "Time Source", MOUNTINFO_TAB,
129
130 /* Hemisphere */
131 IUFillSwitch(&HemisphereS[HEMI_SOUTH], "South", "", ISS_OFF);
132 IUFillSwitch(&HemisphereS[HEMI_NORTH], "North", "", ISS_ON);
133 IUFillSwitchVector(&HemisphereSP, HemisphereS, 2, getDeviceName(), "HEMISPHERE", "Hemisphere", MOUNTINFO_TAB, IP_RO,
135
136 /* How fast do we guide compared to sidereal rate */
137 IUFillNumber(&GuideRateN[RA_AXIS], "RA_GUIDE_RATE", "RA", "%.2f", 0.01, 0.9, 0.1, 0.5);
138 IUFillNumber(&GuideRateN[DEC_AXIS], "DE_GUIDE_RATE", "DE", "%.2f", 0.1, 0.99, 0.1, 0.5);
139 IUFillNumberVector(&GuideRateNP, GuideRateN, 2, getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RW, 0,
140 IPS_IDLE);
141
143
145
147
149
151
152 driver->setDeviceName(getDeviceName());
153
154 // Only CEM40 and GEM45 have 115200 baud, rest are 9600
155 if (strstr(getDeviceName(), "CEM40") || strstr(getDeviceName(), "GEM45"))
157
159 currentDEC = LocationNP[LOCATION_LATITUDE].getValue() > 0 ? 90 : -90;
160 return true;
161}
162
164{
165
166 if (isConnected())
167 {
168 getStartupData();
169
171
172 if (canGuideRate)
173 defineProperty(&GuideRateNP);
174
175 defineProperty(&FirmwareTP);
176 defineProperty(&GPSStatusSP);
177 defineProperty(&TimeSourceSP);
178 defineProperty(&HemisphereSP);
179 }
180 else
181 {
183
184 if (canGuideRate)
185 deleteProperty(GuideRateNP.name);
186
187 deleteProperty(FirmwareTP.name);
188 deleteProperty(GPSStatusSP.name);
189 deleteProperty(TimeSourceSP.name);
190 deleteProperty(HemisphereSP.name);
191 }
192
194
195 return true;
196}
197
198void IEQPro::getStartupData()
199{
200 LOG_DEBUG("Getting firmware data...");
201
202 firmwareInfo = driver->getFirmwareInfo();
203
204 IUSaveText(&FirmwareT[0], firmwareInfo.Model.c_str());
205
206 // Alt-Az models (e.g. "Cube II AA", "AZ Mount Pro") and dual-mode mounts in Alt-Az mode
207 {
208 const std::string &model = firmwareInfo.Model;
209 const bool altAz = (model.size() >= 3 && model.compare(model.size() - 3, 3, " AA") == 0) ||
210 model.find("AZ Mount") != std::string::npos;
212 }
213
214 IUSaveText(&FirmwareT[1], firmwareInfo.MainBoardFirmware.c_str());
215 // The mount reports "xxxxxx" for the hand controller firmware when no Go2Nova
216 // hand controller is present in the serial path (e.g. connected directly to the
217 // mount's RS-232 port). Show "N/A" instead of the raw placeholder.
218 const bool controllerReported = !firmwareInfo.ControllerFirmware.empty() &&
219 firmwareInfo.ControllerFirmware.find_first_not_of('x') != std::string::npos;
220 IUSaveText(&FirmwareT[2], controllerReported ? firmwareInfo.ControllerFirmware.c_str() : "N/A");
221 IUSaveText(&FirmwareT[3], firmwareInfo.RAFirmware.c_str());
222 IUSaveText(&FirmwareT[4], firmwareInfo.DEFirmware.c_str());
223
224 FirmwareTP.s = IPS_OK;
225 IDSetText(&FirmwareTP, nullptr);
226
227
228 LOG_DEBUG("Getting guiding rate...");
229 double raGuideRate = 0, deGuideRate = 0;
230 if (driver->getGuideRate(&raGuideRate, &deGuideRate))
231 {
232 GuideRateN[RA_AXIS].value = raGuideRate;
233 GuideRateN[DEC_AXIS].value = deGuideRate;
234 IDSetNumber(&GuideRateNP, nullptr);
235 }
236
237 double utc_offset;
238 int yy, dd, mm, hh, minute, ss;
239 if (driver->getUTCDateTime(&utc_offset, &yy, &mm, &dd, &hh, &minute, &ss))
240 {
241 char isoDateTime[32] = {0};
242 char utcOffset[8] = {0};
243
244 snprintf(isoDateTime, 32, "%04d-%02d-%02dT%02d:%02d:%02d", yy, mm, dd, hh, minute, ss);
245 snprintf(utcOffset, 8, "%4.2f", utc_offset);
246
247 TimeTP[UTC].setText(isoDateTime);
248 TimeTP[OFFSET].setText(utcOffset);
249
250 LOGF_INFO("Mount UTC offset is %s. UTC time is %s", utcOffset, isoDateTime);
251
252 TimeTP.setState(IPS_OK);
253 TimeTP.apply();
254 }
255
256 // Get Longitude and Latitude from mount
257 double longitude = 0, latitude = 0;
258 if (driver->getStatus(&scopeInfo))
259 {
260 longitude = scopeInfo.longitude;
261 latitude = scopeInfo.latitude;
262
263 // Convert to INDI standard longitude (0 to 360 Eastward)
264 if (longitude < 0)
265 longitude += 360;
266
267 LOGF_INFO("Mount Longitude %g Latitude %g", longitude, latitude);
268
269 LocationNP[LOCATION_LATITUDE].setValue(latitude);
270 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
271 LocationNP.setState(IPS_OK);
272
273 LocationNP.apply();
274
275 saveConfig(true, "GEOGRAPHIC_COORD");
276 }
277 else if (IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LONG", &longitude) == 0 &&
278 IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LAT", &latitude) == 0)
279 {
280 LocationNP[LOCATION_LATITUDE].setValue(latitude);
281 LocationNP[LOCATION_LONGITUDE].setValue(longitude);
282 LocationNP.setState(IPS_OK);
283
284 LocationNP.apply();
285 }
286
287 if (InitPark())
288 {
289 // If loading parking data is successful, we just set the default parking values.
290 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
292 }
293 else
294 {
295 // Otherwise, we set all parking data to default in case no parking data is found.
296 SetAxis1Park(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
298 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
300 }
301
302 // can we read pier side?
304 if (driver->getPierSide(&pierSide) && pierSide != IEQ_PIER_UNKNOWN)
305 {
306 // add the pier side capability
307 auto cap = GetTelescopeCapability();
310 }
311
312 // if (isSimulation())
313 // {
314 // if (isParked())
315 // set_sim_system_status(ST_PARKED);
316 // else
317 // set_sim_system_status(ST_STOPPED);
318 // }
319}
320
321bool IEQPro::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
322{
323 // Check guider interface
324 if (GI::processNumber(dev, name, values, names, n))
325 return true;
326
327 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
328 {
329 // Guiding Rate
330 if (!strcmp(name, GuideRateNP.name))
331 {
332 IUUpdateNumber(&GuideRateNP, values, names, n);
333
334 if (driver->setGuideRate(GuideRateN[RA_AXIS].value, GuideRateN[DEC_AXIS].value))
335 GuideRateNP.s = IPS_OK;
336 else
337 GuideRateNP.s = IPS_ALERT;
338
339 IDSetNumber(&GuideRateNP, nullptr);
340
341 return true;
342 }
343 }
344
345 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
346}
347
349{
350 iEQ::Base::Info newInfo;
351
352 bool rc = driver->getStatus(&newInfo);
353
354 if (rc)
355 {
356 IUResetSwitch(&GPSStatusSP);
357 GPSStatusS[newInfo.gpsStatus].s = ISS_ON;
358 IDSetSwitch(&GPSStatusSP, nullptr);
359
360 IUResetSwitch(&TimeSourceSP);
361 TimeSourceS[newInfo.timeSource].s = ISS_ON;
362 IDSetSwitch(&TimeSourceSP, nullptr);
363
364 IUResetSwitch(&HemisphereSP);
365 HemisphereS[newInfo.hemisphere].s = ISS_ON;
366 IDSetSwitch(&HemisphereSP, nullptr);
367
368 /*
369 TelescopeTrackMode trackMode = TRACK_SIDEREAL;
370
371 switch (newInfo.trackRate)
372 {
373 case TR_SIDEREAL:
374 trackMode = TRACK_SIDEREAL;
375 break;
376 case TR_SOLAR:
377 trackMode = TRACK_SOLAR;
378 break;
379 case TR_LUNAR:
380 trackMode = TRACK_LUNAR;
381 break;
382 case TR_KING:
383 trackMode = TRACK_SIDEREAL;
384 break;
385 case TR_CUSTOM:
386 trackMode = TRACK_CUSTOM;
387 break;
388 }*/
389
390 switch (newInfo.systemStatus)
391 {
392 case ST_STOPPED:
393 TrackModeSP.setState(IPS_IDLE);
394 // If we cannot park natively and we already parked
395 // scope, we do not want its state to change to IDLE
396 // For scopes that can park natively, ST_PARKED would be
397 // set already.
398 if (canParkNatively || TrackState != SCOPE_PARKED)
400 break;
401 case ST_PARKED:
402 TrackModeSP.setState(IPS_IDLE);
404 if (!isParked())
405 SetParked(true);
406 // If a Home operation was in progress, mark it complete.
407 if (HomeSP.getState() == IPS_BUSY)
408 {
409 HomeSP.reset();
410 HomeSP.setState(IPS_OK);
411 HomeSP.apply();
412 LOG_INFO("Mount arrived at home position.");
413 }
414 break;
415 case ST_HOME:
416 TrackModeSP.setState(IPS_IDLE);
418 // The mount reports ST_HOME once it settles on the home switch.
419 // Clear the Home property only if a Home operation was actually
420 // requested (it is BUSY); the mount also reports ST_HOME at rest.
421 if (HomeSP.getState() == IPS_BUSY)
422 {
423 HomeSP.reset();
424 HomeSP.setState(IPS_OK);
425 HomeSP.apply();
426 LOG_INFO("Mount arrived at home position.");
427 }
428 break;
429 case ST_SLEWING:
431 slewDirty = true;
434 break;
437 case ST_GUIDING:
438 if (TrackState == SCOPE_PARKING && canParkNatively == false)
439 {
440 if (slewDirty)
441 {
442 LOG_INFO("Manual parking complete. Shut the mount down.");
443 TrackModeSP.setState(IPS_IDLE);
445 SetTrackEnabled(false);
446 SetParked(true);
447 slewDirty = false;
448 }
449 }
450 else
451 {
452 TrackModeSP.setState(IPS_BUSY);
454 if (scopeInfo.systemStatus == ST_SLEWING)
455 LOG_INFO("Slew complete, tracking...");
456 else if (scopeInfo.systemStatus == ST_MERIDIAN_FLIPPING)
457 LOG_INFO("Meridian flip complete, tracking...");
458 }
459 break;
460 }
461
462 TrackModeSP.reset();
463 TrackModeSP[newInfo.trackRate].setState(ISS_ON);
464 TrackModeSP.apply();
465
466 scopeInfo = newInfo;
467 }
468
469 if (HasPierSide())
470 {
471 IEQ_PIER_SIDE pierSide;
472 if (driver->getPierSide(&pierSide))
473 {
475 switch (pierSide)
476 {
477 case IEQ_PIER_UNKNOWN:
479 tps = PIER_UNKNOWN;
480 break;
481 case IEQ_PIER_EAST:
482 tps = PIER_EAST;
483 break;
484 case IEQ_PIER_WEST:
485 tps = PIER_WEST;
486 break;
487 }
488 setPierSide(tps);
489 }
490 }
491
492 rc = driver->getCoords(&currentRA, &currentDEC);
493
494 if (rc)
495 NewRaDec(currentRA, currentDEC);
496
497 return rc;
498}
499
500bool IEQPro::Goto(double r, double d)
501{
502 targetRA = r;
503 targetDEC = d;
504 char RAStr[64] = {0}, DecStr[64] = {0};
505
506 fs_sexa(RAStr, targetRA, 2, 3600);
507 fs_sexa(DecStr, targetDEC, 2, 3600);
508
509 if (driver->setRA(r) == false || driver->setDE(d) == false)
510 {
511 LOG_ERROR("Error setting RA/DEC.");
512 return false;
513 }
514
515 if (driver->slew() == false)
516 {
517 LOG_ERROR("Failed to slew.");
518 return false;
519 }
520
521 iEQ::Base::Info newInfo;
522
523 // Wait until the mount system status changes to SLEWING
524 // up to 500ms
525 for (int i = 0; i < 5; i++)
526 {
527 bool rc = driver->getStatus(&newInfo);
528 if (rc && newInfo.systemStatus == ST_SLEWING)
529 break;
530 std::this_thread::sleep_for(std::chrono::milliseconds(100));
531 }
532
533 if (newInfo.systemStatus == ST_SLEWING)
534 {
536 LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
537 return true;
538 }
539 else
540 {
541 LOG_ERROR("Mount status failed to update to slewing.");
542 return false;
543 }
544}
545
546bool IEQPro::Sync(double ra, double dec)
547{
548 if (driver->setRA(ra) == false || driver->setDE(dec) == false)
549 {
550 LOG_ERROR("Error setting RA/DEC.");
551 return false;
552 }
553
554 if (driver->sync() == false)
555 {
556 LOG_ERROR("Failed to sync.");
557 }
558
559 EqNP.setState(IPS_OK);
560
561 currentRA = ra;
562 currentDEC = dec;
563
564 NewRaDec(currentRA, currentDEC);
565
566 return true;
567}
568
570{
571 return driver->abort();
572}
573
575{
576#if 0
577 targetRA = GetAxis1Park();
578 targetDEC = GetAxis2Park();
579
580 if (set_ieqpro_ra(PortFD, targetRA) == false || set_ieqpro_dec(PortFD, targetDEC) == false)
581 {
582 LOG_ERROR("Error setting RA/DEC.");
583 return false;
584 }
585
586 if (slew_ieqpro(PortFD) == false)
587 {
588 LOG_ERROR("Failed to slew tp parking position.");
589 return false;
590 }
591
592 char RAStr[64] = {0}, DecStr[64] = {0};
593 fs_sexa(RAStr, targetRA, 2, 3600);
594 fs_sexa(DecStr, targetDEC, 2, 3600);
595
597 LOGF_INFO("Telescope parking in progress to RA: %s DEC: %s", RAStr, DecStr);
598
599 return true;
600#endif
601
602 double parkAz = GetAxis1Park();
603 double parkAlt = GetAxis2Park();
604
605 char AzStr[16], AltStr[16];
606 fs_sexa(AzStr, parkAz, 2, 3600);
607 fs_sexa(AltStr, parkAlt, 2, 3600);
608 LOGF_DEBUG("Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
609
610 // Check if mount supports native Alt/Az parking
611 if (canParkNatively)
612 {
613 if (driver->setParkAz(parkAz) && driver->setParkAlt(parkAlt))
614 {
615 if (driver->park())
616 {
618 LOG_INFO("Parking is in progress...");
619 return true;
620 }
621 else
622 return false;
623 }
624 else
625 return false;
626 }
627
628 // Otherwise fallback to Alt/Az --> RA/DE parking
629 INDI::IHorizontalCoordinates horizontalPos;
630 horizontalPos.azimuth = parkAz;
631 horizontalPos.altitude = parkAlt;
632 INDI::IEquatorialCoordinates equatorialPos;
633
634 INDI::HorizontalToEquatorial(&horizontalPos, &m_Location, ln_get_julian_from_sys(), &equatorialPos);
635
636 if (Goto(equatorialPos.rightascension, equatorialPos.declination))
637 {
639 LOG_INFO("Parking is in progress...");
640
641 slewDirty = false;
642 return true;
643 }
644 else
645 return false;
646}
647
649{
650 // If we can park natively, let's try to unpark the mount first.
651 // If that fails, we return. Otherwise, we proceed even when
652 // we are manually unparking.
653 if (canParkNatively && driver->unpark() == false)
654 return false;
655
656 SetParked(false);
658 return true;
659}
660
662{
663 // if (isSimulation())
664 // {
665 // set_sim_gps_status(GPS_DATA_OK);
666 // set_sim_system_status(ST_STOPPED);
667 // set_sim_track_rate(TR_SIDEREAL);
668 // set_sim_slew_rate(SR_3);
669 // set_sim_time_source(TS_GPS);
670 // set_sim_hemisphere(HEMI_NORTH);
671 // }
672
673 if (driver->initCommunication(PortFD) == false)
674 return false;
675
676 canParkNatively = driver->isCommandSupported("MP1", true);
677 canFindHome = driver->isCommandSupported("MSH", true);
678 canGuideRate = driver->isCommandSupported("RG", true);
679
680 return true;
681}
682
683bool IEQPro::updateTime(ln_date *utc, double utc_offset)
684{
685 struct ln_zonedate ltm;
686
687 ln_date_to_zonedate(utc, &ltm, utc_offset * 3600.0);
688
689 // Set Local Time
690 if (driver->setLocalTime(ltm.hours, ltm.minutes, ltm.seconds) == false)
691 {
692 LOG_ERROR("Error setting local time.");
693 return false;
694 }
695
696 // Send it as YY (i.e. 2015 --> 15)
697 ltm.years -= 2000;
698
699 // Set Local date
700 if (driver->setLocalDate(ltm.years, ltm.months, ltm.days) == false)
701 {
702 LOG_ERROR("Error setting local date.");
703 return false;
704 }
705
706 // UTC Offset
707 if (driver->setUTCOffset(utc_offset) == false)
708 {
709 LOG_ERROR("Error setting UTC Offset.");
710 return false;
711 }
712
713 LOG_INFO("Time and date updated.");
714
715 return true;
716}
717
718bool IEQPro::updateLocation(double latitude, double longitude, double elevation)
719{
720 INDI_UNUSED(elevation);
721
722 if (longitude > 180)
723 longitude -= 360;
724
725 if (driver->setLongitude(longitude) == false)
726 {
727 LOG_ERROR("Failed to set longitude.");
728 return false;
729 }
730
731 if (driver->setLatitude(latitude) == false)
732 {
733 LOG_ERROR("Failed to set latitude.");
734 return false;
735 }
736
737 char l[32] = {0}, L[32] = {0};
738 fs_sexa(l, latitude, 3, 3600);
739 fs_sexa(L, longitude, 4, 3600);
740
741 LOGF_INFO("Site location updated to Lat %.32s - Long %.32s", l, L);
742
743 return true;
744}
745
746void IEQPro::debugTriggered(bool enable)
747{
748 driver->setDebugEnabled(enable);
749}
750
752{
753 INDI_UNUSED(enable);
754 //driver->setSi(enable);
755}
756
758{
760 {
761 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
762 return false;
763 }
764
765 switch (command)
766 {
767 case MOTION_START:
768 if (driver->startMotion((dir == DIRECTION_NORTH ? IEQ_N : IEQ_S)) == false)
769 {
770 LOG_ERROR("Error setting N/S motion direction.");
771 return false;
772 }
773 else
774 LOGF_INFO("Moving toward %s.", (dir == DIRECTION_NORTH) ? "North" : "South");
775 break;
776
777 case MOTION_STOP:
778 if (driver->stopMotion((dir == DIRECTION_NORTH ? IEQ_N : IEQ_S)) == false)
779 {
780 LOG_ERROR("Error stopping N/S motion.");
781 return false;
782 }
783 else
784 LOGF_INFO("%s motion stopped.", (dir == DIRECTION_NORTH) ? "North" : "South");
785 break;
786 }
787
788 return true;
789}
790
792{
794 {
795 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
796 return false;
797 }
798
799 switch (command)
800 {
801 case MOTION_START:
802 if (driver->startMotion((dir == DIRECTION_WEST ? IEQ_W : IEQ_E)) == false)
803 {
804 LOG_ERROR("Error setting N/S motion direction.");
805 return false;
806 }
807 else
808 LOGF_INFO("Moving toward %s.", (dir == DIRECTION_WEST) ? "West" : "East");
809 break;
810
811 case MOTION_STOP:
812 if (driver->stopMotion((dir == DIRECTION_WEST ? IEQ_W : IEQ_E)) == false)
813 {
814 LOG_ERROR("Error stopping W/E motion.");
815 return false;
816 }
817 else
818 LOGF_INFO("%s motion stopped.", (dir == DIRECTION_WEST) ? "West" : "East");
819 break;
820 }
821
822 return true;
823}
824
826{
827 bool rc = driver->startGuide(IEQ_N, ms);
828 return (rc ? IPS_OK : IPS_ALERT);
829}
830
832{
833 bool rc = driver->startGuide(IEQ_S, ms);
834 return (rc ? IPS_OK : IPS_ALERT);
835}
836
838{
839 bool rc = driver->startGuide(IEQ_E, ms);
840 return (rc ? IPS_OK : IPS_ALERT);
841}
842
844{
845 bool rc = driver->startGuide(IEQ_W, ms);
846 return (rc ? IPS_OK : IPS_ALERT);
847}
848
849bool IEQPro::SetSlewRate(int index)
850{
851 SlewRate rate = static_cast<SlewRate>(index);
852 return driver->setSlewRate(rate);
853}
854
856{
858
859 return true;
860}
861
862//void IEQPro::mountSim()
863//{
864// static struct timeval ltv;
865// struct timeval tv;
866// double dt, da, dx;
867// int nlocked;
868
869// /* update elapsed time since last poll, don't presume exactly POLLMS */
870// gettimeofday(&tv, nullptr);
871
872// if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
873// ltv = tv;
874
875// dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
876// ltv = tv;
877// da = SLEWRATE * dt;
878
879// /* Process per current state. We check the state of EQUATORIAL_COORDS and act accordingly */
880// switch (TrackState)
881// {
882// case SCOPE_IDLE:
883// currentRA += (TrackRateN[AXIS_RA].value / 3600.0 * dt) / 15.0;
884// currentRA = range24(currentRA);
885// break;
886
887// case SCOPE_TRACKING:
888// if (TrackModeS[1].s == ISS_ON)
889// {
890// currentRA += ( ((TRACKRATE_SIDEREAL / 3600.0) - (TrackRateN[AXIS_RA].value / 3600.0)) * dt) / 15.0;
891// currentDEC += ( (TrackRateN[AXIS_DE].value / 3600.0) * dt);
892// }
893// break;
894
895// case SCOPE_SLEWING:
896// case SCOPE_PARKING:
897// /* slewing - nail it when both within one pulse @ SLEWRATE */
898// nlocked = 0;
899
900// dx = targetRA - currentRA;
901
902// // Take shortest path
903// if (fabs(dx) > 12)
904// dx *= -1;
905
906// if (fabs(dx) <= da)
907// {
908// currentRA = targetRA;
909// nlocked++;
910// }
911// else if (dx > 0)
912// currentRA += da / 15.;
913// else
914// currentRA -= da / 15.;
915
916// if (currentRA < 0)
917// currentRA += 24;
918// else if (currentRA > 24)
919// currentRA -= 24;
920
921// dx = targetDEC - currentDEC;
922// if (fabs(dx) <= da)
923// {
924// currentDEC = targetDEC;
925// nlocked++;
926// }
927// else if (dx > 0)
928// currentDEC += da;
929// else
930// currentDEC -= da;
931
932// if (nlocked == 2)
933// {
934// if (TrackState == SCOPE_SLEWING)
935// set_sim_system_status(ST_TRACKING_PEC_OFF);
936// else
937// set_sim_system_status(ST_PARKED);
938// }
939
940// break;
941
942// default:
943// break;
944// }
945
946// set_sim_ra(currentRA);
947// set_sim_dec(currentDEC);
948//}
949
951{
952 INDI::IEquatorialCoordinates equatorialCoords {currentRA, currentDEC};
953 INDI::IHorizontalCoordinates horizontalCoords {0, 0};
954 INDI::EquatorialToHorizontal(&equatorialCoords, &m_Location, ln_get_julian_from_sys(), &horizontalCoords);
955 double parkAZ = horizontalCoords.azimuth;
956 double parkAlt = horizontalCoords.altitude;
957 char AzStr[16], AltStr[16];
958 fs_sexa(AzStr, parkAZ, 2, 3600);
959 fs_sexa(AltStr, parkAlt, 2, 3600);
960 LOGF_DEBUG("Setting current parking position to coordinates Az (%s) Alt (%s)...", AzStr, AltStr);
961 SetAxis1Park(parkAZ);
962 SetAxis2Park(parkAlt);
963
964 return true;
965}
966
968{
969 // By default azimuth 0
970 SetAxis1Park(0);
971
972 // Altitude = latitude of observer
974
975 return true;
976}
977
978bool IEQPro::SetTrackMode(uint8_t mode)
979{
980 TrackRate rate = static_cast<TrackRate>(mode);
981
982 if (driver->setTrackMode(rate))
983 return true;
984
985 return false;
986}
987
988bool IEQPro::SetTrackRate(double raRate, double deRate)
989{
990 static bool deRateWarning = true;
991
992 // Convert to arcsecs/s to +/- 0.0100 accepted by
993 double ieqRARate = raRate - TRACKRATE_SIDEREAL;
994 if (deRate != 0 && deRateWarning)
995 {
996 // Only send warning once per session
997 deRateWarning = false;
998 LOG_WARN("Custom Declination tracking rate is not implemented yet.");
999 }
1000
1001 if (driver->setCustomRATrackRate(ieqRARate))
1002 return true;
1003
1004 return false;
1005}
1006
1007bool IEQPro::SetTrackEnabled(bool enabled)
1008{
1009 if (enabled)
1010 {
1011 // If we are engaging tracking, let us first set tracking mode, and if we have custom mode, then tracking rate.
1012 // NOTE: Is this the correct order? or should tracking be switched on first before making these changes? Need to test.
1013 SetTrackMode(TrackModeSP.findOnSwitchIndex());
1014 if (TrackModeSP[TR_CUSTOM].getState() == ISS_ON)
1015 SetTrackRate(TrackRateNP[AXIS_RA].getValue(), TrackRateNP[AXIS_DE].getValue());
1016 }
1017
1018 return driver->setTrackEnabled(enabled);
1019}
1020
1022{
1023 switch (action)
1024 {
1025 case HOME_FIND:
1026 if (!canFindHome && (firmwareInfo.Model.find("CEM") == std::string::npos &&
1027 firmwareInfo.Model.find("GEM45") == std::string::npos &&
1028 firmwareInfo.Model.find("HAE") == std::string::npos &&
1029 firmwareInfo.Model.find("HAZ") == std::string::npos &&
1030 firmwareInfo.Model.find("HEM") == std::string::npos))
1031 {
1032 LOG_WARN("Home search is not supported in this model.");
1033 return IPS_ALERT;
1034 }
1035
1036 if (driver->findHome() == false)
1037 {
1038 return IPS_ALERT;
1039 }
1040
1041 LOG_INFO("Searching for home position...");
1042 return IPS_BUSY;
1043
1044 case HOME_SET:
1045 if (driver->setCurrentHome() == false)
1046 {
1047 return IPS_ALERT;
1048 }
1049
1050 LOG_INFO("Home position set to current coordinates.");
1051 return IPS_OK;
1052
1053 case HOME_GO:
1054 if (driver->gotoHome() == false)
1055 {
1056 return IPS_ALERT;
1057 }
1058
1059 LOG_INFO("Slewing to home position...");
1060 return IPS_BUSY;
1061
1062 default:
1063 return IPS_ALERT;
1064 }
1065
1066 return IPS_ALERT;
1067}
@ FW_MODEL
@ FW_DEC
@ FW_RA
@ SR_1
@ GPS_OFF
@ GPS_ON
#define MOUNTINFO_TAB
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
Definition ieqpro.cpp:831
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
Definition ieqpro.cpp:1007
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition ieqpro.cpp:855
IEQPro()
Definition ieqpro.cpp:44
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
Definition ieqpro.cpp:500
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition ieqpro.cpp:71
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Definition ieqpro.cpp:546
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
Definition ieqpro.cpp:825
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition ieqpro.cpp:967
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
Definition ieqpro.cpp:163
virtual bool Handshake() override
perform handshake with device to check communication
Definition ieqpro.cpp:661
virtual bool UnPark() override
Unpark the telescope if already parked.
Definition ieqpro.cpp:648
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition ieqpro.cpp:746
virtual void simulationTriggered(bool enable) override
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
Definition ieqpro.cpp:751
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
Definition ieqpro.cpp:843
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition ieqpro.cpp:950
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
Definition ieqpro.cpp:849
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
Definition ieqpro.cpp:569
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
Definition ieqpro.cpp:837
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
Definition ieqpro.cpp:791
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
Definition ieqpro.cpp:683
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition ieqpro.cpp:321
virtual const char * getDefaultName() override
Definition ieqpro.cpp:66
virtual bool ReadScopeStatus() override
Read telescope status.
Definition ieqpro.cpp:348
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
Definition ieqpro.cpp:988
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
Definition ieqpro.cpp:757
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Execute a homing action.
Definition ieqpro.cpp:1021
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
Definition ieqpro.cpp:978
virtual bool Park() override
Park the telescope to its home position.
Definition ieqpro.cpp:574
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
Definition ieqpro.cpp:718
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)
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
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
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.
The BaseFirmware class provides control for iOptron version 2014 v2.0 protocol.
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 HomeSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertyText TimeTP
INDI::PropertyNumber LocationNP
bool slew_ieqpro(int fd)
double ra
bool set_ieqpro_dec(int fd, double dec)
double dec
bool set_ieqpro_ra(int fd, double ra)
#define RA_AXIS
#define DEC_AXIS
@ 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
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_WEST
INDI_DIR_NS
@ 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
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
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
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
@ TR_SIDEREAL
@ TR_CUSTOM
@ TS_CONTROLLER
@ TS_RS232
@ FW_BOARD
@ FW_CONTROLLER
@ GPS_DATA_OK
@ HEMI_NORTH
@ HEMI_SOUTH
@ ST_HOME
@ ST_SLEWING
@ ST_MERIDIAN_FLIPPING
@ ST_TRACKING_PEC_OFF
@ ST_STOPPED
@ ST_TRACKING_PEC_ON
@ ST_GUIDING
@ ST_PARKED
IEQ_PIER_SIDE
@ IEQ_PIER_EAST
@ IEQ_PIER_WEST
@ IEQ_PIER_UNCERTAIN
@ IEQ_PIER_UNKNOWN
TrackRate trackRate
SystemStatus systemStatus
TimeSource timeSource
Hemisphere hemisphere
GPSStatus gpsStatus