8#include <KActionCollection>
9#include <KNotification>
11#include <QtDBus/qdbusmetatype.h>
15#include "domeadaptor.h"
25Dome::Dome(GenericDevice *parent) : ConcreteDevice(parent)
27 qRegisterMetaType<ISD::Dome::Status>(
"ISD::Dome::Status");
28 qDBusRegisterMetaType<ISD::Dome::Status>();
30 qRegisterMetaType<ISD::Dome::ShutterStatus>(
"ISD::Dome::ShutterStatus");
31 qDBusRegisterMetaType<ISD::Dome::ShutterStatus>();
33 new DomeAdaptor(
this);
34 m_DBusObjectPath =
QString(
"/KStars/INDI/Dome/%1").
arg(getID());
38void Dome::registerProperty(INDI::Property prop)
40 if (!prop.getRegistered())
43 if (prop.isNameMatch(
"ABS_DOME_POSITION"))
47 else if (prop.isNameMatch(
"REL_DOME_POSITION"))
51 else if (prop.isNameMatch(
"DOME_ABORT_MOTION"))
55 else if (prop.isNameMatch(
"DOME_PARK"))
59 else if (prop.isNameMatch(
"DOME_SHUTTER"))
64 ConcreteDevice::registerProperty(prop);
67void Dome::processNumber(INDI::Property prop)
69 auto nvp = prop.getNumber();
70 if (nvp->isNameMatch(
"ABS_DOME_POSITION"))
72 emit positionChanged(nvp->at(0)->getValue());
76void Dome::processSwitch(INDI::Property prop)
78 auto svp = prop.getSwitch();
79 if (svp->isNameMatch(
"CONNECTION"))
81 auto conSP = svp->findWidgetByName(
"CONNECT");
84 if (conSP->getState() == ISS_ON)
95 else if (svp->isNameMatch(
"DOME_PARK"))
99 auto sp = svp->findWidgetByName(
"PARK");
102 if (svp->getState() == IPS_ALERT)
104 m_ParkStatus = PARK_ERROR;
105 emit newParkStatus(PARK_ERROR);
117 else if (svp->getState() == IPS_BUSY && sp->getState() == ISS_ON && m_ParkStatus != PARK_PARKING)
119 m_ParkStatus = PARK_PARKING;
121 emit newParkStatus(m_ParkStatus);
123 if (m_Status != DOME_PARKING)
125 m_Status = DOME_PARKING;
126 emit newStatus(m_Status);
129 else if (svp->getState() == IPS_BUSY && sp->getState() == ISS_OFF && m_ParkStatus != PARK_UNPARKING)
131 m_ParkStatus = PARK_UNPARKING;
133 emit newParkStatus(m_ParkStatus);
135 if (m_Status != DOME_UNPARKING)
137 m_Status = DOME_UNPARKING;
138 emit newStatus(m_Status);
141 else if (svp->getState() == IPS_OK && sp->getState() == ISS_ON && m_ParkStatus != PARK_PARKED)
143 m_ParkStatus = PARK_PARKED;
145 emit newParkStatus(m_ParkStatus);
154 if (m_Status != DOME_PARKED)
156 m_Status = DOME_PARKED;
157 emit newStatus(m_Status);
161 else if ( (svp->getState() == IPS_OK || svp->getState() == IPS_IDLE) && sp->s == ISS_OFF && m_ParkStatus != PARK_UNPARKED)
163 m_ParkStatus = PARK_UNPARKED;
173 emit newParkStatus(m_ParkStatus);
175 if (m_Status != DOME_IDLE)
177 m_Status = DOME_IDLE;
178 emit newStatus(m_Status);
183 else if (svp->isNameMatch(
"DOME_MOTION"))
185 Status lastStatus = m_Status;
187 if (svp->getState() == IPS_BUSY && lastStatus != DOME_MOVING_CW && lastStatus != DOME_MOVING_CCW
188 && lastStatus != DOME_PARKING
189 && lastStatus != DOME_UNPARKING)
191 m_Status = svp->at(0)->getState() == ISS_ON ? DOME_MOVING_CW : DOME_MOVING_CCW;
192 emit newStatus(m_Status);
195 if (!canAbsoluteMove() && !canRelativeMove())
197 m_ParkStatus = (m_Status == DOME_MOVING_CW) ? PARK_UNPARKING : PARK_PARKING;
198 emit newParkStatus(m_ParkStatus);
201 else if (svp->getState() == IPS_OK && (lastStatus == DOME_MOVING_CW || lastStatus == DOME_MOVING_CCW))
203 m_Status = DOME_TRACKING;
204 emit newStatus(m_Status);
206 else if (svp->getState() == IPS_IDLE && lastStatus != DOME_IDLE)
208 m_Status = DOME_IDLE;
209 emit newStatus(m_Status);
211 else if (svp->getState() == IPS_ALERT)
213 m_Status = DOME_ERROR;
214 emit newStatus(m_Status);
217 else if (svp->isNameMatch(
"DOME_SHUTTER"))
219 if (svp->getState() == IPS_ALERT)
221 emit newShutterStatus(SHUTTER_ERROR);
225 if (m_ShutterStatus == SHUTTER_CLOSING)
226 m_ShutterStatus = SHUTTER_OPEN;
228 m_ShutterStatus = SHUTTER_CLOSED;
230 emit newShutterStatus(m_ShutterStatus);
233 ShutterStatus
status = parseShutterStatus(prop);
237 case SHUTTER_CLOSING:
238 if (m_ShutterStatus != SHUTTER_CLOSING)
240 m_ShutterStatus = SHUTTER_CLOSING;
242 emit newShutterStatus(m_ShutterStatus);
245 case SHUTTER_OPENING:
246 if (m_ShutterStatus != SHUTTER_OPENING)
248 m_ShutterStatus = SHUTTER_OPENING;
250 emit newShutterStatus(m_ShutterStatus);
254 if (m_ShutterStatus != SHUTTER_CLOSED)
256 m_ShutterStatus = SHUTTER_CLOSED;
258 emit newShutterStatus(m_ShutterStatus);
262 if (m_ShutterStatus != SHUTTER_OPEN)
264 m_ShutterStatus = SHUTTER_OPEN;
266 emit newShutterStatus(m_ShutterStatus);
276 else if (svp->isNameMatch(
"DOME_AUTOSYNC"))
278 auto sp = svp->findWidgetByName(
"DOME_AUTOSYNC_ENABLE");
280 emit newAutoSyncStatus(sp->s == ISS_ON);
286 if (m_CanAbort ==
false)
289 auto motionSP = getSwitch(
"DOME_ABORT_MOTION");
294 auto abortSW = motionSP->findWidgetByName(
"ABORT");
299 abortSW->setState(ISS_ON);
300 sendNewProperty(motionSP);
307 auto parkSP = getSwitch(
"DOME_PARK");
312 auto parkSW = parkSP->findWidgetByName(
"PARK");
318 parkSW->setState(ISS_ON);
319 sendNewProperty(parkSP);
326 auto parkSP = getSwitch(
"DOME_PARK");
331 auto parkSW = parkSP->findWidgetByName(
"UNPARK");
337 parkSW->setState(ISS_ON);
338 sendNewProperty(parkSP);
343bool Dome::isMoving()
const
345 auto motionSP = getSwitch(
"DOME_MOTION");
347 if (motionSP && motionSP->getState() == IPS_BUSY)
353double Dome::position()
const
355 auto az = getNumber(
"ABS_DOME_POSITION");
360 return az->at(0)->getValue();
363bool Dome::setPosition(
double position)
365 auto az = getNumber(
"ABS_DOME_POSITION");
370 az->at(0)->setValue(position);
375bool Dome::setRelativePosition(
double position)
377 auto azDiff = getNumber(
"REL_DOME_POSITION");
381 azDiff->at(0)->setValue(position);
382 sendNewProperty(azDiff);
386bool Dome::isAutoSync()
388 auto autosync = getSwitch(
"DOME_AUTOSYNC");
392 auto autosyncSW = autosync->findWidgetByName(
"DOME_AUTOSYNC_ENABLE");
396 return (autosyncSW->s == ISS_ON);
399bool Dome::setAutoSync(
bool activate)
401 auto autosync = getSwitch(
"DOME_AUTOSYNC");
405 auto autosyncSW = autosync->findWidgetByName(activate ?
"DOME_AUTOSYNC_ENABLE" :
"DOME_AUTOSYNC_DISABLE");
410 autosyncSW->setState(ISS_ON);
411 sendNewProperty(autosync);
416bool Dome::moveDome(DomeDirection dir, DomeMotionCommand operation)
418 auto domeMotion = getSwitch(
"DOME_MOTION");
422 auto opSwitch = domeMotion->findWidgetByName(dir == DomeDirection::DOME_CW ?
"DOME_CW" :
"DOME_CCW");
427 opSwitch->setState(operation == DomeMotionCommand::MOTION_START ? ISS_ON : ISS_OFF);
428 sendNewProperty(domeMotion);
432bool Dome::controlShutter(
bool open)
434 auto shutterSP = getSwitch(
"DOME_SHUTTER");
438 auto shutterSW = shutterSP->findWidgetByName(open ?
"SHUTTER_OPEN" :
"SHUTTER_CLOSE");
443 shutterSW->setState(ISS_ON);
444 sendNewProperty(shutterSP);
449Dome::ShutterStatus Dome::shutterStatus()
451 auto shutterSP = getSwitch(
"DOME_SHUTTER");
453 return parseShutterStatus(shutterSP);
456Dome::ShutterStatus Dome::parseShutterStatus(INDI::Property prop)
458 if (prop.isValid() ==
false)
459 return SHUTTER_UNKNOWN;
461 auto svp = prop.getSwitch();
463 auto sp = svp->findWidgetByName(
"SHUTTER_OPEN");
465 return SHUTTER_UNKNOWN;
467 if (svp->getState() == IPS_ALERT)
468 return SHUTTER_ERROR;
469 else if (svp->getState() == IPS_BUSY)
470 return (sp->s == ISS_ON) ? SHUTTER_OPENING : SHUTTER_CLOSING;
471 else if (svp->getState() == IPS_OK)
472 return (sp->s == ISS_ON) ? SHUTTER_OPEN : SHUTTER_CLOSED;
475 return SHUTTER_UNKNOWN;
478const QString Dome::getStatusString(Dome::Status status,
bool translated)
480 return translated ? domeStates[
status].toString() : domeStates[
status].untranslatedText();
488 argument << static_cast<int>(source);
499 dest =
static_cast<ISD::Dome::Status
>(a);
506 argument << static_cast<int>(source);
517 dest =
static_cast<ISD::Dome::ShutterStatus
>(a);
Q_INVOKABLE QAction * action(const QString &name) const
static KNotification * event(const QString &eventId, const QString &text=QString(), const QPixmap &pixmap=QPixmap(), const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
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.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
QString arg(Args &&... args) const const