8#include <KActionCollection>
9#include <KNotification>
11#include <QtDBus/qdbusmetatype.h>
15#include "domeadaptor.h"
16#include "ksnotification.h"
21const QList<KLocalizedString> Dome::domeStates = {
ki18n(
"Idle"),
ki18n(
"Moving clockwise"),
ki18n(
"Moving counter clockwise"),
28 qRegisterMetaType<ISD::Dome::Status>(
"ISD::Dome::Status");
29 qDBusRegisterMetaType<ISD::Dome::Status>();
31 qRegisterMetaType<ISD::Dome::ShutterStatus>(
"ISD::Dome::ShutterStatus");
32 qDBusRegisterMetaType<ISD::Dome::ShutterStatus>();
34 new DomeAdaptor(
this);
35 m_DBusObjectPath =
QString(
"/KStars/INDI/Dome/%1").
arg(getID());
39void Dome::registerProperty(INDI::Property prop)
41 if (!prop.getRegistered())
44 if (prop.isNameMatch(
"ABS_DOME_POSITION"))
48 else if (prop.isNameMatch(
"REL_DOME_POSITION"))
52 else if (prop.isNameMatch(
"DOME_ABORT_MOTION"))
56 else if (prop.isNameMatch(
"DOME_PARK"))
60 else if (prop.isNameMatch(
"DOME_SHUTTER"))
65 ConcreteDevice::registerProperty(prop);
68void Dome::processNumber(INDI::Property prop)
70 auto nvp = prop.getNumber();
71 if (nvp->isNameMatch(
"ABS_DOME_POSITION"))
73 emit positionChanged(nvp->at(0)->getValue());
77void Dome::processSwitch(INDI::Property prop)
79 auto svp = prop.getSwitch();
80 if (svp->isNameMatch(
"CONNECTION"))
82 auto conSP = svp->findWidgetByName(
"CONNECT");
85 if (conSP->getState() == ISS_ON)
96 else if (svp->isNameMatch(
"DOME_PARK"))
100 auto sp = svp->findWidgetByName(
"PARK");
103 if (svp->getState() == IPS_ALERT)
105 m_ParkStatus = PARK_ERROR;
106 emit newParkStatus(PARK_ERROR);
118 else if (svp->getState() == IPS_BUSY && sp->getState() == ISS_ON && m_ParkStatus != PARK_PARKING)
120 m_ParkStatus = PARK_PARKING;
121 KSNotification::event(
QLatin1String(
"DomeParking"),
i18n(
"Dome parking is in progress"), KSNotification::Observatory,
122 KSNotification::Info);
123 emit newParkStatus(m_ParkStatus);
125 if (m_Status != DOME_PARKING)
127 m_Status = DOME_PARKING;
128 emit newStatus(m_Status);
131 else if (svp->getState() == IPS_BUSY && sp->getState() == ISS_OFF && m_ParkStatus != PARK_UNPARKING)
133 m_ParkStatus = PARK_UNPARKING;
134 KSNotification::event(
QLatin1String(
"DomeUnparking"),
i18n(
"Dome unparking is in progress"), KSNotification::Observatory,
135 KSNotification::Info);
136 emit newParkStatus(m_ParkStatus);
138 if (m_Status != DOME_UNPARKING)
140 m_Status = DOME_UNPARKING;
141 emit newStatus(m_Status);
144 else if (svp->getState() == IPS_OK && sp->getState() == ISS_ON && m_ParkStatus != PARK_PARKED)
146 m_ParkStatus = PARK_PARKED;
147 KSNotification::event(
QLatin1String(
"DomeParked"),
i18n(
"Dome parked"), KSNotification::Observatory,
148 KSNotification::Info);
149 emit newParkStatus(m_ParkStatus);
158 if (m_Status != DOME_PARKED)
160 m_Status = DOME_PARKED;
161 emit newStatus(m_Status);
165 else if ( (svp->getState() == IPS_OK || svp->getState() == IPS_IDLE) && sp->s == ISS_OFF && m_ParkStatus != PARK_UNPARKED)
167 m_ParkStatus = PARK_UNPARKED;
168 KSNotification::event(
QLatin1String(
"DomeUnparked"),
i18n(
"Dome unparked"), KSNotification::Observatory,
169 KSNotification::Info);
178 emit newParkStatus(m_ParkStatus);
180 if (m_Status != DOME_IDLE)
182 m_Status = DOME_IDLE;
183 emit newStatus(m_Status);
188 else if (svp->isNameMatch(
"DOME_MOTION"))
190 Status lastStatus = m_Status;
192 if (svp->getState() == IPS_BUSY && lastStatus != DOME_MOVING_CW && lastStatus != DOME_MOVING_CCW
193 && lastStatus != DOME_PARKING
194 && lastStatus != DOME_UNPARKING)
196 m_Status = svp->at(0)->getState() == ISS_ON ? DOME_MOVING_CW : DOME_MOVING_CCW;
197 emit newStatus(m_Status);
200 if (!canAbsoluteMove() && !canRelativeMove())
202 m_ParkStatus = (m_Status == DOME_MOVING_CW) ? PARK_UNPARKING : PARK_PARKING;
203 emit newParkStatus(m_ParkStatus);
206 else if (svp->getState() == IPS_OK && (lastStatus == DOME_MOVING_CW || lastStatus == DOME_MOVING_CCW))
208 m_Status = DOME_TRACKING;
209 emit newStatus(m_Status);
211 else if (svp->getState() == IPS_IDLE && lastStatus != DOME_IDLE)
213 m_Status = DOME_IDLE;
214 emit newStatus(m_Status);
216 else if (svp->getState() == IPS_ALERT)
218 m_Status = DOME_ERROR;
219 emit newStatus(m_Status);
222 else if (svp->isNameMatch(
"DOME_SHUTTER"))
224 if (svp->getState() == IPS_ALERT)
226 emit newShutterStatus(SHUTTER_ERROR);
230 if (m_ShutterStatus == SHUTTER_CLOSING)
231 m_ShutterStatus = SHUTTER_OPEN;
233 m_ShutterStatus = SHUTTER_CLOSED;
235 emit newShutterStatus(m_ShutterStatus);
238 ShutterStatus
status = parseShutterStatus(prop);
242 case SHUTTER_CLOSING:
243 if (m_ShutterStatus != SHUTTER_CLOSING)
245 m_ShutterStatus = SHUTTER_CLOSING;
246 KSNotification::event(
QLatin1String(
"ShutterClosing"),
i18n(
"Shutter closing is in progress"), KSNotification::Observatory,
247 KSNotification::Info);
248 emit newShutterStatus(m_ShutterStatus);
251 case SHUTTER_OPENING:
252 if (m_ShutterStatus != SHUTTER_OPENING)
254 m_ShutterStatus = SHUTTER_OPENING;
255 KSNotification::event(
QLatin1String(
"ShutterOpening"),
i18n(
"Shutter opening is in progress"), KSNotification::Observatory,
256 KSNotification::Info);
257 emit newShutterStatus(m_ShutterStatus);
261 if (m_ShutterStatus != SHUTTER_CLOSED)
263 m_ShutterStatus = SHUTTER_CLOSED;
264 KSNotification::event(
QLatin1String(
"ShutterClosed"),
i18n(
"Shutter closed"), KSNotification::Observatory,
265 KSNotification::Info);
266 emit newShutterStatus(m_ShutterStatus);
270 if (m_ShutterStatus != SHUTTER_OPEN)
272 m_ShutterStatus = SHUTTER_OPEN;
273 KSNotification::event(
QLatin1String(
"ShutterOpened"),
i18n(
"Shutter opened"), KSNotification::Observatory,
274 KSNotification::Info);
275 emit newShutterStatus(m_ShutterStatus);
285 else if (svp->isNameMatch(
"DOME_AUTOSYNC"))
287 auto sp = svp->findWidgetByName(
"DOME_AUTOSYNC_ENABLE");
289 emit newAutoSyncStatus(sp->s == ISS_ON);
295 if (m_CanAbort ==
false)
298 auto motionSP = getSwitch(
"DOME_ABORT_MOTION");
303 auto abortSW = motionSP->findWidgetByName(
"ABORT");
308 abortSW->setState(ISS_ON);
309 sendNewProperty(motionSP);
316 auto parkSP = getSwitch(
"DOME_PARK");
321 auto parkSW = parkSP->findWidgetByName(
"PARK");
327 parkSW->setState(ISS_ON);
328 sendNewProperty(parkSP);
335 auto parkSP = getSwitch(
"DOME_PARK");
340 auto parkSW = parkSP->findWidgetByName(
"UNPARK");
346 parkSW->setState(ISS_ON);
347 sendNewProperty(parkSP);
352bool Dome::isMoving()
const
354 auto motionSP = getSwitch(
"DOME_MOTION");
356 if (motionSP && motionSP->getState() == IPS_BUSY)
362double Dome::position()
const
364 auto az = getNumber(
"ABS_DOME_POSITION");
369 return az->at(0)->getValue();
374 auto az = getNumber(
"ABS_DOME_POSITION");
379 az->at(0)->setValue(position);
384bool Dome::setRelativePosition(
double position)
386 auto azDiff = getNumber(
"REL_DOME_POSITION");
390 azDiff->at(0)->setValue(position);
391 sendNewProperty(azDiff);
395bool Dome::isAutoSync()
397 auto autosync = getSwitch(
"DOME_AUTOSYNC");
401 auto autosyncSW = autosync->findWidgetByName(
"DOME_AUTOSYNC_ENABLE");
405 return (autosyncSW->s == ISS_ON);
408bool Dome::setAutoSync(
bool activate)
410 auto autosync = getSwitch(
"DOME_AUTOSYNC");
414 auto autosyncSW = autosync->findWidgetByName(activate ?
"DOME_AUTOSYNC_ENABLE" :
"DOME_AUTOSYNC_DISABLE");
419 autosyncSW->setState(ISS_ON);
420 sendNewProperty(autosync);
425bool Dome::moveDome(DomeDirection dir, DomeMotionCommand operation)
427 auto domeMotion = getSwitch(
"DOME_MOTION");
431 auto opSwitch = domeMotion->findWidgetByName(dir == DomeDirection::DOME_CW ?
"DOME_CW" :
"DOME_CCW");
436 opSwitch->setState(operation == DomeMotionCommand::MOTION_START ? ISS_ON : ISS_OFF);
437 sendNewProperty(domeMotion);
441bool Dome::controlShutter(
bool open)
443 auto shutterSP = getSwitch(
"DOME_SHUTTER");
447 auto shutterSW = shutterSP->findWidgetByName(open ?
"SHUTTER_OPEN" :
"SHUTTER_CLOSE");
452 shutterSW->setState(ISS_ON);
453 sendNewProperty(shutterSP);
458Dome::ShutterStatus Dome::shutterStatus()
460 auto shutterSP = getSwitch(
"DOME_SHUTTER");
462 return parseShutterStatus(shutterSP);
465Dome::ShutterStatus Dome::parseShutterStatus(INDI::Property prop)
467 if (prop.isValid() ==
false)
468 return SHUTTER_UNKNOWN;
470 auto svp = prop.getSwitch();
472 auto sp = svp->findWidgetByName(
"SHUTTER_OPEN");
474 return SHUTTER_UNKNOWN;
476 if (svp->getState() == IPS_ALERT)
477 return SHUTTER_ERROR;
478 else if (svp->getState() == IPS_BUSY)
479 return (sp->s == ISS_ON) ? SHUTTER_OPENING : SHUTTER_CLOSING;
480 else if (svp->getState() == IPS_OK)
481 return (sp->s == ISS_ON) ? SHUTTER_OPEN : SHUTTER_CLOSED;
484 return SHUTTER_UNKNOWN;
487const QString Dome::getStatusString(Dome::Status status,
bool translated)
489 return translated ? domeStates[
status].toString() : domeStates[
status].untranslatedText();
497 argument << static_cast<int>(source);
508 dest =
static_cast<ISD::Dome::Status
>(a);
515 argument << static_cast<int>(source);
526 dest =
static_cast<ISD::Dome::ShutterStatus
>(a);
532 auto nvp = getNumber(
"DOME_MEASUREMENTS");
535 auto radius = nvp->findWidgetByName(
"DM_DOME_RADIUS");
537 return radius->getValue();
544 auto nvp = getNumber(
"DOME_MEASUREMENTS");
547 auto width = nvp->findWidgetByName(
"DM_SHUTTER_WIDTH");
549 return width->getValue();
556 auto nvp = getNumber(
"DOME_MEASUREMENTS");
559 auto north = nvp->findWidgetByName(
"DM_NORTH_DISPLACEMENT");
561 return north->getValue();
568 auto nvp = getNumber(
"DOME_MEASUREMENTS");
571 auto east = nvp->findWidgetByName(
"DM_EAST_DISPLACEMENT");
573 return east->getValue();
580 auto nvp = getNumber(
"DOME_MEASUREMENTS");
583 auto up = nvp->findWidgetByName(
"DM_UP_DISPLACEMENT");
585 return up->getValue();
592 auto nvp = getNumber(
"DOME_MEASUREMENTS");
595 auto ota = nvp->findWidgetByName(
"DM_OTA_OFFSET");
597 return ota->getValue();
The ConcreteDevice class.
void sendNewProperty(INDI::Property prop)
Send new property command to server.
double getNorthDisplacement() const
getNorthDisplacement Get the north displacement in meters
double getDomeRadius() const
getDomeRadius Get the dome radius in meters
Q_SCRIPTABLE bool setPosition(double position)
setPosition Set azimuth absolute position.
double getOTAOffset() const
getOTAOffset Get the OTA offset in meters
double getShutterWidth() const
getShutterWidth Get the shutter width in meters
double getEastDisplacement() const
getEastDisplacement Get the east displacement in meters
double getUpDisplacement() const
getUpDisplacement Get the up displacement in meters
GenericDevice is the Generic Device for INDI devices.
Q_INVOKABLE QAction * action(const QString &name) const
static KStars * Instance()
void slotSetDomeEnabled(bool enable)
slotSetDomeEnabled call when dome comes online or goes offline.
virtual KActionCollection * actionCollection() const
KLocalizedString KI18N_EXPORT ki18n(const char *text)
QString i18n(const char *text, const TYPE &arg...)
ISD is a collection of INDI Standard Devices.
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
QString arg(Args &&... args) const const