7#include <indi/indidevice.h>
11#include "clientmanagerlite.h"
12#include "inditelescopelite.h"
14#include "kstarslite.h"
15#include "skymaplite.h"
17TelescopeLite::TelescopeLite(INDI::BaseDevice *device)
18 : minAlt(-1), maxAlt(-1), IsParked(false), clientManager(
KStarsLite::Instance()->clientManagerLite()),
19 baseDevice(device), slewRateIndex(0)
21 setDeviceName(device->getDeviceName());
23 connect(clientManager, &ClientManagerLite::newINDIProperty,
this, &TelescopeLite::updateSlewRate);
24 connect(clientManager, &ClientManagerLite::newINDISwitch,
this, &TelescopeLite::updateSlewRate);
27void TelescopeLite::updateSlewRate(
const QString &deviceName,
const QString &propName)
29 if (deviceName == baseDevice->getDeviceName() && propName ==
"TELESCOPE_SLEW_RATE")
31 auto slewRateSP = baseDevice->getSwitch(
"TELESCOPE_SLEW_RATE");
33 for (
int i = 0; i < slewRateSP->count(); ++i)
35 if (slewRateSP->at(i).getState() == ISS_ON)
41 m_slewRateLabels.
clear();
42 for (
int i = 0; i < slewRateSP->count(); ++i)
44 m_slewRateLabels.
push_back(slewRateSP->at(i)->getLabel());
46 emit slewRateUpdate(index, m_slewRateLabels.
size());
51TelescopeLite::~TelescopeLite()
55void TelescopeLite::setSlewDecreasable(
bool slewDecreasable)
57 if (m_slewDecreasable != slewDecreasable)
59 m_slewDecreasable = slewDecreasable;
60 emit slewDecreasableChanged(slewDecreasable);
64void TelescopeLite::setSlewIncreasable(
bool slewIncreasable)
66 if (m_slewIncreasable != slewIncreasable)
68 m_slewIncreasable = slewIncreasable;
69 emit slewIncreasableChanged(slewIncreasable);
73void TelescopeLite::setSlewRateLabel(
const QString &slewRateLabel)
75 if (m_slewRateLabel != slewRateLabel)
77 m_slewRateLabel = slewRateLabel;
78 emit slewRateLabelChanged(slewRateLabel);
82void TelescopeLite::setDeviceName(
const QString &deviceName)
84 if (m_deviceName != deviceName)
86 m_deviceName = deviceName;
87 emit deviceNameChanged(deviceName);
91void TelescopeLite::registerProperty(INDI::Property prop)
93 if (prop->isNameMatch(
"TELESCOPE_INFO"))
95 auto ti = prop->getNumber();
104 if (prop->isNameMatch(
"TELESCOPE_PARK"))
106 auto svp = prop->getSwitch();
110 auto sp = svp->findWidgetByName(
"PARK");
113 IsParked = ((sp->getState() == ISS_ON) && svp->getState() == IPS_OK);
119void TelescopeLite::processNumber(INumberVectorProperty *nvp)
121 if (!strcmp(nvp->name,
"EQUATORIAL_EOD_COORD"))
123 INumber *RA = IUFindNumber(nvp,
"RA");
124 INumber *DEC = IUFindNumber(nvp,
"DEC");
126 if (RA ==
nullptr || DEC ==
nullptr)
129 currentCoord.setRA(RA->value);
130 currentCoord.setDec(DEC->value);
139 if (!strcmp(nvp->name,
"EQUATORIAL_COORD"))
141 INumber *RA = IUFindNumber(nvp,
"RA");
142 INumber *DEC = IUFindNumber(nvp,
"DEC");
144 if (RA ==
nullptr || DEC ==
nullptr)
147 currentCoord.setRA0(RA->value);
148 currentCoord.setDec0(DEC->value);
149 currentCoord.apparentCoord(
static_cast<long double>(J2000),
KStarsLite::Instance()->data()->ut().djd());
158 if (!strcmp(nvp->name,
"HORIZONTAL_COORD"))
160 INumber *Az = IUFindNumber(nvp,
"AZ");
161 INumber *Alt = IUFindNumber(nvp,
"ALT");
163 if (Az ==
nullptr || Alt ==
nullptr)
166 currentCoord.setAz(Az->value);
167 currentCoord.setAlt(Alt->value);
181void TelescopeLite::processSwitch(ISwitchVectorProperty *svp)
199bool TelescopeLite::canGuide()
201 auto raPulse = baseDevice->getNumber(
"TELESCOPE_TIMED_GUIDE_WE");
202 auto decPulse = baseDevice->getNumber(
"TELESCOPE_TIMED_GUIDE_NS");
204 return raPulse && decPulse;
207bool TelescopeLite::canSync()
209 auto motionSP = baseDevice->getSwitch(
"ON_COORD_SET");
214 auto syncSW = motionSP->findWidgetByName(
"SYNC");
216 return (syncSW !=
nullptr);
219bool TelescopeLite::canPark()
221 auto parkSP = baseDevice->getSwitch(
"TELESCOPE_PARK");
226 auto parkSW = parkSP->findWidgetByName(
"PARK");
228 return (parkSW !=
nullptr);
231bool TelescopeLite::isSlewing()
233 auto EqProp = baseDevice->getNumber(
"EQUATORIAL_EOD_COORD");
237 return (EqProp->getState() == IPS_BUSY);
240bool TelescopeLite::isInMotion()
242 bool inMotion =
false;
243 bool inSlew = isSlewing();
245 auto movementSP = baseDevice->getSwitch(
"TELESCOPE_MOTION_NS");
247 inMotion = (movementSP->getState() == IPS_BUSY);
249 movementSP = baseDevice->getSwitch(
"TELESCOPE_MOTION_WE");
251 inMotion = ((movementSP->getState() == IPS_BUSY) || inMotion);
253 return (inSlew || inMotion);
256bool TelescopeLite::sendCoords(
SkyPoint *ScopeTarget)
258 INumber *RAEle =
nullptr;
259 INumber *DecEle =
nullptr;
260 INumber *AzEle =
nullptr;
261 INumber *AltEle =
nullptr;
262 double currentRA = 0, currentDEC = 0, currentAlt = 0, currentAz = 0, targetAlt = 0;
263 bool useJ2000(
false);
265 auto EqProp = baseDevice->getNumber(
"EQUATORIAL_EOD_COORD");
269 EqProp = baseDevice->getNumber(
"EQUATORIAL_COORD");
274 auto HorProp = baseDevice->getNumber(
"HORIZONTAL_COORD");
276 if (EqProp && EqProp->getPermission() == IP_RO)
279 if (HorProp && HorProp->getPermission() == IP_RO)
286 RAEle = IUFindNumber(EqProp,
"RA");
289 DecEle = IUFindNumber(EqProp,
"DEC");
296 currentRA = RAEle->value;
297 currentDEC = DecEle->value;
304 AzEle = IUFindNumber(HorProp,
"AZ");
307 AltEle = IUFindNumber(HorProp,
"ALT");
311 currentAz = AzEle->value;
312 currentAlt = AltEle->value;
316 if (EqProp ==
nullptr && HorProp ==
nullptr)
333 if (ScopeTarget->
dec0().Degrees() == 180.0)
335 ScopeTarget->
setRA0(ScopeTarget->
ra());
338 ra = ScopeTarget->
ra();
339 de = ScopeTarget->
dec();
343 ra = ScopeTarget->
ra0();
344 de = ScopeTarget->
dec0();
349 ra = ScopeTarget->
ra();
350 de = ScopeTarget->
dec();
353 RAEle->value = ra.
Hours();
355 clientManager->sendNewNumber(EqProp);
357 RAEle->value = currentRA;
358 DecEle->value = currentDEC;
363 AzEle->value = ScopeTarget->
az().Degrees();
364 AltEle->value = ScopeTarget->
alt().Degrees();
365 clientManager->sendNewNumber(HorProp);
366 AzEle->value = currentAz;
367 AltEle->value = currentAlt;
373bool TelescopeLite::slew(
double ra,
double dec)
380 return slew(&target);
383bool TelescopeLite::slew(
SkyPoint *ScopeTarget)
385 auto motionSP = baseDevice->getSwitch(
"ON_COORD_SET");
390 auto slewSW = motionSP->findWidgetByName(
"TRACK");
393 slewSW = motionSP->findWidgetByName(
"SLEW");
398 if (slewSW->setState() != ISS_ON)
401 slewSW->setState(ISS_ON);
402 clientManager->sendNewSwitch(motionSP);
404 if (Options::iNDILogging())
405 qDebug() <<
"ISD:Telescope: " << slewSW->getName();
408 return sendCoords(ScopeTarget);
411bool TelescopeLite::sync(
double ra,
double dec)
418 return sync(&target);
421bool TelescopeLite::sync(
SkyPoint *ScopeTarget)
423 auto motionSP = baseDevice->getSwitch(
"ON_COORD_SET");
428 auto syncSW = motionSP->findWidgetByName(
"SYNC");
433 if (syncSW->getState() != ISS_ON)
436 syncSW->setState(ISS_ON);
437 clientManager->sendNewSwitch(motionSP);
439 if (Options::iNDILogging())
440 qDebug() <<
"ISD:Telescope: Syncing...";
443 return sendCoords(ScopeTarget);
446bool TelescopeLite::abort()
448 auto motionSP = baseDevice->getSwitch(
"TELESCOPE_ABORT_MOTION");
453 auto abortSW = motionSP->findWidgetByName(
"ABORT");
458 if (Options::iNDILogging())
459 qDebug() <<
"ISD:Telescope: Aborted." <<
endl;
461 abortSW->setState(ISS_ON);
462 clientManager->sendNewSwitch(motionSP);
467bool TelescopeLite::park()
469 auto parkSP = baseDevice->getSwitch(
"TELESCOPE_PARK");
474 auto parkSW = parkSP->findWidgetByName(
"PARK");
479 if (Options::iNDILogging())
480 qDebug() <<
"ISD:Telescope: Parking..." <<
endl;
483 parkSW->setState(ISS_ON);
484 clientManager->sendNewSwitch(parkSP);
489bool TelescopeLite::unPark()
491 auto parkSP = baseDevice->getSwitch(
"TELESCOPE_PARK");
496 auto parkSW = parkSP->findWidgetByName(
"UNPARK");
501 if (Options::iNDILogging())
502 qDebug() <<
"ISD:Telescope: UnParking..." <<
endl;
505 parkSW->setState(ISS_ON);
506 clientManager->sendNewSwitch(parkSP);
511bool TelescopeLite::getEqCoords(
double *ra,
double *dec)
513 auto EqProp = baseDevice->getNumber(
"EQUATORIAL_EOD_COORD");
518 auto RAEle = EqProp->findWidgetByName(
"RA");
522 auto DecEle = EqProp->findWidgetByName(
"DEC");
526 *ra = RAEle->getValue();
527 *
dec = DecEle->getValue();
532bool TelescopeLite::moveNS(TelescopeMotionNS dir, TelescopeMotionCommand cmd)
534 auto motionSP = baseDevice->getSwitch(
"TELESCOPE_MOTION_NS");
539 auto motionNorth = motionSP->findWidgetByName(
"MOTION_NORTH");
540 auto motionSouth = motionSP->findWidgetByName(
"MOTION_SOUTH");
542 if (!motionNorth || !motionSouth)
546 if (dir == MOTION_NORTH && motionNorth->getState() == ((cmd == MOTION_START) ? ISS_ON : ISS_OFF))
549 if (dir == MOTION_SOUTH && motionSouth->getState() == ((cmd == MOTION_START) ? ISS_ON : ISS_OFF))
554 if (cmd == MOTION_START)
556 if (dir == MOTION_NORTH)
557 motionNorth->setState(ISS_ON);
559 motionSouth->setState(ISS_ON);
562 if (cmd == MOTION_STOP)
564 if (dir == MOTION_NORTH)
565 motionNorth->setState(ISS_OFF);
567 motionSouth->setState(ISS_OFF);
570 clientManager->sendNewSwitch(motionSP);
575bool TelescopeLite::moveWE(TelescopeMotionWE dir, TelescopeMotionCommand cmd)
577 auto motionSP = baseDevice->getSwitch(
"TELESCOPE_MOTION_WE");
579 if (motionSP ==
nullptr)
582 auto motionWest = motionSP->findWidgetByName(
"MOTION_WEST");
583 auto motionEast = motionSP->findWidgetByName(
"MOTION_EAST");
585 if (motionWest ==
nullptr || motionEast ==
nullptr)
589 if (dir == MOTION_WEST && motionWest->getState() == ((cmd == MOTION_START) ? ISS_ON : ISS_OFF))
592 if (dir == MOTION_EAST && motionEast->getState() == ((cmd == MOTION_START) ? ISS_ON : ISS_OFF))
595 IUResetSwitch(motionSP);
597 if (cmd == MOTION_START)
599 if (dir == MOTION_WEST)
600 motionWest->setState(ISS_ON);
602 motionEast->setState(ISS_ON);
605 if (cmd == MOTION_STOP)
607 if (dir == MOTION_WEST)
608 motionWest->setState(ISS_OFF);
610 motionEast->setState(ISS_OFF);
613 clientManager->sendNewSwitch(motionSP);
618bool TelescopeLite::setSlewRate(
int index)
620 auto slewRateSP = baseDevice->getSwitch(
"TELESCOPE_SLEW_RATE");
622 if (slewRateSP ==
nullptr)
625 int maxSlewRate = slewRateSP->count();
631 else if (index >= maxSlewRate)
633 index = maxSlewRate - 1;
636 if (slewRateSP->at(index)->getState() != ISS_ON || index != slewRateIndex)
640 slewRateSP->at(index)->setState(ISS_ON);
642 slewRateIndex = index;
643 setSlewRateLabel(slewRateSP->at(index)->getLabel());
644 setSlewDecreasable(index != 0);
645 setSlewIncreasable(index != maxSlewRate - 1);
647 clientManager->sendNewSwitch(slewRateSP);
653bool TelescopeLite::decreaseSlewRate()
655 return setSlewRate(slewRateIndex - 1);
658bool TelescopeLite::increaseSlewRate()
660 return setSlewRate(slewRateIndex + 1);
663void TelescopeLite::setAltLimits(
double minAltitude,
double maxAltitude)
665 minAlt = minAltitude;
666 maxAlt = maxAltitude;
669bool TelescopeLite::isParked()
This class loads QML files and connects SkyMapLite and KStarsData Unlike KStars class it is not a mai...
static KStarsLite * Instance()
The sky coordinates of a point in the sky.
void apparentCoord(long double jd0, long double jdf)
Computes the apparent coordinates for this SkyPoint for any epoch, accounting for the effects of prec...
const CachingDms & dec() const
const CachingDms & ra0() const
void setDec(dms d)
Sets Dec, the current Declination.
void setRA(dms &r)
Sets RA, the current Right Ascension.
const CachingDms & ra() const
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
void setRA0(dms r)
Sets RA0, the catalog Right Ascension.
const CachingDms & dec0() const
void setDec0(dms d)
Sets Dec0, the catalog Declination.
An angle, stored as degrees, but expressible in many ways.
const double & Degrees() const
GeoCoordinates geo(const QVariant &location)
void push_back(parameter_type value)
qsizetype size() const const
QTextStream & dec(QTextStream &stream)
QTextStream & endl(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)