File indexing completed on 2024-07-21 06:28:21

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <QTimer>
0011 
0012 #include "indiconcretedevice.h"
0013 
0014 namespace ISD
0015 {
0016 /**
0017  * @class Dome
0018  * Class handles control of INDI dome devices. Both open and closed loop (sensor feedback) domes are supported.
0019  *
0020  * @author Jasem Mutlaq
0021  */
0022 class Dome : public ConcreteDevice
0023 {
0024         Q_OBJECT
0025         Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI.Dome")
0026         Q_PROPERTY(bool canPark READ canPark)
0027         Q_PROPERTY(bool canAbsoluteMove READ canAbsoluteMove)
0028         Q_PROPERTY(bool canRelativeMove READ canRelativeMove)
0029         Q_PROPERTY(bool canAbort READ canAbort)
0030         Q_PROPERTY(bool isMoving READ isMoving)
0031         Q_PROPERTY(ISD::Dome::Status status READ status NOTIFY newStatus)
0032         Q_PROPERTY(ISD::Dome::ShutterStatus shutterStatus READ shutterStatus NOTIFY newShutterStatus)
0033         Q_PROPERTY(ISD::ParkStatus parkStatus READ parkStatus NOTIFY newParkStatus)
0034         Q_PROPERTY(double position READ position WRITE setPosition NOTIFY positionChanged)
0035 
0036     public:
0037         explicit Dome(GenericDevice *parent);
0038 
0039         // DBUS
0040         const QString &name()
0041         {
0042             return m_Parent->getDeviceName();
0043         }
0044         // DBus
0045         bool connected()
0046         {
0047             return m_Parent->isConnected();
0048         }
0049 
0050         typedef enum
0051         {
0052             DOME_IDLE,
0053             DOME_MOVING_CW,
0054             DOME_MOVING_CCW,
0055             DOME_TRACKING,
0056             DOME_PARKING,
0057             DOME_UNPARKING,
0058             DOME_PARKED,
0059             DOME_ERROR
0060         } Status;
0061 
0062         typedef enum
0063         {
0064             SHUTTER_UNKNOWN,
0065             SHUTTER_OPEN,
0066             SHUTTER_CLOSED,
0067             SHUTTER_OPENING,
0068             SHUTTER_CLOSING,
0069             SHUTTER_ERROR
0070         } ShutterStatus;
0071 
0072         typedef enum
0073         {
0074             DOME_CW,
0075             DOME_CCW
0076         } DomeDirection;
0077 
0078         typedef enum
0079         {
0080             MOTION_START,
0081             MOTION_STOP
0082         } DomeMotionCommand;
0083 
0084 
0085         void processSwitch(INDI::Property prop) override;
0086         void processNumber(INDI::Property prop) override;
0087         void registerProperty(INDI::Property prop) override;
0088 
0089         Q_SCRIPTABLE bool canPark() const
0090         {
0091             return m_CanPark;
0092         }
0093         Q_SCRIPTABLE bool canAbsoluteMove() const
0094         {
0095             return m_CanAbsMove;
0096         }
0097         Q_SCRIPTABLE bool canRelativeMove() const
0098         {
0099             return m_CanRelMove;
0100         }
0101         Q_SCRIPTABLE bool canAbort() const
0102         {
0103             return m_CanAbort;
0104         }
0105         Q_SCRIPTABLE bool isParked() const
0106         {
0107             return m_ParkStatus == PARK_PARKED;
0108         }
0109         bool isMoving() const;
0110 
0111         /**
0112          * @return position Dome Azimuth position in degrees
0113          */
0114         Q_SCRIPTABLE double position() const;
0115         /**
0116          * @brief setPosition Set azimuth absolute position.
0117          * @param position Position in degrees 0 to +360
0118          * @return true if successful, false otherwise
0119          */
0120         Q_SCRIPTABLE bool setPosition(double position);
0121 
0122         bool setRelativePosition(double position);
0123 
0124         bool moveDome(DomeDirection dir, DomeMotionCommand operation);
0125 
0126         /** DBus Interface Function
0127          * @brief moveCW Start motion in clock-wise direction.
0128          * @return True if command is successful, false otherwise.
0129          */
0130         Q_SCRIPTABLE bool moveCW()
0131         {
0132             return moveDome(DOME_CW, MOTION_START);
0133         }
0134 
0135         /** DBus Interface Function
0136          * @brief moveCCW Start motion in counter-clock-wise direction.
0137          * @return True if command is successful, false otherwise.
0138          */
0139         Q_SCRIPTABLE bool moveCCW()
0140         {
0141             return moveDome(DOME_CCW, MOTION_START);
0142         }
0143 
0144         Q_SCRIPTABLE bool hasShutter() const
0145         {
0146             return m_HasShutter;
0147         }
0148 
0149         /**
0150          * @brief isRolloffRoof Do we have a roll off structure?
0151          * @return True if we do, false otherwise.
0152          */
0153         bool isRolloffRoof()
0154         {
0155             return (canAbsoluteMove() == false && canRelativeMove() == false);
0156         }
0157 
0158         // slaving
0159         bool isAutoSync();
0160         bool setAutoSync(bool activate);
0161 
0162         Status status() const
0163         {
0164             return m_Status;
0165         }
0166         ISD::ParkStatus parkStatus() const
0167         {
0168             return m_ParkStatus;
0169         }
0170         static const QString getStatusString (Status status, bool translated = true);
0171 
0172         ShutterStatus shutterStatus();
0173         ShutterStatus parseShutterStatus(INDI::Property prop);
0174 
0175         Q_SCRIPTABLE bool abort();
0176         Q_SCRIPTABLE bool park();
0177         Q_SCRIPTABLE bool unpark();
0178 
0179         Q_SCRIPTABLE bool controlShutter(bool open);
0180         bool openShutter()
0181         {
0182             return controlShutter(true);
0183         }
0184         bool closeShutter()
0185         {
0186             return controlShutter(false);
0187         }
0188 
0189     signals:
0190         void newStatus(ISD::Dome::Status status);
0191         void newParkStatus(ISD::ParkStatus status);
0192         void newShutterStatus(ISD::Dome::ShutterStatus status);
0193         void newAutoSyncStatus(bool enabled);
0194         void positionChanged(double degrees);
0195 
0196     private:
0197         ParkStatus m_ParkStatus { PARK_UNKNOWN };
0198         ShutterStatus m_ShutterStatus { SHUTTER_UNKNOWN };
0199         Status m_Status { DOME_IDLE };
0200         bool m_CanAbsMove { false };
0201         bool m_CanRelMove { false };
0202         bool m_CanPark { false };
0203         bool m_CanAbort { false };
0204         bool m_HasShutter { false };
0205         static const QList<const char *> domeStates;
0206 };
0207 }
0208 
0209 Q_DECLARE_METATYPE(ISD::Dome::Status)
0210 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::Dome::Status &source);
0211 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::Dome::Status &dest);
0212 
0213 Q_DECLARE_METATYPE(ISD::Dome::ShutterStatus)
0214 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::Dome::ShutterStatus &source);
0215 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::Dome::ShutterStatus &dest);